Skip to contentSkip to conversation

procfs: Use proper units for noMMU statm

PATCH Superseded [email protected] 2 participants 4 messages Nov 14, 2009 – Nov 16, 2009

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

PATCH 1/1 procfs: Use proper units for noMMU statm

On no-MMU systems, sizes reported in /proc/n/statm have units of bytes. Per Documentation/filesystems/proc.txt, these values should be in pages.

---

fs/proc/task_nommu.c +5 -2
diff -uprN a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
@@ -110,8 +110,11 @@ int task_statm(struct mm_struct *mm, int
 		}
 	}
 
-	size += (*text = mm->end_code - mm->start_code);
-	size += (*data = mm->start_stack - mm->start_data);
+	size >>= PAGE_SHIFT;
+	*text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK))
+		>> PAGE_SHIFT;
+	*data = (mm->start_stack - mm->start_data) >> PAGE_SHIFT;
+	size += *text + *data;
 	up_read(&mm->mmap_sem);
 	*resident = size;
 	return size;
#1 lore raw
Quoted 9 lines · On Fri, Nov 13, 2009 at 07:52:14PM -0600, [email protected] wrote:

On no-MMU systems, sizes reported in /proc/n/statm have units of bytes. Per Documentation/filesystems/proc.txt, these values should be in pages.

---
diff -uprN a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c

fs/proc/task_nommu.c int task_statm(struct mm_struct *mm, int · line 116

Quoted 9 lines
fs/proc/task_nommu.c +4 -2
@@ -110,8 +110,11 @@ int task_statm(struct mm_struct *mm, int
 		}
 	}
 
-	size += (*text = mm->end_code - mm->start_code);
-	size += (*data = mm->start_stack - mm->start_data);
+	size >>= PAGE_SHIFT;
+	*text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK))
+		>> PAGE_SHIFT;
+	*data = (mm->start_stack - mm->start_data) >> PAGE_SHIFT;

Are '->start_stack' and '->start_data' already page aligned on NOMMU arch?

If yes, this patch looks good.

Quoted 10 lines
fs/proc/task_nommu.c +1 -1
+	size += *text + *data;
 	up_read(&mm->mmap_sem);
 	*resident = size;
 	return size;
 
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 1 line
Live like a child, think like the god.
#2 lore raw
Quoted 10 lines · Américo Wang

fs/proc/task_nommu.c int task_statm(struct mm_struct *mm, int · line 116

Quoted 6 lines · On Fri, Nov 13, 2009 at 07:52:14PM -0600, [email protected] wrote:

On no-MMU systems, sizes reported in /proc/n/statm have units of bytes. Per Documentation/filesystems/proc.txt, these values should be in pages.

...

fs/proc/task_nommu.c +1 -0
+	*data = (mm->start_stack - mm->start_data) >> PAGE_SHIFT;

Are '->start_stack' and '->start_data' already page aligned on NOMMU arch?

In looking over binfmt_flat.c (main executable type for noMMU systems), I don't think there's a guarantee of more than 32- or 64-bit alignment. Thanks for the suggestion, I'll submit an updated patch.

------------------------------------------------------------------------
Steven J. Magnani "I claim this network for MARS!
www.digidescorp.com Earthling, return my space modulator!"

#include <standard.disclaimer>

#3 lore raw

PATCH v2 1/1 procfs: Use proper units for noMMU statm

Reworked to guarantee page alignment of terms used in data size calculation and to reduce time spent with mmap_sem held.

On no-MMU systems, sizes reported in /proc/n/statm have units of bytes. Per Documentation/filesystems/proc.txt, these values should be in pages.

---

fs/proc/task_nommu.c +6 -2
diff -uprN a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
@@ -110,9 +110,13 @@ int task_statm(struct mm_struct *mm, int
 		}
 	}
 
-	size += (*text = mm->end_code - mm->start_code);
-	size += (*data = mm->start_stack - mm->start_data);
+	*text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK))
+		>> PAGE_SHIFT;
+	*data = (PAGE_ALIGN(mm->start_stack) - (mm->start_data & PAGE_MASK))
+		>> PAGE_SHIFT;
 	up_read(&mm->mmap_sem);
+	size >>= PAGE_SHIFT;
+	size += *text + *data;
 	*resident = size;
 	return size;
 }