Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 258948
b: refs/heads/master
c: c15bef3
h: refs/heads/master
v: v3
  • Loading branch information
Dmitry Fink authored and Linus Torvalds committed Jul 26, 2011
1 parent e5e30ce commit bdeb918
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 43 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: c9d8c3d0896bfa5b57531ecc41a85ffbc6d87dbe
refs/heads/master: c15bef3099c346f2124367bff46954b59e13c3ee
34 changes: 13 additions & 21 deletions trunk/mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,17 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
return 0;

if (sysctl_overcommit_memory == OVERCOMMIT_GUESS) {
unsigned long n;
free = global_page_state(NR_FREE_PAGES);
free += global_page_state(NR_FILE_PAGES);

/*
* shmem pages shouldn't be counted as free in this
* case, they can't be purged, only swapped out, and
* that won't affect the overall amount of available
* memory in the system.
*/
free -= global_page_state(NR_SHMEM);

free = global_page_state(NR_FILE_PAGES);
free += nr_swap_pages;

/*
Expand All @@ -135,35 +143,19 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
*/
free += global_page_state(NR_SLAB_RECLAIMABLE);

/*
* Leave the last 3% for root
*/
if (!cap_sys_admin)
free -= free / 32;

if (free > pages)
return 0;

/*
* nr_free_pages() is very expensive on large systems,
* only call if we're about to fail.
*/
n = nr_free_pages();

/*
* Leave reserved pages. The pages are not for anonymous pages.
*/
if (n <= totalreserve_pages)
if (free <= totalreserve_pages)
goto error;
else
n -= totalreserve_pages;
free -= totalreserve_pages;

/*
* Leave the last 3% for root
*/
if (!cap_sys_admin)
n -= n / 32;
free += n;
free -= free / 32;

if (free > pages)
return 0;
Expand Down
34 changes: 13 additions & 21 deletions trunk/mm/nommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1884,9 +1884,17 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
return 0;

if (sysctl_overcommit_memory == OVERCOMMIT_GUESS) {
unsigned long n;
free = global_page_state(NR_FREE_PAGES);
free += global_page_state(NR_FILE_PAGES);

/*
* shmem pages shouldn't be counted as free in this
* case, they can't be purged, only swapped out, and
* that won't affect the overall amount of available
* memory in the system.
*/
free -= global_page_state(NR_SHMEM);

free = global_page_state(NR_FILE_PAGES);
free += nr_swap_pages;

/*
Expand All @@ -1897,35 +1905,19 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
*/
free += global_page_state(NR_SLAB_RECLAIMABLE);

/*
* Leave the last 3% for root
*/
if (!cap_sys_admin)
free -= free / 32;

if (free > pages)
return 0;

/*
* nr_free_pages() is very expensive on large systems,
* only call if we're about to fail.
*/
n = nr_free_pages();

/*
* Leave reserved pages. The pages are not for anonymous pages.
*/
if (n <= totalreserve_pages)
if (free <= totalreserve_pages)
goto error;
else
n -= totalreserve_pages;
free -= totalreserve_pages;

/*
* Leave the last 3% for root
*/
if (!cap_sys_admin)
n -= n / 32;
free += n;
free -= free / 32;

if (free > pages)
return 0;
Expand Down

0 comments on commit bdeb918

Please sign in to comment.