Modify Golang Maximum memory limit

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. Excerpted from Golang Nut

You can tune the mheapmap_bits in Malloc.h and arena_size on MALLOC.GOC to reducememory usage, as long as they statisfy th is: (1UL << (mheapmap_bits)) >= arena_size(for example, I changed mheapmap_bits to, and arena_size to ' 4ll<<30 ', all testspassed, and the size of BSS secti ONS is dropped to about 10MB for Bin/go: linux-amd64 Go $ size Bin/go # before text data BSS Dec hex filename 4491897 97552 33672424 38261873 247d471 bin/go linux-amd64 Go $ size Bin/go # after text data BSS Dec hex filename 4491924 97552 8506600 13096076 c7d48c bin/go)
And for the record, this problem was not caused by the reserved VM space (which was 16GBon 64-bit hosts, as they are mapped With Prot_none, i.e, they won ' t maps to any physicalmemory). Its real cause is the big runtime.mheap.

$ VI malloc.hmheapmap_bits=16
$ VI malloc.gocarena_size=1ll<<28
$ go install-a-v Stdthen rebuilt my app which reduce its VPS footprint from 60MB to 20MB!!!
Previously:mheapmap_bits=19arena_size=1ll<<28reduced the footprint to 24MB, so I imagine going lower have diminishin G returns.
I can ' t help but wonder, if the memory usage was a bug, or whether these memory settings should be made available as flags  In go build, or sometime in the future, the runtime'll probably be improved to make good choices automatically. Is it worth putting in a feature Request/bug report?
Given that the apps RSS are 2.5MB, I ' m thinking the total footprint should be around 5-10MB? If So, there's probably more work to do and I would is happy to test.
However, knocking off ~70% of the RAM requirements is absolutely fantastic, so thanks everyone for your time and helpful s Uggestions.
Cheers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.