Lines Matching +full:mm +full:- +full:0
1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/mm.h>
11 #include <linux/sched/mm.h>
17 * "non-shared". Shared memory may get counted more than once, for
18 * each process that owns it. Non-shared memory is counted
21 void task_mem(struct seq_file *m, struct mm_struct *mm) in task_mem() argument
23 VMA_ITERATOR(vmi, mm, 0); in task_mem()
26 unsigned long bytes = 0, sbytes = 0, slack = 0, size; in task_mem()
28 mmap_read_lock(mm); in task_mem()
32 region = vma->vm_region; in task_mem()
35 size += region->vm_end - region->vm_start; in task_mem()
37 size = vma->vm_end - vma->vm_start; in task_mem()
40 if (atomic_read(&mm->mm_count) > 1 || in task_mem()
41 is_nommu_shared_mapping(vma->vm_flags)) { in task_mem()
46 slack = region->vm_end - vma->vm_end; in task_mem()
50 if (atomic_read(&mm->mm_count) > 1) in task_mem()
51 sbytes += kobjsize(mm); in task_mem()
53 bytes += kobjsize(mm); in task_mem()
55 if (current->fs && current->fs->users > 1) in task_mem()
56 sbytes += kobjsize(current->fs); in task_mem()
58 bytes += kobjsize(current->fs); in task_mem()
60 if (current->files && atomic_read(¤t->files->count) > 1) in task_mem()
61 sbytes += kobjsize(current->files); in task_mem()
63 bytes += kobjsize(current->files); in task_mem()
65 if (current->sighand && refcount_read(¤t->sighand->count) > 1) in task_mem()
66 sbytes += kobjsize(current->sighand); in task_mem()
68 bytes += kobjsize(current->sighand); in task_mem()
72 mmap_read_unlock(mm); in task_mem()
81 unsigned long task_vsize(struct mm_struct *mm) in task_vsize() argument
83 VMA_ITERATOR(vmi, mm, 0); in task_vsize()
85 unsigned long vsize = 0; in task_vsize()
87 mmap_read_lock(mm); in task_vsize()
89 vsize += vma->vm_end - vma->vm_start; in task_vsize()
90 mmap_read_unlock(mm); in task_vsize()
94 unsigned long task_statm(struct mm_struct *mm, in task_statm() argument
98 VMA_ITERATOR(vmi, mm, 0); in task_statm()
101 unsigned long size = kobjsize(mm); in task_statm()
103 mmap_read_lock(mm); in task_statm()
106 region = vma->vm_region; in task_statm()
109 size += region->vm_end - region->vm_start; in task_statm()
113 *text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) in task_statm()
115 *data = (PAGE_ALIGN(mm->start_stack) - (mm->start_data & PAGE_MASK)) in task_statm()
117 mmap_read_unlock(mm); in task_statm()
129 struct mm_struct *mm = vma->vm_mm; in nommu_vma_show() local
130 unsigned long ino = 0; in nommu_vma_show()
132 dev_t dev = 0; in nommu_vma_show()
134 unsigned long long pgoff = 0; in nommu_vma_show()
136 flags = vma->vm_flags; in nommu_vma_show()
137 file = vma->vm_file; in nommu_vma_show()
140 struct inode *inode = file_inode(vma->vm_file); in nommu_vma_show()
141 dev = inode->i_sb->s_dev; in nommu_vma_show()
142 ino = inode->i_ino; in nommu_vma_show()
143 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT; in nommu_vma_show()
146 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1); in nommu_vma_show()
148 "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ", in nommu_vma_show()
149 vma->vm_start, in nommu_vma_show()
150 vma->vm_end, in nommu_vma_show()
151 flags & VM_READ ? 'r' : '-', in nommu_vma_show()
152 flags & VM_WRITE ? 'w' : '-', in nommu_vma_show()
153 flags & VM_EXEC ? 'x' : '-', in nommu_vma_show()
161 } else if (mm && vma_is_initial_stack(vma)) { in nommu_vma_show()
167 return 0; in nommu_vma_show()
181 struct vm_area_struct *vma = vma_next(&priv->iter); in proc_get_vma()
184 *ppos = vma->vm_start; in proc_get_vma()
186 *ppos = -1UL; in proc_get_vma()
194 struct proc_maps_private *priv = m->private; in m_start()
196 struct mm_struct *mm; in m_start() local
199 if (last_addr == -1UL) in m_start()
202 /* pin the task and mm whilst we play with them */ in m_start()
203 priv->task = get_proc_task(priv->inode); in m_start()
204 if (!priv->task) in m_start()
205 return ERR_PTR(-ESRCH); in m_start()
207 mm = priv->mm; in m_start()
208 if (!mm || !mmget_not_zero(mm)) { in m_start()
209 put_task_struct(priv->task); in m_start()
210 priv->task = NULL; in m_start()
214 if (mmap_read_lock_killable(mm)) { in m_start()
215 mmput(mm); in m_start()
216 put_task_struct(priv->task); in m_start()
217 priv->task = NULL; in m_start()
218 return ERR_PTR(-EINTR); in m_start()
221 vma_iter_init(&priv->iter, mm, last_addr); in m_start()
228 struct proc_maps_private *priv = m->private; in m_stop()
229 struct mm_struct *mm = priv->mm; in m_stop() local
231 if (!priv->task) in m_stop()
234 mmap_read_unlock(mm); in m_stop()
235 mmput(mm); in m_stop()
236 put_task_struct(priv->task); in m_stop()
237 priv->task = NULL; in m_stop()
242 return proc_get_vma(m->private, ppos); in m_next()
259 return -ENOMEM; in maps_open()
261 priv->inode = inode; in maps_open()
262 priv->mm = proc_mem_open(inode, PTRACE_MODE_READ); in maps_open()
263 if (IS_ERR(priv->mm)) { in maps_open()
264 int err = PTR_ERR(priv->mm); in maps_open()
270 return 0; in maps_open()
276 struct seq_file *seq = file->private_data; in map_release()
277 struct proc_maps_private *priv = seq->private; in map_release()
279 if (priv->mm) in map_release()
280 mmdrop(priv->mm); in map_release()