Memory fragmentation
Brought to you by:
obarthel
Hello obarthel,
In recent months users of this thread at amiga.org were figuring why clib2 version of web browser called NetSurf gets slower when moving from page to page.
We discovered that NetSurf does a lot small memory de/allocations. It's better explained by Chris Young (author of RaAction version of NetSurf) here :
http://www.amiga.org/forums/showpost.php?p=804753&postcount=223
Do you think you could take a look and fix this part at best ?
Thanks
Maybe you could borrow buddy allocator from ixemul ?
I have latest sources if you want.
I believe that a buddy allocator will not resolve the problem. Buddies still need to be freed and match for the fragmentation to be kept at bay. This is a problem which is known to be difficult to tackle with buddy allocators, or the Amiga exec memory management system.
What promises to help is a different approach, using what is called a "slab allocator". I just got around implementing one in clib2, and the change is available right now. It does still need to be tested, though.
Amazing. Will compile and let you know if it works.
I hope that it does work in the first place - this is untested code for now. My current plan is to perform testing during this weekend, but don't let me discourage you :-)
In order to activate the slab allocator, you will need to declare a global variable in your program which sets the slab size, like so:
ULONG __slab_max_size = 4096;
This will make all allocations smaller than 4096 bytes wind up in "slabs", with the respective slab selected by allocation size. Larger allocations will be handled separately. Allocating memory, and freeing it, should be very fast if the allocations fit into the slabs. Also, memory fragmentation should be very low.
However, the trick is to select a slab size which matches the requirements of the application. 4096 bytes may be too large, or it may not be large enough. clib2 currently lacks any means to figure out at runtime how well-utilized the slabs are, and this will have to follow if/when the slab allocator works as expected.
Last edit: Olaf Barthel 2016-11-17
The new slab allocator is much better-tested now. Please have another look, it might actually work now ;-)
Can you bump version number so netsurf devs could update toolchain?
Last edit: apj 2016-11-18
What can I say, new allocator works like a charm.
NetSurf even loads pages faster now.
Thank you.
You're welcome :-)
If the new slab allocator does prove itself, it might help other Amiga software which has the same demands as NetSurf. The Amiga's built in memory management system seems to be much better suited for programs which use very little memory, or only use memory over a short span of time. NetSurf appears to be the complete opposite of that kind of program.
May I close this ticket now? ;-)
Close that sucker ;-)