processes calling malloc

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
stonedzealot

processes calling malloc

Post 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?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:processes calling malloc

Post 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
stonedzealot

Re:processes calling malloc

Post 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?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:processes calling malloc

Post 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?
? ? ?
stonedzealot

Re:processes calling malloc

Post by stonedzealot »

Nevermind, stupid question... 7 in the morning right before class, don't worry about it. But the first part was right?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:processes calling malloc

Post 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 ...
Post Reply