does malloc cause swapping out?

Monika plug-devel@lists.PLUG.phoenix.az.us
Fri Apr 12 15:00:02 2002


Hello,

I would like to know if malloc can cause pages to be swapped out.

Here's an extended version of my question:

This is what I was able to find out and what hopefully is correct:

Each process gets a chunk of memory to manage at the beginning of its
execution. There is a code segment, heap space that grows "upwards" and stack
that grows "downwards". A space between a stack and a heap is sort of a
no-man's land that gets allocated with mmap as the executions progresses.

Malloc can raise up the heap and it is implemented by a syscall brk.
If brk wants to raise the end of the heap, but there is no free space,
because there is something in there that was allocated with mmap, then
brk returns an old address of the end of the heap.

Now here's where my confusion starts. I did a little bit of function tracing
(on 2.2.x kernel) and noticed that kmalloc can eventaully cause pages to be
swapped out (if the region immediatelly above the heap is allocated and we
need to increase the heap space). 

I wanted to check if malloc() can eventually cause pages to be swapped out
similarly to what kernel malloc (kmalloc) can do.

I did a search on google and didn't find anything that would give me a good
explanation, nor a definite answer. I looked at malloc.c files on my machine
and ehm... that didn't work too well either and caused a bit more
confusion on my part (probably due to my lack of good knowledge of C). 

What I'm confused about is when kmalloc is invoked vs. when malloc is invoked
and also how exactly libc malloc calls syscall brk and how it manages the
situation when brk returns the same address (meaning that heap space cannot be
raised any higher).

I did look at the implementation of brk and it didn't seem to do any attempts
to swap out pages.

I would appreciate any ideas/redirections/enlightening answers, even if they
will make me feel as if I asked a dumb question ;-)

thanks,
my ears are open,
Monika