Page 1 of 1

What heap algorithm is Linux using?

Posted: Thu Apr 04, 2019 2:13 am
by LIC
I have seen that there are several kernel heap algorithms with their pros and cons. What about Linux? What is the heap algorithm that the Linux Kernel is using?

Thanks for your answers

Re: What heap algorithm is Linux using?

Posted: Thu Apr 04, 2019 3:03 am
by iansjack
If only the source code wad available to answer this sort of question.

If only someone had written a book describing the workings of the Linux kernel.

Seriously - without wishing to appear rude - there is a wealth of information available on the web and in print about the Linux kernel. You will learn far more by doing your own research than by asking someone else to do it for you. Amongst other publications let me recommend: https://www.amazon.com/Professional-Ker ... 0470343435

Re: What heap algorithm is Linux using?

Posted: Thu Apr 04, 2019 4:01 am
by bzt
Hi
LIC wrote:I have seen that there are several kernel heap algorithms with their pros and cons. What about Linux? What is the heap algorithm that the Linux Kernel is using?

Thanks for your answers
A quick google search reveals that Linux is using the buddy allocator for page allocation and slab allocator for heap, which algorithm originates from Solaris' allocator.

https://www.kernel.org/doc/gorman/html/ ... nd009.html
https://en.wikipedia.org/wiki/Buddy_memory_allocation
https://www.kernel.org/doc/gorman/html/ ... nd011.html
https://en.wikipedia.org/wiki/Slab_allocation

Cheers,
bzt

Re: What heap algorithm is Linux using?

Posted: Thu Apr 04, 2019 7:45 am
by Solar
iansjack wrote:If only the source code wad available to answer this sort of question.
Source code tells you lots about the "how". Unless there are comments, figuring out the "what" can be somewhat of a stretch, especially in a code base of that magnitude. And even then you usually get the "what" on a rather too-fine-grained level. Usually we rely on documentation to tell us the high-level "what" and "why".

Re: What heap algorithm is Linux using?

Posted: Thu Apr 04, 2019 8:48 am
by iansjack
Solar wrote:
iansjack wrote:If only the source code wad available to answer this sort of question.
Source code tells you lots about the "how". Unless there are comments, figuring out the "what" can be somewhat of a stretch, especially in a code base of that magnitude. And even then you usually get the "what" on a rather too-fine-grained level. Usually we rely on documentation to tell us the high-level "what" and "why".
Which - of course - is why I also recommended books.

A combination of the two is - IMO - better than relying upon inaccurate generalisations such as " it uses the buddy allocator".

Re: What heap algorithm is Linux using?

Posted: Thu Apr 04, 2019 2:39 pm
by LIC
Thank you for your replies, I tried to check the answer by myself with the Linux kernel code but with all the files, I could not find out a clue on where to look for this part of the kernel first.

Thank you for the links !