fs: Add FOP_HUGE_PAGES
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Tue, 9 Apr 2024 08:41:33 +0000 (10:41 +0200)
committerChristian Brauner <brauner@kernel.org>
Tue, 9 Apr 2024 08:53:44 +0000 (10:53 +0200)
Instead of checking for specific file_operations, add a bit to
file_operations which denotes a file that only contain hugetlb pages.
This lets us make hugetlbfs_file_operations static, and removes
is_file_shm_hugepages() completely.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Link: https://lore.kernel.org/r/20240407201122.3783877-1-willy@infradead.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/hugetlbfs/inode.c
include/linux/fs.h
include/linux/hugetlb.h
include/linux/shm.h
ipc/shm.c

index 6502c7e776d195e1d004908964f74ce5a76d6db2..34ac73cc36b1cf49cf2cce951355c7837ad6e350 100644 (file)
@@ -40,7 +40,7 @@
 #include <linux/sched/mm.h>
 
 static const struct address_space_operations hugetlbfs_aops;
-const struct file_operations hugetlbfs_file_operations;
+static const struct file_operations hugetlbfs_file_operations;
 static const struct inode_operations hugetlbfs_dir_inode_operations;
 static const struct inode_operations hugetlbfs_inode_operations;
 
@@ -1301,13 +1301,14 @@ static void init_once(void *foo)
        inode_init_once(&ei->vfs_inode);
 }
 
-const struct file_operations hugetlbfs_file_operations = {
+static const struct file_operations hugetlbfs_file_operations = {
        .read_iter              = hugetlbfs_read_iter,
        .mmap                   = hugetlbfs_file_mmap,
        .fsync                  = noop_fsync,
        .get_unmapped_area      = hugetlb_get_unmapped_area,
        .llseek                 = default_llseek,
        .fallocate              = hugetlbfs_fallocate,
+       .fop_flags              = FOP_HUGE_PAGES,
 };
 
 static const struct inode_operations hugetlbfs_dir_inode_operations = {
index 2ba98930c4c4f8ed35dbd9e636257936ef04c4e0..b053f98393e66a433a39c100669ae1352299729e 100644 (file)
@@ -2052,6 +2052,8 @@ struct file_operations {
 #define FOP_MMAP_SYNC          ((__force fop_flags_t)(1 << 2))
 /* Supports non-exclusive O_DIRECT writes from multiple threads */
 #define FOP_DIO_PARALLEL_WRITE ((__force fop_flags_t)(1 << 3))
+/* Contains huge pages */
+#define FOP_HUGE_PAGES         ((__force fop_flags_t)(1 << 4))
 
 /* Wrap a directory iterator that needs exclusive inode access */
 int wrap_directory_iterator(struct file *, struct dir_context *,
index 77b30a8c6076b6cf536baf490c613be9a70d8c61..b06f7c426d3829ca07ea1f83e1c6fb98cb337b65 100644 (file)
@@ -554,17 +554,13 @@ static inline struct hugetlbfs_inode_info *HUGETLBFS_I(struct inode *inode)
        return container_of(inode, struct hugetlbfs_inode_info, vfs_inode);
 }
 
-extern const struct file_operations hugetlbfs_file_operations;
 extern const struct vm_operations_struct hugetlb_vm_ops;
 struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct,
                                int creat_flags, int page_size_log);
 
-static inline bool is_file_hugepages(struct file *file)
+static inline bool is_file_hugepages(const struct file *file)
 {
-       if (file->f_op == &hugetlbfs_file_operations)
-               return true;
-
-       return is_file_shm_hugepages(file);
+       return file->f_op->fop_flags & FOP_HUGE_PAGES;
 }
 
 static inline struct hstate *hstate_inode(struct inode *i)
index c55bef0538e58427cdc2c2193ce3b96b3c9b4b80..1d3d3ae958fbd3a4334a26ed597e44b640d8b96e 100644 (file)
@@ -16,7 +16,6 @@ struct sysv_shm {
 
 long do_shmat(int shmid, char __user *shmaddr, int shmflg, unsigned long *addr,
              unsigned long shmlba);
-bool is_file_shm_hugepages(struct file *file);
 void exit_shm(struct task_struct *task);
 #define shm_init_task(task) INIT_LIST_HEAD(&(task)->sysvshm.shm_clist)
 #else
@@ -30,10 +29,6 @@ static inline long do_shmat(int shmid, char __user *shmaddr,
 {
        return -ENOSYS;
 }
-static inline bool is_file_shm_hugepages(struct file *file)
-{
-       return false;
-}
 static inline void exit_shm(struct task_struct *task)
 {
 }
index a89f001a8bf07250baaca4455c22263ce5ab4769..3e3071252dac65350588cd3eb04b84f80a38411b 100644 (file)
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -662,8 +662,8 @@ static const struct file_operations shm_file_operations = {
 };
 
 /*
- * shm_file_operations_huge is now identical to shm_file_operations,
- * but we keep it distinct for the sake of is_file_shm_hugepages().
+ * shm_file_operations_huge is now identical to shm_file_operations
+ * except for fop_flags
  */
 static const struct file_operations shm_file_operations_huge = {
        .mmap           = shm_mmap,
@@ -672,13 +672,9 @@ static const struct file_operations shm_file_operations_huge = {
        .get_unmapped_area      = shm_get_unmapped_area,
        .llseek         = noop_llseek,
        .fallocate      = shm_fallocate,
+       .fop_flags      = FOP_HUGE_PAGES,
 };
 
-bool is_file_shm_hugepages(struct file *file)
-{
-       return file->f_op == &shm_file_operations_huge;
-}
-
 static const struct vm_operations_struct shm_vm_ops = {
        .open   = shm_open,     /* callback for a new vm-area open */
        .close  = shm_close,    /* callback for when the vm-area is released */