Avoid using brk() and sbrk() for memory allocation. The malloc(3) memory allocation package offers a more portable, convenient, and efficient approach. Here's why:
Portability:
malloc() is a standard C library function, ensuring its availability across various platforms and operating systems.
brk() and sbrk() are system-specific functions that may not be available or have different behaviors on different systems.
@ljs I used sbrk() when I had to implement a malloc() back at university. I didn’t touch it again afterwards and I will only do that again if I really must 😂
@ljs I've seen the old version (I was first assuming IT = Information Technology)
@ljs @frankenmichl @vbabka glibc does that - the main thread's arena IIRC uses brk(), but other arenas (which start being created when you create more threads) use a big PROT_NONE allocation that is progressively made accessible.
(Which, by the way, gives us this fun behavior: https://lore.kernel.org/all/20241008-stack-gap-inaccessible-v1-1-848d4d891f21@google.com/ )
@ljs @frankenmichl @vbabka I DON'T FIND THE BUGS, THE BUGS FIND ME
@ljs @frankenmichl @vbabka Why? Nothing gets really allocated at brk() or mmap() time. Map your entire address space read/write and be done. As a bonus, you can get a rough feeling of what debugging bad pointers was like before MMUs were invented…
@ljs @frankenmichl @vbabka I did not actually directly run scripts/get_maintainers.pl and instead used "b4 prep --auto-to-cc" and then, when that gave me a bunch of Rust maintainers because I mentioned Rust once in the diff, threw away the entire recipient list and wrote my own one manually...
And I mean, I also think my patch wasn't pretty, I agree with you on that. 😛
Yeah, I wish the kernel never had the concept of stacks that grow...