From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx115.postini.com [74.125.245.115]) by kanga.kvack.org (Postfix) with SMTP id 703F36B004F for ; Wed, 7 Dec 2011 21:38:40 -0500 (EST) Received: by qcsd17 with SMTP id d17so1230585qcs.14 for ; Wed, 07 Dec 2011 18:38:39 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <20111205161443.GA20663@tiehlicka.suse.cz> References: <20111205161443.GA20663@tiehlicka.suse.cz> Date: Thu, 8 Dec 2011 10:38:39 +0800 Message-ID: Subject: Re: Question about __zone_watermark_ok: why there is a "+ 1" in computing free_pages? From: Wang Sheng-Hui Content-Type: multipart/alternative; boundary=0016e686e5aae2217904b38b9036 Sender: owner-linux-mm@kvack.org List-ID: To: Michal Hocko Cc: linux-mm@kvack.org, Mel Gorman , Andrew Morton --0016e686e5aae2217904b38b9036 Content-Type: text/plain; charset=ISO-8859-1 Sorry, Michal. 2011/12/6 Michal Hocko > On Fri 25-11-11 09:21:35, Wang Sheng-Hui wrote: > > In line 1459, we have "free_pages -= (1 << order) + 1;". > > Suppose allocating one 0-order page, here we'll get > > free_pages -= 1 + 1 > > I wonder why there is a "+ 1"? > > Good spot. Check the patch bellow. > --- > From 38a1cf351b111e8791d2db538c8b0b912f5df8b8 Mon Sep 17 00:00:00 2001 > From: Michal Hocko > Date: Mon, 5 Dec 2011 17:04:23 +0100 > Subject: [PATCH] mm: fix off-by-two in __zone_watermark_ok > > 88f5acf8 [mm: page allocator: adjust the per-cpu counter threshold when > memory is low] changed the form how free_pages is calculated but it > forgot that we used to do free_pages - ((1 << order) - 1) so we ended up > with off-by-two when calculating free_pages. > > Spotted-by: Wang Sheng-Hui > Signed-off-by: Michal Hocko > --- > mm/page_alloc.c | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 9dd443d..8a2f1b6 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -1457,7 +1457,7 @@ static bool __zone_watermark_ok(struct zone *z, int > order, unsigned long mark, > long min = mark; > int o; > > - free_pages -= (1 << order) + 1; > + free_pages -= (1 << order) - 1; > I don't understand why there is additional "-1". Use 0-order allocation as example: 0-order page ---- one 4K page free_pages should subtract 1. Here, free_pages will subtract 0? > if (alloc_flags & ALLOC_HIGH) > min -= min / 2; > if (alloc_flags & ALLOC_HARDER) > -- > 1.7.7.3 > > -- > Michal Hocko > SUSE Labs > SUSE LINUX s.r.o. > Lihovarska 1060/12 > 190 00 Praha 9 > Czech Republic > --0016e686e5aae2217904b38b9036 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Sorry, Michal.

2011/12/6 Michal Hocko <mhocko@suse.cz>=
On Fri 25-11-11 09:21:35, Wang Sheng-Hui wrote:
> In line 1459, we have "free_pages -=3D (1 << order) + 1;&qu= ot;.
> Suppose allocating one 0-order page, here we'll get
> =A0 =A0 free_pages -=3D 1 + 1
> I wonder why there is a "+ 1"?

Good spot. Check the patch bellow.
---
>>From 38a1cf351b111e8791d2db538c8b0b912f5df8b8 Mon Sep 17 00:00:00 2001
From: Michal Hocko <mhocko@suse.cz= >
Date: Mon, 5 Dec 2011 17:04:23 +0100
Subject: [PATCH] mm: fix off-by-two in __zone_watermark_ok

88f5acf8 [mm: page allocator: adjust the per-cpu counter threshold when
memory is low] changed the form how free_pages is calculated but it
forgot that we used to do free_pages - ((1 << order) - 1) so we ended= up
with off-by-two when calculating free_pages.

Spotted-by: Wang Sheng-Hui <shhuiw@g= mail.com>
Signed-off-by: Michal Hocko <mhocko@su= se.cz>
---
=A0mm/page_alloc.c | =A0 =A02 +-
=A01 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 9dd443d..8a2f1b6 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1457,7 +1457,7 @@ static bool __zone_watermark_ok(struct zone *z, int o= rder, unsigned long mark,
=A0 =A0 =A0 =A0long min =3D mark;
=A0 =A0 =A0 =A0int o;

- =A0 =A0 =A0 free_pages -=3D (1 << order) + 1;
+ =A0 =A0 =A0 free_pages -=3D (1 << order) - 1;
=
I don't understand why there is additional "-1".
Use 0-order allocation as example:
=A0=A0=A0=A0=A0 0-order page ---- one 4K page
free_pages should subtract 1. Here, free_pages will subtract 0?
=A0
=A0 =A0 =A0 =A0if (alloc_flags & ALLOC_HIGH)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0min -=3D min / 2;
=A0 =A0 =A0 =A0if (alloc_flags & ALLOC_HARDER)
--
1.7.7.3

--
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9
Czech Republic

--0016e686e5aae2217904b38b9036-- -- 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: email@kvack.org