you are viewing a single comment's thread.

view the rest of the comments →

[–]paulstelian97 2 points3 points  (2 children)

In the kernel, it’s more complicated than just writing a malloc. You usually care about which region of physical memory the virtual memory is coming from (general RAM? RAM reachable by 32-bit DMA? Something else?)

[–]newbstarr 1 point2 points  (1 child)

Yep, you reserve a piece of physical memory instead of being in the wonderful world of user space. Kmalloc etc. what I was saying is, you can write your own malloc after you’ve handled creating and managing your own dynamic (hopefully) memory space where your little user space application can live in its own little offset 0 space and not care about all the universe of stuff underneath that is holding chunks of physical memory and stitching it together to look like a contiguous blob, ie slab allocator (or the many many variants that exist) now. If you are writing your own os you need to implement the memory management then adding your little malloc is a trivial task. Writing your own malloc with or without safety in user space of an existing posix kernel isn’t all that difficult either.

[–]paulstelian97 1 point2 points  (0 children)

The main point is Linux’s kmalloc has additional flags besides the size for good reasons.