lkml.org 
[lkml]   [1996]   [Aug]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Subjectmalloc()'s interaction with the kernel
Date
Hi,

I'm interested in finding out what type of system-level events
take place when a user process calls malloc() and free().

The main situation I'm having trouble understanding is this:
imagine that a process's heap is full of malloc()ed stuff, so
that on the next call to malloc it is going to run out of heap
space. So when it calls malloc(), malloc is (I assume) going to
call brk() to increase the process's data segment size. Then,
when the task tries to use the new memory, it will page fault,
and the OS will have to map some more pages into its address
space, calling something like page_alloc() and then putting the
pages into its page table in the new space made by brk().

My question is: how do we determine when we can free these new
pages? If they are used to hold several malloc()ed blocks, it
seems difficult to keep track of when _all_ the blocks within a
particular page are free()d so that the page itself may be freed
with a system call. Does the C library keep a count of how many
blocks are malloc()ed inside each page?

I'd appreciate it if someone could clear this point up for me, as
well as pointing out the inevitable errors in my guesswork above.
Apologies if this isn't strongly kernel-related, but I couldn't
think of a better place to ask.

Jason.

\
 
 \ /
  Last update: 2005-03-22 13:37    [W:0.071 / U:0.552 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site