不知这篇文章是否可以给你帮上忙在一般情况下, 用内存断点调用brk()来约束进程的映象范围时,
内核要判别所要扩展的虚存页面数是否超过
当前所能分配的最多虚存页面数来决定是否完成扩展,
sysctl_overcommit_memory标志可以使内核跳过这一步, 
从而基于brk()调用的malloc()库函数可以得到更多的虚存.; mm/mmap.c:int sysctl_overcommit_memory;/*
* sys_brk() for the most part doesn't need the global kernel
* lock, except when an application is doing something nasty
* like trying to un-brk an area that has already been mapped
* to a regular file. in this case, the unmapping will need
* to invoke file system routines that need the global lock.
*/
asmlinkage unsigned long sys_brk(unsigned long brk)
{
unsigned long rlim, retval;
unsigned long newbrk, oldbrk;
struct mm_struct *mm = current->mm;down(&mm->mmap_sem);if (brk end_code) 虚存断点不能小于代码段
goto out;
newbrk = PAGE_ALIGN(brk); 新的虚存断点
oldbrk = PAGE_ALIGN(mm->brk); 原来的虚存断点
if (oldbrk == newbrk)
goto set_brk;/* Always allow shrinking brk. */
if (brk brk) { 如果新的虚存断点小于原来的断点
if (!do_munmap(mm, newbrk, oldbrk-newbrk)) 清除断点间的虚存映射
goto set_brk;
goto out;
}/* Check against rlimit.. */
rlim = current->rlim[RLIMIT_DATA].rlim_cur; 取进程数据段限额
if (rlim start_data > rlim)
如果新断点超过限额
goto out;/* Check against existing mmap mappings. */
if (find_vma_intersection(mm, oldbrk, newbrk+PAGE_SIZE))
新的断点是否与某段虚存重叠
goto out;/* Check if we have enough memory.. */
if (!vm_enough_memory((newbrk-oldbrk) >> PAGE_SHIFT))
新扩展的内存页是否超过可分配虚拟内存页数量
goto out;/* Ok, looks good - let it rip. */
if (do_brk(oldbrk, newbrk-oldbrk) != oldbrk) 将原内存断点扩展到新断点
goto out;
set_brk:
mm->brk = brk;
out:
retval = mm->brk;
up(&mm->mmap_sem);
return retval;
}
/* Check that a process has enough memory to allocate a
* new virtual mapping.
*/
int vm_enough_memory(long pages)
{
/* Stupid algorithm to decide if we have enough memory: while
* simple, it hopefully works in most obvious cases.. Easy to
* fool it, but this should catch most mistakes.
*/
/* 23/11/98 NJC: Somewhat less stupid version of algorithm,
* which tries to do "TheRightThing". Instead of using half of
* (buffers+cache), use the minimum values. Allow an extra 2%
* of num_physpages for safety margin.
*/long free;/* Sometimes we want to use more memory than we have. */
if (sysctl_overcommit_memory)
return 1; 无条件返回TRUEfree = atomic_read(&buffermem_pages); 取块缓冲所占页面数
free += atomic_read(&page_cache_size); 加上页缓冲所占页面数
free += nr_free_pages(); 加上自由页面数
free += nr_swap_pages; 加上交换盘的可用页面数, 得到总可分配页面数
return free > pages; 如果大于申请空间,则返回TRUE
}