All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: Add RWH_RMAP_EXCLUDE flag to exclude files from rmap sharing
@ 2026-04-21  2:09 Yibin Liu
  2026-04-21 14:38 ` Matthew Wilcox
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Yibin Liu @ 2026-04-21  2:09 UTC (permalink / raw)
  To: linux-mm
  Cc: akpm, Liam.Howlett, viro, brauner, mjguzik, wujianyong, huangsj,
	zhongyuan

UnixBench execl/shellscript (dynamically linked binaries) at 64+ cores are
bottlenecked on the i_mmap_rwsem semaphore due to heavy vma insert/remove
operations on the i_mmap tree, where libc.so.6 is the most frequent,
followed by ld-linux-x86-64.so.2 and the test executable itself.

This patch marks such files to skip rmap operations, avoiding frequent
interval tree insert/remove that cause i_mmap_rwsem lock contention.
The downside is these files can no longer be reclaimed (along with compact
and ksm), but since they are small and resident anyway, it's acceptable.
When all mapping processes exit, files can still be reclaimed normally.

Performance testing shows ~80% improvement in UnixBench execl/shellscript
scores on Hygon 7490, AMD zen4 9754 and Intel emerald rapids platform.

Signed-off-by: Yibin Liu <liuyibin@hygon.cn>
---
 fs/fcntl.c                 | 1 +
 fs/open.c                  | 6 ++++++
 include/linux/fs.h         | 3 +++
 include/uapi/linux/fcntl.h | 1 +
 mm/mmap.c                  | 3 ++-
 mm/vma.c                   | 8 +++++---
 6 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/fs/fcntl.c b/fs/fcntl.c
index beab8080badf..9b7cc1544735 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -349,6 +349,7 @@ static bool rw_hint_valid(u64 hint)
 	case RWH_WRITE_LIFE_MEDIUM:
 	case RWH_WRITE_LIFE_LONG:
 	case RWH_WRITE_LIFE_EXTREME:
+	case RWH_RMAP_EXCLUDE:
 		return true;
 	default:
 		return false;
diff --git a/fs/open.c b/fs/open.c
index 681d405bc61e..643ab7c6b461 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -46,6 +46,10 @@ int do_truncate(struct mnt_idmap *idmap, struct dentry *dentry,
 	if (length < 0)
 		return -EINVAL;
 
+	/* Prevent truncate on files marked as RMAP_EXCLUDE (e.g., libc, ld.so) */
+	if (filp && (filp->f_mode & FMODE_RMAP_EXCLUDE))
+		return -EPERM;
+
 	newattrs.ia_size = length;
 	newattrs.ia_valid = ATTR_SIZE | time_attrs;
 	if (filp) {
@@ -892,6 +896,8 @@ static int do_dentry_open(struct file *f,
 	path_get(&f->f_path);
 	f->f_inode = inode;
 	f->f_mapping = inode->i_mapping;
+	if (inode->i_write_hint == RWH_RMAP_EXCLUDE)
+		f->f_mode |= FMODE_RMAP_EXCLUDE;
 	f->f_wb_err = filemap_sample_wb_err(f->f_mapping);
 	f->f_sb_err = file_sample_sb_err(f);
 
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 11559c513dfb..d5c9e5a4c2b9 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -189,6 +189,9 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
 /* File does not contribute to nr_files count */
 #define FMODE_NOACCOUNT		((__force fmode_t)(1 << 29))
 
+/* File should exclude vma from rmap interval tree */
+#define FMODE_RMAP_EXCLUDE	((__force fmode_t)(1 << 30))
+
 /*
  * The two FMODE_NONOTIFY* define which fsnotify events should not be generated
  * for an open file. These are the possible values of
diff --git a/include/uapi/linux/fcntl.h b/include/uapi/linux/fcntl.h
index aadfbf6e0cb3..4969b4762071 100644
--- a/include/uapi/linux/fcntl.h
+++ b/include/uapi/linux/fcntl.h
@@ -72,6 +72,7 @@
 #define RWH_WRITE_LIFE_MEDIUM	3
 #define RWH_WRITE_LIFE_LONG	4
 #define RWH_WRITE_LIFE_EXTREME	5
+#define RWH_RMAP_EXCLUDE	6
 
 /*
  * The originally introduced spelling is remained from the first
diff --git a/mm/mmap.c b/mm/mmap.c
index 2311ae7c2ff4..3eb00997e86a 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1830,7 +1830,8 @@ __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
 				mapping_allow_writable(mapping);
 			flush_dcache_mmap_lock(mapping);
 			/* insert tmp into the share list, just after mpnt */
-			vma_interval_tree_insert_after(tmp, mpnt,
+			if (!(file->f_mode & FMODE_RMAP_EXCLUDE))
+				vma_interval_tree_insert_after(tmp, mpnt,
 					&mapping->i_mmap);
 			flush_dcache_mmap_unlock(mapping);
 			i_mmap_unlock_write(mapping);
diff --git a/mm/vma.c b/mm/vma.c
index 377321b48734..f1e36e6a8702 100644
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -234,7 +234,8 @@ static void __vma_link_file(struct vm_area_struct *vma,
 		mapping_allow_writable(mapping);
 
 	flush_dcache_mmap_lock(mapping);
-	vma_interval_tree_insert(vma, &mapping->i_mmap);
+	if (!(vma->vm_file->f_mode & FMODE_RMAP_EXCLUDE))
+		vma_interval_tree_insert(vma, &mapping->i_mmap);
 	flush_dcache_mmap_unlock(mapping);
 }
 
@@ -339,10 +340,11 @@ static void vma_complete(struct vma_prepare *vp, struct vma_iterator *vmi,
 			 struct mm_struct *mm)
 {
 	if (vp->file) {
-		if (vp->adj_next)
+		if (vp->adj_next && !(vp->adj_next->vm_file->f_mode & FMODE_RMAP_EXCLUDE))
 			vma_interval_tree_insert(vp->adj_next,
 						 &vp->mapping->i_mmap);
-		vma_interval_tree_insert(vp->vma, &vp->mapping->i_mmap);
+		if (!(vp->vma->vm_file->f_mode & FMODE_RMAP_EXCLUDE))
+			vma_interval_tree_insert(vp->vma, &vp->mapping->i_mmap);
 		flush_dcache_mmap_unlock(vp->mapping);
 	}
 
-- 
2.34.1




^ permalink raw reply related	[flat|nested] 14+ messages in thread
* Re: [PATCH] mm: Add RWH_RMAP_EXCLUDE flag to exclude files from rmap sharing
@ 2026-05-01  6:26 kernel test robot
  0 siblings, 0 replies; 14+ messages in thread
From: kernel test robot @ 2026-05-01  6:26 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp

:::::: 
:::::: Manual check reason: "low confidence bisect report"
:::::: 

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20260421020932.3212532-1-liuyibin@hygon.cn>
References: <20260421020932.3212532-1-liuyibin@hygon.cn>
TO: Yibin Liu <liuyibin@hygon.cn>
TO: linux-mm@kvack.org
CC: akpm@linux-foundation.org
CC: Liam.Howlett@oracle.com
CC: viro@zeniv.linux.org.uk
CC: brauner@kernel.org
CC: mjguzik@gmail.com
CC: wujianyong@hygon.cn
CC: huangsj@hygon.cn
CC: zhongyuan@hygon.cn

Hi Yibin,

kernel test robot noticed the following build errors:

[auto build test ERROR on akpm-mm/mm-everything]

url:    https://github.com/intel-lab-lkp/linux/commits/Yibin-Liu/mm-Add-RWH_RMAP_EXCLUDE-flag-to-exclude-files-from-rmap-sharing/20260423-115604
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20260421020932.3212532-1-liuyibin%40hygon.cn
patch subject: [PATCH] mm: Add RWH_RMAP_EXCLUDE flag to exclude files from rmap sharing
:::::: branch date: 8 days ago
:::::: commit date: 8 days ago
config: x86_64-allnoconfig-bpf (https://download.01.org/0day-ci/archive/20260501/202605010820.9zCdrX8I-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260501/202605010820.9zCdrX8I-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/r/202605010820.9zCdrX8I-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from main.c:10:
   ../../../mm/vma.c: In function '__vma_link_file':
>> ../../../mm/vma.c:237:27: error: 'struct file' has no member named 'f_mode'
     237 |         if (!(vma->vm_file->f_mode & FMODE_RMAP_EXCLUDE))
         |                           ^~
>> ../../../mm/vma.c:237:38: error: 'FMODE_RMAP_EXCLUDE' undeclared (first use in this function)
     237 |         if (!(vma->vm_file->f_mode & FMODE_RMAP_EXCLUDE))
         |                                      ^~~~~~~~~~~~~~~~~~
   ../../../mm/vma.c:237:38: note: each undeclared identifier is reported only once for each function it appears in
   ../../../mm/vma.c: In function 'vma_complete':
   ../../../mm/vma.c:343:60: error: 'struct file' has no member named 'f_mode'
     343 |                 if (vp->adj_next && !(vp->adj_next->vm_file->f_mode & FMODE_RMAP_EXCLUDE))
         |                                                            ^~
   ../../../mm/vma.c:343:71: error: 'FMODE_RMAP_EXCLUDE' undeclared (first use in this function)
     343 |                 if (vp->adj_next && !(vp->adj_next->vm_file->f_mode & FMODE_RMAP_EXCLUDE))
         |                                                                       ^~~~~~~~~~~~~~~~~~
   ../../../mm/vma.c:346:39: error: 'struct file' has no member named 'f_mode'
     346 |                 if (!(vp->vma->vm_file->f_mode & FMODE_RMAP_EXCLUDE))
         |                                       ^~

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2026-05-01  6:26 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-21  2:09 [PATCH] mm: Add RWH_RMAP_EXCLUDE flag to exclude files from rmap sharing Yibin Liu
2026-04-21 14:38 ` Matthew Wilcox
2026-04-21 15:37 ` Pedro Falcato
2026-04-22  7:19   ` David Hildenbrand (Arm)
2026-04-21 19:46 ` Mateusz Guzik
2026-04-22 13:03   ` 答复: " Yibin Liu
2026-04-22 10:49 ` Lorenzo Stoakes
2026-04-22 12:51   ` 答复: " Yibin Liu
2026-04-22 16:16     ` Lorenzo Stoakes
2026-04-24  1:08       ` 答复: " Yibin Liu
2026-04-24  3:20         ` Matthew Wilcox
2026-04-24  6:20           ` Mateusz Guzik
2026-04-24  6:54             ` Mateusz Guzik
  -- strict thread matches above, loose matches on Subject: below --
2026-05-01  6:26 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.