[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220324070158.22969-7-jaewon31.kim@samsung.com>
Date: Thu, 24 Mar 2022 16:01:56 +0900
From: Jaewon Kim <jaewon31.kim@...sung.com>
To: rppt@...nel.org, vbabka@...e.cz, akpm@...ux-foundation.org
Cc: linux-mm@...ck.org, linux-kernel@...r.kernel.org,
ytk.lee@...sung.com, jaewon31.kim@...il.com,
Jaewon Kim <jaewon31.kim@...sung.com>
Subject: [PATCH 6/8] memblock: recognize late free by checking PageReserved
There are some cases in which reserved pages are freed late after the
initial memblock_free_all of mem_init. We'd like to recognize this
late free pages, and update the memsize information.
Because additional job is needed to a no-map or reusable region, the
late free is usually done to a map and unusable region. So only for map
and unusable region, check if some pages within the region is freed. The
freed pages can be recoginzed by checking if PageReserved flag is clear.
To be fast, let's skip other pages within 1 MB range. And this check is
done when a user wants to see the memsize information.
This is an example. If all pages are freed the region size will be 0.
Before
0x0a2300000-0x0a2400000 0x00100000 ( 1024 KB ) map unusable latefree
After
0x0a2300000-0x0a2300000 0x00000000 ( 0 KB ) map unusable latefree
Signed-off-by: Jaewon Kim <jaewon31.kim@...sung.com>
---
mm/memblock.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/mm/memblock.c b/mm/memblock.c
index aee22dbc2500..597ec7fb5bb2 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -2455,6 +2455,39 @@ static int memsize_rgn_cmp(const void *a, const void *b)
return 0;
}
+/* assume that freed size is always MB aligned */
+static inline void memblock_memsize_check_size(struct memsize_rgn_struct *rgn)
+{
+ phys_addr_t phy, end, freed = 0;
+ bool has_freed = false;
+ struct page *page;
+
+ if (rgn->reusable || rgn->nomap)
+ return;
+
+ /* check the first page of each 1 MB */
+ phy = rgn->base;
+ end = rgn->base + rgn->size;
+ while (phy < end) {
+ unsigned long pfn = __phys_to_pfn(phy);
+
+ if (!pfn_valid(pfn))
+ return;
+ page = pfn_to_page(pfn);
+ if (!has_freed && !PageReserved(page)) {
+ has_freed = true;
+ freed = phy;
+ } else if (has_freed && PageReserved(page)) {
+ has_freed = false;
+ memblock_memsize_free(freed, phy - freed);
+ }
+
+ if (has_freed && (phy + SZ_1M >= end))
+ memblock_memsize_free(freed, end - freed);
+ phy += SZ_1M;
+ }
+}
+
static int memblock_memsize_show(struct seq_file *m, void *private)
{
int i;
@@ -2468,6 +2501,7 @@ static int memblock_memsize_show(struct seq_file *m, void *private)
long size;
rgn = &memsize_rgn[i];
+ memblock_memsize_check_size(rgn);
base = rgn->base;
size = rgn->size;
end = base + size;
--
2.17.1
Powered by blists - more mailing lists