From patchwork Sat Jul 30 16:35:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: haoxin X-Patchwork-Id: 12933023 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F41AFC04A68 for ; Sat, 30 Jul 2022 16:35:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E40136B0071; Sat, 30 Jul 2022 12:35:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DEF4B8E0002; Sat, 30 Jul 2022 12:35:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CDE138E0001; Sat, 30 Jul 2022 12:35:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id BF33A6B0071 for ; Sat, 30 Jul 2022 12:35:45 -0400 (EDT) Received: from smtpin31.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7E102404D5 for ; Sat, 30 Jul 2022 16:35:45 +0000 (UTC) X-FDA: 79744317450.31.252C479 Received: from out30-44.freemail.mail.aliyun.com (out30-44.freemail.mail.aliyun.com [115.124.30.44]) by imf23.hostedemail.com (Postfix) with ESMTP id 4CE7E1400D8 for ; Sat, 30 Jul 2022 16:35:42 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R831e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VKrLbJS_1659198937; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VKrLbJS_1659198937) by smtp.aliyun-inc.com; Sun, 31 Jul 2022 00:35:39 +0800 From: Xin Hao To: adobriyan@gmail.com Cc: akpm@linux-foundation.org, keescook@chromium.org, xhao@linux.alibaba.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH] mm: add last level page table numa info to /proc/pid/numa_pgtable Date: Sun, 31 Jul 2022 00:35:28 +0800 Message-Id: <20220730163528.48377-1-xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.44 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659198945; a=rsa-sha256; cv=none; b=YQA6v2LKEOTd7MwFPDrKmbrLhWNM+kgsr583oNewQZoMBDLSybyTHcKRqD/Sym17oqcIcp p8mMHe9/nwTKrBh531Fl9HDYEokDBZhv9vllrfmor1jDo3SuqBAGz6KDt03rAz8zznstfH Y61JkGSc173BARu1TCDceE0ceIz951Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659198945; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=VLgsh0z+XFjP/85xbtWvm198z3yT/z5L2US8xSBkdeY=; b=mcwUT3kqprvukO/tARHvc3iGNDJFGGZXjSbkYCMgh4Z8rWDas3i9pqfZSFQ/D5giALkbcQ +8zAeGwdaeyi0yxL4XRAgJJssVDyAv7d8V1iaDMvtaZShrk7Af8WEwABtSQDjSXrXwpXLZ /WEyg4yJrbvr1AAengO+6R/J1Y/06H4= X-Stat-Signature: 5r3p9aoebjy7bwqir43ixrx6omdxnjqn X-Rspamd-Queue-Id: 4CE7E1400D8 X-Rspam-User: X-Rspamd-Server: rspam05 Authentication-Results: imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.44 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com X-HE-Tag: 1659198942-807670 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: In many data center servers, the shared memory architectures is Non-Uniform Memory Access (NUMA), remote numa node data access often brings a high latency problem, but what we are easy to ignore is that the page table remote numa access, It can also leads to a performance degradation. So there add a new interface in /proc, This will help developers to get more info about performance issues if they are caused by cross-NUMA. Signed-off-by: Xin Hao --- fs/proc/base.c | 6 ++- fs/proc/internal.h | 1 + fs/proc/task_mmu.c | 129 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+), 2 deletions(-) -- 2.31.0 diff --git a/fs/proc/base.c b/fs/proc/base.c index 8dfa36a99c74..de60351813ec 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2626,7 +2626,7 @@ static struct dentry *proc_pident_instantiate(struct dentry *dentry, return d_splice_alias(inode, dentry); } -static struct dentry *proc_pident_lookup(struct inode *dir, +static struct dentry *proc_pident_lookup(struct inode *dir, struct dentry *dentry, const struct pid_entry *p, const struct pid_entry *end) @@ -2839,7 +2839,7 @@ static const struct pid_entry attr_dir_stuff[] = { static int proc_attr_dir_readdir(struct file *file, struct dir_context *ctx) { - return proc_pident_readdir(file, ctx, + return proc_pident_readdir(file, ctx, attr_dir_stuff, ARRAY_SIZE(attr_dir_stuff)); } @@ -3224,6 +3224,7 @@ static const struct pid_entry tgid_base_stuff[] = { REG("maps", S_IRUGO, proc_pid_maps_operations), #ifdef CONFIG_NUMA REG("numa_maps", S_IRUGO, proc_pid_numa_maps_operations), + REG("numa_pgtable", S_IRUGO, proc_pid_numa_pgtable_operations), #endif REG("mem", S_IRUSR|S_IWUSR, proc_mem_operations), LNK("cwd", proc_cwd_link), @@ -3571,6 +3572,7 @@ static const struct pid_entry tid_base_stuff[] = { #endif #ifdef CONFIG_NUMA REG("numa_maps", S_IRUGO, proc_pid_numa_maps_operations), + REG("numa_pgtable", S_IRUGO, proc_pid_numa_pgtable_operations), #endif REG("mem", S_IRUSR|S_IWUSR, proc_mem_operations), LNK("cwd", proc_cwd_link), diff --git a/fs/proc/internal.h b/fs/proc/internal.h index 06a80f78433d..e7ed9ef097b6 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h @@ -296,6 +296,7 @@ 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_pid_numa_maps_operations; +extern const struct file_operations proc_pid_numa_pgtable_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_clear_refs_operations; diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 2d04e3470d4c..a51befb47ea8 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1999,4 +1999,133 @@ const struct file_operations proc_pid_numa_maps_operations = { .release = proc_map_release, }; +struct pgtable_numa_maps { + unsigned long node[MAX_NUMNODES]; +}; + +struct pgtable_numa_private { + struct proc_maps_private proc_maps; + struct pgtable_numa_maps md; +}; + +static void gather_pgtable_stats(struct page *page, struct pgtable_numa_maps *md) +{ + md->node[page_to_nid(page)] += 1; +} + +static struct page *can_gather_pgtable_numa_stats(pmd_t pmd, struct vm_area_struct *vma, + unsigned long addr) +{ + struct page *page; + int nid; + + if (!pmd_present(pmd)) + return NULL; + + if (pmd_huge(pmd)) + return NULL; + + page = pmd_page(pmd); + nid = page_to_nid(page); + if (!node_isset(nid, node_states[N_MEMORY])) + return NULL; + + return page; +} + +static int gather_pgtable_numa_stats(pmd_t *pmd, unsigned long addr, + unsigned long end, struct mm_walk *walk) +{ + struct pgtable_numa_maps *md = walk->private; + struct vm_area_struct *vma = walk->vma; + struct page *page; + + if (pmd_huge(*pmd)) { + struct page *pmd_page; + + pmd_page = virt_to_page(pmd); + if (!pmd_page) + return 0; + + if (!node_isset(page_to_nid(pmd_page), node_states[N_MEMORY])) + return 0; + + gather_pgtable_stats(pmd_page, md); + goto out; + } + + page = can_gather_pgtable_numa_stats(*pmd, vma, addr); + if (!page) + return 0; + + gather_pgtable_stats(page, md); + +out: + cond_resched(); + return 0; +} + +static const struct mm_walk_ops show_numa_pgtable_ops = { + .pmd_entry = gather_pgtable_numa_stats, +}; + +/* + * Display the page talbe allocated per node via /proc. + */ +static int show_numa_pgtable(struct seq_file *m, void *v) +{ + struct pgtable_numa_private *numa_priv = m->private; + struct vm_area_struct *vma = v; + struct pgtable_numa_maps *md = &numa_priv->md; + struct mm_struct *mm = vma->vm_mm; + struct file *file = vma->vm_file; + int nid; + + if (!mm) + return 0; + + memset(md, 0, sizeof(*md)); + + seq_printf(m, "%08lx ", vma->vm_start); + + if (file) { + seq_puts(m, " file="); + seq_file_path(m, file, "\n\t= "); + } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) { + seq_puts(m, " heap"); + } else if (is_stack(vma)) { + seq_puts(m, " stack"); + } + + /* mmap_lock is held by m_start */ + walk_page_vma(vma, &show_numa_pgtable_ops, md); + + for_each_node_state(nid, N_MEMORY) { + if (md->node[nid]) + seq_printf(m, " N%d=%lu", nid, md->node[nid]); + } + seq_putc(m, '\n'); + + return 0; +} +static const struct seq_operations proc_pid_numa_pgtable_op = { + .start = m_start, + .next = m_next, + .stop = m_stop, + .show = show_numa_pgtable, +}; + +static int pid_numa_pgtable_open(struct inode *inode, struct file *file) +{ + return proc_maps_open(inode, file, &proc_pid_numa_pgtable_op, + sizeof(struct pgtable_numa_private)); +} + +const struct file_operations proc_pid_numa_pgtable_operations = { + .open = pid_numa_pgtable_open, + .read = seq_read, + .llseek = seq_lseek, + .release = proc_map_release, +}; + #endif /* CONFIG_NUMA */