From: Dave Hansen <haveblue@us.ibm.com>
To: mpm@selenic.com
Cc: linux-mm@kvack.org, Dave Hansen <haveblue@us.ibm.com>
Subject: [RFC][PATCH 9/9] pagemap: export swap ptes
Date: Tue, 21 Aug 2007 13:42:59 -0700 [thread overview]
Message-ID: <20070821204259.1F6E8A44@kernel> (raw)
In-Reply-To: <20070821204248.0F506A29@kernel>
In addition to understanding which physical pages are
used by a process, it would also be very nice to
enumerate how much swap space a process is using.
This patch enables /proc/<pid>/pagemap to display
swap ptes. In the process, it also changes the
constant that we used to indicate non-present ptes
before.
Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
---
lxc-dave/fs/proc/task_mmu.c | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff -puN fs/proc/task_mmu.c~pagemap-export-swap-ptes fs/proc/task_mmu.c
--- lxc/fs/proc/task_mmu.c~pagemap-export-swap-ptes 2007-08-21 13:30:55.000000000 -0700
+++ lxc-dave/fs/proc/task_mmu.c 2007-08-21 13:30:55.000000000 -0700
@@ -7,6 +7,8 @@
#include <linux/pagemap.h>
#include <linux/ptrace.h>
#include <linux/mempolicy.h>
+#include <linux/swap.h>
+#include <linux/swapops.h>
#include <asm/elf.h>
#include <asm/uaccess.h>
@@ -506,9 +508,13 @@ struct pagemapread {
int index;
unsigned long __user *out;
};
-
#define PM_ENTRY_BYTES sizeof(unsigned long)
-#define PM_NOT_PRESENT ((unsigned long)-1)
+#define PM_RESERVED_BITS 3
+#define PM_RESERVED_OFFSET (BITS_PER_LONG-PM_RESERVED_BITS)
+#define PM_RESERVED_MASK (((1<<PM_RESERVED_BITS)-1) << PM_RESERVED_OFFSET)
+#define PM_SPECIAL(nr) (((nr) << PM_RESERVED_OFFSET) | PM_RESERVED_MASK)
+#define PM_NOT_PRESENT PM_SPECIAL(1)
+#define PM_SWAP PM_SPECIAL(2)
#define PAGEMAP_END_OF_BUFFER 1
static int add_to_pagemap(unsigned long addr, unsigned long pfn,
@@ -539,6 +545,21 @@ static int pagemap_pte_hole(unsigned lon
return err;
}
+unsigned long swap_pte_to_pagemap_entry(pte_t pte)
+{
+ unsigned long ret = 0;
+ swp_entry_t entry = pte_to_swp_entry(pte);
+ unsigned long offset;
+ unsigned long swap_file_nr;
+
+ offset = swp_offset(entry);
+ swap_file_nr = swp_type(entry);
+ ret = PM_SWAP | swap_file_nr | (offset << MAX_SWAPFILES_SHIFT);
+ return ret;
+}
+
+
+
static int pagemap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
void *private)
{
@@ -549,7 +570,9 @@ static int pagemap_pte_range(pmd_t *pmd,
pte = pte_offset_map(pmd, addr);
for (; addr != end; pte++, addr += PAGE_SIZE) {
unsigned long pfn = PM_NOT_PRESENT;
- if (pte_present(*pte))
+ if (is_swap_pte(*pte))
+ pfn = swap_pte_to_pagemap_entry(*pte);
+ else if (pte_present(*pte))
pfn = pte_pfn(*pte);
err = add_to_pagemap(addr, pfn, pm);
if (err)
_
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2007-08-21 20:43 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-21 20:42 [RFC][PATCH 1/9] /proc/pid/pagemap update Dave Hansen
2007-08-21 20:42 ` [RFC][PATCH 2/9] pagemap: remove file header Dave Hansen
2007-08-21 21:24 ` Matt Mackall
2007-08-21 20:42 ` [RFC][PATCH 3/9] pagemap: use PAGE_MASK/PAGE_ALIGN() Dave Hansen
2007-08-21 21:25 ` Matt Mackall
2007-08-21 20:42 ` [RFC][PATCH 4/9] pagemap: remove open-coded sizeof(unsigned long) Dave Hansen
2007-08-21 21:26 ` Matt Mackall
2007-08-21 20:42 ` [RFC][PATCH 5/9] introduce TASK_SIZE_OF() for all arches Dave Hansen
2007-08-21 20:42 ` [RFC][PATCH 6/9] pagemap: give -1's a name Dave Hansen
2007-08-21 21:27 ` Matt Mackall
2007-08-21 20:42 ` [RFC][PATCH 7/9] pagewalk: add handler for empty ranges Dave Hansen
2007-08-30 7:28 ` Nick Piggin
2007-09-03 12:32 ` Matt Mackall
2007-08-21 20:42 ` [RFC][PATCH 8/9] pagemap: use page walker pte_hole() helper Dave Hansen
2007-08-21 22:01 ` Matt Mackall
2007-08-21 22:38 ` Dave Hansen
2007-08-21 20:42 ` Dave Hansen [this message]
2007-08-21 21:49 ` [RFC][PATCH 9/9] pagemap: export swap ptes Matt Mackall
2007-08-21 22:26 ` Dave Hansen
2007-08-21 21:23 ` [RFC][PATCH 1/9] /proc/pid/pagemap update Matt Mackall
2007-08-21 21:26 ` Dave Hansen
2007-08-21 22:07 ` Matt Mackall
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=20070821204259.1F6E8A44@kernel \
--to=haveblue@us.ibm.com \
--cc=linux-mm@kvack.org \
--cc=mpm@selenic.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.