Skip to content

Commit a2ade7b

Browse files
Alexey Dobriyantorvalds
authored andcommitted
proc: use unsigned long inside /proc/*/statm
/proc/*/statm code needlessly truncates data from unsigned long to int. One needs only 8+ TB of RAM to make truncation visible. Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Reviewed-by: WANG Cong <xiyou.wangcong@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 34e49d4 commit a2ade7b

4 files changed

Lines changed: 12 additions & 9 deletions

File tree

‎fs/proc/array.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,15 +535,15 @@ int proc_tgid_stat(struct seq_file *m, struct pid_namespace *ns,
535535
int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
536536
struct pid *pid, struct task_struct *task)
537537
{
538-
int size = 0, resident = 0, shared = 0, text = 0, lib = 0, data = 0;
538+
unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
539539
struct mm_struct *mm = get_task_mm(task);
540540

541541
if (mm) {
542542
size = task_statm(mm, &shared, &text, &data, &resident);
543543
mmput(mm);
544544
}
545-
seq_printf(m, "%d %d %d %d %d %d %d\n",
546-
size, resident, shared, text, lib, data, 0);
545+
seq_printf(m, "%lu %lu %lu %lu 0 %lu 0\n",
546+
size, resident, shared, text, data);
547547

548548
return 0;
549549
}

‎fs/proc/internal.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ extern spinlock_t proc_subdir_lock;
9696
struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *);
9797
int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir);
9898
unsigned long task_vsize(struct mm_struct *);
99-
int task_statm(struct mm_struct *, int *, int *, int *, int *);
99+
unsigned long task_statm(struct mm_struct *,
100+
unsigned long *, unsigned long *, unsigned long *, unsigned long *);
100101
void task_mem(struct seq_file *, struct mm_struct *);
101102

102103
static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)

‎fs/proc/task_mmu.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ unsigned long task_vsize(struct mm_struct *mm)
6666
return PAGE_SIZE * mm->total_vm;
6767
}
6868

69-
int task_statm(struct mm_struct *mm, int *shared, int *text,
70-
int *data, int *resident)
69+
unsigned long task_statm(struct mm_struct *mm,
70+
unsigned long *shared, unsigned long *text,
71+
unsigned long *data, unsigned long *resident)
7172
{
7273
*shared = get_mm_counter(mm, MM_FILEPAGES);
7374
*text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK))

‎fs/proc/task_nommu.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,14 @@ unsigned long task_vsize(struct mm_struct *mm)
9292
return vsize;
9393
}
9494

95-
int task_statm(struct mm_struct *mm, int *shared, int *text,
96-
int *data, int *resident)
95+
unsigned long task_statm(struct mm_struct *mm,
96+
unsigned long *shared, unsigned long *text,
97+
unsigned long *data, unsigned long *resident)
9798
{
9899
struct vm_area_struct *vma;
99100
struct vm_region *region;
100101
struct rb_node *p;
101-
int size = kobjsize(mm);
102+
unsigned long size = kobjsize(mm);
102103

103104
down_read(&mm->mmap_sem);
104105
for (p = rb_first(&mm->mm_rb); p; p = rb_next(p)) {

0 commit comments

Comments
 (0)