All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm, page_alloc: fix potential false positive in __zone_watermark_ok
@ 2017-11-02 12:50 ` Vlastimil Babka
  0 siblings, 0 replies; 4+ messages in thread
From: Vlastimil Babka @ 2017-11-02 12:50 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, linux-kernel, Mel Gorman, Joonsoo Kim, Rik van Riel,
	David Rientjes, Johannes Weiner, Vlastimil Babka

Since commit 97a16fc82a7c ("mm, page_alloc: only enforce watermarks for order-0
allocations"), __zone_watermark_ok() check for high-order allocations will
shortcut per-migratetype free list checks for ALLOC_HARDER allocations, and
return true as long as there's free page of any migratetype. The intention is
that ALLOC_HARDER can allocate from MIGRATE_HIGHATOMIC free lists, while normal
allocations can't.

However, as a side effect, the watermark check will then also return true when
there are pages only on the MIGRATE_ISOLATE list, or (prior to CMA conversion
to ZONE_MOVABLE) on the MIGRATE_CMA list. Since the allocation cannot actually
obtain isolated pages, and might not be able to obtain CMA pages, this can
result in a false positive.

The condition should be rare and perhaps the outcome is not a fatal one. Still,
it's better if the watermark check is correct. There also shouldn't be a
performance tradeoff here.

Fixes: 97a16fc82a7c ("mm, page_alloc: only enforce watermarks for order-0 allocations")
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
---
 mm/page_alloc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 79cdac1fee42..f43039945148 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3032,9 +3032,6 @@ bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark,
 		if (!area->nr_free)
 			continue;
 
-		if (alloc_harder)
-			return true;
-
 		for (mt = 0; mt < MIGRATE_PCPTYPES; mt++) {
 			if (!list_empty(&area->free_list[mt]))
 				return true;
@@ -3044,6 +3041,9 @@ bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark,
 		if (!list_empty(&area->free_list[MIGRATE_CMA]))
 			return true;
 #endif
+		if (alloc_harder &&
+			!list_empty(&area->free_list[MIGRATE_HIGHATOMIC]))
+			return true;
 	}
 	return false;
 }
-- 
2.14.3

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

* [PATCH] mm, page_alloc: fix potential false positive in __zone_watermark_ok
@ 2017-11-02 12:50 ` Vlastimil Babka
  0 siblings, 0 replies; 4+ messages in thread
From: Vlastimil Babka @ 2017-11-02 12:50 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, linux-kernel, Mel Gorman, Joonsoo Kim, Rik van Riel,
	David Rientjes, Johannes Weiner, Vlastimil Babka

Since commit 97a16fc82a7c ("mm, page_alloc: only enforce watermarks for order-0
allocations"), __zone_watermark_ok() check for high-order allocations will
shortcut per-migratetype free list checks for ALLOC_HARDER allocations, and
return true as long as there's free page of any migratetype. The intention is
that ALLOC_HARDER can allocate from MIGRATE_HIGHATOMIC free lists, while normal
allocations can't.

However, as a side effect, the watermark check will then also return true when
there are pages only on the MIGRATE_ISOLATE list, or (prior to CMA conversion
to ZONE_MOVABLE) on the MIGRATE_CMA list. Since the allocation cannot actually
obtain isolated pages, and might not be able to obtain CMA pages, this can
result in a false positive.

The condition should be rare and perhaps the outcome is not a fatal one. Still,
it's better if the watermark check is correct. There also shouldn't be a
performance tradeoff here.

Fixes: 97a16fc82a7c ("mm, page_alloc: only enforce watermarks for order-0 allocations")
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
---
 mm/page_alloc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 79cdac1fee42..f43039945148 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3032,9 +3032,6 @@ bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark,
 		if (!area->nr_free)
 			continue;
 
-		if (alloc_harder)
-			return true;
-
 		for (mt = 0; mt < MIGRATE_PCPTYPES; mt++) {
 			if (!list_empty(&area->free_list[mt]))
 				return true;
@@ -3044,6 +3041,9 @@ bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark,
 		if (!list_empty(&area->free_list[MIGRATE_CMA]))
 			return true;
 #endif
+		if (alloc_harder &&
+			!list_empty(&area->free_list[MIGRATE_HIGHATOMIC]))
+			return true;
 	}
 	return false;
 }
-- 
2.14.3

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

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

* Re: [PATCH] mm, page_alloc: fix potential false positive in __zone_watermark_ok
  2017-11-02 12:50 ` Vlastimil Babka
@ 2017-11-02 13:23   ` Mel Gorman
  -1 siblings, 0 replies; 4+ messages in thread
From: Mel Gorman @ 2017-11-02 13:23 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: Andrew Morton, linux-mm, linux-kernel, Joonsoo Kim, Rik van Riel,
	David Rientjes, Johannes Weiner

On Thu, Nov 02, 2017 at 01:50:01PM +0100, Vlastimil Babka wrote:
> Since commit 97a16fc82a7c ("mm, page_alloc: only enforce watermarks for order-0
> allocations"), __zone_watermark_ok() check for high-order allocations will
> shortcut per-migratetype free list checks for ALLOC_HARDER allocations, and
> return true as long as there's free page of any migratetype. The intention is
> that ALLOC_HARDER can allocate from MIGRATE_HIGHATOMIC free lists, while normal
> allocations can't.
> 
> However, as a side effect, the watermark check will then also return true when
> there are pages only on the MIGRATE_ISOLATE list, or (prior to CMA conversion
> to ZONE_MOVABLE) on the MIGRATE_CMA list. Since the allocation cannot actually
> obtain isolated pages, and might not be able to obtain CMA pages, this can
> result in a false positive.
> 
> The condition should be rare and perhaps the outcome is not a fatal one. Still,
> it's better if the watermark check is correct. There also shouldn't be a
> performance tradeoff here.
> 
> Fixes: 97a16fc82a7c ("mm, page_alloc: only enforce watermarks for order-0 allocations")
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>

That outcome shouldn't be fatal or even misleading as the subsequent
allocation attempt should fail due to not finding pages on an
appropriate list. Still, as you say, the watermark check should not be
misleading.

Acked-by: Mel Gorman <mgorman@techsingularity.net>

-- 
Mel Gorman
SUSE Labs

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

* Re: [PATCH] mm, page_alloc: fix potential false positive in __zone_watermark_ok
@ 2017-11-02 13:23   ` Mel Gorman
  0 siblings, 0 replies; 4+ messages in thread
From: Mel Gorman @ 2017-11-02 13:23 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: Andrew Morton, linux-mm, linux-kernel, Joonsoo Kim, Rik van Riel,
	David Rientjes, Johannes Weiner

On Thu, Nov 02, 2017 at 01:50:01PM +0100, Vlastimil Babka wrote:
> Since commit 97a16fc82a7c ("mm, page_alloc: only enforce watermarks for order-0
> allocations"), __zone_watermark_ok() check for high-order allocations will
> shortcut per-migratetype free list checks for ALLOC_HARDER allocations, and
> return true as long as there's free page of any migratetype. The intention is
> that ALLOC_HARDER can allocate from MIGRATE_HIGHATOMIC free lists, while normal
> allocations can't.
> 
> However, as a side effect, the watermark check will then also return true when
> there are pages only on the MIGRATE_ISOLATE list, or (prior to CMA conversion
> to ZONE_MOVABLE) on the MIGRATE_CMA list. Since the allocation cannot actually
> obtain isolated pages, and might not be able to obtain CMA pages, this can
> result in a false positive.
> 
> The condition should be rare and perhaps the outcome is not a fatal one. Still,
> it's better if the watermark check is correct. There also shouldn't be a
> performance tradeoff here.
> 
> Fixes: 97a16fc82a7c ("mm, page_alloc: only enforce watermarks for order-0 allocations")
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>

That outcome shouldn't be fatal or even misleading as the subsequent
allocation attempt should fail due to not finding pages on an
appropriate list. Still, as you say, the watermark check should not be
misleading.

Acked-by: Mel Gorman <mgorman@techsingularity.net>

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

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

end of thread, other threads:[~2017-11-02 13:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-02 12:50 [PATCH] mm, page_alloc: fix potential false positive in __zone_watermark_ok Vlastimil Babka
2017-11-02 12:50 ` Vlastimil Babka
2017-11-02 13:23 ` Mel Gorman
2017-11-02 13:23   ` Mel Gorman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.