[bootopts] Add heap= option for dynamic sizing of kernel heap #1993
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Here you go @toncho11 and @FrenkelS: this new /bootopts option will allow ELKS to boot up with a minimum of extra kernel resources, allowing for a usable contiguous block of memory ~500Kb for Doom, and more if UMB memory is available.
Adds
heap=
/bootopts option to set the size of the internal kernel heap at startup. By default, ELKS will try to reserve up to 64k of memory for use in its heap allocator for runtime kernel resources. In practice, because of the existing static data from the compiled C routines, this amounts to a ~45k heap. My testing shows that the kernel is stable lowering this to 15k when tasks, buffers, cache, and nodes are also lowered, thus saving ~30k memory, which is then available for user programs, e.g. Doom.Here's a screenshot of
meminfo
running directly after boot with the reduced resource options in effect:Notice at the bottom right there's 492K of 520k available, with the largest block being 499,888 bytes. If the kernel were to be recompiled with minimal drivers (e.g. no networking), this could be made even larger.
I have modified the default /bootopts to include both the "normal" settings for kernel resources and the example used to generate the display above, to make it easy to play with. Be aware that no checking is done on the heap size passed, and passing a value too low can cause system instability or crashes. I played around and found 15000 as a working lower limit, given the other option values.
Here's the defaults:
And the minimal system:
Notice the 'n' at the end of the line, that passes 'n' to /bin/init which means don't run ./etc/rc.sys on startup, which also saves memory fragmentation at the cost of the clock not being set and auto-mounts not processed, etc.
Feel free to play around with these resource settings, depending on what Doom requires.
The startup boot screen is slightly changed: at the bottom right, it now displays the largest contiguous block of memory before running /bin/init, followed by the released "INITPROC" code segment, followed by the UMB memory configured. Since the startup screen is tight on space, This might be shown as "509+9+64K free" which means 509k contiguous main memory plus a 9k free block plus a 64k UMB free block. It also shows the number of tasks, files, inodes and heap for reference.
Here's the changed startup screen (note we've moved to v0.8.0-pre3):
Other enhancements include showing "MEM" instead of "SEG" in
meminfo
for easier understanding, and "CACH" instead of "BUFH" to differentiate cache= L1 buffers from L2 buf= buffers.