ever wondered how kmalloc() worked? of course you have, and luckily for you i've just finished a questionably long post diving into the kernels slab allocator! 🤓
ever wondered how kmalloc() worked? of course you have, and luckily for you i've just finished a questionably long post diving into the kernels slab allocator! 🤓
@sam4k As I said, missing the demo unfortunately, but everything else is here:
https://ljrk.codeberg.page/unixv6-alloc.html
If you have any questions/comments, please hit me up :)
A reference to http://www.usenix.org/publications/library/proceedings/bos94/full_papers/bonwick.ps might be appropriate.
- Bart
@bsmaalders thank you for the suggestion!
I've added a brief paragraph and reference to the end of the slab introduction :)
Cool, thanks! I worked at Sun at the time, and sat down the hall from Jeff. He went on later to be part of the core team for ZFS.
@sam4k Thanks for sharing, it's a great post!
I'm eager to try out `slxbtrace` now. 😁
A while ago I did attempt to trace operations on a kmalloc cache using eBPF, but ended up getting a lot of interference from what I suspected was my own instrumentation, so I gave up. 😕
Have you experienced similar issues with `slxbtrace`?
@laomaiweng thank you, I'm glad you liked it!
I'll hopefully have some time to get it into a shareable state soon 😅
For slxbtrace, I used the bcc tools Python front-end to write the bpf programs (great documentation and surprisingly quick to get into!).
At the moment I'm using the kmem:kmalloc and kmem:free tracepoints as hooks; filtering on gfp_flags and size for the cache I want.
With this setup I haven't noticed any issues with interference; hope that helps a bit?!
@sam4k Oh nice, I was using bpftrace directly, didn't know there was a Python frontend.
I think I was using those tracepoints too, I'll perhaps give it another go in a few weeks.
Or use slxbtrace if it's been published by then. 😛
@snowytrees awesome, i'm glad its helpful :)
i've got a couple of posts on the vm subsystem and plan to do a deeper dive at some point!
@snowytrees from what I can see, that paper is based on the 2.6 kernel which is a tad old!
Personally, i would look for more modern resources. A lot of the fundamentals and concepts may be similar, but it's a time investment enough to get into this so imo you might as well learn contemporary implementations where possible; especially if you're looking to write a kernel module.
That said, of course resources can be few and far between and depends on how you learn :)
I found "Linux Kernel Programming: A comprehensive guide to kernel internals, writing kernel modules, and kernel synchronization" a nice read/reference. It's based on the 5.x kernel and was published in 2021, it doesn't go into deep detail but imo provides enough information for you to be able to probe other resources/source for additional detail.
@snowytrees @sam4k I am writing a book on the whole mm subsystem specifically (targeting linux 6.0) however, it won't be out for another year and a half :)
I wrote a couple sets of (incomplete) notes on mm, nothing on slab there though.
https://github.com/lorenzo-stoakes/linux-mm-notes
https://github.com/lorenzo-stoakes/linux-vm-notes
Incredible post @sam4k !