FAQ
Hi All,

I'm new newbie in GO. I inspected a simpel hello world program running on
Mac and found that there are two threads for that process. I'm so confused
since I didn't use goroutine or something like that. Below is the code and
the running info. I tried to google something about this but helpless. Your
explanation is appreciated.

helloGo.go

package main

import "fmt"

func main() {
fmt.Printf("hello, world\n")
for {

}
}


PID COMMAND %CPU TIME #TH #WQ #POR #MREG RPRVT RSHRD RSIZE
22849 top 8.3 00:01.39 1/1 0 24 31 1128K 216K 1876K
22846 bash 0.0 00:00.00 1 0 21 26 400K 756K 1236K
22845 login 0.0 00:00.03 2 1 33 67 976K 276K 4644K
22844 helloGo 100.4 00:22.13 2/1 0 5 156 464K 212K 1116K

Thanks,
Joe

--

Search Discussions

  • Minux at Oct 14, 2012 at 4:43 am
    the other thread is for GC (actually the scavenger who
    tries to return unused memory back to OS).
    On Oct 14, 2012 12:39 PM, "Joe" wrote:

    Hi All,

    I'm new newbie in GO. I inspected a simpel hello world program running on
    Mac and found that there are two threads for that process. I'm so confused
    since I didn't use goroutine or something like that. Below is the code and
    the running info. I tried to google something about this but helpless. Your
    explanation is appreciated.

    helloGo.go

    package main

    import "fmt"

    func main() {
    fmt.Printf("hello, world\n")
    for {

    }
    }


    PID COMMAND %CPU TIME #TH #WQ #POR #MREG RPRVT RSHRD RSIZE
    22849 top 8.3 00:01.39 1/1 0 24 31 1128K 216K 1876K
    22846 bash 0.0 00:00.00 1 0 21 26 400K 756K 1236K
    22845 login 0.0 00:00.03 2 1 33 67 976K 276K 4644K
    22844 helloGo 100.4 00:22.13 2/1 0 5 156 464K 212K 1116K

    Thanks,
    Joe

    --

    --
  • Kevin Gillette at Oct 14, 2012 at 12:28 pm
    So the GC will actually now call brk/sbrk with a lower/negative value now?
    I figured the gc GC would never improve on that aspect of its tcmalloc
    origin.
    On Saturday, October 13, 2012 10:43:48 PM UTC-6, minux wrote:

    the other thread is for GC (actually the scavenger who
    tries to return unused memory back to OS).
    On Oct 14, 2012 12:39 PM, "Joe" <joel...@gmail.com <javascript:>> wrote:

    Hi All,

    I'm new newbie in GO. I inspected a simpel hello world program running on
    Mac and found that there are two threads for that process. I'm so confused
    since I didn't use goroutine or something like that. Below is the code and
    the running info. I tried to google something about this but helpless. Your
    explanation is appreciated.

    helloGo.go

    package main

    import "fmt"

    func main() {
    fmt.Printf("hello, world\n")
    for {

    }
    }


    PID COMMAND %CPU TIME #TH #WQ #POR #MREG RPRVT RSHRD
    RSIZE
    22849 top 8.3 00:01.39 1/1 0 24 31 1128K 216K
    1876K
    22846 bash 0.0 00:00.00 1 0 21 26 400K 756K
    1236K
    22845 login 0.0 00:00.03 2 1 33 67 976K 276K
    4644K
    22844 helloGo 100.4 00:22.13 2/1 0 5 156 464K 212K
    1116K

    Thanks,
    Joe

    --

    --
  • Minux at Oct 14, 2012 at 1:49 pm

    On Sun, Oct 14, 2012 at 8:28 PM, Kevin Gillette wrote:

    So the GC will actually now call brk/sbrk with a lower/negative value now?
    I figured the gc GC would never improve on that aspect of its tcmalloc
    origin.
    munmap, actually.

    yes, GC can actually return memory to the OS.

    --
  • Dmitry Vyukov at Oct 15, 2012 at 3:58 am

    On Sunday, October 14, 2012 5:42:19 PM UTC+4, minux wrote:
    On Sun, Oct 14, 2012 at 8:28 PM, Kevin Gillette <extempor...@gmail.com<javascript:>
    wrote:
    So the GC will actually now call brk/sbrk with a lower/negative value
    now? I figured the gc GC would never improve on that aspect of its tcmalloc
    origin.
    munmap, actually.

    yes, GC can actually return memory to the OS.
    It calls madvise(MADV_DONTNEED) rather than munmap().

    --
  • Minux at Oct 15, 2012 at 12:42 pm

    On Mon, Oct 15, 2012 at 11:58 AM, Dmitry Vyukov wrote:
    On Sunday, October 14, 2012 5:42:19 PM UTC+4, minux wrote:
    On Sun, Oct 14, 2012 at 8:28 PM, Kevin Gillette wrote:

    So the GC will actually now call brk/sbrk with a lower/negative value
    now? I figured the gc GC would never improve on that aspect of its tcmalloc
    origin.
    munmap, actually.
    yes, GC can actually return memory to the OS.
    It calls madvise(MADV_DONTNEED) rather than munmap().
    Oops, you're right. function runtime·SysUnused in mem_$GOOS.c does that.
    (on linux and darwin are supported now).

    --
  • Joe at Oct 14, 2012 at 3:33 pm
    Thank you minux. i'm trying to look into it for more detail.
    On Sunday, October 14, 2012 12:43:48 AM UTC-4, minux wrote:

    the other thread is for GC (actually the scavenger who
    tries to return unused memory back to OS).
    On Oct 14, 2012 12:39 PM, "Joe" <joel...@gmail.com <javascript:>> wrote:

    Hi All,

    I'm new newbie in GO. I inspected a simpel hello world program running on
    Mac and found that there are two threads for that process. I'm so confused
    since I didn't use goroutine or something like that. Below is the code and
    the running info. I tried to google something about this but helpless. Your
    explanation is appreciated.

    helloGo.go

    package main

    import "fmt"

    func main() {
    fmt.Printf("hello, world\n")
    for {

    }
    }


    PID COMMAND %CPU TIME #TH #WQ #POR #MREG RPRVT RSHRD
    RSIZE
    22849 top 8.3 00:01.39 1/1 0 24 31 1128K 216K
    1876K
    22846 bash 0.0 00:00.00 1 0 21 26 400K 756K
    1236K
    22845 login 0.0 00:00.03 2 1 33 67 976K 276K
    4644K
    22844 helloGo 100.4 00:22.13 2/1 0 5 156 464K 212K
    1116K

    Thanks,
    Joe

    --

    --
  • Minux at Oct 14, 2012 at 3:56 pm

    On Sun, Oct 14, 2012 at 11:33 PM, Joe wrote:

    i'm trying to look into it for more detail.
    FYI the other thread is running this (function runtime·MHeap_Scavenger):
    http://tip.golang.org/src/pkg/runtime/mheap.c#L346

    You can get the current criterion for returning memory to the OS.

    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 14, '12 at 4:39a
activeOct 15, '12 at 12:42p
posts8
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase