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