linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Sonny Rao <sonnyrao@chromium.org>
Cc: linux-kernel@vger.kernel.org,
	Fengguang Wu <fengguang.wu@intel.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Michal Hocko <mhocko@suse.cz>,
	linux-mm@kvack.org, Mandeep Singh Baines <msb@chromium.org>,
	Johannes Weiner <jweiner@redhat.com>,
	Olof Johansson <olofj@chromium.org>,
	Will Drewry <wad@chromium.org>, Kees Cook <keescook@chromium.org>,
	Aaron Durbin <adurbin@chromium.org>,
	Puneet Kumar <puneetster@chromium.org>
Subject: Re: [PATCH] mm: Fix calculation of dirtyable memory
Date: Thu, 8 Nov 2012 15:37:56 -0800	[thread overview]
Message-ID: <20121108153756.cca505da.akpm@linux-foundation.org> (raw)
In-Reply-To: <1352417135-25122-1-git-send-email-sonnyrao@chromium.org>

On Thu,  8 Nov 2012 15:25:35 -0800
Sonny Rao <sonnyrao@chromium.org> wrote:

> The system uses global_dirtyable_memory() to calculate
> number of dirtyable pages/pages that can be allocated
> to the page cache.  A bug causes an underflow thus making
> the page count look like a big unsigned number.  This in turn
> confuses the dirty writeback throttling to aggressively write
> back pages as they become dirty (usually 1 page at a time).
> 
> Fix is to ensure there is no underflow while doing the math.
> 
> Signed-off-by: Sonny Rao <sonnyrao@chromium.org>
> Signed-off-by: Puneet Kumar <puneetster@chromium.org>
> ---
>  mm/page-writeback.c |   17 +++++++++++++----
>  1 files changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/page-writeback.c b/mm/page-writeback.c
> index 830893b..2a6356c 100644
> --- a/mm/page-writeback.c
> +++ b/mm/page-writeback.c
> @@ -194,11 +194,19 @@ static unsigned long highmem_dirtyable_memory(unsigned long total)
>  	unsigned long x = 0;
>  
>  	for_each_node_state(node, N_HIGH_MEMORY) {
> +		unsigned long nr_pages;
>  		struct zone *z =
>  			&NODE_DATA(node)->node_zones[ZONE_HIGHMEM];
>  
> -		x += zone_page_state(z, NR_FREE_PAGES) +
> -		     zone_reclaimable_pages(z) - z->dirty_balance_reserve;
> +		nr_pages = zone_page_state(z, NR_FREE_PAGES) +
> +			zone_reclaimable_pages(z);
> +		/*
> +		 * Unreclaimable memory (kernel memory or anonymous memory
> +		 * without swap) can bring down the dirtyable pages below
> +		 * the zone's dirty balance reserve.
> +		 */
> +		if (nr_pages >= z->dirty_balance_reserve)
> +			x += nr_pages - z->dirty_balance_reserve;

If the system has two nodes and one is below its dirty_balance_reserve,
we could end up with something like:

	x = 0;
	...
	x += 1000;
	...
	x += -100;

In this case, your fix would cause highmem_dirtyable_memory() to return
1000.  Would it be better to instead return 900?

IOW, we instead add logic along the lines of

	if ((long)x < 0)
		x = 0;
	return x;

--
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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2012-11-08 23:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-08 23:25 [PATCH] mm: Fix calculation of dirtyable memory Sonny Rao
2012-11-08 23:37 ` Andrew Morton [this message]
2012-11-09  0:42   ` [PATCHv2] " Sonny Rao
2012-11-09  0:45     ` Sonny Rao
2012-11-09  0:52       ` Sonny Rao
2012-11-09  2:36         ` Fengguang Wu
2012-11-12 19:35           ` [PATCH] " Sonny Rao
2012-11-12 20:32             ` Johannes Weiner
2012-11-12 21:35               ` [PATCHv4] " Sonny Rao
2012-11-17 20:41                 ` Damien Wyart
2012-11-19 13:40                 ` Johannes Weiner
2012-11-19 18:41                   ` [PATCHv5] " Sonny Rao
2012-11-19 18:44                     ` Sonny Rao
2012-11-19 19:22                       ` Damien Wyart

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=20121108153756.cca505da.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=adurbin@chromium.org \
    --cc=fengguang.wu@intel.com \
    --cc=jweiner@redhat.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.cz \
    --cc=msb@chromium.org \
    --cc=olofj@chromium.org \
    --cc=puneetster@chromium.org \
    --cc=sonnyrao@chromium.org \
    --cc=wad@chromium.org \
    /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;
as well as URLs for NNTP newsgroup(s).