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

fs: Add FOP_HUGE_PAGES

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>

authored by

Matthew Wilcox (Oracle) and committed by
Christian Brauner
886b94d2 62917165

+10 -20
+3 -2
fs/hugetlbfs/inode.c
··· 40 40 #include <linux/sched/mm.h> 41 41 42 42 static const struct address_space_operations hugetlbfs_aops; 43 - const struct file_operations hugetlbfs_file_operations; 43 + static const struct file_operations hugetlbfs_file_operations; 44 44 static const struct inode_operations hugetlbfs_dir_inode_operations; 45 45 static const struct inode_operations hugetlbfs_inode_operations; 46 46 ··· 1301 1301 inode_init_once(&ei->vfs_inode); 1302 1302 } 1303 1303 1304 - const struct file_operations hugetlbfs_file_operations = { 1304 + static const struct file_operations hugetlbfs_file_operations = { 1305 1305 .read_iter = hugetlbfs_read_iter, 1306 1306 .mmap = hugetlbfs_file_mmap, 1307 1307 .fsync = noop_fsync, 1308 1308 .get_unmapped_area = hugetlb_get_unmapped_area, 1309 1309 .llseek = default_llseek, 1310 1310 .fallocate = hugetlbfs_fallocate, 1311 + .fop_flags = FOP_HUGE_PAGES, 1311 1312 }; 1312 1313 1313 1314 static const struct inode_operations hugetlbfs_dir_inode_operations = {
+2
include/linux/fs.h
··· 2052 2052 #define FOP_MMAP_SYNC ((__force fop_flags_t)(1 << 2)) 2053 2053 /* Supports non-exclusive O_DIRECT writes from multiple threads */ 2054 2054 #define FOP_DIO_PARALLEL_WRITE ((__force fop_flags_t)(1 << 3)) 2055 + /* Contains huge pages */ 2056 + #define FOP_HUGE_PAGES ((__force fop_flags_t)(1 << 4)) 2055 2057 2056 2058 /* Wrap a directory iterator that needs exclusive inode access */ 2057 2059 int wrap_directory_iterator(struct file *, struct dir_context *,
+2 -6
include/linux/hugetlb.h
··· 554 554 return container_of(inode, struct hugetlbfs_inode_info, vfs_inode); 555 555 } 556 556 557 - extern const struct file_operations hugetlbfs_file_operations; 558 557 extern const struct vm_operations_struct hugetlb_vm_ops; 559 558 struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct, 560 559 int creat_flags, int page_size_log); 561 560 562 - static inline bool is_file_hugepages(struct file *file) 561 + static inline bool is_file_hugepages(const struct file *file) 563 562 { 564 - if (file->f_op == &hugetlbfs_file_operations) 565 - return true; 566 - 567 - return is_file_shm_hugepages(file); 563 + return file->f_op->fop_flags & FOP_HUGE_PAGES; 568 564 } 569 565 570 566 static inline struct hstate *hstate_inode(struct inode *i)
-5
include/linux/shm.h
··· 16 16 17 17 long do_shmat(int shmid, char __user *shmaddr, int shmflg, unsigned long *addr, 18 18 unsigned long shmlba); 19 - bool is_file_shm_hugepages(struct file *file); 20 19 void exit_shm(struct task_struct *task); 21 20 #define shm_init_task(task) INIT_LIST_HEAD(&(task)->sysvshm.shm_clist) 22 21 #else ··· 28 29 unsigned long shmlba) 29 30 { 30 31 return -ENOSYS; 31 - } 32 - static inline bool is_file_shm_hugepages(struct file *file) 33 - { 34 - return false; 35 32 } 36 33 static inline void exit_shm(struct task_struct *task) 37 34 {
+3 -7
ipc/shm.c
··· 662 662 }; 663 663 664 664 /* 665 - * shm_file_operations_huge is now identical to shm_file_operations, 666 - * but we keep it distinct for the sake of is_file_shm_hugepages(). 665 + * shm_file_operations_huge is now identical to shm_file_operations 666 + * except for fop_flags 667 667 */ 668 668 static const struct file_operations shm_file_operations_huge = { 669 669 .mmap = shm_mmap, ··· 672 672 .get_unmapped_area = shm_get_unmapped_area, 673 673 .llseek = noop_llseek, 674 674 .fallocate = shm_fallocate, 675 + .fop_flags = FOP_HUGE_PAGES, 675 676 }; 676 - 677 - bool is_file_shm_hugepages(struct file *file) 678 - { 679 - return file->f_op == &shm_file_operations_huge; 680 - } 681 677 682 678 static const struct vm_operations_struct shm_vm_ops = { 683 679 .open = shm_open, /* callback for a new vm-area open */