shmem: show swap usage in smaps From: Konstantin Khlebnikov Signed-off-by: Konstantin Khlebnikov --- fs/proc/task_mmu.c | 3 +++ include/linux/mm.h | 2 ++ mm/shmem.c | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 956b75d61809..09a94cec159e 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -624,6 +624,9 @@ static int show_smap(struct seq_file *m, void *v, int is_pid) /* mmap_sem is held in m_start */ walk_page_vma(vma, &smaps_walk); + if (vma->vm_ops && vma->vm_ops->get_swap_usage) + mss.swap += vma->vm_ops->get_swap_usage(vma) << PAGE_SHIFT; + show_map_vma(m, vma, is_pid); seq_printf(m, diff --git a/include/linux/mm.h b/include/linux/mm.h index 6571dd78e984..477a46987859 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -292,6 +292,8 @@ struct vm_operations_struct { */ struct page *(*find_special_page)(struct vm_area_struct *vma, unsigned long addr); + + unsigned long (*get_swap_usage)(struct vm_area_struct *vma); }; struct mmu_gather; diff --git a/mm/shmem.c b/mm/shmem.c index cf2d0ca010bc..492f78f51fc2 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1363,6 +1363,13 @@ static struct mempolicy *shmem_get_policy(struct vm_area_struct *vma, } #endif +static unsigned long shmem_get_swap_usage(struct vm_area_struct *vma) +{ + struct inode *inode = file_inode(vma->vm_file); + + return SHMEM_I(inode)->swapped; +} + int shmem_lock(struct file *file, int lock, struct user_struct *user) { struct inode *inode = file_inode(file); @@ -3198,6 +3205,7 @@ static const struct vm_operations_struct shmem_vm_ops = { .set_policy = shmem_set_policy, .get_policy = shmem_get_policy, #endif + .get_swap_usage = shmem_get_swap_usage, }; static struct dentry *shmem_mount(struct file_system_type *fs_type,