linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Question about __zone_watermark_ok: why there is a "+ 1" in computing free_pages?
@ 2011-11-25  1:21 Wang Sheng-Hui
  2011-12-05 16:14 ` Michal Hocko
  0 siblings, 1 reply; 6+ messages in thread
From: Wang Sheng-Hui @ 2011-11-25  1:21 UTC (permalink / raw)
  To: linux-mm, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1309 bytes --]

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"?

1448/*
1449 * Return true if free pages are above 'mark'. This takes into account
the order
1450 * of the allocation.
1451 */
1452static bool __zone_watermark_ok(struct zone *z, int order, unsigned
long mark,
1453                      int classzone_idx, int alloc_flags, long
free_pages)
1454{
1455        /* free_pages my go negative - that's OK */
1456        long min = mark;
1457        int o;
1458
1459        free_pages -= (1 << order) + 1;
1460        if (alloc_flags & ALLOC_HIGH)
1461                min -= min / 2;
1462        if (alloc_flags & ALLOC_HARDER)
1463                min -= min / 4;
1464
1465        if (free_pages <= min + z->lowmem_reserve[classzone_idx])
1466                return false;
1467        for (o = 0; o < order; o++) {
1468                /* At the next order, this order's pages become
unavailable */
1469                free_pages -= z->free_area[o].nr_free << o;
1470
1471                /* Require fewer higher order pages to be free */
1472                min >>= 1;
1473
1474                if (free_pages <= min)
1475                        return false;
1476        }
1477        return true;
1478}

[-- Attachment #2: Type: text/html, Size: 1525 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about __zone_watermark_ok: why there is a "+ 1" in computing free_pages?
  2011-11-25  1:21 Question about __zone_watermark_ok: why there is a "+ 1" in computing free_pages? Wang Sheng-Hui
@ 2011-12-05 16:14 ` Michal Hocko
  2011-12-05 17:06   ` Mel Gorman
                     ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Michal Hocko @ 2011-12-05 16:14 UTC (permalink / raw)
  To: Wang Sheng-Hui; +Cc: linux-mm, linux-kernel, Mel Gorman, Andrew Morton

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.
---

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about __zone_watermark_ok: why there is a "+ 1" in computing free_pages?
  2011-12-05 16:14 ` Michal Hocko
@ 2011-12-05 17:06   ` Mel Gorman
  2011-12-08  2:38   ` Wang Sheng-Hui
  2011-12-08 16:24   ` KOSAKI Motohiro
  2 siblings, 0 replies; 6+ messages in thread
From: Mel Gorman @ 2011-12-05 17:06 UTC (permalink / raw)
  To: Michal Hocko; +Cc: Wang Sheng-Hui, linux-mm, linux-kernel, Andrew Morton

On Mon, Dec 05, 2011 at 05:14:43PM +0100, Michal Hocko wrote:
> 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@gmail.com>
> Signed-off-by: Michal Hocko <mhocko@suse.cz>

Acked-by: Mel Gorman <mgorman@suse.de>

-- 
Mel Gorman
SUSE Labs

--
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>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about __zone_watermark_ok: why there is a "+ 1" in computing free_pages?
  2011-12-05 16:14 ` Michal Hocko
  2011-12-05 17:06   ` Mel Gorman
@ 2011-12-08  2:38   ` Wang Sheng-Hui
  2011-12-08  8:05     ` Michal Hocko
  2011-12-08 16:24   ` KOSAKI Motohiro
  2 siblings, 1 reply; 6+ messages in thread
From: Wang Sheng-Hui @ 2011-12-08  2:38 UTC (permalink / raw)
  To: Michal Hocko; +Cc: linux-mm, Mel Gorman, Andrew Morton

[-- Attachment #1: Type: text/plain, Size: 1789 bytes --]

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 -= (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 <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@gmail.com>
> Signed-off-by: Michal Hocko <mhocko@suse.cz>
> ---
>  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
>

[-- Attachment #2: Type: text/html, Size: 2628 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about __zone_watermark_ok: why there is a "+ 1" in computing free_pages?
  2011-12-08  2:38   ` Wang Sheng-Hui
@ 2011-12-08  8:05     ` Michal Hocko
  0 siblings, 0 replies; 6+ messages in thread
From: Michal Hocko @ 2011-12-08  8:05 UTC (permalink / raw)
  To: Wang Sheng-Hui; +Cc: linux-mm, Mel Gorman, Andrew Morton

On Thu 08-12-11 10:38:39, Wang Sheng-Hui wrote:
> 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 -= (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 <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@gmail.com>
> > Signed-off-by: Michal Hocko <mhocko@suse.cz>
> > ---
> >  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?

Check out all the conditions for free_pages...

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

--
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>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about __zone_watermark_ok: why there is a "+ 1" in computing free_pages?
  2011-12-05 16:14 ` Michal Hocko
  2011-12-05 17:06   ` Mel Gorman
  2011-12-08  2:38   ` Wang Sheng-Hui
@ 2011-12-08 16:24   ` KOSAKI Motohiro
  2 siblings, 0 replies; 6+ messages in thread
From: KOSAKI Motohiro @ 2011-12-08 16:24 UTC (permalink / raw)
  To: Michal Hocko
  Cc: Wang Sheng-Hui, linux-mm, linux-kernel, Mel Gorman, Andrew Morton

(12/5/11 11:14 AM), Michal Hocko wrote:
> 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<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@gmail.com>
> Signed-off-by: Michal Hocko<mhocko@suse.cz>
> ---
>   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;
>   	if (alloc_flags&  ALLOC_HIGH)
>   		min -= min / 2;
>   	if (alloc_flags&  ALLOC_HARDER)

Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>


--
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>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-12-08 16:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-25  1:21 Question about __zone_watermark_ok: why there is a "+ 1" in computing free_pages? Wang Sheng-Hui
2011-12-05 16:14 ` Michal Hocko
2011-12-05 17:06   ` Mel Gorman
2011-12-08  2:38   ` Wang Sheng-Hui
2011-12-08  8:05     ` Michal Hocko
2011-12-08 16:24   ` KOSAKI Motohiro

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).