Commit c07e02db authored by Martin Hicks's avatar Martin Hicks Committed by Linus Torvalds

[PATCH] VM: add page_state info to per-node meminfo

Add page_state info to the per-node meminfo file in sysfs.  This is mostly
just for informational purposes.

The lack of this information was brought up recently during a discussion
regarding pagecache clearing, and I put this patch together to test out one
of the suggestions.

It seems like interesting info to have, so I'm submitting the patch.
Signed-off-by: default avatarMartin Hicks <mort@sgi.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent e070ad49
...@@ -39,13 +39,25 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf) ...@@ -39,13 +39,25 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
int n; int n;
int nid = dev->id; int nid = dev->id;
struct sysinfo i; struct sysinfo i;
struct page_state ps;
unsigned long inactive; unsigned long inactive;
unsigned long active; unsigned long active;
unsigned long free; unsigned long free;
si_meminfo_node(&i, nid); si_meminfo_node(&i, nid);
get_page_state_node(&ps, nid);
__get_zone_counts(&active, &inactive, &free, NODE_DATA(nid)); __get_zone_counts(&active, &inactive, &free, NODE_DATA(nid));
/* Check for negative values in these approximate counters */
if ((long)ps.nr_dirty < 0)
ps.nr_dirty = 0;
if ((long)ps.nr_writeback < 0)
ps.nr_writeback = 0;
if ((long)ps.nr_mapped < 0)
ps.nr_mapped = 0;
if ((long)ps.nr_slab < 0)
ps.nr_slab = 0;
n = sprintf(buf, "\n" n = sprintf(buf, "\n"
"Node %d MemTotal: %8lu kB\n" "Node %d MemTotal: %8lu kB\n"
"Node %d MemFree: %8lu kB\n" "Node %d MemFree: %8lu kB\n"
...@@ -55,7 +67,11 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf) ...@@ -55,7 +67,11 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
"Node %d HighTotal: %8lu kB\n" "Node %d HighTotal: %8lu kB\n"
"Node %d HighFree: %8lu kB\n" "Node %d HighFree: %8lu kB\n"
"Node %d LowTotal: %8lu kB\n" "Node %d LowTotal: %8lu kB\n"
"Node %d LowFree: %8lu kB\n", "Node %d LowFree: %8lu kB\n"
"Node %d Dirty: %8lu kB\n"
"Node %d Writeback: %8lu kB\n"
"Node %d Mapped: %8lu kB\n"
"Node %d Slab: %8lu kB\n",
nid, K(i.totalram), nid, K(i.totalram),
nid, K(i.freeram), nid, K(i.freeram),
nid, K(i.totalram - i.freeram), nid, K(i.totalram - i.freeram),
...@@ -64,7 +80,11 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf) ...@@ -64,7 +80,11 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
nid, K(i.totalhigh), nid, K(i.totalhigh),
nid, K(i.freehigh), nid, K(i.freehigh),
nid, K(i.totalram - i.totalhigh), nid, K(i.totalram - i.totalhigh),
nid, K(i.freeram - i.freehigh)); nid, K(i.freeram - i.freehigh),
nid, K(ps.nr_dirty),
nid, K(ps.nr_writeback),
nid, K(ps.nr_mapped),
nid, K(ps.nr_slab));
n += hugetlb_report_node_meminfo(nid, buf + n); n += hugetlb_report_node_meminfo(nid, buf + n);
return n; return n;
} }
......
...@@ -134,6 +134,7 @@ struct page_state { ...@@ -134,6 +134,7 @@ struct page_state {
}; };
extern void get_page_state(struct page_state *ret); extern void get_page_state(struct page_state *ret);
extern void get_page_state_node(struct page_state *ret, int node);
extern void get_full_page_state(struct page_state *ret); extern void get_full_page_state(struct page_state *ret);
extern unsigned long __read_page_state(unsigned long offset); extern unsigned long __read_page_state(unsigned long offset);
extern void __mod_page_state(unsigned long offset, unsigned long delta); extern void __mod_page_state(unsigned long offset, unsigned long delta);
......
...@@ -1130,19 +1130,20 @@ EXPORT_SYMBOL(nr_pagecache); ...@@ -1130,19 +1130,20 @@ EXPORT_SYMBOL(nr_pagecache);
DEFINE_PER_CPU(long, nr_pagecache_local) = 0; DEFINE_PER_CPU(long, nr_pagecache_local) = 0;
#endif #endif
void __get_page_state(struct page_state *ret, int nr) void __get_page_state(struct page_state *ret, int nr, cpumask_t *cpumask)
{ {
int cpu = 0; int cpu = 0;
memset(ret, 0, sizeof(*ret)); memset(ret, 0, sizeof(*ret));
cpus_and(*cpumask, *cpumask, cpu_online_map);
cpu = first_cpu(cpu_online_map); cpu = first_cpu(*cpumask);
while (cpu < NR_CPUS) { while (cpu < NR_CPUS) {
unsigned long *in, *out, off; unsigned long *in, *out, off;
in = (unsigned long *)&per_cpu(page_states, cpu); in = (unsigned long *)&per_cpu(page_states, cpu);
cpu = next_cpu(cpu, cpu_online_map); cpu = next_cpu(cpu, *cpumask);
if (cpu < NR_CPUS) if (cpu < NR_CPUS)
prefetch(&per_cpu(page_states, cpu)); prefetch(&per_cpu(page_states, cpu));
...@@ -1153,19 +1154,33 @@ void __get_page_state(struct page_state *ret, int nr) ...@@ -1153,19 +1154,33 @@ void __get_page_state(struct page_state *ret, int nr)
} }
} }
void get_page_state_node(struct page_state *ret, int node)
{
int nr;
cpumask_t mask = node_to_cpumask(node);
nr = offsetof(struct page_state, GET_PAGE_STATE_LAST);
nr /= sizeof(unsigned long);
__get_page_state(ret, nr+1, &mask);
}
void get_page_state(struct page_state *ret) void get_page_state(struct page_state *ret)
{ {
int nr; int nr;
cpumask_t mask = CPU_MASK_ALL;
nr = offsetof(struct page_state, GET_PAGE_STATE_LAST); nr = offsetof(struct page_state, GET_PAGE_STATE_LAST);
nr /= sizeof(unsigned long); nr /= sizeof(unsigned long);
__get_page_state(ret, nr + 1); __get_page_state(ret, nr + 1, &mask);
} }
void get_full_page_state(struct page_state *ret) void get_full_page_state(struct page_state *ret)
{ {
__get_page_state(ret, sizeof(*ret) / sizeof(unsigned long)); cpumask_t mask = CPU_MASK_ALL;
__get_page_state(ret, sizeof(*ret) / sizeof(unsigned long), &mask);
} }
unsigned long __read_page_state(unsigned long offset) unsigned long __read_page_state(unsigned long offset)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment