Skip to content

Commit 80ae2fd

Browse files
Vladimir Davydovtorvalds
authored andcommitted
proc: add kpagecgroup file
/proc/kpagecgroup contains a 64-bit inode number of the memory cgroup each page is charged to, indexed by PFN. Having this information is useful for estimating a cgroup working set size. The file is present if CONFIG_PROC_PAGE_MONITOR && CONFIG_MEMCG. Signed-off-by: Vladimir Davydov <[email protected]> Reviewed-by: Andres Lagar-Cavilla <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Raghavendra K T <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Greg Thelen <[email protected]> Cc: Michel Lespinasse <[email protected]> Cc: David Rientjes <[email protected]> Cc: Pavel Emelyanov <[email protected]> Cc: Cyrill Gorcunov <[email protected]> Cc: Jonathan Corbet <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent e993d90 commit 80ae2fd

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

Documentation/vm/pagemap.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pagemap is a new (as of 2.6.25) set of interfaces in the kernel that allow
55
userspace programs to examine the page tables and related information by
66
reading files in /proc.
77

8-
There are three components to pagemap:
8+
There are four components to pagemap:
99

1010
* /proc/pid/pagemap. This file lets a userspace process find out which
1111
physical frame each virtual page is mapped to. It contains one 64-bit
@@ -71,6 +71,10 @@ There are three components to pagemap:
7171
23. BALLOON
7272
24. ZERO_PAGE
7373

74+
* /proc/kpagecgroup. This file contains a 64-bit inode number of the
75+
memory cgroup each page is charged to, indexed by PFN. Only available when
76+
CONFIG_MEMCG is set.
77+
7478
Short descriptions to the page flags:
7579

7680
0. LOCKED

fs/proc/page.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/proc_fs.h>
1010
#include <linux/seq_file.h>
1111
#include <linux/hugetlb.h>
12+
#include <linux/memcontrol.h>
1213
#include <linux/kernel-page-flags.h>
1314
#include <asm/uaccess.h>
1415
#include "internal.h"
@@ -225,10 +226,62 @@ static const struct file_operations proc_kpageflags_operations = {
225226
.read = kpageflags_read,
226227
};
227228

229+
#ifdef CONFIG_MEMCG
230+
static ssize_t kpagecgroup_read(struct file *file, char __user *buf,
231+
size_t count, loff_t *ppos)
232+
{
233+
u64 __user *out = (u64 __user *)buf;
234+
struct page *ppage;
235+
unsigned long src = *ppos;
236+
unsigned long pfn;
237+
ssize_t ret = 0;
238+
u64 ino;
239+
240+
pfn = src / KPMSIZE;
241+
count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src);
242+
if (src & KPMMASK || count & KPMMASK)
243+
return -EINVAL;
244+
245+
while (count > 0) {
246+
if (pfn_valid(pfn))
247+
ppage = pfn_to_page(pfn);
248+
else
249+
ppage = NULL;
250+
251+
if (ppage)
252+
ino = page_cgroup_ino(ppage);
253+
else
254+
ino = 0;
255+
256+
if (put_user(ino, out)) {
257+
ret = -EFAULT;
258+
break;
259+
}
260+
261+
pfn++;
262+
out++;
263+
count -= KPMSIZE;
264+
}
265+
266+
*ppos += (char __user *)out - buf;
267+
if (!ret)
268+
ret = (char __user *)out - buf;
269+
return ret;
270+
}
271+
272+
static const struct file_operations proc_kpagecgroup_operations = {
273+
.llseek = mem_lseek,
274+
.read = kpagecgroup_read,
275+
};
276+
#endif /* CONFIG_MEMCG */
277+
228278
static int __init proc_page_init(void)
229279
{
230280
proc_create("kpagecount", S_IRUSR, NULL, &proc_kpagecount_operations);
231281
proc_create("kpageflags", S_IRUSR, NULL, &proc_kpageflags_operations);
282+
#ifdef CONFIG_MEMCG
283+
proc_create("kpagecgroup", S_IRUSR, NULL, &proc_kpagecgroup_operations);
284+
#endif
232285
return 0;
233286
}
234287
fs_initcall(proc_page_init);

0 commit comments

Comments
 (0)