]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm/show_mem: optimize si_meminfo_node by reducing redundant code
authorYe Liu <liuye@kylinos.cn>
Tue, 25 Mar 2025 07:38:03 +0000 (15:38 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 12 May 2025 00:48:08 +0000 (17:48 -0700)
Refactors the si_meminfo_node() function by reducing redundant code and
improving readability.

Moved the calculation of managed_pages inside the existing loop that
processes pgdat->node_zones, eliminating the need for a separate loop.

Simplified the logic by removing unnecessary preprocessor conditionals.

Ensured that both totalram, totalhigh, and other memory statistics are
consistently set without duplication.

This change results in cleaner and more efficient code without altering
functionality.

Link: https://lkml.kernel.org/r/20250325073803.852594-1-ye.liu@linux.dev
Signed-off-by: Ye Liu <liuye@kylinos.cn>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/show_mem.c

index 6af13bcd2ab36e024177ee68ba122ac6cff9dd42..ad373b4b6e394c1a2bcf26b20e7a18e8467dc5fc 100644 (file)
@@ -94,26 +94,20 @@ void si_meminfo_node(struct sysinfo *val, int nid)
        unsigned long free_highpages = 0;
        pg_data_t *pgdat = NODE_DATA(nid);
 
-       for (zone_type = 0; zone_type < MAX_NR_ZONES; zone_type++)
-               managed_pages += zone_managed_pages(&pgdat->node_zones[zone_type]);
-       val->totalram = managed_pages;
-       val->sharedram = node_page_state(pgdat, NR_SHMEM);
-       val->freeram = sum_zone_node_page_state(nid, NR_FREE_PAGES);
-#ifdef CONFIG_HIGHMEM
        for (zone_type = 0; zone_type < MAX_NR_ZONES; zone_type++) {
                struct zone *zone = &pgdat->node_zones[zone_type];
-
+               managed_pages += zone_managed_pages(zone);
                if (is_highmem(zone)) {
                        managed_highpages += zone_managed_pages(zone);
                        free_highpages += zone_page_state(zone, NR_FREE_PAGES);
                }
        }
+
+       val->totalram = managed_pages;
+       val->sharedram = node_page_state(pgdat, NR_SHMEM);
+       val->freeram = sum_zone_node_page_state(nid, NR_FREE_PAGES);
        val->totalhigh = managed_highpages;
        val->freehigh = free_highpages;
-#else
-       val->totalhigh = managed_highpages;
-       val->freehigh = free_highpages;
-#endif
        val->mem_unit = PAGE_SIZE;
 }
 #endif