@@ -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;
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@samsung.com> --- mm/memblock.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)