0

I want to execute a "Hello world" program written using Go on device with very limited memory.

When running it over Linux, the current memory footprint seems to be very high (64MB VM Size and 40MB VM Data for hello world).

How can I configure the Go runtime environment to use less memory?

Rick-777
  • 9,714
  • 5
  • 34
  • 50
  • What is your current configuration? What linux? What device? – Theolodis May 01 '14 at 10:03
  • 1
    Please consider bringing this up on the [`go-nuts` mailing list](http://groups.google.com/d/forum/golang-nuts) -- Go has definitely been successfully used in embedded world (for instance, see [this](https://groups.google.com/d/topic/golang-nuts/HRPjKC2Tddw/discussion) and [this](http://dave.cheney.net/unofficial-arm-tarballs) and [this](https://code.google.com/p/go-wiki/wiki/GoArm)) and you might get decent help there. – kostix May 01 '14 at 13:26

1 Answers1

3

Note that memory usage indicators having "virtual" in their names are useless to analyze as they are, as stated, virtual.

Go's runtime (for binaries built by the gc toolchain, gccgo might use it own approach to allocation—I don't know for sure) on Linux uses the so-called "arena allocator" which at startup tells the OS it wants to "own" a memory region of a pretty huge size, the OS acknowledges this but no memory is really allocated (no physical memory pages, that is), and real allocation only happens when the process really requests the memory.

Due to this, the only sensible memory parameter to analyze is RSS—Resident Set Size, which is the amount of physical memory mapped to the process' address space—the memory it physically allocated and owns—as opposed to virtual stats. See this for a good explanation and skim through this in general.

Community
  • 1
  • 1
kostix
  • 51,517
  • 14
  • 93
  • 176
  • 1
    Of course, an embedded device might not have virtual memory, or at least not lazy allocation. –  May 01 '14 at 15:06
  • @delnan: I challenge you to find an embedded linux that does not support virtual memory. I know they exist, but I've never encountered one. I suspect anything but C would be ill suited to run in such an environment. – deft_code May 02 '14 at 16:36
  • @deft_code Note that I talk about embedded devices in general, not just those running Linux. Also, is lazy allocation as universal as virtual memory? I would suspect that it's one of the first things most embedded devices turn off; it's of no use for typical embedded software (which takes care of every single byte) and takes a bit of resources. –  May 02 '14 at 16:38