Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef __SHMEM_FS_H |
3 | #define __SHMEM_FS_H | |
4 | ||
40e041a2 | 5 | #include <linux/file.h> |
1da177e4 LT |
6 | #include <linux/swap.h> |
7 | #include <linux/mempolicy.h> | |
d9d90e5e | 8 | #include <linux/pagemap.h> |
7e496299 | 9 | #include <linux/percpu_counter.h> |
38f38657 | 10 | #include <linux/xattr.h> |
d7167b14 | 11 | #include <linux/fs_parser.h> |
d9712937 | 12 | #include <linux/userfaultfd_k.h> |
1da177e4 LT |
13 | |
14 | /* inode in-kernel data */ | |
15 | ||
eafc474e CM |
16 | #ifdef CONFIG_TMPFS_QUOTA |
17 | #define SHMEM_MAXQUOTAS 2 | |
18 | #endif | |
19 | ||
1da177e4 LT |
20 | struct shmem_inode_info { |
21 | spinlock_t lock; | |
40e041a2 | 22 | unsigned int seals; /* shmem seals */ |
1da177e4 LT |
23 | unsigned long flags; |
24 | unsigned long alloced; /* data pages alloced to file */ | |
3ed47db3 | 25 | unsigned long swapped; /* subtotal assigned to swap */ |
d144bf62 | 26 | pgoff_t fallocend; /* highest fallocate endindex */ |
779750d2 | 27 | struct list_head shrinklist; /* shrinkable hpage inodes */ |
1da177e4 | 28 | struct list_head swaplist; /* chain of maybes on swap */ |
779750d2 | 29 | struct shared_policy policy; /* NUMA memory alloc policy */ |
38f38657 | 30 | struct simple_xattrs xattrs; /* list of xattrs */ |
af53d3e9 | 31 | atomic_t stop_eviction; /* hold when working on inode */ |
f7cd16a5 | 32 | struct timespec64 i_crtime; /* file creation time */ |
e408e695 | 33 | unsigned int fsflags; /* flags for FS_IOC_[SG]ETFLAGS */ |
e09764cf CM |
34 | #ifdef CONFIG_TMPFS_QUOTA |
35 | struct dquot *i_dquot[MAXQUOTAS]; | |
36 | #endif | |
1da177e4 LT |
37 | struct inode vfs_inode; |
38 | }; | |
39 | ||
cb241339 HD |
40 | #define SHMEM_FL_USER_VISIBLE FS_FL_USER_VISIBLE |
41 | #define SHMEM_FL_USER_MODIFIABLE \ | |
42 | (FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | FS_NOATIME_FL) | |
43 | #define SHMEM_FL_INHERITED (FS_NODUMP_FL | FS_NOATIME_FL) | |
e408e695 | 44 | |
1da177e4 LT |
45 | struct shmem_sb_info { |
46 | unsigned long max_blocks; /* How many blocks are allowed */ | |
7e496299 | 47 | struct percpu_counter used_blocks; /* How many are allocated */ |
1da177e4 LT |
48 | unsigned long max_inodes; /* How many inodes are allowed */ |
49 | unsigned long free_inodes; /* How many are left for allocation */ | |
bf11b9a8 | 50 | raw_spinlock_t stat_lock; /* Serialize shmem_sb_info changes */ |
5a6e75f8 KS |
51 | umode_t mode; /* Mount mode for root directory */ |
52 | unsigned char huge; /* Whether to try for hugepages */ | |
8751e039 EB |
53 | kuid_t uid; /* Mount uid for root directory */ |
54 | kgid_t gid; /* Mount gid for root directory */ | |
ea3271f7 | 55 | bool full_inums; /* If i_ino should be uint or ino_t */ |
2c6efe9c | 56 | bool noswap; /* ignores VM reclaim / swap requests */ |
e809d5f0 CD |
57 | ino_t next_ino; /* The next per-sb inode number to use */ |
58 | ino_t __percpu *ino_batch; /* The next per-cpu inode number to use */ | |
71fe804b | 59 | struct mempolicy *mpol; /* default memory policy for mappings */ |
779750d2 KS |
60 | spinlock_t shrinklist_lock; /* Protects shrinklist */ |
61 | struct list_head shrinklist; /* List of shinkable inodes */ | |
62 | unsigned long shrinklist_len; /* Length of shrinklist */ | |
1da177e4 LT |
63 | }; |
64 | ||
65 | static inline struct shmem_inode_info *SHMEM_I(struct inode *inode) | |
66 | { | |
67 | return container_of(inode, struct shmem_inode_info, vfs_inode); | |
68 | } | |
69 | ||
072441e2 HD |
70 | /* |
71 | * Functions in mm/shmem.c called directly from elsewhere: | |
72 | */ | |
d7167b14 | 73 | extern const struct fs_parameter_spec shmem_fs_parameters[]; |
9096bbe9 | 74 | extern void shmem_init(void); |
f3235626 | 75 | extern int shmem_init_fs_context(struct fs_context *fc); |
072441e2 HD |
76 | extern struct file *shmem_file_setup(const char *name, |
77 | loff_t size, unsigned long flags); | |
c7277090 EP |
78 | extern struct file *shmem_kernel_file_setup(const char *name, loff_t size, |
79 | unsigned long flags); | |
703321b6 MA |
80 | extern struct file *shmem_file_setup_with_mnt(struct vfsmount *mnt, |
81 | const char *name, loff_t size, unsigned long flags); | |
072441e2 | 82 | extern int shmem_zero_setup(struct vm_area_struct *); |
c01d5b30 HD |
83 | extern unsigned long shmem_get_unmapped_area(struct file *, unsigned long addr, |
84 | unsigned long len, unsigned long pgoff, unsigned long flags); | |
d7c9e99a | 85 | extern int shmem_lock(struct file *file, int lock, struct ucounts *ucounts); |
3a4f8a0b | 86 | #ifdef CONFIG_SHMEM |
30e6a51d HS |
87 | extern const struct address_space_operations shmem_aops; |
88 | static inline bool shmem_mapping(struct address_space *mapping) | |
89 | { | |
90 | return mapping->a_ops == &shmem_aops; | |
91 | } | |
3a4f8a0b HD |
92 | #else |
93 | static inline bool shmem_mapping(struct address_space *mapping) | |
94 | { | |
95 | return false; | |
96 | } | |
97 | #endif /* CONFIG_SHMEM */ | |
24513264 | 98 | extern void shmem_unlock_mapping(struct address_space *mapping); |
d9d90e5e HD |
99 | extern struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, |
100 | pgoff_t index, gfp_t gfp_mask); | |
94c1e62d | 101 | extern void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end); |
10a9c496 | 102 | int shmem_unuse(unsigned int type); |
2b2af54a | 103 | |
2cf13384 DS |
104 | extern bool shmem_is_huge(struct inode *inode, pgoff_t index, bool shmem_huge_force, |
105 | struct mm_struct *mm, unsigned long vm_flags); | |
b4aca547 | 106 | #ifdef CONFIG_SHMEM |
6a15a370 | 107 | extern unsigned long shmem_swap_usage(struct vm_area_struct *vma); |
b4aca547 SP |
108 | #else |
109 | static inline unsigned long shmem_swap_usage(struct vm_area_struct *vma) | |
110 | { | |
111 | return 0; | |
112 | } | |
113 | #endif | |
48131e03 VB |
114 | extern unsigned long shmem_partial_swap_usage(struct address_space *mapping, |
115 | pgoff_t start, pgoff_t end); | |
6a15a370 | 116 | |
923e2f0e | 117 | /* Flag allocation requirements to shmem_get_folio */ |
f3f0e1d2 KS |
118 | enum sgp_type { |
119 | SGP_READ, /* don't exceed i_size, don't allocate page */ | |
acdd9f8e | 120 | SGP_NOALLOC, /* similar, but fail on hole or use fallocated page */ |
f3f0e1d2 | 121 | SGP_CACHE, /* don't exceed i_size, may allocate page */ |
f3f0e1d2 KS |
122 | SGP_WRITE, /* may exceed i_size, may allocate !Uptodate page */ |
123 | SGP_FALLOC, /* like SGP_WRITE, but make existing page Uptodate */ | |
124 | }; | |
125 | ||
4e1fc793 MWO |
126 | int shmem_get_folio(struct inode *inode, pgoff_t index, struct folio **foliop, |
127 | enum sgp_type sgp); | |
f01b2b3e MWO |
128 | struct folio *shmem_read_folio_gfp(struct address_space *mapping, |
129 | pgoff_t index, gfp_t gfp); | |
130 | ||
131 | static inline struct folio *shmem_read_folio(struct address_space *mapping, | |
132 | pgoff_t index) | |
133 | { | |
134 | return shmem_read_folio_gfp(mapping, index, mapping_gfp_mask(mapping)); | |
135 | } | |
f3f0e1d2 | 136 | |
d9d90e5e HD |
137 | static inline struct page *shmem_read_mapping_page( |
138 | struct address_space *mapping, pgoff_t index) | |
139 | { | |
140 | return shmem_read_mapping_page_gfp(mapping, index, | |
141 | mapping_gfp_mask(mapping)); | |
142 | } | |
143 | ||
f3f0e1d2 KS |
144 | static inline bool shmem_file(struct file *file) |
145 | { | |
146 | if (!IS_ENABLED(CONFIG_SHMEM)) | |
147 | return false; | |
148 | if (!file || !file->f_mapping) | |
149 | return false; | |
150 | return shmem_mapping(file->f_mapping); | |
151 | } | |
152 | ||
d144bf62 HD |
153 | /* |
154 | * If fallocate(FALLOC_FL_KEEP_SIZE) has been used, there may be pages | |
155 | * beyond i_size's notion of EOF, which fallocate has committed to reserving: | |
156 | * which split_huge_page() must therefore not delete. This use of a single | |
157 | * "fallocend" per inode errs on the side of not deleting a reservation when | |
158 | * in doubt: there are plenty of cases when it preserves unreserved pages. | |
159 | */ | |
160 | static inline pgoff_t shmem_fallocend(struct inode *inode, pgoff_t eof) | |
161 | { | |
162 | return max(eof, SHMEM_I(inode)->fallocend); | |
163 | } | |
164 | ||
800d8c63 KS |
165 | extern bool shmem_charge(struct inode *inode, long pages); |
166 | extern void shmem_uncharge(struct inode *inode, long pages); | |
167 | ||
3460f6e5 | 168 | #ifdef CONFIG_USERFAULTFD |
4c27fe4c | 169 | #ifdef CONFIG_SHMEM |
61c50040 | 170 | extern int shmem_mfill_atomic_pte(pmd_t *dst_pmd, |
4c27fe4c MR |
171 | struct vm_area_struct *dst_vma, |
172 | unsigned long dst_addr, | |
173 | unsigned long src_addr, | |
d9712937 | 174 | uffd_flags_t flags, |
d7be6d7e | 175 | struct folio **foliop); |
3460f6e5 | 176 | #else /* !CONFIG_SHMEM */ |
61c50040 | 177 | #define shmem_mfill_atomic_pte(dst_pmd, dst_vma, dst_addr, \ |
d7be6d7e | 178 | src_addr, flags, foliop) ({ BUG(); 0; }) |
3460f6e5 AR |
179 | #endif /* CONFIG_SHMEM */ |
180 | #endif /* CONFIG_USERFAULTFD */ | |
4c27fe4c | 181 | |
eafc474e CM |
182 | /* |
183 | * Used space is stored as unsigned 64-bit value in bytes but | |
184 | * quota core supports only signed 64-bit values so use that | |
185 | * as a limit | |
186 | */ | |
187 | #define SHMEM_QUOTA_MAX_SPC_LIMIT 0x7fffffffffffffffLL /* 2^63-1 */ | |
188 | #define SHMEM_QUOTA_MAX_INO_LIMIT 0x7fffffffffffffffLL | |
189 | ||
e09764cf CM |
190 | #ifdef CONFIG_TMPFS_QUOTA |
191 | extern const struct dquot_operations shmem_quota_operations; | |
192 | extern struct quota_format_type shmem_quota_format; | |
193 | #endif /* CONFIG_TMPFS_QUOTA */ | |
194 | ||
1da177e4 | 195 | #endif |