Page 1 of 1
processes calling malloc
Posted: Sun Jan 30, 2005 9:08 pm
by stonedzealot
I'm confused, now that I've got multiple processes running within my OS, I'm wondering just where the memory for a process calling malloc() comes from. Could someone break it down to me how execution flows after a malloc() call?
Re:processes calling malloc
Posted: Mon Jan 31, 2005 2:52 am
by Pype.Clicker
well, 'malloc' actually allocates *virtual* memory. It has its own internal lists for reusing recently freed blocks and (in unix style, at least) calls "more_core()" to extend the "heap" area when it cannot successfully grant a request.
Receiving "more_core()" at kernel level simply require you to change process's regions descriptions and to change the state of some page from "invalid" to "automatically allocate a zero'ed page" ...
When you actually need a page (some may be pre-loaded) in that newly-activated region, you take a lock on the physical memory manager, request one (or more) free pages and unlock then write page address in tables.
HTH
Re:processes calling malloc
Posted: Mon Jan 31, 2005 7:22 am
by stonedzealot
So malloc() is something that I don't need to implement until I focus on writing a glibc equivalent, but when I write it I also need to have a kernel component that will interpret the more_core() function?
That seems to be pretty far away, as of yet, but how big of blocks are we talking with this malloc()? I know that my kernel heap allocated with respect to integers, would this be much the same thing?
Re:processes calling malloc
Posted: Mon Jan 31, 2005 7:47 am
by Pype.Clicker
wangpeng wrote:
how big of blocks are we talking with this malloc()? I know that my kernel heap allocated with respect to integers, would this be much the same thing?
? ? ?
Re:processes calling malloc
Posted: Mon Jan 31, 2005 10:26 am
by stonedzealot
Nevermind, stupid question... 7 in the morning right before class, don't worry about it. But the first part was right?
Re:processes calling malloc
Posted: Mon Jan 31, 2005 11:37 am
by Pype.Clicker
wangpeng wrote:
So malloc() is something that I don't need to implement until I focus on writing a glibc equivalent, but when I write it I also need to have a kernel component that will interpret the more_core() function?
Indeed. Now, an independent issue is whether you need a malloc-like service for kernel's own needs and how to implement that service ...