From: Hugh Dickins <hughd@google.com>
To: Dmitry Fink <dmitry.fink@palm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Minchan Kim <minchan.kim@gmail.com>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] mmap: Fix and tidy up overcommit page arithmetic
Date: Mon, 11 Jul 2011 10:33:11 -0700 (PDT) [thread overview]
Message-ID: <alpine.LSU.2.00.1107111030480.1752@sister.anvils> (raw)
In-Reply-To: <1310348510-16957-1-git-send-email-dmitry.fink@palm.com>
On Sun, 10 Jul 2011, Dmitry Fink wrote:
> - shmem pages are not immediately available, but they are not
> potentially available either, even if we swap them out, they will
> just relocate from memory into swap, total amount of immediate and
> potentially available memory is not going to be affected, so we
> shouldn't count them as potentially free in the first place.
>
> - nr_free_pages() is not an expensive operation anymore, there is
> no need to split the decision making in two halves and repeat code.
>
> Signed-off-by: Dmitry Fink <dmitry.fink@palm.com>
> Reviewed-by: Minchan Kim <minchan.kim@gmail.com>
> Acked-by: Hugh Dickins <hughd@google.com>
Just right: thanks a lot for redoing it this way, Dmitry.
> ---
> mm/mmap.c | 34 +++++++++++++---------------------
> mm/nommu.c | 34 +++++++++++++---------------------
> 2 files changed, 26 insertions(+), 42 deletions(-)
>
> diff --git a/mm/mmap.c b/mm/mmap.c
> index d49736f..a65efd4 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -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;
>
> /*
> @@ -136,34 +144,18 @@ 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;
> diff --git a/mm/nommu.c b/mm/nommu.c
> index 9edc897..76f2b4b 100644
> --- a/mm/nommu.c
> +++ b/mm/nommu.c
> @@ -1885,9 +1885,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;
>
> /*
> @@ -1899,34 +1907,18 @@ 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;
> --
> 1.7.6
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
prev parent reply other threads:[~2011-07-11 17:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-03 19:39 [PATCH 1/1] mmap: Don't count shmem pages as free in __vm_enough_memory Dmitry Fink
2011-07-04 0:43 ` Minchan Kim
2011-07-04 3:10 ` Dmitry Fink (Palm GBU)
2011-07-04 3:48 ` Minchan Kim
2011-07-08 22:22 ` Hugh Dickins
2011-07-09 20:42 ` [PATCH] mmap: Fix and tidy up overcommit page arithmetic Dmitry Fink
2011-07-09 20:55 ` Dmitry Fink
2011-07-10 23:08 ` Minchan Kim
2011-07-11 1:41 ` Dmitry Fink
2011-07-11 17:33 ` Hugh Dickins [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LSU.2.00.1107111030480.1752@sister.anvils \
--to=hughd@google.com \
--cc=akpm@linux-foundation.org \
--cc=dmitry.fink@palm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan.kim@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox