From: Haiqiang Gong <Haiqiang.Gong@mediatek.com>
To: <linux-kernel@vger.kernel.org>
Cc: <haiqiang.gong@mediatek.com>, <mike.zhang@mediatek.com>,
Andrew Morton <akpm@linux-foundation.org>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>, <linux-mm@kvack.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-mediatek@lists.infradead.org>,
Haiqiang Gong <Haiqiang.Gong@mediatek.com>
Subject: [PATCH] mm/compaction: add check mechanism to avoid cma alloc fail
Date: Mon, 22 Jan 2024 10:23:17 +0800 [thread overview]
Message-ID: <20240122022317.30091-1-Haiqiang.Gong@mediatek.com> (raw)
cma alloc may fail when we doing cma alloc/free test on kernel 5.10/5.15.
We found that the next memory cannot be migrated because of the alloc of
fs as next backtrace:
__alloc_pages_nodemask
pagecache_get_page
grow_dev_page
__getblk_gfp
ext4_sb_breadahead_unmovable
__ext4_get_inode_loc
__ext4_iget
ext4_lookup
__lookup_slow
walk_component
path_lookupat
filename_lookup
vfs_statx
This kind of unmovable memory is not placed in the cma buffer when kernel
memory alloc but is migrated in by kcompactd when the kernel migration.
It will cause memory can't be migrate when cma alloc.
Add check mechanism in the compaction_alloc() where kcompaced alloc for
memory. Will return NULL and give up this memory migration if the
allocated memory is in the cma buffer and the memory is unmovable.
Signed-off-by: Haiqiang Gong <Haiqiang.Gong@mediatek.com>
---
mm/compaction.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/mm/compaction.c b/mm/compaction.c
index 27ada42924d5..29c0661adc22 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -25,6 +25,11 @@
#include <linux/psi.h>
#include "internal.h"
+#ifdef CONFIG_CMA
+#include <linux/cma.h>
+#include "cma.h"
+#endif
+
#ifdef CONFIG_COMPACTION
/*
* Fragmentation score check interval for proactive compaction purposes.
@@ -1758,6 +1763,33 @@ static void isolate_freepages(struct compact_control *cc)
split_map_pages(freelist);
}
+#ifdef CONFIG_CMA
+static bool is_in_cma_range(struct folio *folio)
+{
+ int i;
+ unsigned long pfn = 0;
+ struct page *page = folio_page(folio, 0);
+
+ pfn = page_to_pfn(page);
+ for (i = 0; i < cma_area_count; i++) {
+ struct cma *cma = &cma_areas[i];
+
+ if (cma->base_pfn <= pfn && (cma->base_pfn + cma->count) > pfn)
+ return true;
+ }
+
+ return false;
+}
+
+static bool forbid_move_to_cma_range(struct folio *src, struct folio *dst)
+{
+ if (folio_mapping(src) && is_in_cma_range(dst))
+ return true;
+
+ return false;
+}
+#endif
+
/*
* This is a migrate-callback that "allocates" freepages by taking pages
* from the isolated freelists in the block we are migrating to.
@@ -1775,6 +1807,12 @@ static struct folio *compaction_alloc(struct folio *src, unsigned long data)
}
dst = list_entry(cc->freepages.next, struct folio, lru);
+#ifdef CONFIG_CMA
+ if (forbid_move_to_cma_range(src, dst)) {
+ pr_notice("kcompactd: could not move non-cma memory to cma buffer\n");
+ return NULL;
+ }
+#endif
list_del(&dst->lru);
cc->nr_freepages--;
--
2.25.1
next reply other threads:[~2024-01-22 3:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-22 2:23 Haiqiang Gong [this message]
2024-01-22 3:31 ` Matthew Wilcox
2024-01-23 12:14 ` 回复: " Haiqiang Gong (龚海强)
2024-01-24 7:20 ` Haiqiang Gong (龚海强)
2024-01-24 18:40 ` Matthew Wilcox
2024-01-27 11:03 ` Haiqiang Gong (龚海强)
2024-01-27 16:23 ` Matthew Wilcox
2024-01-22 6:59 ` Baolin Wang
2024-01-24 1:41 ` 回复: " Haiqiang Gong (龚海强)
2024-01-24 7:37 ` Haiqiang Gong (龚海强)
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=20240122022317.30091-1-Haiqiang.Gong@mediatek.com \
--to=haiqiang.gong@mediatek.com \
--cc=akpm@linux-foundation.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-mm@kvack.org \
--cc=matthias.bgg@gmail.com \
--cc=mike.zhang@mediatek.com \
/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