public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* [gccgo] How to reduce VmData usage in go executables?
@ 2018-12-11 17:49 Aaron_Wright
  2018-12-11 18:12 ` Florian Weimer
  0 siblings, 1 reply; 3+ messages in thread
From: Aaron_Wright @ 2018-12-11 17:49 UTC (permalink / raw)
  To: gcc-help

I'm working on an embedded device with 512 MiB of RAM. When I start a go 
executable compiled with gccgo, it allocates over 800-900 MiB of memory 
(VmData) right off the bat. This is around 180% of the memory available on 
the device. I would like to reduce this to a value that is reasonable for 
my device, but after hours of research, I cannot pinpoint where this 
memory is being allocated, what it is for, nor how I can tweak the amount.

I'm cross compiling to i686 on ubuntu with i686-linux-gnu like so:

> #!/bin/bash
> 
> TOOLCHAIN_PREFIX=i686-linux-gnu
> OPTIMIZATION_FLAG="-O3"
> 
> CGO_ENABLED=1 \
> CC=${TOOLCHAIN_PREFIX}-gcc-8 \
> CXX=${TOOLCHAIN_PREFIX}-g++-8 \
> AR=${TOOLCHAIN_PREFIX}-ar \
> GCCGO=${TOOLCHAIN_PREFIX}-gccgo-8 \
> CGO_CFLAGS="-g ${OPTIMIZATION_FLAG}" \
> CGO_CPPFLAGS="" \
> CGO_CXXFLAGS="-g ${OPTIMIZATION_FLAG}" \
> CGO_FFLAGS="-g ${OPTIMIZATION_FLAG}" \
> CGO_LDFLAGS="-g ${OPTIMIZATION_FLAG}" \
> GOOS=linux \
> GOARCH=386 \
> go build -x \
>    -compiler=gccgo \
>    -gccgoflags=all="-static -g ${OPTIMIZATION_FLAG}" \
>    $1

My gcc version is 8.2.0:

> $ i686-linux-gnu-gccgo-8 --version
> i686-linux-gnu-gccgo-8 (Ubuntu 8.2.0-1ubuntu2~18.04) 8.2.0
> Copyright (C) 2018 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is 
NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR 
PURPOSE.

The go executable that allocates 800-900 MiB of RAM is:

> package main
> 
> import (
>       "fmt"
>       "time"
> )
> 
> func main() {
>       fmt.Println("hello world")
>       time.Sleep(1000000000 * 5)
> }

I've played with the GOGC environment variable, but that only makes VmData 
wiggle a few MiB one way or the other. I also tried looking through the 
gccgo/libgo source code, but I got lost quickly. If anyone could set me on 
the right path, I would be grateful.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [gccgo] How to reduce VmData usage in go executables?
  2018-12-11 17:49 [gccgo] How to reduce VmData usage in go executables? Aaron_Wright
@ 2018-12-11 18:12 ` Florian Weimer
  2018-12-12  0:54   ` Aaron_Wright
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Weimer @ 2018-12-11 18:12 UTC (permalink / raw)
  To: Aaron_Wright; +Cc: gcc-help

* Aaron Wright:

> The go executable that allocates 800-900 MiB of RAM is:

How do you measure memory utilization?

Thanks,
Florian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [gccgo] How to reduce VmData usage in go executables?
  2018-12-11 18:12 ` Florian Weimer
@ 2018-12-12  0:54   ` Aaron_Wright
  0 siblings, 0 replies; 3+ messages in thread
From: Aaron_Wright @ 2018-12-12  0:54 UTC (permalink / raw)
  To: Florian Weimer; +Cc: gcc-help

Florian Weimer <fweimer@redhat.com> wrote on 12/11/2018 09:49:01 AM:
> * Aaron Wright:
> 
> > The go executable that allocates 800-900 MiB of RAM is:
> 
> How do you measure memory utilization?

A couple ways. The first is just looking at the output of top (busybox), 
the VSZ column. The second is /proc/<pid>/status, which reports:

VmPeak:   811692 kB
VmSize:   811692 kB
VmLck:         0 kB
VmPin:         0 kB
VmHWM:      5796 kB
VmRSS:      5796 kB
VmData:   807196 kB
VmStk:       132 kB
VmExe:      2936 kB
VmLib:         0 kB
VmPTE:        52 kB
VmPMD:         0 kB
VmSwap:        0 kB

I'm aware that VmData, VmPeak, VmSize, etc are all virtual memory, but I'm 
worried that if the process has that allocated, it could try to use it at 
some point, which would not be good for my device. Perhaps (most likely) 
I'm not understanding these variables completely, but the huge numbers are 
"scary" for other developers and I.

It's my understanding that go executables most likely use some arena 
allocation and manage their own memory, but 800 MiB for a hello world 
executable on a box with only 512 MiB of RAM seems extreme to me.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-12-11 18:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-11 17:49 [gccgo] How to reduce VmData usage in go executables? Aaron_Wright
2018-12-11 18:12 ` Florian Weimer
2018-12-12  0:54   ` Aaron_Wright

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).