From: "Yang Shi" <yang.s@alibaba-inc.com>
To: cl@linux.com, penberg@kernel.org, rientjes@google.com,
iamjoonsoo.kim@lge.com, akpm@linux-foundation.org,
mhocko@kernel.org
Cc: "Yang Shi" <yang.s@alibaba-inc.com>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>
Subject: [PATCH 1/2] mm: extract common code for calculating total memory size
Date: Thu, 26 Oct 2017 06:48:59 +0800 [thread overview]
Message-ID: <1508971740-118317-2-git-send-email-yang.s@alibaba-inc.com> (raw)
In-Reply-To: <1508971740-118317-1-git-send-email-yang.s@alibaba-inc.com>
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 <yang.s@alibaba-inc.com>
---
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
next prev parent reply other threads:[~2017-10-25 22:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-25 22:48 [PATCH 0/2 -mmotm] oom: show single slab cache in oom whose size > 10% of total system memory Yang Shi
2017-10-25 22:48 ` Yang Shi [this message]
2017-10-27 10:00 ` [PATCH 1/2] mm: extract common code for calculating total memory size Christopher Lameter
2017-10-27 16:51 ` Yang Shi
2017-10-31 16:45 ` Yang Shi
2017-10-25 22:49 ` [PATCH 2/2] mm: oom: dump single excessive slab cache when oom Yang Shi
2017-10-26 14:53 ` Michal Hocko
2017-10-26 16:15 ` Yang Shi
2017-10-26 16:27 ` Michal Hocko
2017-10-26 17:14 ` Michal Hocko
2017-10-31 16:47 ` Yang Shi
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=1508971740-118317-2-git-send-email-yang.s@alibaba-inc.com \
--to=yang.s@alibaba-inc.com \
--cc=akpm@linux-foundation.org \
--cc=cl@linux.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=penberg@kernel.org \
--cc=rientjes@google.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;
as well as URLs for NNTP newsgroup(s).