Skip to content

Commit 886b94d

Browse files
Matthew Wilcox (Oracle)brauner
authored andcommitted
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>
1 parent 6291716 commit 886b94d

File tree

5 files changed

+10
-20
lines changed

5 files changed

+10
-20
lines changed

fs/hugetlbfs/inode.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include <linux/sched/mm.h>
4141

4242
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;
4444
static const struct inode_operations hugetlbfs_dir_inode_operations;
4545
static const struct inode_operations hugetlbfs_inode_operations;
4646

@@ -1301,13 +1301,14 @@ static void init_once(void *foo)
13011301
inode_init_once(&ei->vfs_inode);
13021302
}
13031303

1304-
const struct file_operations hugetlbfs_file_operations = {
1304+
static const struct file_operations hugetlbfs_file_operations = {
13051305
.read_iter = hugetlbfs_read_iter,
13061306
.mmap = hugetlbfs_file_mmap,
13071307
.fsync = noop_fsync,
13081308
.get_unmapped_area = hugetlb_get_unmapped_area,
13091309
.llseek = default_llseek,
13101310
.fallocate = hugetlbfs_fallocate,
1311+
.fop_flags = FOP_HUGE_PAGES,
13111312
};
13121313

13131314
static const struct inode_operations hugetlbfs_dir_inode_operations = {

include/linux/fs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,6 +2052,8 @@ struct file_operations {
20522052
#define FOP_MMAP_SYNC ((__force fop_flags_t)(1 << 2))
20532053
/* Supports non-exclusive O_DIRECT writes from multiple threads */
20542054
#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))
20552057

20562058
/* Wrap a directory iterator that needs exclusive inode access */
20572059
int wrap_directory_iterator(struct file *, struct dir_context *,

include/linux/hugetlb.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -554,17 +554,13 @@ static inline struct hugetlbfs_inode_info *HUGETLBFS_I(struct inode *inode)
554554
return container_of(inode, struct hugetlbfs_inode_info, vfs_inode);
555555
}
556556

557-
extern const struct file_operations hugetlbfs_file_operations;
558557
extern const struct vm_operations_struct hugetlb_vm_ops;
559558
struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct,
560559
int creat_flags, int page_size_log);
561560

562-
static inline bool is_file_hugepages(struct file *file)
561+
static inline bool is_file_hugepages(const struct file *file)
563562
{
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;
568564
}
569565

570566
static inline struct hstate *hstate_inode(struct inode *i)

include/linux/shm.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ struct sysv_shm {
1616

1717
long do_shmat(int shmid, char __user *shmaddr, int shmflg, unsigned long *addr,
1818
unsigned long shmlba);
19-
bool is_file_shm_hugepages(struct file *file);
2019
void exit_shm(struct task_struct *task);
2120
#define shm_init_task(task) INIT_LIST_HEAD(&(task)->sysvshm.shm_clist)
2221
#else
@@ -30,10 +29,6 @@ static inline long do_shmat(int shmid, char __user *shmaddr,
3029
{
3130
return -ENOSYS;
3231
}
33-
static inline bool is_file_shm_hugepages(struct file *file)
34-
{
35-
return false;
36-
}
3732
static inline void exit_shm(struct task_struct *task)
3833
{
3934
}

ipc/shm.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,8 @@ static const struct file_operations shm_file_operations = {
662662
};
663663

664664
/*
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
667667
*/
668668
static const struct file_operations shm_file_operations_huge = {
669669
.mmap = shm_mmap,
@@ -672,13 +672,9 @@ static const struct file_operations shm_file_operations_huge = {
672672
.get_unmapped_area = shm_get_unmapped_area,
673673
.llseek = noop_llseek,
674674
.fallocate = shm_fallocate,
675+
.fop_flags = FOP_HUGE_PAGES,
675676
};
676677

677-
bool is_file_shm_hugepages(struct file *file)
678-
{
679-
return file->f_op == &shm_file_operations_huge;
680-
}
681-
682678
static const struct vm_operations_struct shm_vm_ops = {
683679
.open = shm_open, /* callback for a new vm-area open */
684680
.close = shm_close, /* callback for when the vm-area is released */

0 commit comments

Comments
 (0)