[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241116175922.3265872-2-pasha.tatashin@soleen.com>
Date: Sat, 16 Nov 2024 17:59:17 +0000
From: Pasha Tatashin <pasha.tatashin@...een.com>
To: pasha.tatashin@...een.com,
linux-kernel@...r.kernel.org,
linux-mm@...ck.org,
linux-doc@...r.kernel.org,
linux-fsdevel@...r.kernel.org,
cgroups@...r.kernel.org,
linux-kselftest@...r.kernel.org,
akpm@...ux-foundation.org,
corbet@....net,
derek.kiernan@....com,
dragan.cvetic@....com,
arnd@...db.de,
gregkh@...uxfoundation.org,
viro@...iv.linux.org.uk,
brauner@...nel.org,
jack@...e.cz,
tj@...nel.org,
hannes@...xchg.org,
mhocko@...nel.org,
roman.gushchin@...ux.dev,
shakeel.butt@...ux.dev,
muchun.song@...ux.dev,
Liam.Howlett@...cle.com,
lorenzo.stoakes@...cle.com,
vbabka@...e.cz,
jannh@...gle.com,
shuah@...nel.org,
vegard.nossum@...cle.com,
vattunuru@...vell.com,
schalla@...vell.com,
david@...hat.com,
willy@...radead.org,
osalvador@...e.de,
usama.anjum@...labora.com,
andrii@...nel.org,
ryan.roberts@....com,
peterx@...hat.com,
oleg@...hat.com,
tandersen@...flix.com,
rientjes@...gle.com,
gthelen@...gle.com
Subject: [RFCv1 1/6] mm: Make get_vma_name() function public
Page Detective will be using get_vma_name() that is currently used by
fs/proc to show names of VMAs in /proc/<pid>/smaps for example.
Move this function to mm/vma.c, and make it accessible by modules.
Signed-off-by: Pasha Tatashin <pasha.tatashin@...een.com>
---
fs/proc/task_mmu.c | 61 ----------------------------------------------
include/linux/fs.h | 3 +++
mm/vma.c | 60 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 63 insertions(+), 61 deletions(-)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index e52bd96137a6..b28c42b7a591 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/fs.h b/include/linux/fs.h
index 3559446279c1..a25b72397af5 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -3474,6 +3474,9 @@ void setattr_copy(struct mnt_idmap *, struct inode *inode,
extern int file_update_time(struct file *file);
+void get_vma_name(struct vm_area_struct *vma, const struct path **path,
+ const char **name, const char **name_fmt);
+
static inline bool vma_is_dax(const struct vm_area_struct *vma)
{
return vma->vm_file && IS_DAX(vma->vm_file->f_mapping->host);
diff --git a/mm/vma.c b/mm/vma.c
index 7621384d64cf..1bd589fbc3c7 100644
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -2069,3 +2069,63 @@ void mm_drop_all_locks(struct mm_struct *mm)
mutex_unlock(&mm_all_locks_mutex);
}
+
+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_GPL(get_vma_name);
--
2.47.0.338.g60cca15819-goog
Powered by blists - more mailing lists