About do_brk function in linux

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
chenrvmldd
Posts: 10
Joined: Sat Mar 01, 2008 11:27 pm

About do_brk function in linux

Post by chenrvmldd »

Hi,
I have some problems about do_brk function in linux,I think many of friends here know more about linux souce code than I do,
We all know that when the process wants to allocate heap space for users,we use the function do_brk,then do_brk will use make_pages_present,then my questions are:
1.in do_brk,if we want to use make_pages_present function,we should set the vm_lockflag,then vm_lock flag is always set in do_brk,if be set,when it is set?
2.when make_pages_present function have been used by do_brk,we know that a parameter called "write "will be passed to handle_mm_fault function by make_pages_present,in this situation,the value of the parameter "write" must be 1,so when the handle_mm_fault needs to use handle_pte_fault,the handle_pte_fault will use alloc_pages function to allocate page frame(physical memory) for the process heap space,that is to say we will build the mapping from the virtual address to physical address,then I do not understand linux has lazy-allocation feature,why in this situation it immediately allocates memory for the process ,why it does not delay the allocation until the process really accesses the page.
chenrvmldd
Posts: 10
Joined: Sat Mar 01, 2008 11:27 pm

Re: About do_brk function in linux

Post by chenrvmldd »

Do some one know that? I can not understand why that
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: About do_brk function in linux

Post by Combuster »

This place is mainly about homebrew OSes, not linux internals.

From what I gathered from your post alone, do_brk calls make_pages_present, which in turn tells the MM to to perform a specific action on a pagefault (allocate a page when it is being written to) Now go figure wether that is lazy allocation or not.

As for the first question, it's even less understandable what you are trying to do here.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply