From patchwork Mon Jul 23 11:19:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 10540001 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E815B1805 for ; Mon, 23 Jul 2018 11:20:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D478B28608 for ; Mon, 23 Jul 2018 11:20:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C3F0328600; Mon, 23 Jul 2018 11:20:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C7D128600 for ; Mon, 23 Jul 2018 11:20:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CC2D16B000E; Mon, 23 Jul 2018 07:19:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C29FA6B000C; Mon, 23 Jul 2018 07:19:53 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A9BB6B0010; Mon, 23 Jul 2018 07:19:53 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id 36D6B6B000C for ; Mon, 23 Jul 2018 07:19:53 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id e1-v6so155982pld.23 for ; Mon, 23 Jul 2018 04:19:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=vPU6XP9wOaJpqHeU2i10iyExVxyMb/myImZiYhi0vEg=; b=G1tV9w6vV9C4uvpdAAf1i1aMXUwfAO5hex0sDhTL00TpOYLnOdg2KqqGcblOGLcS70 XR2p3TQvpwUP+Gy6D0yEz9Y8nXdKd8Pf6y3pjVe6c2wHmwc5+9iOEYofT57G9fxAay1e GV7/pOaFFRaAiIvmm2w+2hLjWIVJ32Erl5PoJ7CibcyoOWc+K3EPvAKPGgCcuKJNrdms V3KHh28ONEpQfhE6iqv41zjOOm6u0i9OjJ9iXUIK/yNL8XzmKBCpDR6Q6L4INh5c+/h1 jN0B0YB4ag0ZVYcCAOrp72U8lLfU+RxY36xT1Nzhgb/aQCNwRyJfTYJWrXD22DQNxQyS 0ctw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Gm-Message-State: AOUpUlHPlOZvyuScTaNL0kn0UNYC9q729c3D2gQhu7vUxchbXbta29Cb pJiwDOUnvlWu2u0n1lmUzUmJB2+h8b2SiVfEflZBijWC2/VLeW96vGGGVnBdNQnzK6g+jar0fgx a5JLHQXvDG+vm/Y6L2hY2p9n1rYL7jAIK/9v67DDu/G3uxE4Yosvbah+F48Cu0O7jyw== X-Received: by 2002:aa7:824d:: with SMTP id e13-v6mr12783383pfn.97.1532344792881; Mon, 23 Jul 2018 04:19:52 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfAKG57OYce9qNsVk1CGI0K4H2SR9Qipn/E80ULvHdPNH3MMd6jt/SMQm/yRBl7sUfqR0RL X-Received: by 2002:aa7:824d:: with SMTP id e13-v6mr12783321pfn.97.1532344791777; Mon, 23 Jul 2018 04:19:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532344791; cv=none; d=google.com; s=arc-20160816; b=lsX3lJM1WEQJTGkC7sMHSRtVr9UocMWyP7z18C11E1OGBrXUgez8spzEiOMmfuHOap DL0RNM4bWj3BdfZIPk2yGQdiR+czZuGw5gPArCJSZmyCpHaq1zR144Vak7SOMT6yAddR BoyXqZk87PQNx8Z2etFrkKwZvPMBLKsKFW2cFfgM9mupM4Ni6xYYfeZgmwDCnshKBiuU W7PuYV0mieJzhBB/Eqdf766TSrGMeM03Mzv+l3D9jIqVjJfgb3pdKtPYvIODOmVoJGVr dmb3j+uPWXlh9diT+En5+zpBTme6N1Tm/bqoJZnWZHdEo1DdsJYpXK/RHJG/looKzpaA b0mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=vPU6XP9wOaJpqHeU2i10iyExVxyMb/myImZiYhi0vEg=; b=FOsPDBxeGFcQB/9NYR+lp7kss0+ddPLBW/ks5qvUcuvY2hx15ACY742wSbYnrt++4B JgLybw3QUYaYfTHMcK+3WTdXCzfcv7qUSQ8VFbPZWsk52rMgGOi+77eySDAQ+R1KkqKC 2h54Cv0Ow6J1y7LW/+w+7tPj8uLi97Ujw42kKIpXZWATkIKnhBhtsThvcX4MKPH8LkcD 63CBSRDstFCixLwupQoWhHt4i2f2n2U4+NSDPyl4E59k4m44w0wvz+lHLWIp+O3aAOSz bTUYm3316rjgoI+TXv1/2v/kE3TpHyesiC9WNEw5lV9QqTv8K2iHOd23oZfX706nXnKY rC9w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz Received: from mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id e132-v6si8626691pfg.171.2018.07.23.04.19.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 04:19:51 -0700 (PDT) Received-SPF: pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id BF42DADDF; Mon, 23 Jul 2018 11:19:49 +0000 (UTC) From: Vlastimil Babka To: Andrew Morton Cc: Daniel Colascione , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alexey Dobriyan , linux-api@vger.kernel.org, Vlastimil Babka Subject: [PATCH 1/4] mm: /proc/pid/*maps remove is_pid and related wrappers Date: Mon, 23 Jul 2018 13:19:30 +0200 Message-Id: <20180723111933.15443-2-vbabka@suse.cz> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180723111933.15443-1-vbabka@suse.cz> References: <20180723111933.15443-1-vbabka@suse.cz> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Commit b76437579d13 ("procfs: mark thread stack correctly in proc//maps") introduced differences between /proc/PID/maps and /proc/PID/task/TID/maps to mark thread stacks properly, and this was also done for smaps and numa_maps. However it didn't work properly and was ultimately removed by commit b18cb64ead40 ("fs/proc: Stop trying to report thread stacks"). Now the is_pid parameter for the related show_*() functions is unused and we can remove it together with wrapper functions and ops structures that differ for PID and TID cases only in this parameter. Signed-off-by: Vlastimil Babka --- fs/proc/base.c | 6 +-- fs/proc/internal.h | 3 -- fs/proc/task_mmu.c | 114 +++++-------------------------------------- fs/proc/task_nommu.c | 39 ++------------- 4 files changed, 18 insertions(+), 144 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index aaffc0c30216..ad047977ed04 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -3309,12 +3309,12 @@ static const struct pid_entry tid_base_stuff[] = { REG("cmdline", S_IRUGO, proc_pid_cmdline_ops), ONE("stat", S_IRUGO, proc_tid_stat), ONE("statm", S_IRUGO, proc_pid_statm), - REG("maps", S_IRUGO, proc_tid_maps_operations), + REG("maps", S_IRUGO, proc_pid_maps_operations), #ifdef CONFIG_PROC_CHILDREN REG("children", S_IRUGO, proc_tid_children_operations), #endif #ifdef CONFIG_NUMA - REG("numa_maps", S_IRUGO, proc_tid_numa_maps_operations), + REG("numa_maps", S_IRUGO, proc_pid_numa_maps_operations), #endif REG("mem", S_IRUSR|S_IWUSR, proc_mem_operations), LNK("cwd", proc_cwd_link), @@ -3324,7 +3324,7 @@ static const struct pid_entry tid_base_stuff[] = { REG("mountinfo", S_IRUGO, proc_mountinfo_operations), #ifdef CONFIG_PROC_PAGE_MONITOR REG("clear_refs", S_IWUSR, proc_clear_refs_operations), - REG("smaps", S_IRUGO, proc_tid_smaps_operations), + REG("smaps", S_IRUGO, proc_pid_smaps_operations), REG("smaps_rollup", S_IRUGO, proc_pid_smaps_rollup_operations), REG("pagemap", S_IRUSR, proc_pagemap_operations), #endif diff --git a/fs/proc/internal.h b/fs/proc/internal.h index da3dbfa09e79..0c538769512a 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h @@ -297,12 +297,9 @@ struct proc_maps_private { struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode); extern const struct file_operations proc_pid_maps_operations; -extern const struct file_operations proc_tid_maps_operations; extern const struct file_operations proc_pid_numa_maps_operations; -extern const struct file_operations proc_tid_numa_maps_operations; extern const struct file_operations proc_pid_smaps_operations; extern const struct file_operations proc_pid_smaps_rollup_operations; -extern const struct file_operations proc_tid_smaps_operations; extern const struct file_operations proc_clear_refs_operations; extern const struct file_operations proc_pagemap_operations; diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index dfd73a4616ce..a3f98ca50981 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -294,7 +294,7 @@ static void show_vma_header_prefix(struct seq_file *m, } static void -show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid) +show_map_vma(struct seq_file *m, struct vm_area_struct *vma) { struct mm_struct *mm = vma->vm_mm; struct file *file = vma->vm_file; @@ -357,35 +357,18 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid) seq_putc(m, '\n'); } -static int show_map(struct seq_file *m, void *v, int is_pid) +static int show_map(struct seq_file *m, void *v) { - show_map_vma(m, v, is_pid); + show_map_vma(m, v); m_cache_vma(m, v); return 0; } -static int show_pid_map(struct seq_file *m, void *v) -{ - return show_map(m, v, 1); -} - -static int show_tid_map(struct seq_file *m, void *v) -{ - return show_map(m, v, 0); -} - static const struct seq_operations proc_pid_maps_op = { .start = m_start, .next = m_next, .stop = m_stop, - .show = show_pid_map -}; - -static const struct seq_operations proc_tid_maps_op = { - .start = m_start, - .next = m_next, - .stop = m_stop, - .show = show_tid_map + .show = show_map }; static int pid_maps_open(struct inode *inode, struct file *file) @@ -393,11 +376,6 @@ static int pid_maps_open(struct inode *inode, struct file *file) return do_maps_open(inode, file, &proc_pid_maps_op); } -static int tid_maps_open(struct inode *inode, struct file *file) -{ - return do_maps_open(inode, file, &proc_tid_maps_op); -} - const struct file_operations proc_pid_maps_operations = { .open = pid_maps_open, .read = seq_read, @@ -405,13 +383,6 @@ const struct file_operations proc_pid_maps_operations = { .release = proc_map_release, }; -const struct file_operations proc_tid_maps_operations = { - .open = tid_maps_open, - .read = seq_read, - .llseek = seq_lseek, - .release = proc_map_release, -}; - /* * Proportional Set Size(PSS): my share of RSS. * @@ -733,7 +704,7 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned long hmask, #define SEQ_PUT_DEC(str, val) \ seq_put_decimal_ull_width(m, str, (val) >> 10, 8) -static int show_smap(struct seq_file *m, void *v, int is_pid) +static int show_smap(struct seq_file *m, void *v) { struct proc_maps_private *priv = m->private; struct vm_area_struct *vma = v; @@ -796,7 +767,7 @@ static int show_smap(struct seq_file *m, void *v, int is_pid) mss->pss_locked += mss->pss; if (!rollup_mode) { - show_map_vma(m, vma, is_pid); + show_map_vma(m, vma); } else if (last_vma) { show_vma_header_prefix( m, mss->first_vma_start, vma->vm_end, 0, 0, 0, 0); @@ -845,28 +816,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid) } #undef SEQ_PUT_DEC -static int show_pid_smap(struct seq_file *m, void *v) -{ - return show_smap(m, v, 1); -} - -static int show_tid_smap(struct seq_file *m, void *v) -{ - return show_smap(m, v, 0); -} - static const struct seq_operations proc_pid_smaps_op = { .start = m_start, .next = m_next, .stop = m_stop, - .show = show_pid_smap -}; - -static const struct seq_operations proc_tid_smaps_op = { - .start = m_start, - .next = m_next, - .stop = m_stop, - .show = show_tid_smap + .show = show_smap }; static int pid_smaps_open(struct inode *inode, struct file *file) @@ -893,11 +847,6 @@ static int pid_smaps_rollup_open(struct inode *inode, struct file *file) return 0; } -static int tid_smaps_open(struct inode *inode, struct file *file) -{ - return do_maps_open(inode, file, &proc_tid_smaps_op); -} - const struct file_operations proc_pid_smaps_operations = { .open = pid_smaps_open, .read = seq_read, @@ -912,13 +861,6 @@ const struct file_operations proc_pid_smaps_rollup_operations = { .release = proc_map_release, }; -const struct file_operations proc_tid_smaps_operations = { - .open = tid_smaps_open, - .read = seq_read, - .llseek = seq_lseek, - .release = proc_map_release, -}; - enum clear_refs_types { CLEAR_REFS_ALL = 1, CLEAR_REFS_ANON, @@ -1728,7 +1670,7 @@ static int gather_hugetlb_stats(pte_t *pte, unsigned long hmask, /* * Display pages allocated per node and memory policy via /proc. */ -static int show_numa_map(struct seq_file *m, void *v, int is_pid) +static int show_numa_map(struct seq_file *m, void *v) { struct numa_maps_private *numa_priv = m->private; struct proc_maps_private *proc_priv = &numa_priv->proc_maps; @@ -1812,45 +1754,17 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid) return 0; } -static int show_pid_numa_map(struct seq_file *m, void *v) -{ - return show_numa_map(m, v, 1); -} - -static int show_tid_numa_map(struct seq_file *m, void *v) -{ - return show_numa_map(m, v, 0); -} - static const struct seq_operations proc_pid_numa_maps_op = { .start = m_start, .next = m_next, .stop = m_stop, - .show = show_pid_numa_map, + .show = show_numa_map, }; -static const struct seq_operations proc_tid_numa_maps_op = { - .start = m_start, - .next = m_next, - .stop = m_stop, - .show = show_tid_numa_map, -}; - -static int numa_maps_open(struct inode *inode, struct file *file, - const struct seq_operations *ops) -{ - return proc_maps_open(inode, file, ops, - sizeof(struct numa_maps_private)); -} - static int pid_numa_maps_open(struct inode *inode, struct file *file) { - return numa_maps_open(inode, file, &proc_pid_numa_maps_op); -} - -static int tid_numa_maps_open(struct inode *inode, struct file *file) -{ - return numa_maps_open(inode, file, &proc_tid_numa_maps_op); + return proc_maps_open(inode, file, &proc_pid_numa_maps_op, + sizeof(struct numa_maps_private)); } const struct file_operations proc_pid_numa_maps_operations = { @@ -1860,10 +1774,4 @@ const struct file_operations proc_pid_numa_maps_operations = { .release = proc_map_release, }; -const struct file_operations proc_tid_numa_maps_operations = { - .open = tid_numa_maps_open, - .read = seq_read, - .llseek = seq_lseek, - .release = proc_map_release, -}; #endif /* CONFIG_NUMA */ diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c index 5b62f57bd9bc..0b63d68dedb2 100644 --- a/fs/proc/task_nommu.c +++ b/fs/proc/task_nommu.c @@ -142,8 +142,7 @@ static int is_stack(struct vm_area_struct *vma) /* * display a single VMA to a sequenced file */ -static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma, - int is_pid) +static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma) { struct mm_struct *mm = vma->vm_mm; unsigned long ino = 0; @@ -189,22 +188,11 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma, /* * display mapping lines for a particular process's /proc/pid/maps */ -static int show_map(struct seq_file *m, void *_p, int is_pid) +static int show_map(struct seq_file *m, void *_p) { struct rb_node *p = _p; - return nommu_vma_show(m, rb_entry(p, struct vm_area_struct, vm_rb), - is_pid); -} - -static int show_pid_map(struct seq_file *m, void *_p) -{ - return show_map(m, _p, 1); -} - -static int show_tid_map(struct seq_file *m, void *_p) -{ - return show_map(m, _p, 0); + return nommu_vma_show(m, rb_entry(p, struct vm_area_struct, vm_rb)); } static void *m_start(struct seq_file *m, loff_t *pos) @@ -260,14 +248,7 @@ static const struct seq_operations proc_pid_maps_ops = { .start = m_start, .next = m_next, .stop = m_stop, - .show = show_pid_map -}; - -static const struct seq_operations proc_tid_maps_ops = { - .start = m_start, - .next = m_next, - .stop = m_stop, - .show = show_tid_map + .show = show_map }; static int maps_open(struct inode *inode, struct file *file, @@ -308,11 +289,6 @@ static int pid_maps_open(struct inode *inode, struct file *file) return maps_open(inode, file, &proc_pid_maps_ops); } -static int tid_maps_open(struct inode *inode, struct file *file) -{ - return maps_open(inode, file, &proc_tid_maps_ops); -} - const struct file_operations proc_pid_maps_operations = { .open = pid_maps_open, .read = seq_read, @@ -320,10 +296,3 @@ const struct file_operations proc_pid_maps_operations = { .release = map_release, }; -const struct file_operations proc_tid_maps_operations = { - .open = tid_maps_open, - .read = seq_read, - .llseek = seq_lseek, - .release = map_release, -}; - From patchwork Mon Jul 23 11:19:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 10539993 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7F9AE1805 for ; Mon, 23 Jul 2018 11:19:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67EDA28600 for ; Mon, 23 Jul 2018 11:19:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B92428609; Mon, 23 Jul 2018 11:19:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37AC328600 for ; Mon, 23 Jul 2018 11:19:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 290A36B0006; Mon, 23 Jul 2018 07:19:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 23F0B6B000A; Mon, 23 Jul 2018 07:19:53 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 106BD6B000C; Mon, 23 Jul 2018 07:19:53 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id C212F6B0006 for ; Mon, 23 Jul 2018 07:19:52 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id x2-v6so187992plv.0 for ; Mon, 23 Jul 2018 04:19:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=ctLPVpDP/xgC2pHU/YvrpFTbtXwGY3rY8ISq8eK7yoQ=; b=p8+87GwweDkTlcU77QyvVN6OcGloVEILcW9KrguA5zIwWOv9KjeYnSimykdDgpQKC9 UPV8/Mj6rHV8lp2z53DB1jfcQ7dCCSGe45VF71otqoeu9v7ojGdtw+stkMJePvkyh2dl PBKoV64WJIxKoCyZUQRGbhMgAt2tldDs2AlJGwJR0RFpjWGY9Ri0hqG6BeIfVGOSs6It HUeBE3JRhSRpVCF+4bSTNHSdOLvQQwuPODhfvhk1r+N9ase7GNe2SS1qvToxLT7FtKXh NbAgdP9XqLr/paLtr3bgFyjgf7KR1XThGK77SWoapYjW9e9GxNzs/M8pCez3Rp5crXdF cYGg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Gm-Message-State: AOUpUlFAFHUtwnc0yKRvKBwTQ0qjw7JFpZLP/dx/eHQImDUdx6cl0e2j eWWMOA/2XxBUTaFGvAHP9o8FFeE5BSUFJKo5tJNJpoxUaLrwo6ho1rV4fF6My6t+Hwvw4PqH1IN MCCArH3/n11IinfylBZdb4fCvYpRNtMUaGSNYEAW+6/BF/wMcf5grZ4YmAkCcG7LUnA== X-Received: by 2002:a65:5288:: with SMTP id y8-v6mr11753548pgp.284.1532344792498; Mon, 23 Jul 2018 04:19:52 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcPRASiplt79NfpRdl25c2qS76mNTinrfoFrLE33aCBFtZAsWg844xsxoWDJt5Qh/Q8+zNc X-Received: by 2002:a65:5288:: with SMTP id y8-v6mr11753505pgp.284.1532344791713; Mon, 23 Jul 2018 04:19:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532344791; cv=none; d=google.com; s=arc-20160816; b=vJ+yJCEytWP5f4lQChZeSMKmsZedW+aV5zbvb8a4BqVeXvYbB56vpyxZUo/Yh+psLP PYD6ahywewyHbrN9PoJ6WsCtAiH29kRqt2/YadMYJMCptDvYaDkODGH32m8K5BPnYXLJ 3Vb+ZxkGOK7zqPav6AR9zbpZ93d5zA8nWbvdk8tNazjNI1hErNrKW3iLHl+gbUscWkBW HqVACwn1iHnlsWgXLL7fAUWE11udQCFyMPBoULSgp7FWQzQUVQrn8aQWxbRRsisU7JSF dJK9h1HqY9bvD/BwDAfa1ReX42N9UHRyh0CPzinmxzbSjbJ95+20d/Wb7LoPv6gPqZEq UqZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ctLPVpDP/xgC2pHU/YvrpFTbtXwGY3rY8ISq8eK7yoQ=; b=CNtfmhoFAM2eKFhw/+bQK4V6VDwYyyNa8ItQen6TqAHWv4WJtkQEfRpW+WyL3hnJSo ihEEGFhr2CP7NK05vWv+aNcI8nqvKfqn9xTe4+bTzQKXpzoQYyGJr6uHODjZjYayhKBc 3jNtC4Ikm8QUUYQ8txvsRsbypkKzMCQAdHVKItZrPjo17A5ghDwES6KTDk2mdwDeFlW6 ey1ErcVZcIIGlS3NzdZOArkdcRDPmOKzKzilt9DIr4LhA8GDKHANgDWsPjVoCKC9q2XT X3x6uXnq7B1L2sFSRtlMMjl+Y7PZGWs/iGX+JUnaswjtHpNnUjDVLjvhcEQ3pG9g2ncE E19A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz Received: from mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id v190-v6si8615556pgd.668.2018.07.23.04.19.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 04:19:51 -0700 (PDT) Received-SPF: pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D2A27AEDA; Mon, 23 Jul 2018 11:19:49 +0000 (UTC) From: Vlastimil Babka To: Andrew Morton Cc: Daniel Colascione , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alexey Dobriyan , linux-api@vger.kernel.org, Vlastimil Babka Subject: [PATCH 2/4] mm: proc/pid/smaps: factor out mem stats gathering Date: Mon, 23 Jul 2018 13:19:31 +0200 Message-Id: <20180723111933.15443-3-vbabka@suse.cz> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180723111933.15443-1-vbabka@suse.cz> References: <20180723111933.15443-1-vbabka@suse.cz> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP To prepare for handling /proc/pid/smaps_rollup differently from /proc/pid/smaps factor out vma mem stats gathering from show_smap() - it will be used by both. Signed-off-by: Vlastimil Babka Signed-off-by: Vlastimil Babka --- fs/proc/task_mmu.c | 55 ++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index a3f98ca50981..d2ca88c92d9d 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -702,14 +702,9 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned long hmask, } #endif /* HUGETLB_PAGE */ -#define SEQ_PUT_DEC(str, val) \ - seq_put_decimal_ull_width(m, str, (val) >> 10, 8) -static int show_smap(struct seq_file *m, void *v) +static void smap_gather_stats(struct vm_area_struct *vma, + struct mem_size_stats *mss) { - struct proc_maps_private *priv = m->private; - struct vm_area_struct *vma = v; - struct mem_size_stats mss_stack; - struct mem_size_stats *mss; struct mm_walk smaps_walk = { .pmd_entry = smaps_pte_range, #ifdef CONFIG_HUGETLB_PAGE @@ -717,23 +712,6 @@ static int show_smap(struct seq_file *m, void *v) #endif .mm = vma->vm_mm, }; - int ret = 0; - bool rollup_mode; - bool last_vma; - - if (priv->rollup) { - rollup_mode = true; - mss = priv->rollup; - if (mss->first) { - mss->first_vma_start = vma->vm_start; - mss->first = false; - } - last_vma = !m_next_vma(priv, vma); - } else { - rollup_mode = false; - memset(&mss_stack, 0, sizeof(mss_stack)); - mss = &mss_stack; - } smaps_walk.private = mss; @@ -765,6 +743,35 @@ static int show_smap(struct seq_file *m, void *v) walk_page_vma(vma, &smaps_walk); if (vma->vm_flags & VM_LOCKED) mss->pss_locked += mss->pss; +} + +#define SEQ_PUT_DEC(str, val) \ + seq_put_decimal_ull_width(m, str, (val) >> 10, 8) +static int show_smap(struct seq_file *m, void *v) +{ + struct proc_maps_private *priv = m->private; + struct vm_area_struct *vma = v; + struct mem_size_stats mss_stack; + struct mem_size_stats *mss; + int ret = 0; + bool rollup_mode; + bool last_vma; + + if (priv->rollup) { + rollup_mode = true; + mss = priv->rollup; + if (mss->first) { + mss->first_vma_start = vma->vm_start; + mss->first = false; + } + last_vma = !m_next_vma(priv, vma); + } else { + rollup_mode = false; + memset(&mss_stack, 0, sizeof(mss_stack)); + mss = &mss_stack; + } + + smap_gather_stats(vma, mss); if (!rollup_mode) { show_map_vma(m, vma); From patchwork Mon Jul 23 11:19:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 10539999 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9800490E3 for ; Mon, 23 Jul 2018 11:19:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84D5228600 for ; Mon, 23 Jul 2018 11:19:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7894F28609; Mon, 23 Jul 2018 11:19:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11D3A28608 for ; Mon, 23 Jul 2018 11:19:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 96B5A6B0007; Mon, 23 Jul 2018 07:19:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 746436B0266; Mon, 23 Jul 2018 07:19:53 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 598676B000A; Mon, 23 Jul 2018 07:19:53 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by kanga.kvack.org (Postfix) with ESMTP id EDFC06B0008 for ; Mon, 23 Jul 2018 07:19:52 -0400 (EDT) Received: by mail-pg1-f199.google.com with SMTP id j4-v6so136562pgq.16 for ; Mon, 23 Jul 2018 04:19:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=nlFl8omVkHqTPGxhjkyVGbAgCc7XIVdRzoqDMnvmdGM=; b=bcCpAqUM6zyq2WKoX4duA6jWaSlrxA0HOx5d1dgM72WwieUd8V9CmMR4no7YDYoeGj yjjF0p09LNTCfJ5xDhcpr1ekx9q+xs9Pq/jZ6TxwXqji2R3zd94eSOPnBuiZ5+fbHUiF 6cGSSi2UbSSHFX6za22fQMWIVIyKXfmjMEoRNeIdOksQR4imA5ytVJMKss9U9w+WIDVD QipmQYu6lPg4ZDMIsE24jxTX8GL/khNMHRz0VS1c2aYXClozPiedPSi2EBPD5LiLHBPH sA18JOn77urgBEoxcxXGyLsI2tdn/4NTfdpjEEpkyM77r6De0/R3zEn34Kr5minivi5a oPjg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Gm-Message-State: AOUpUlE0KuPf66OvQ8w2gOAXkqlThJQkx47PbzQr0IseBzestO/iPM5V 2n8dATlxJcd3vrHO12R7g5FYUuzKEDV/IxmMagn5SnRZa/06xBwoSv3F7WKSarweoqrz3mgt7MF pJmlyHWNuJNrGckWHJ5V+ACNE+jXAKfhsaUTX9ra604+3JesZpSe64Gw229f8iJ+OjA== X-Received: by 2002:a62:4add:: with SMTP id c90-v6mr12896972pfj.23.1532344792674; Mon, 23 Jul 2018 04:19:52 -0700 (PDT) X-Google-Smtp-Source: AAOMgpde29L3GuBcfW/tC7q5uGDGwCbpQRLvbjBlsXc811LbpQZBBNgBJFpYcjei0QXqTPQ9BVl1 X-Received: by 2002:a62:4add:: with SMTP id c90-v6mr12896938pfj.23.1532344791826; Mon, 23 Jul 2018 04:19:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532344791; cv=none; d=google.com; s=arc-20160816; b=kHE0dtOcnrEarnc01G0bBQIhs+PPJIBkkR8tAGC+wV6KR8i9ZilKz+DQIjSGqJdufv YbXrqsltr9jDivCaUziDYVWDhVwn9aH6hs6uMajahBjU0TXEMy2JY0YHuZplrUvngy50 SZPF9W7egWnrZCFT0PRi/2HwQQwsYbC3Aipvp3YiWVMepTfiVe16FYKyOwN0Bt+ClfHB 5L24x5JIhRv99IJDkXJmF6kpjGzccR0lmBtif2qhCW6iSEzXUsAYw4STUhffd+JOJbvv 0uWRX+e2zQj3bX8nrA51kzCIxGh6QXr5iMQNDvqbi6SCTsGPbWs6/hChIL13hm/n55RD ITSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=nlFl8omVkHqTPGxhjkyVGbAgCc7XIVdRzoqDMnvmdGM=; b=lANc6sX5VdSfBtb/dJ/7cZ+vquTFXqsm4P4a6HvInRendS9az5vGFiaiBkCbTTgr0q OXk8/DoaPOgIVrjFEfOSMNR2Bq7O2f8Gjwwu85Br5dn03mjvecaTN5tY6+rejAwDZZ6F Ya5CFnis8vMIVDi0o0LvrSKI5ixWLCGRJVfyVf/DKnxevBsl60aIvTrx77CRMhMSMfEz WdKSo1E+4oXATCfPj0lbQgphOe5yXQUIIicvDcON3EjJmmrNAh2EncfG7ULCeq0V7EHN 4fb3iAHVXccteomOKpsymN1KF+EnG1GRzxBa9xcBolt4NrM22wzsS8iD3TzFFX6/gbWf WcAg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz Received: from mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id d1-v6si8739483pfk.166.2018.07.23.04.19.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 04:19:51 -0700 (PDT) Received-SPF: pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id E453BAEDB; Mon, 23 Jul 2018 11:19:49 +0000 (UTC) From: Vlastimil Babka To: Andrew Morton Cc: Daniel Colascione , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alexey Dobriyan , linux-api@vger.kernel.org, Vlastimil Babka Subject: [PATCH 3/4] mm: proc/pid/smaps: factor out common stats printing Date: Mon, 23 Jul 2018 13:19:32 +0200 Message-Id: <20180723111933.15443-4-vbabka@suse.cz> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180723111933.15443-1-vbabka@suse.cz> References: <20180723111933.15443-1-vbabka@suse.cz> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP To prepare for handling /proc/pid/smaps_rollup differently from /proc/pid/smaps factor out from show_smap() printing the parts of output that are common for both variants, which is the bulk of the gathered memory stats. Signed-off-by: Vlastimil Babka --- fs/proc/task_mmu.c | 51 ++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index d2ca88c92d9d..1d6d315fd31b 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -747,6 +747,32 @@ static void smap_gather_stats(struct vm_area_struct *vma, #define SEQ_PUT_DEC(str, val) \ seq_put_decimal_ull_width(m, str, (val) >> 10, 8) + +/* Show the contents common for smaps and smaps_rollup */ +static void __show_smap(struct seq_file *m, struct mem_size_stats *mss) +{ + SEQ_PUT_DEC("Rss: ", mss->resident); + SEQ_PUT_DEC(" kB\nPss: ", mss->pss >> PSS_SHIFT); + SEQ_PUT_DEC(" kB\nShared_Clean: ", mss->shared_clean); + SEQ_PUT_DEC(" kB\nShared_Dirty: ", mss->shared_dirty); + SEQ_PUT_DEC(" kB\nPrivate_Clean: ", mss->private_clean); + SEQ_PUT_DEC(" kB\nPrivate_Dirty: ", mss->private_dirty); + SEQ_PUT_DEC(" kB\nReferenced: ", mss->referenced); + SEQ_PUT_DEC(" kB\nAnonymous: ", mss->anonymous); + SEQ_PUT_DEC(" kB\nLazyFree: ", mss->lazyfree); + SEQ_PUT_DEC(" kB\nAnonHugePages: ", mss->anonymous_thp); + SEQ_PUT_DEC(" kB\nShmemPmdMapped: ", mss->shmem_thp); + SEQ_PUT_DEC(" kB\nShared_Hugetlb: ", mss->shared_hugetlb); + seq_put_decimal_ull_width(m, " kB\nPrivate_Hugetlb: ", + mss->private_hugetlb >> 10, 7); + SEQ_PUT_DEC(" kB\nSwap: ", mss->swap); + SEQ_PUT_DEC(" kB\nSwapPss: ", + mss->swap_pss >> PSS_SHIFT); + SEQ_PUT_DEC(" kB\nLocked: ", + mss->pss_locked >> PSS_SHIFT); + seq_puts(m, " kB\n"); +} + static int show_smap(struct seq_file *m, void *v) { struct proc_maps_private *priv = m->private; @@ -791,28 +817,9 @@ static int show_smap(struct seq_file *m, void *v) seq_puts(m, " kB\n"); } - if (!rollup_mode || last_vma) { - SEQ_PUT_DEC("Rss: ", mss->resident); - SEQ_PUT_DEC(" kB\nPss: ", mss->pss >> PSS_SHIFT); - SEQ_PUT_DEC(" kB\nShared_Clean: ", mss->shared_clean); - SEQ_PUT_DEC(" kB\nShared_Dirty: ", mss->shared_dirty); - SEQ_PUT_DEC(" kB\nPrivate_Clean: ", mss->private_clean); - SEQ_PUT_DEC(" kB\nPrivate_Dirty: ", mss->private_dirty); - SEQ_PUT_DEC(" kB\nReferenced: ", mss->referenced); - SEQ_PUT_DEC(" kB\nAnonymous: ", mss->anonymous); - SEQ_PUT_DEC(" kB\nLazyFree: ", mss->lazyfree); - SEQ_PUT_DEC(" kB\nAnonHugePages: ", mss->anonymous_thp); - SEQ_PUT_DEC(" kB\nShmemPmdMapped: ", mss->shmem_thp); - SEQ_PUT_DEC(" kB\nShared_Hugetlb: ", mss->shared_hugetlb); - seq_put_decimal_ull_width(m, " kB\nPrivate_Hugetlb: ", - mss->private_hugetlb >> 10, 7); - SEQ_PUT_DEC(" kB\nSwap: ", mss->swap); - SEQ_PUT_DEC(" kB\nSwapPss: ", - mss->swap_pss >> PSS_SHIFT); - SEQ_PUT_DEC(" kB\nLocked: ", - mss->pss_locked >> PSS_SHIFT); - seq_puts(m, " kB\n"); - } + if (!rollup_mode || last_vma) + __show_smap(m, mss); + if (!rollup_mode) { if (arch_pkeys_enabled()) seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma)); From patchwork Mon Jul 23 11:19:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 10540011 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A07311805 for ; Mon, 23 Jul 2018 11:20:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8842F28639 for ; Mon, 23 Jul 2018 11:20:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BAFF28653; Mon, 23 Jul 2018 11:20:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C874E28639 for ; Mon, 23 Jul 2018 11:20:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB46B6B0008; Mon, 23 Jul 2018 07:19:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D015C6B0266; Mon, 23 Jul 2018 07:19:53 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8F5B6B026A; Mon, 23 Jul 2018 07:19:53 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f71.google.com (mail-pl0-f71.google.com [209.85.160.71]) by kanga.kvack.org (Postfix) with ESMTP id 38B7C6B000E for ; Mon, 23 Jul 2018 07:19:53 -0400 (EDT) Received: by mail-pl0-f71.google.com with SMTP id 31-v6so180248pld.6 for ; Mon, 23 Jul 2018 04:19:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=biWYGvo/cmFKsVN7AQvNTE8IZU/1+i91c+50vkBx4xk=; b=RSQpzS9LYFZXusuwCXFtUi3hcWr2XXjLd/u9925d1Znk+rxOJEyqbbgC/Pj2J7fM+P yNOkD9N+BxOvKKN/owo/g0WebAMRKT7nTB8UeFBA+9mV7dqLk3hHVQ0GvCUcsPB8yJwB RWlbbuvbRMAgKUCA/t0YkofGueWi+uFtlwp895mLNhn0v/1wFLDWbtJp6EXcFRFHiqBm iuQdAUQ2TL7EsWZiAolZDhyUfghoIvwixqbRgIBMMuLAZSUccGR/CMrEECSKs5XhfaPL 6dCTLA9EsTfhZhWhTycP9jH06JxOkqMJiH+cqB6NtztPFohY1qmNQdcXTCD0xuiAw+p8 Jy9Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Gm-Message-State: AOUpUlGcoZ3WN1F5HCdtiKQ/W9NmxFrxuQzQQ9RrRfRZI0sKQaPzrtvq HoPQfAB60XvYDIUENysJbth8zF5+f6nAr9db7CStXhjkg8yIYT0m3OAK2AIKfHK5/e23NxGbl+2 a5FHSFE75US6M7W/1ZFMKA+9wzZQeIa0aciONwt6euyWClj1QKmUIMuXfMmsiq31uUQ== X-Received: by 2002:a17:902:28e4:: with SMTP id f91-v6mr12624304plb.70.1532344792901; Mon, 23 Jul 2018 04:19:52 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf6lhpUIb/8dt13ZTTPadyCKJCEDglr7dJyf4Z9bPwl80UmU9yIiyNgnw20FHedJ3RE/eA1 X-Received: by 2002:a17:902:28e4:: with SMTP id f91-v6mr12624252plb.70.1532344791876; Mon, 23 Jul 2018 04:19:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532344791; cv=none; d=google.com; s=arc-20160816; b=Vz/7/GVXlDA26pd2DnHXZutz/mrtZoWRBMHz0MJiaRQWImy/X6hNM0rB0HGyFQsDRI gxSYwsMdB/ySXCU3/2K8h8mOHdJBkh8rH7WcWNQ4c3n3VwxgVp9TMf9Pb/356OywSO3o QUH6HaQ1wh7FUT8H3mbvqUGTqm9HGDZLKWwcQhW9kO2STH3VyrmxgHM+btoUs5qBhebM OxTEbwUPlwhK2r/rIQwWNbVp0dZLR0pctoZsChmiwH1q6O8JuCMmyxduX0GgS5+AG+Z/ 0Lz3wUuQt94LZFLWolTmrs9s85HyO3PV/EakFw6G5kK80dWPOeR0LDyowv1EE8i6CXiq DBEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=biWYGvo/cmFKsVN7AQvNTE8IZU/1+i91c+50vkBx4xk=; b=HBOUApBaaUJ//ascVwQ5ZLXAZ0wJQiBYEbLAlT2wMa0Qh664eig1xTF4+Zf4sp40Sl PxOEAMcNyLoNYzxtbn4kPqeHHjlU8vLu3gTikLcKaRejcABqVNGnObnSbULXaC/rumm5 oWAtYwWT64UAioS6us9dQ+UxT2Et6npMwLrd8XE+vLBDdM2ftQYeuY47mDyCaWpbPAL8 gmHbUXJ00hPTY2p874HvrjXV28PuQDmsDIIJZJ62As6o8jBxopzJiZTNoB84mt6qcZ3e q+QHhQ79nk/fQdOdQKqUa/1Xgi3fqctJqBxd4t3JnECTK9VLx7eSmcLIHVFYbrgsPYx6 aM1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz Received: from mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id b13-v6si8457409pgb.356.2018.07.23.04.19.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 04:19:51 -0700 (PDT) Received-SPF: pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 0D204AF3B; Mon, 23 Jul 2018 11:19:50 +0000 (UTC) From: Vlastimil Babka To: Andrew Morton Cc: Daniel Colascione , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alexey Dobriyan , linux-api@vger.kernel.org, Vlastimil Babka Subject: [PATCH 4/4] mm: proc/pid/smaps_rollup: convert to single value seq_file Date: Mon, 23 Jul 2018 13:19:33 +0200 Message-Id: <20180723111933.15443-5-vbabka@suse.cz> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180723111933.15443-1-vbabka@suse.cz> References: <20180723111933.15443-1-vbabka@suse.cz> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The /proc/pid/smaps_rollup file is currently implemented via the m_start/m_next/m_stop seq_file iterators shared with the other maps files, that iterate over vma's. However, the rollup file doesn't print anything for each vma, only accumulate the stats. There are some issues with the current code as reported in [1] - the accumulated stats can get skewed if seq_file start()/stop() op is called multiple times, if show() is called multiple times, and after seeks to non-zero position. Patch [1] fixed those within existing design, but I believe it is fundamentally wrong to expose the vma iterators to the seq_file mechanism when smaps_rollup shows logically a single set of values for the whole address space. This patch thus refactors the code to provide a single "value" at offset 0, with vma iteration to gather the stats done internally. This fixes the situations where results are skewed, and simplifies the code, especially in show_smap(), at the expense of somewhat less code reuse. [1] https://marc.info/?l=linux-mm&m=151927723128134&w=2 Reported-by: Daniel Colascione Signed-off-by: Vlastimil Babka Reported-by: Daniel Colascione Signed-off-by: Vlastimil Babka Reviewed-by: Alexey Dobriyan --- fs/proc/task_mmu.c | 136 ++++++++++++++++++++++++++++----------------- 1 file changed, 86 insertions(+), 50 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 1d6d315fd31b..31109e67804c 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -404,7 +404,6 @@ const struct file_operations proc_pid_maps_operations = { #ifdef CONFIG_PROC_PAGE_MONITOR struct mem_size_stats { - bool first; unsigned long resident; unsigned long shared_clean; unsigned long shared_dirty; @@ -418,11 +417,12 @@ struct mem_size_stats { unsigned long swap; unsigned long shared_hugetlb; unsigned long private_hugetlb; - unsigned long first_vma_start; + unsigned long last_vma_end; u64 pss; u64 pss_locked; u64 swap_pss; bool check_shmem_swap; + bool finished; }; static void smaps_account(struct mem_size_stats *mss, struct page *page, @@ -775,58 +775,57 @@ static void __show_smap(struct seq_file *m, struct mem_size_stats *mss) static int show_smap(struct seq_file *m, void *v) { - struct proc_maps_private *priv = m->private; struct vm_area_struct *vma = v; - struct mem_size_stats mss_stack; - struct mem_size_stats *mss; - int ret = 0; - bool rollup_mode; - bool last_vma; - - if (priv->rollup) { - rollup_mode = true; - mss = priv->rollup; - if (mss->first) { - mss->first_vma_start = vma->vm_start; - mss->first = false; - } - last_vma = !m_next_vma(priv, vma); - } else { - rollup_mode = false; - memset(&mss_stack, 0, sizeof(mss_stack)); - mss = &mss_stack; - } + struct mem_size_stats mss; - smap_gather_stats(vma, mss); + memset(&mss, 0, sizeof(mss)); - if (!rollup_mode) { - show_map_vma(m, vma); - } else if (last_vma) { - show_vma_header_prefix( - m, mss->first_vma_start, vma->vm_end, 0, 0, 0, 0); - seq_pad(m, ' '); - seq_puts(m, "[rollup]\n"); - } else { - ret = SEQ_SKIP; - } + smap_gather_stats(vma, &mss); - if (!rollup_mode) { - SEQ_PUT_DEC("Size: ", vma->vm_end - vma->vm_start); - SEQ_PUT_DEC(" kB\nKernelPageSize: ", vma_kernel_pagesize(vma)); - SEQ_PUT_DEC(" kB\nMMUPageSize: ", vma_mmu_pagesize(vma)); - seq_puts(m, " kB\n"); - } + show_map_vma(m, vma); - if (!rollup_mode || last_vma) - __show_smap(m, mss); + SEQ_PUT_DEC("Size: ", vma->vm_end - vma->vm_start); + SEQ_PUT_DEC(" kB\nKernelPageSize: ", vma_kernel_pagesize(vma)); + SEQ_PUT_DEC(" kB\nMMUPageSize: ", vma_mmu_pagesize(vma)); + seq_puts(m, " kB\n"); + + __show_smap(m, &mss); + + if (arch_pkeys_enabled()) + seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma)); + show_smap_vma_flags(m, vma); - if (!rollup_mode) { - if (arch_pkeys_enabled()) - seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma)); - show_smap_vma_flags(m, vma); - } m_cache_vma(m, vma); - return ret; + + return 0; +} + +static int show_smaps_rollup(struct seq_file *m, void *v) +{ + struct proc_maps_private *priv = m->private; + struct mem_size_stats *mss = priv->rollup; + struct vm_area_struct *vma; + + /* + * We might be called multiple times when e.g. the seq buffer + * overflows. Gather the stats only once. + */ + if (!mss->finished) { + for (vma = priv->mm->mmap; vma; vma = vma->vm_next) { + smap_gather_stats(vma, mss); + mss->last_vma_end = vma->vm_end; + } + mss->finished = true; + } + + show_vma_header_prefix(m, priv->mm->mmap->vm_start, + mss->last_vma_end, 0, 0, 0, 0); + seq_pad(m, ' '); + seq_puts(m, "[rollup]\n"); + + __show_smap(m, mss); + + return 0; } #undef SEQ_PUT_DEC @@ -837,6 +836,44 @@ static const struct seq_operations proc_pid_smaps_op = { .show = show_smap }; +static void *smaps_rollup_start(struct seq_file *m, loff_t *ppos) +{ + struct proc_maps_private *priv = m->private; + struct mm_struct *mm; + + if (*ppos != 0) + return NULL; + + priv->task = get_proc_task(priv->inode); + if (!priv->task) + return ERR_PTR(-ESRCH); + + mm = priv->mm; + if (!mm || !mmget_not_zero(mm)) + return NULL; + + memset(priv->rollup, 0, sizeof(*priv->rollup)); + + down_read(&mm->mmap_sem); + hold_task_mempolicy(priv); + + return mm; +} + +static void *smaps_rollup_next(struct seq_file *m, void *v, loff_t *pos) +{ + (*pos)++; + vma_stop(m->private); + return NULL; +} + +static const struct seq_operations proc_pid_smaps_rollup_op = { + .start = smaps_rollup_start, + .next = smaps_rollup_next, + .stop = m_stop, + .show = show_smaps_rollup +}; + static int pid_smaps_open(struct inode *inode, struct file *file) { return do_maps_open(inode, file, &proc_pid_smaps_op); @@ -846,18 +883,17 @@ static int pid_smaps_rollup_open(struct inode *inode, struct file *file) { struct seq_file *seq; struct proc_maps_private *priv; - int ret = do_maps_open(inode, file, &proc_pid_smaps_op); + int ret = do_maps_open(inode, file, &proc_pid_smaps_rollup_op); if (ret < 0) return ret; seq = file->private_data; priv = seq->private; - priv->rollup = kzalloc(sizeof(*priv->rollup), GFP_KERNEL); + priv->rollup = kmalloc(sizeof(*priv->rollup), GFP_KERNEL); if (!priv->rollup) { proc_map_release(inode, file); return -ENOMEM; } - priv->rollup->first = true; return 0; }