Add arena allocator to cpp86, c86 and as86 #21
Merged
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.
Adds the ELKS arena allocator to CPP86, C86 and AS86, as discussed in ghaerr/elks#2140 (comment).
Also renames nasm -> nasm86 and ndisasm -> ndisasm86.
@rafael2k, I got CPP and C86 to function well, but could not get the "big pig" nasm86 to work with the arena allocator. It seems it uses a LOT of memory. If you turn on
sysctl kern.debug=1
you will be able to see the FMEMALLOC it attempts doing. Runningsysctl malloc.debug=2 (or 3)
displays heap debugging in detail. I'm going to think about how to best proceed a little more; I am thinking of adding yet more malloc/fmemalloc monitoring, with an option that just shows the totals used, rather than all the detail. NASM isn't linked with the debug or arena allocator so it won't have as much debugging info.LD86 does not need changing at this time, as it only uses fmemalloc in one place. So I've left it alone for now, pending getting NASM86 working.
You'll see the changes made for CPP, C86 and AS86 are very straightforward. I did the same thing for NASM86, basically changing
#if __ELKS__
to#if 0
and adding mem.c (see compiler/mem.c or cpp/mem.c for details). But it runs out of memory. You're welcome to try to get it to work with the new allocator. The problem seems to be it does a lot of fmemalloc 640 byte allocations, then a big one from which there is no memory. All in all, we need to learn more about the actual allocations NASM86 is doing in order to figure out what to do better.On another note, when a memory failure happens, the new code runs meminfo displayed to the console, showing what the memory layout looks like. The bad news is there is far less free memory than I thought, since make86 is running, and it seems it forks itself then execs a /bin/sh -c which is huge, to run the make targets. This results in tons of memory being used. I am working on a solution to that.
C86 itself would not run with the arena allocator getting 64K of arena at startup, I had to reduce it to 32K. Here's a look at what meminfo showed before that change:
Note the largest free space is 49K after C86 starts up! Wow.
Also something to consider is that we don't need the larger heapsize= specifications for the default data segment when using the arena allocator, since it doesn't allocate from the default data segment. This mean they can be drastically reduced. You're welcome to play with that too. We should discuss this more so we fully understand which programs are using what memory, as I can see the system is going to remain tight.
Overall, this is ready to commit, as everything still works as nasm86 has been left alone. I wasn't able to test building chess though, as stdint.h got all messed up and I don't have the "dev kit" installed on my root directory since I am testing on QEMU with a 2880k floppy image which is almost full. I did test with test.c "Hello world" which builds and runs.
Let me know what you think the next steps should be. Ultimately, we have the allocators now, but need to figure the best ways to use them for NASM.