3 #include <linux/file.h>
4 #include <linux/seq_file.h>
7 * Logic: we've got two memory sums for each process, "shared", and
8 * "non-shared". Shared memory may get counted more then once, for
9 * each process that owns it. Non-shared memory is counted
12 char *task_mem(struct mm_struct *mm, char *buffer)
14 unsigned long bytes = 0, sbytes = 0, slack = 0;
15 struct mm_tblock_struct *tblock;
17 down_read(&mm->mmap_sem);
18 for (tblock = &mm->context.tblock; tblock; tblock = tblock->next) {
21 bytes += kobjsize(tblock);
22 if (atomic_read(&mm->mm_count) > 1 ||
23 tblock->rblock->refcount > 1) {
24 sbytes += kobjsize(tblock->rblock->kblock);
25 sbytes += kobjsize(tblock->rblock);
27 bytes += kobjsize(tblock->rblock->kblock);
28 bytes += kobjsize(tblock->rblock);
29 slack += kobjsize(tblock->rblock->kblock) -
34 if (atomic_read(&mm->mm_count) > 1)
35 sbytes += kobjsize(mm);
37 bytes += kobjsize(mm);
39 if (current->fs && atomic_read(¤t->fs->count) > 1)
40 sbytes += kobjsize(current->fs);
42 bytes += kobjsize(current->fs);
44 if (current->files && atomic_read(¤t->files->count) > 1)
45 sbytes += kobjsize(current->files);
47 bytes += kobjsize(current->files);
49 if (current->sighand && atomic_read(¤t->sighand->count) > 1)
50 sbytes += kobjsize(current->sighand);
52 bytes += kobjsize(current->sighand);
54 bytes += kobjsize(current); /* includes kernel stack */
56 buffer += sprintf(buffer,
58 "Slack:\t%8lu bytes\n"
59 "Shared:\t%8lu bytes\n",
60 bytes, slack, sbytes);
62 up_read(&mm->mmap_sem);
66 unsigned long task_vsize(struct mm_struct *mm)
68 struct mm_tblock_struct *tbp;
69 unsigned long vsize = 0;
71 for (tbp = &mm->context.tblock; tbp; tbp = tbp->next) {
73 vsize += kobjsize(tbp->rblock->kblock);
79 int task_statm(struct mm_struct *mm, int *shared, int *text,
80 int *data, int *resident)
82 struct mm_tblock_struct *tbp;
83 int size = kobjsize(mm);
85 for (tbp = &mm->context.tblock; tbp; tbp = tbp->next) {
87 size += kobjsize(tbp->next);
89 size += kobjsize(tbp->rblock);
90 size += kobjsize(tbp->rblock->kblock);
94 size += (*text = mm->end_code - mm->start_code);
95 size += (*data = mm->start_stack - mm->start_data);
102 * Albert D. Cahalan suggested to fake entries for the traditional
103 * sections here. This might be worth investigating.
105 static int show_map(struct seq_file *m, void *v)
109 static void *m_start(struct seq_file *m, loff_t *pos)
113 static void m_stop(struct seq_file *m, void *v)
116 static void *m_next(struct seq_file *m, void *v, loff_t *pos)
120 struct seq_operations proc_pid_maps_op = {