Skip to contentSkip to conversation

maps: show swapped out pages in smaps

RFC PATCH New Fengguang Wu 1 participant 1 message Aug 17, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 maps: show swapped out pages in smaps

Show the amount of swapped out pages in /proc/<pid>/smaps. Currently there's no way to know who is using the swap file.

A possible better way to support it is to add a new counter to struct_mm. Or maybe not that important at all?

---
 fs/proc/task_mmu.c |   12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
fs/proc/task_mmu.c +9 -3
@@ -324,6 +324,7 @@ struct mem_size_stats
 	unsigned long private_clean;
 	unsigned long private_dirty;
 	unsigned long referenced;
+	unsigned long swapped;
 
 	/*
 	 * Proportional Set Size(PSS): my share of RSS.
@@ -367,8 +368,11 @@ static int smaps_pte_range(pmd_t *pmd, u
 	pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
 	for (; addr != end; pte++, addr += PAGE_SIZE) {
 		ptent = *pte;
-		if (!pte_present(ptent))
+		if (!pte_present(ptent)) {
+			if (!pte_none(ptent) && !pte_file(ptent))
+				mms->swapped += PAGE_SIZE;
 			continue;
+		}
 
 		mss->resident += PAGE_SIZE;
 
@@ -425,7 +429,8 @@ static int show_smap(struct seq_file *m,
 		   "Shared_Dirty:   %8lu kB\n"
 		   "Private_Clean:  %8lu kB\n"
 		   "Private_Dirty:  %8lu kB\n"
-		   "Referenced:     %8lu kB\n",
+		   "Referenced:     %8lu kB\n"
+		   "Swapped:        %8lu kB\n",
 		   (vma->vm_end - vma->vm_start) >> 10,
 		   sarg.mss.resident >> 10,
 		   (unsigned long)(sarg.mss.pss >> (10 + PSS_ERROR_BITS)),
@@ -433,7 +438,8 @@ static int show_smap(struct seq_file *m,
 		   sarg.mss.shared_dirty  >> 10,
 		   sarg.mss.private_clean >> 10,
 		   sarg.mss.private_dirty >> 10,
-		   sarg.mss.referenced >> 10);
+		   sarg.mss.referenced    >> 10,
+		   sarg.mss.swapped       >> 10);
 
 	return ret;
 }