Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm: shmem: use SHMEM_F_* flags instead of VM_* flags

shmem_inode_info::flags can have the VM flags VM_NORESERVE and VM_LOCKED.
These are used to suppress pre-accounting or to lock the pages in the
inode respectively. Using the VM flags directly makes it difficult to add
shmem-specific flags that are unrelated to VM behavior since one would
need to find a VM flag not used by shmem and re-purpose it.

Introduce SHMEM_F_NORESERVE and SHMEM_F_LOCKED which represent the same
information, but their bits are independent of the VM flags. Callers can
still pass VM_NORESERVE to shmem_get_inode(), but it gets transformed to
the shmem-specific flag internally.

No functional changes intended.

Link: https://lkml.kernel.org/r/20251125165850.3389713-11-pasha.tatashin@soleen.com
Signed-off-by: Pratyush Yadav <ptyadav@amazon.de>
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Tested-by: David Matlack <dmatlack@google.com>
Cc: Aleksander Lobakin <aleksander.lobakin@intel.com>
Cc: Alexander Graf <graf@amazon.com>
Cc: Alice Ryhl <aliceryhl@google.com>
Cc: Andriy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: anish kumar <yesanishhere@gmail.com>
Cc: Anna Schumaker <anna.schumaker@oracle.com>
Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Borislav Betkov <bp@alien8.de>
Cc: Chanwoo Choi <cw00.choi@samsung.com>
Cc: Chen Ridong <chenridong@huawei.com>
Cc: Chris Li <chrisl@kernel.org>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Daniel Wagner <wagi@kernel.org>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Jeffery <djeffery@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Guixin Liu <kanie@linux.alibaba.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Jann Horn <jannh@google.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Joanthan Cameron <Jonathan.Cameron@huawei.com>
Cc: Joel Granados <joel.granados@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Lennart Poettering <lennart@poettering.net>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Leon Romanovsky <leonro@nvidia.com>
Cc: Lukas Wunner <lukas@wunner.de>
Cc: Marc Rutland <mark.rutland@arm.com>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Matthew Maurer <mmaurer@google.com>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Myugnjoo Ham <myungjoo.ham@samsung.com>
Cc: Parav Pandit <parav@nvidia.com>
Cc: Pratyush Yadav <pratyush@kernel.org>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Saeed Mahameed <saeedm@nvidia.com>
Cc: Samiullah Khawaja <skhawaja@google.com>
Cc: Song Liu <song@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Stuart Hayes <stuart.w.hayes@gmail.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleinxer <tglx@linutronix.de>
Cc: Thomas Weißschuh <linux@weissschuh.net>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: William Tu <witu@nvidia.com>
Cc: Yoann Congal <yoann.congal@smile.fr>
Cc: Zhu Yanjun <yanjun.zhu@linux.dev>
Cc: Zijun Hu <quic_zijuhu@quicinc.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Pratyush Yadav and committed by
Andrew Morton
6ff1610c 7a5afa7e

+21 -13
+6
include/linux/shmem_fs.h
··· 10 10 #include <linux/xattr.h> 11 11 #include <linux/fs_parser.h> 12 12 #include <linux/userfaultfd_k.h> 13 + #include <linux/bits.h> 13 14 14 15 struct swap_iocb; 15 16 ··· 19 18 #ifdef CONFIG_TMPFS_QUOTA 20 19 #define SHMEM_MAXQUOTAS 2 21 20 #endif 21 + 22 + /* Suppress pre-accounting of the entire object size. */ 23 + #define SHMEM_F_NORESERVE BIT(0) 24 + /* Disallow swapping. */ 25 + #define SHMEM_F_LOCKED BIT(1) 22 26 23 27 struct shmem_inode_info { 24 28 spinlock_t lock;
+15 -13
mm/shmem.c
··· 175 175 */ 176 176 static inline int shmem_acct_size(unsigned long flags, loff_t size) 177 177 { 178 - return (flags & VM_NORESERVE) ? 178 + return (flags & SHMEM_F_NORESERVE) ? 179 179 0 : security_vm_enough_memory_mm(current->mm, VM_ACCT(size)); 180 180 } 181 181 182 182 static inline void shmem_unacct_size(unsigned long flags, loff_t size) 183 183 { 184 - if (!(flags & VM_NORESERVE)) 184 + if (!(flags & SHMEM_F_NORESERVE)) 185 185 vm_unacct_memory(VM_ACCT(size)); 186 186 } 187 187 188 188 static inline int shmem_reacct_size(unsigned long flags, 189 189 loff_t oldsize, loff_t newsize) 190 190 { 191 - if (!(flags & VM_NORESERVE)) { 191 + if (!(flags & SHMEM_F_NORESERVE)) { 192 192 if (VM_ACCT(newsize) > VM_ACCT(oldsize)) 193 193 return security_vm_enough_memory_mm(current->mm, 194 194 VM_ACCT(newsize) - VM_ACCT(oldsize)); ··· 206 206 */ 207 207 static inline int shmem_acct_blocks(unsigned long flags, long pages) 208 208 { 209 - if (!(flags & VM_NORESERVE)) 209 + if (!(flags & SHMEM_F_NORESERVE)) 210 210 return 0; 211 211 212 212 return security_vm_enough_memory_mm(current->mm, ··· 215 215 216 216 static inline void shmem_unacct_blocks(unsigned long flags, long pages) 217 217 { 218 - if (flags & VM_NORESERVE) 218 + if (flags & SHMEM_F_NORESERVE) 219 219 vm_unacct_memory(pages * VM_ACCT(PAGE_SIZE)); 220 220 } 221 221 ··· 1551 1551 int nr_pages; 1552 1552 bool split = false; 1553 1553 1554 - if ((info->flags & VM_LOCKED) || sbinfo->noswap) 1554 + if ((info->flags & SHMEM_F_LOCKED) || sbinfo->noswap) 1555 1555 goto redirty; 1556 1556 1557 1557 if (!total_swap_pages) ··· 2910 2910 * ipc_lock_object() when called from shmctl_do_lock(), 2911 2911 * no serialization needed when called from shm_destroy(). 2912 2912 */ 2913 - if (lock && !(info->flags & VM_LOCKED)) { 2913 + if (lock && !(info->flags & SHMEM_F_LOCKED)) { 2914 2914 if (!user_shm_lock(inode->i_size, ucounts)) 2915 2915 goto out_nomem; 2916 - info->flags |= VM_LOCKED; 2916 + info->flags |= SHMEM_F_LOCKED; 2917 2917 mapping_set_unevictable(file->f_mapping); 2918 2918 } 2919 - if (!lock && (info->flags & VM_LOCKED) && ucounts) { 2919 + if (!lock && (info->flags & SHMEM_F_LOCKED) && ucounts) { 2920 2920 user_shm_unlock(inode->i_size, ucounts); 2921 - info->flags &= ~VM_LOCKED; 2921 + info->flags &= ~SHMEM_F_LOCKED; 2922 2922 mapping_clear_unevictable(file->f_mapping); 2923 2923 } 2924 2924 retval = 0; ··· 3062 3062 spin_lock_init(&info->lock); 3063 3063 atomic_set(&info->stop_eviction, 0); 3064 3064 info->seals = F_SEAL_SEAL; 3065 - info->flags = flags & VM_NORESERVE; 3065 + info->flags = (flags & VM_NORESERVE) ? SHMEM_F_NORESERVE : 0; 3066 3066 info->i_crtime = inode_get_mtime(inode); 3067 3067 info->fsflags = (dir == NULL) ? 0 : 3068 3068 SHMEM_I(dir)->fsflags & SHMEM_FL_INHERITED; ··· 5804 5804 /* common code */ 5805 5805 5806 5806 static struct file *__shmem_file_setup(struct vfsmount *mnt, const char *name, 5807 - loff_t size, unsigned long flags, unsigned int i_flags) 5807 + loff_t size, unsigned long vm_flags, 5808 + unsigned int i_flags) 5808 5809 { 5810 + unsigned long flags = (vm_flags & VM_NORESERVE) ? SHMEM_F_NORESERVE : 0; 5809 5811 struct inode *inode; 5810 5812 struct file *res; 5811 5813 ··· 5824 5822 return ERR_PTR(-ENOMEM); 5825 5823 5826 5824 inode = shmem_get_inode(&nop_mnt_idmap, mnt->mnt_sb, NULL, 5827 - S_IFREG | S_IRWXUGO, 0, flags); 5825 + S_IFREG | S_IRWXUGO, 0, vm_flags); 5828 5826 if (IS_ERR(inode)) { 5829 5827 shmem_unacct_size(flags, size); 5830 5828 return ERR_CAST(inode);