~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/shmem_fs.h

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef __SHMEM_FS_H
  3 #define __SHMEM_FS_H
  4 
  5 #include <linux/file.h>
  6 #include <linux/swap.h>
  7 #include <linux/mempolicy.h>
  8 #include <linux/pagemap.h>
  9 #include <linux/percpu_counter.h>
 10 #include <linux/xattr.h>
 11 #include <linux/fs_parser.h>
 12 #include <linux/userfaultfd_k.h>
 13 
 14 /* inode in-kernel data */
 15 
 16 #ifdef CONFIG_TMPFS_QUOTA
 17 #define SHMEM_MAXQUOTAS 2
 18 #endif
 19 
 20 struct shmem_inode_info {
 21         spinlock_t              lock;
 22         unsigned int            seals;          /* shmem seals */
 23         unsigned long           flags;
 24         unsigned long           alloced;        /* data pages alloced to file */
 25         unsigned long           swapped;        /* subtotal assigned to swap */
 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 */
 34         struct shared_policy    policy;         /* NUMA memory alloc policy */
 35         struct simple_xattrs    xattrs;         /* list of xattrs */
 36         pgoff_t                 fallocend;      /* highest fallocate endindex */
 37         unsigned int            fsflags;        /* for FS_IOC_[SG]ETFLAGS */
 38         atomic_t                stop_eviction;  /* hold when working on inode */
 39 #ifdef CONFIG_TMPFS_QUOTA
 40         struct dquot __rcu      *i_dquot[MAXQUOTAS];
 41 #endif
 42         struct inode            vfs_inode;
 43 };
 44 
 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)
 49 
 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 
 57 struct shmem_sb_info {
 58         unsigned long max_blocks;   /* How many blocks are allowed */
 59         struct percpu_counter used_blocks;  /* How many are allocated */
 60         unsigned long max_inodes;   /* How many inodes are allowed */
 61         unsigned long free_ispace;  /* How much ispace left for allocation */
 62         raw_spinlock_t stat_lock;   /* Serialize shmem_sb_info changes */
 63         umode_t mode;               /* Mount mode for root directory */
 64         unsigned char huge;         /* Whether to try for hugepages */
 65         kuid_t uid;                 /* Mount uid for root directory */
 66         kgid_t gid;                 /* Mount gid for root directory */
 67         bool full_inums;            /* If i_ino should be uint or ino_t */
 68         bool noswap;                /* ignores VM reclaim / swap requests */
 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 */
 71         struct mempolicy *mpol;     /* default memory policy for mappings */
 72         spinlock_t shrinklist_lock;   /* Protects shrinklist */
 73         struct list_head shrinklist;  /* List of shinkable inodes */
 74         unsigned long shrinklist_len; /* Length of shrinklist */
 75         struct shmem_quota_limits qlimits; /* Default quota limits */
 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 
 83 /*
 84  * Functions in mm/shmem.c called directly from elsewhere:
 85  */
 86 extern const struct fs_parameter_spec shmem_fs_parameters[];
 87 extern void shmem_init(void);
 88 extern int shmem_init_fs_context(struct fs_context *fc);
 89 extern struct file *shmem_file_setup(const char *name,
 90                                         loff_t size, unsigned long flags);
 91 extern struct file *shmem_kernel_file_setup(const char *name, loff_t size,
 92                                             unsigned long flags);
 93 extern struct file *shmem_file_setup_with_mnt(struct vfsmount *mnt,
 94                 const char *name, loff_t size, unsigned long flags);
 95 extern int shmem_zero_setup(struct vm_area_struct *);
 96 extern unsigned long shmem_get_unmapped_area(struct file *, unsigned long addr,
 97                 unsigned long len, unsigned long pgoff, unsigned long flags);
 98 extern int shmem_lock(struct file *file, int lock, struct ucounts *ucounts);
 99 #ifdef CONFIG_SHMEM
100 bool shmem_mapping(struct address_space *mapping);
101 #else
102 static inline bool shmem_mapping(struct address_space *mapping)
103 {
104         return false;
105 }
106 #endif /* CONFIG_SHMEM */
107 extern void shmem_unlock_mapping(struct address_space *mapping);
108 extern struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,
109                                         pgoff_t index, gfp_t gfp_mask);
110 extern void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end);
111 int shmem_unuse(unsigned int type);
112 
113 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
114 extern bool shmem_is_huge(struct inode *inode, pgoff_t index, bool shmem_huge_force,
115                           struct mm_struct *mm, unsigned long vm_flags);
116 unsigned long shmem_allowable_huge_orders(struct inode *inode,
117                                 struct vm_area_struct *vma, pgoff_t index,
118                                 bool global_huge);
119 #else
120 static __always_inline bool shmem_is_huge(struct inode *inode, pgoff_t index, bool shmem_huge_force,
121                                           struct mm_struct *mm, unsigned long vm_flags)
122 {
123         return false;
124 }
125 static inline unsigned long shmem_allowable_huge_orders(struct inode *inode,
126                                 struct vm_area_struct *vma, pgoff_t index,
127                                 bool global_huge)
128 {
129         return 0;
130 }
131 #endif
132 
133 #ifdef CONFIG_SHMEM
134 extern unsigned long shmem_swap_usage(struct vm_area_struct *vma);
135 #else
136 static inline unsigned long shmem_swap_usage(struct vm_area_struct *vma)
137 {
138         return 0;
139 }
140 #endif
141 extern unsigned long shmem_partial_swap_usage(struct address_space *mapping,
142                                                 pgoff_t start, pgoff_t end);
143 
144 /* Flag allocation requirements to shmem_get_folio */
145 enum sgp_type {
146         SGP_READ,       /* don't exceed i_size, don't allocate page */
147         SGP_NOALLOC,    /* similar, but fail on hole or use fallocated page */
148         SGP_CACHE,      /* don't exceed i_size, may allocate page */
149         SGP_WRITE,      /* may exceed i_size, may allocate !Uptodate page */
150         SGP_FALLOC,     /* like SGP_WRITE, but make existing page Uptodate */
151 };
152 
153 int shmem_get_folio(struct inode *inode, pgoff_t index, struct folio **foliop,
154                 enum sgp_type sgp);
155 struct folio *shmem_read_folio_gfp(struct address_space *mapping,
156                 pgoff_t index, gfp_t gfp);
157 
158 static inline struct folio *shmem_read_folio(struct address_space *mapping,
159                 pgoff_t index)
160 {
161         return shmem_read_folio_gfp(mapping, index, mapping_gfp_mask(mapping));
162 }
163 
164 static inline struct page *shmem_read_mapping_page(
165                                 struct address_space *mapping, pgoff_t index)
166 {
167         return shmem_read_mapping_page_gfp(mapping, index,
168                                         mapping_gfp_mask(mapping));
169 }
170 
171 static inline bool shmem_file(struct file *file)
172 {
173         if (!IS_ENABLED(CONFIG_SHMEM))
174                 return false;
175         if (!file || !file->f_mapping)
176                 return false;
177         return shmem_mapping(file->f_mapping);
178 }
179 
180 /*
181  * If fallocate(FALLOC_FL_KEEP_SIZE) has been used, there may be pages
182  * beyond i_size's notion of EOF, which fallocate has committed to reserving:
183  * which split_huge_page() must therefore not delete.  This use of a single
184  * "fallocend" per inode errs on the side of not deleting a reservation when
185  * in doubt: there are plenty of cases when it preserves unreserved pages.
186  */
187 static inline pgoff_t shmem_fallocend(struct inode *inode, pgoff_t eof)
188 {
189         return max(eof, SHMEM_I(inode)->fallocend);
190 }
191 
192 extern bool shmem_charge(struct inode *inode, long pages);
193 extern void shmem_uncharge(struct inode *inode, long pages);
194 
195 #ifdef CONFIG_USERFAULTFD
196 #ifdef CONFIG_SHMEM
197 extern int shmem_mfill_atomic_pte(pmd_t *dst_pmd,
198                                   struct vm_area_struct *dst_vma,
199                                   unsigned long dst_addr,
200                                   unsigned long src_addr,
201                                   uffd_flags_t flags,
202                                   struct folio **foliop);
203 #else /* !CONFIG_SHMEM */
204 #define shmem_mfill_atomic_pte(dst_pmd, dst_vma, dst_addr, \
205                                src_addr, flags, foliop) ({ BUG(); 0; })
206 #endif /* CONFIG_SHMEM */
207 #endif /* CONFIG_USERFAULTFD */
208 
209 /*
210  * Used space is stored as unsigned 64-bit value in bytes but
211  * quota core supports only signed 64-bit values so use that
212  * as a limit
213  */
214 #define SHMEM_QUOTA_MAX_SPC_LIMIT 0x7fffffffffffffffLL /* 2^63-1 */
215 #define SHMEM_QUOTA_MAX_INO_LIMIT 0x7fffffffffffffffLL
216 
217 #ifdef CONFIG_TMPFS_QUOTA
218 extern const struct dquot_operations shmem_quota_operations;
219 extern struct quota_format_type shmem_quota_format;
220 #endif /* CONFIG_TMPFS_QUOTA */
221 
222 #endif
223 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php