PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command
2971 xan 20 0 794M 2288 1696 S 0.0 0.2 0:00.02 ./
webserver.out
2972 xan 20 0 794M 2288 1696 S 0.0 0.2 0:00.02 ./
webserver.out
3029 xan 20 0 794M 2288 1696 S 0.0 0.2 0:00.00 ./
webserver.out
when it's more and more virtual memory. Why Go consumes so much
virtual memory while the res and shr are so small?
It is usually a configuration parameter of your system. In 32 bits, it
is probably 3GB and can't get above. In 64-bit, there might be a
limit, and otherwise there is virtually none (here I think it's
256TB).
> 2) which algorithm use Go for reserve virt memory?
In 32 bits, the algorithm consists in reseving 768MB. In 64-bit mode,
it's more complicated, and it's not 768MB from the beginning.
Rémy.
Le 21 mars 2012 21:27, Xan <xanc...@gmail.com> a écrit :
> @DisposaBoy: so:
> 1) what is the limit of virtual memory?
It is usually a configuration parameter of your system. In 32 bits, it
is probably 3GB and can't get above. In 64-bit, there might be a
limit, and otherwise there is virtually none (here I think it's
256TB).
> 2) which algorithm use Go for reserve virt memory?
In 32 bits, the algorithm consists in reseving 768MB. In 64-bit mode,
it's more complicated, and it's not 768MB from the beginning.
Rémy.
2012/3/21 Rémy Oudompheng <remyoud...@gmail.com>
> 2) which algorithm use Go for reserve virt memory?
In 32 bits, the algorithm consists in reseving 768MB. In 64-bit mode,
it's more complicated, and it's not 768MB from the beginning.Is there source code of that? Just curious!
Don't worry about it, you have a 4GB address space, of which you can
use 3G, it has nothing to do with your available RAM.
--
Aram Hăvărneanu
--
matt kane's brain
http://hydrogenproject.com
I guess your VPS use openvz as virtualization.
AFAIK, openvz VM works different than real Linux. Actually, openvz
is more like containter than virtualization.
But, sorry, i don't understand the detail.
Maybe you can compare with hardware or paravirt virtualization like
xen, vmwavre, kvm, or virtualbox
> So does anyone know if there's a practical way to reduce the VM of Go apps?
There's some hacks, but there's really no point. Virtual memory is
(nearly) free, so there's no point limiting it.
Dave.
On 04/11/2012 07:38 AM, krolaw wrote:
> Ok, I guess what I am looking for is an explanation as to why, my tiny
> (practically stateless) go program uses up so much of my VPS' ram. There
> also appears to be a direct correlation between the virtual memory my
> app uses (plus res) and the ram lost.I guess your VPS use openvz as virtualization.
AFAIK, openvz VM works different than real Linux. Actually, openvz
is more like containter than virtualization.
Indeed, well not broken, just different... and OpenVZ because of it's simplicity and greater performance
I have hosted lots of Go programs inside OpenVZ without incident, the
issues with OpenVZ generally relate to running Java processes inside
OpenVZ containers. I don't think OpenVZ was the OP's problem, or if in
fact there was a problem, my reading of the OP's post was they were
confused by the values reported in top and free, not that their VPS
was unable to cope with the 768mb VSS footprint on 32bit linux.
Cheers
Dave
--
Indeed, well not broken, just different... and OpenVZ because of it's simplicity and greater performance is preferred (vs Xen) among VPS hosts, especially the cheaper ones...but it does count virtual memory against you.As such, I'm limited to one go program running per VPS unless I can reduce the virtual memory. It isn't such a big deal, but it does severely reduce go's usefulness in such environments, which seem to becoming more common.
Hang on, if you're using 6g then none of the preceding applies as the
GC allocator behaves differently with the 64bit address space.
Lets start from the beginning, are you able to post some code that
demonstrates a 60mb working set ?
Cheers
Dave
I have confirmed your results (OpenVZ host at BuffaloVPS)
deadwood(~) % ps au | grep a.out
dfc 5734 0.0 0.0 35820 496 pts/7 Sl+ 04:17 0:00
/tmp/go-build712852602/command-line-arguments/_obj/a.out
However calculating how much memory, that is how many pages of VSS
have actually be allocated by the OS (and therefore accounted against
your quota) is not as simple as adding up all the VSS rows.
deadwood(~) % pmap 5734
5734: /tmp/go-build712852602/command-line-arguments/_obj/a.out
0000000000400000 204K r-x--
/tmp/go-build252999911/command-line-arguments/_obj/a.out
0000000000433000 12K rw---
/tmp/go-build252999911/command-line-arguments/_obj/a.out
0000000000436000 32880K rw--- [ anon ]
000000f83fff0000 1088K rwx-- [ anon ]
00002b9dcd60f000 1536K rwx-- [ anon ]
00007fffe1589000 84K rw--- [ stack ]
00007fffe15fd000 12K r-x-- [ anon ]
ffffffffff600000 8192K ----- [ anon ]
I _think_ (need to check the source to confirm) that the 32mb anon map
is the heap, however this has just been mmap'ed by the OS, yet is
virtually unused, which is why the RSS value reported is less than a
megabyte.
You can confirm this yourself. In your example you are using a 256mb
openvz host, you can see that the go program is accounted for as 0.1%
of memory. For comparison the bash shell you're using is accounted for
as 0.7% of memory.
Cheers
Dave
Do you have a program that does not run in your 256mb VPS that has a
working set significantly less than 256mb?
Cheers
Dave
Thanks Dave. Ok, so we can see that the runtime is allocating much more ram than it needs. Is there anything practical that can be done about this?
> 0000000000436000 32880K rw--- [ anon ]
This one is a static data section:
% readelf -S gocode
...
[20] .bss NOBITS 0000000000812e78 00412e78
0000000000012d80 0000000000000000 WA 0 0 8
[21] .noptrbss NOBITS 0000000000825bf8 00425bf8
0000000002009288 0000000000000000 WA 0 0 8
...
0x2009288 = 32MB+epsilon is the size of the data block.
There must be a 32MB block somewhere in the standard library code.
You can show it by adding a print in the linker code. The 32MB block is the
runtime.mheap variable. The big part of this structure is:
struct MHeap
{
...
// span lookup
MSpan *map[1<<MHeapMap_Bits];
...
};
Which is an array of 4M pointers, hence the 32MB. I'm not sure how
tunable it is. Maybe the map could be dynamically mapped at some other
fixed address.
> 000000f83fff0000 1088K rwx-- [ anon ]
This is the heap. It is hardcoded that the heap starts at address
0xf840000000. You must be using 1024kB heap+64kB bitmap (which is
growing backwards, maybe, i'm not sure).
> 00002b7a25e55000 1536K rwx-- [ anon ]
I suppose this is your OS thread stack. What is your thread stack size
(as given by ulimit -s?) You can customize that size using ulimit. I
think Go needs a ridiculously small stack size except if you are using
cgo.
I think with such a small amount of memory it will be more efficient
to put all your services into the same Go program, especially since
they are statically linked.
Rémy.
I can't help but wonder, if the memory usage is a bug, or whether these memory settings should be made available as flags in go build, or sometime in the future, the runtime will probably be improved to make good choices automatically. Is it worth putting in a feature request/bug report?
This looks sort of like the other face of issue 2142. Note Dmitry's comment in the thread that prompted that: https://groups.google.com/d/msg/golang-nuts/bzFaGbmCVMs/3aKl6-Hbg64J
I pay ~$11 per month for a 613 MB t1.micro on ec2. I highly recommend it.
I understand that 2142 is about available arena on 64-bit - it's one of
the two most significant issues in the issues list for me.
The point that I was making was that intelligently growing the heap is
similar to intelligently growing the arena - growing the available heap
space was Dmitry's suggestion that I was pointing to. Perhaps this is
not a useful comparison, but they are conceptually similar.
On Tue, 2012-04-17 at 23:10 +0800, minux wrote:
> On Mon, Apr 16, 2012 at 7:48 PM, kortschak
But you can do a lot with just 128MB VPS or 256MB VPS unless you are running Go or Java. And with 128MB VPS' now as low as $12/year, almost anyone has the funds to experiment with running their own server - and there's heaps of mail (sendmail), dns (nsd), web (nginx), that will run beautifully on these systems in low ram.
Using the same logic, are Windows go issues not important because Darwin and Linux are available?
News! I just tested my Go programs on an OpenVZ VPS with the more modern memory management (vSwap), and ram usage is fantastic. It turned out that my $12/year VPS host came to the party and provided me with OpenVZ vSwap running on Centos. So now my $1/month VPS is worth more to me than many other more expensive OpenVZ systems I am using. (Private message me if you want to know who I used.)