enough

2014-12-27 18:59:14 2 举报
int vm_enough_memory(long pages) { /*函数的主要功能是检查当前可用内存能否满足进程的需要(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. */ unsigned long free; /* Sometimes we want to use more memory than we have. */ if (sysctl_overcommit_memory) return 1; /* The page cache contains buffer pages these days.. */ free = atomic_read(&page_cache_size);//加上页缓冲所占页面数 free += nr_free_pages();//加上自由页面数 free += nr_swap_pages;//加上交换盘的可用页面数, 得到总可分配页面数 /* * This double-counts: the nrpages are both in the page-cache * and in the swapper space. At the same time, this compensates * for the swap-space over-allocation (ie "nr_swap_pages" being * too small. */ free += swapper_space.nrpages;//swapper_space:页面交换缓冲区 /* * The code below doesn't account for free space in the inode * and dentry slab cache, slab cache fragmentation, inodes and * dentries which will become freeable under VM load, etc. * Lets just hope all these (complex) factors balance out... */ free += (dentry_stat.nr_unused * sizeof(struct dentry)) >> PAGE_SHIFT;//逻辑地址右移 free += (inodes_stat.nr_unused * sizeof(struct inode)) >> PAGE_SHIFT;//物理地址右移 return free > pages; }
linux
作者其他创作
大纲/内容
评论
0 条评论
下一页