From: "qiwu.chen" <qiwuchen55@gmail.com>
To: akpm@linux-foundation.org, Liam.Howlett@oracle.com,
vbabka@suse.cz, lorenzo.stoakes@oracle.com
Cc: linux-mm@kvack.org, "qiwu.chen" <qiwu.chen@transsion.com>
Subject: [PATCH] mm: move get_vma_name() from procfs to mm tree
Date: Sun, 29 Sep 2024 17:32:12 +0800 [thread overview]
Message-ID: <20240929093212.40449-1-qiwu.chen@transsion.com> (raw)
Commit acd4b2ecf3bb2 ("fs/procfs: extract logic for getting VMA name
constituents") introduces a generic helper to get VMA name constituents.
Currently, it's statically defined and referenced in fs/proc/task_mmu.c,
which is not opened to users who want to query VMA name more efficiently.
This patch moves get_vma_name() from procfs to mm/mmap.c, and export it
for modules usage.
There should be no functional changes.
Signed-off-by: qiwu.chen <qiwu.chen@transsion.com>
---
fs/proc/task_mmu.c | 61 --------------------------------------
include/linux/mm.h | 2 ++
mm/mmap.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 76 insertions(+), 61 deletions(-)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 72f14fd59c2d..7d414c39367a 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -240,67 +240,6 @@ static int do_maps_open(struct inode *inode, struct file *file,
sizeof(struct proc_maps_private));
}
-static void get_vma_name(struct vm_area_struct *vma,
- const struct path **path,
- const char **name,
- const char **name_fmt)
-{
- struct anon_vma_name *anon_name = vma->vm_mm ? anon_vma_name(vma) : NULL;
-
- *name = NULL;
- *path = NULL;
- *name_fmt = NULL;
-
- /*
- * Print the dentry name for named mappings, and a
- * special [heap] marker for the heap:
- */
- if (vma->vm_file) {
- /*
- * If user named this anon shared memory via
- * prctl(PR_SET_VMA ..., use the provided name.
- */
- if (anon_name) {
- *name_fmt = "[anon_shmem:%s]";
- *name = anon_name->name;
- } else {
- *path = file_user_path(vma->vm_file);
- }
- return;
- }
-
- if (vma->vm_ops && vma->vm_ops->name) {
- *name = vma->vm_ops->name(vma);
- if (*name)
- return;
- }
-
- *name = arch_vma_name(vma);
- if (*name)
- return;
-
- if (!vma->vm_mm) {
- *name = "[vdso]";
- return;
- }
-
- if (vma_is_initial_heap(vma)) {
- *name = "[heap]";
- return;
- }
-
- if (vma_is_initial_stack(vma)) {
- *name = "[stack]";
- return;
- }
-
- if (anon_name) {
- *name_fmt = "[anon:%s]";
- *name = anon_name->name;
- return;
- }
-}
-
static void show_vma_header_prefix(struct seq_file *m,
unsigned long start, unsigned long end,
vm_flags_t flags, unsigned long long pgoff,
diff --git a/include/linux/mm.h b/include/linux/mm.h
index ecf63d2b0582..31abb857e11e 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -3418,6 +3418,8 @@ int expand_downwards(struct vm_area_struct *vma, unsigned long address);
extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long addr);
extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
struct vm_area_struct **pprev);
+extern void get_vma_name(struct vm_area_struct *vma, const struct path **path,
+ const char **name, const char **name_fmt);
/*
* Look up the first VMA which intersects the interval [start_addr, end_addr)
diff --git a/mm/mmap.c b/mm/mmap.c
index ee8f91eaadb9..d6ca383fc302 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -995,6 +995,80 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
return vma;
}
+/**
+ * get_vma_name() - get VMA name with relevant pieces of data.
+ * @vma: The vma to check
+ * @path: The file path given to the vma
+ * @name: The vma name
+ * @name_fmt: The formatted vma name
+ *
+ * Extract generic logic to fetch relevant pieces of data to describe
+ * VMA name. This could be just some string (either special constant or
+ * user-provided), or a string with some formatted wrapping text (e.g.,
+ * "[anon_shmem:<something>]"), or, commonly, file path.
+ */
+void get_vma_name(struct vm_area_struct *vma,
+ const struct path **path,
+ const char **name,
+ const char **name_fmt)
+{
+ struct anon_vma_name *anon_name = vma->vm_mm ? anon_vma_name(vma) : NULL;
+
+ *name = NULL;
+ *path = NULL;
+ *name_fmt = NULL;
+
+ /*
+ * Print the dentry name for named mappings, and a
+ * special [heap] marker for the heap:
+ */
+ if (vma->vm_file) {
+ /*
+ * If user named this anon shared memory via
+ * prctl(PR_SET_VMA ..., use the provided name.
+ */
+ if (anon_name) {
+ *name_fmt = "[anon_shmem:%s]";
+ *name = anon_name->name;
+ } else {
+ *path = file_user_path(vma->vm_file);
+ }
+ return;
+ }
+
+ if (vma->vm_ops && vma->vm_ops->name) {
+ *name = vma->vm_ops->name(vma);
+ if (*name)
+ return;
+ }
+
+ *name = arch_vma_name(vma);
+ if (*name)
+ return;
+
+ if (!vma->vm_mm) {
+ *name = "[vdso]";
+ return;
+ }
+
+ if (vma_is_initial_heap(vma)) {
+ *name = "[heap]";
+ return;
+ }
+
+ if (vma_is_initial_stack(vma)) {
+ *name = "[stack]";
+ return;
+ }
+
+ if (anon_name) {
+ *name_fmt = "[anon:%s]";
+ *name = anon_name->name;
+ return;
+ }
+}
+EXPORT_SYMBOL(get_vma_name);
+
/*
* Verify that the stack growth is acceptable and
* update accounting. This is shared with both the
--
2.25.1
next reply other threads:[~2024-09-29 9:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-29 9:32 qiwu.chen [this message]
2024-09-30 18:05 ` Andrew Morton
2024-10-01 10:55 ` chenqiwu
2024-10-01 11:09 ` Lorenzo Stoakes
2024-09-30 19:03 ` Lorenzo Stoakes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240929093212.40449-1-qiwu.chen@transsion.com \
--to=qiwuchen55@gmail.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=qiwu.chen@transsion.com \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox