linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH for v5.9] mm/page_alloc: handle a missing case for memalloc_nocma_{save/restore} APIs
@ 2020-08-25  4:59 js1304
  2020-08-25  5:10 ` Andrew Morton
  2020-08-25  9:43 ` Vlastimil Babka
  0 siblings, 2 replies; 13+ messages in thread
From: js1304 @ 2020-08-25  4:59 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, linux-kernel, Michal Hocko, Vlastimil Babka,
	Aneesh Kumar K . V, kernel-team, Joonsoo Kim

From: Joonsoo Kim <iamjoonsoo.kim@lge.com>

memalloc_nocma_{save/restore} APIs can be used to skip page allocation
on CMA area, but, there is a missing case and the page on CMA area could
be allocated even if APIs are used. This patch handles this case to fix
the potential issue.

Missing case is an allocation from the pcplist. MIGRATE_MOVABLE pcplist
could have the pages on CMA area so we need to skip it if ALLOC_CMA isn't
specified.

This patch implements this behaviour by checking allocated page from
the pcplist rather than skipping an allocation from the pcplist entirely.
Skipping the pcplist entirely would result in a mismatch between watermark
check and actual page allocation. And, it requires to break current code
layering that order-0 page is always handled by the pcplist. I'd prefer
to avoid it so this patch uses different way to skip CMA page allocation
from the pcplist.

Fixes: 8510e69c8efe (mm/page_alloc: fix memalloc_nocma_{save/restore} APIs)
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
---
 mm/page_alloc.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 0e2bab4..c4abf58 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3341,6 +3341,22 @@ static struct page *rmqueue_pcplist(struct zone *preferred_zone,
 	pcp = &this_cpu_ptr(zone->pageset)->pcp;
 	list = &pcp->lists[migratetype];
 	page = __rmqueue_pcplist(zone,  migratetype, alloc_flags, pcp, list);
+#ifdef CONFIG_CMA
+	if (page) {
+		int mt = get_pcppage_migratetype(page);
+
+		/*
+		 * pcp could have the pages on CMA area and we need to skip it
+		 * when !ALLOC_CMA. Free all pcplist and retry allocation.
+		 */
+		if (is_migrate_cma(mt) && !(alloc_flags & ALLOC_CMA)) {
+			list_add(&page->lru, &pcp->lists[migratetype]);
+			pcp->count++;
+			free_pcppages_bulk(zone, pcp->count, pcp);
+			page = __rmqueue_pcplist(zone, migratetype, alloc_flags, pcp, list);
+		}
+	}
+#endif
 	if (page) {
 		__count_zid_vm_events(PGALLOC, page_zonenum(page), 1);
 		zone_statistics(preferred_zone, zone);
-- 
2.7.4



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

end of thread, other threads:[~2020-09-25  8:58 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-25  4:59 [PATCH for v5.9] mm/page_alloc: handle a missing case for memalloc_nocma_{save/restore} APIs js1304
2020-08-25  5:10 ` Andrew Morton
2020-08-25  5:34   ` Joonsoo Kim
2020-08-26  0:42     ` Andrew Morton
2020-08-26  5:21       ` Joonsoo Kim
2020-08-25  9:43 ` Vlastimil Babka
2020-08-26  5:12   ` Joonsoo Kim
2020-08-27 12:15     ` Vlastimil Babka
2020-08-27 13:35     ` Mel Gorman
2020-08-27 23:54       ` Joonsoo Kim
2020-09-25  4:59         ` Joonsoo Kim
2020-09-25  8:55           ` Vlastimil Babka
2020-09-25  8:58             ` Joonsoo Kim

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