From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752040AbdJYWt2 (ORCPT ); Wed, 25 Oct 2017 18:49:28 -0400 Received: from out0-241.mail.aliyun.com ([140.205.0.241]:50313 "EHLO out0-241.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751775AbdJYWtX (ORCPT ); Wed, 25 Oct 2017 18:49:23 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e02c03300;MF=yang.s@alibaba-inc.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---.9EaJhLx_1508971749; From: "Yang Shi" To: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, mhocko@kernel.org Cc: "Yang Shi" , , Subject: [PATCH 1/2] mm: extract common code for calculating total memory size Date: Thu, 26 Oct 2017 06:48:59 +0800 Message-Id: <1508971740-118317-2-git-send-email-yang.s@alibaba-inc.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1508971740-118317-1-git-send-email-yang.s@alibaba-inc.com> References: <1508971740-118317-1-git-send-email-yang.s@alibaba-inc.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Total memory size is needed by unreclaimable slub oom to check if significant memory is used by a single slab. But, the caculation work is done in show_mem(), so extracting the common code in order to share with others. Signed-off-by: Yang Shi --- include/linux/mm.h | 25 +++++++++++++++++++++++++ lib/show_mem.c | 20 +------------------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 935c4d4..e21b81e 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2050,6 +2050,31 @@ extern int __meminit __early_pfn_to_nid(unsigned long pfn, static inline void zero_resv_unavail(void) {} #endif +static inline void calc_mem_size(unsigned long *total, unsigned long *reserved, + unsigned long *highmem) +{ + pg_data_t *pgdat; + + for_each_online_pgdat(pgdat) { + unsigned long flags; + int zoneid; + + pgdat_resize_lock(pgdat, &flags); + for (zoneid = 0; zoneid < MAX_NR_ZONES; zoneid++) { + struct zone *zone = &pgdat->node_zones[zoneid]; + if (!populated_zone(zone)) + continue; + + *total += zone->present_pages; + *reserved += zone->present_pages - zone->managed_pages; + + if (is_highmem_idx(zoneid)) + *highmem += zone->present_pages; + } + pgdat_resize_unlock(pgdat, &flags); + } +} + extern void set_dma_reserve(unsigned long new_dma_reserve); extern void memmap_init_zone(unsigned long, int, unsigned long, unsigned long, enum memmap_context); diff --git a/lib/show_mem.c b/lib/show_mem.c index 0beaa1d..115475e 100644 --- a/lib/show_mem.c +++ b/lib/show_mem.c @@ -11,30 +11,12 @@ void show_mem(unsigned int filter, nodemask_t *nodemask) { - pg_data_t *pgdat; unsigned long total = 0, reserved = 0, highmem = 0; printk("Mem-Info:\n"); show_free_areas(filter, nodemask); - for_each_online_pgdat(pgdat) { - unsigned long flags; - int zoneid; - - pgdat_resize_lock(pgdat, &flags); - for (zoneid = 0; zoneid < MAX_NR_ZONES; zoneid++) { - struct zone *zone = &pgdat->node_zones[zoneid]; - if (!populated_zone(zone)) - continue; - - total += zone->present_pages; - reserved += zone->present_pages - zone->managed_pages; - - if (is_highmem_idx(zoneid)) - highmem += zone->present_pages; - } - pgdat_resize_unlock(pgdat, &flags); - } + calc_mem_size(&total, &reserved, &highmem); printk("%lu pages RAM\n", total); printk("%lu pages HighMem/MovableOnly\n", highmem); -- 1.8.3.1