Mono GC max-heap-size isn't documented. Is it

2019-03-22 04:24发布

I need to set an upper bound to the memory used by Mono.

According to blogs it's possible to use the parameter max-heap-size to cap the memory usage. According to experimentations, and according to the code, it indeed does what I want.

However, this option isn't documented.

Therefore: is it safe to rely on this option in production (or does it have drawbacks I don't see, like e.g.: no guarantee to still be available in future version of Mono)?

2条回答
何必那么认真
2楼-- · 2019-03-22 05:11

It is documented, and here's one way to get the documentation: export an invalid MONO_GC_PARAMS, start mono:

export MONO_GC_PARAMS=xxx
mono sample.exe

and get the help:

Warning: In environment variable `MONO_GC_PARAMS': Unknown option `xxx`. - Ignoring.

MONO_GC_PARAMS must be a comma-delimited list of one or more of the following:
  max-heap-size=N (where N is an integer, possibly with a k, m or a g suffix)
  soft-heap-limit=n (where N is an integer, possibly with a k, m or a g suffix)
  nursery-size=N (where N is an integer, possibly with a k, m or a g suffix)
  major=COLLECTOR (where COLLECTOR is `marksweep', `marksweep-conc', `marksweep-par', 'marksweep-fixed' or 'marksweep-fixed-par')
  minor=COLLECTOR (where COLLECTOR is `simple' or `split')
  wbarrier=WBARRIER (where WBARRIER is `remset' or `cardtable')
  stack-mark=MARK-METHOD (where MARK-METHOD is 'precise' or 'conservative')
  [no-]cementing
  evacuation-threshold=P (where P is a percentage, an integer in 0-100)
  (no-)lazy-sweep
 Experimental options:
  save-target-ratio=R (where R must be between 0.10 - 2.00).
  default-allowance-ratio=R (where R must be between 1.00 - 10.00).

As you can see max-heap-size is listed, and not in the Experimental Options. So I'd say it's safe.

查看更多
做自己的国王
3楼-- · 2019-03-22 05:18

It is documented in the mono man page :

Sets the maximum size of the heap. The size is specified in bytes and must be a power of two. The suffixes k',m' and `g' can be used to specify kilo-, mega- and gigabytes, respectively. The limit is the sum of the nursery, major heap and large object heap. Once the limit is reached the application will receive OutOfMemoryExceptions when trying to allocate. Not the full extent of memory set in max-heap-size could be available to satisfy a single allocation due to internal fragmentation. By default heap limits is disabled and the GC will try to use all available memory.

查看更多
登录 后发表回答