0001
0002 #ifndef __SHMEM_FS_H
0003 #define __SHMEM_FS_H
0004
0005 #include <linux/file.h>
0006 #include <linux/swap.h>
0007 #include <linux/mempolicy.h>
0008 #include <linux/pagemap.h>
0009 #include <linux/percpu_counter.h>
0010 #include <linux/xattr.h>
0011 #include <linux/fs_parser.h>
0012
0013
0014
0015 struct shmem_inode_info {
0016 spinlock_t lock;
0017 unsigned int seals;
0018 unsigned long flags;
0019 unsigned long alloced;
0020 unsigned long swapped;
0021 pgoff_t fallocend;
0022 struct list_head shrinklist;
0023 struct list_head swaplist;
0024 struct shared_policy policy;
0025 struct simple_xattrs xattrs;
0026 atomic_t stop_eviction;
0027 struct timespec64 i_crtime;
0028 unsigned int fsflags;
0029 struct inode vfs_inode;
0030 };
0031
0032 #define SHMEM_FL_USER_VISIBLE FS_FL_USER_VISIBLE
0033 #define SHMEM_FL_USER_MODIFIABLE \
0034 (FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | FS_NOATIME_FL)
0035 #define SHMEM_FL_INHERITED (FS_NODUMP_FL | FS_NOATIME_FL)
0036
0037 struct shmem_sb_info {
0038 unsigned long max_blocks;
0039 struct percpu_counter used_blocks;
0040 unsigned long max_inodes;
0041 unsigned long free_inodes;
0042 raw_spinlock_t stat_lock;
0043 umode_t mode;
0044 unsigned char huge;
0045 kuid_t uid;
0046 kgid_t gid;
0047 bool full_inums;
0048 ino_t next_ino;
0049 ino_t __percpu *ino_batch;
0050 struct mempolicy *mpol;
0051 spinlock_t shrinklist_lock;
0052 struct list_head shrinklist;
0053 unsigned long shrinklist_len;
0054 };
0055
0056 static inline struct shmem_inode_info *SHMEM_I(struct inode *inode)
0057 {
0058 return container_of(inode, struct shmem_inode_info, vfs_inode);
0059 }
0060
0061
0062
0063
0064 extern const struct fs_parameter_spec shmem_fs_parameters[];
0065 extern void shmem_init(void);
0066 extern int shmem_init_fs_context(struct fs_context *fc);
0067 extern struct file *shmem_file_setup(const char *name,
0068 loff_t size, unsigned long flags);
0069 extern struct file *shmem_kernel_file_setup(const char *name, loff_t size,
0070 unsigned long flags);
0071 extern struct file *shmem_file_setup_with_mnt(struct vfsmount *mnt,
0072 const char *name, loff_t size, unsigned long flags);
0073 extern int shmem_zero_setup(struct vm_area_struct *);
0074 extern unsigned long shmem_get_unmapped_area(struct file *, unsigned long addr,
0075 unsigned long len, unsigned long pgoff, unsigned long flags);
0076 extern int shmem_lock(struct file *file, int lock, struct ucounts *ucounts);
0077 #ifdef CONFIG_SHMEM
0078 extern const struct address_space_operations shmem_aops;
0079 static inline bool shmem_mapping(struct address_space *mapping)
0080 {
0081 return mapping->a_ops == &shmem_aops;
0082 }
0083 #else
0084 static inline bool shmem_mapping(struct address_space *mapping)
0085 {
0086 return false;
0087 }
0088 #endif
0089 extern void shmem_unlock_mapping(struct address_space *mapping);
0090 extern struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,
0091 pgoff_t index, gfp_t gfp_mask);
0092 extern void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end);
0093 int shmem_unuse(unsigned int type);
0094
0095 extern bool shmem_is_huge(struct vm_area_struct *vma,
0096 struct inode *inode, pgoff_t index);
0097 static inline bool shmem_huge_enabled(struct vm_area_struct *vma)
0098 {
0099 return shmem_is_huge(vma, file_inode(vma->vm_file), vma->vm_pgoff);
0100 }
0101 extern unsigned long shmem_swap_usage(struct vm_area_struct *vma);
0102 extern unsigned long shmem_partial_swap_usage(struct address_space *mapping,
0103 pgoff_t start, pgoff_t end);
0104
0105
0106 enum sgp_type {
0107 SGP_READ,
0108 SGP_NOALLOC,
0109 SGP_CACHE,
0110 SGP_WRITE,
0111 SGP_FALLOC,
0112 };
0113
0114 extern int shmem_getpage(struct inode *inode, pgoff_t index,
0115 struct page **pagep, enum sgp_type sgp);
0116
0117 static inline struct page *shmem_read_mapping_page(
0118 struct address_space *mapping, pgoff_t index)
0119 {
0120 return shmem_read_mapping_page_gfp(mapping, index,
0121 mapping_gfp_mask(mapping));
0122 }
0123
0124 static inline bool shmem_file(struct file *file)
0125 {
0126 if (!IS_ENABLED(CONFIG_SHMEM))
0127 return false;
0128 if (!file || !file->f_mapping)
0129 return false;
0130 return shmem_mapping(file->f_mapping);
0131 }
0132
0133
0134
0135
0136
0137
0138
0139
0140 static inline pgoff_t shmem_fallocend(struct inode *inode, pgoff_t eof)
0141 {
0142 return max(eof, SHMEM_I(inode)->fallocend);
0143 }
0144
0145 extern bool shmem_charge(struct inode *inode, long pages);
0146 extern void shmem_uncharge(struct inode *inode, long pages);
0147
0148 #ifdef CONFIG_USERFAULTFD
0149 #ifdef CONFIG_SHMEM
0150 extern int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, pmd_t *dst_pmd,
0151 struct vm_area_struct *dst_vma,
0152 unsigned long dst_addr,
0153 unsigned long src_addr,
0154 bool zeropage, bool wp_copy,
0155 struct page **pagep);
0156 #else
0157 #define shmem_mfill_atomic_pte(dst_mm, dst_pmd, dst_vma, dst_addr, \
0158 src_addr, zeropage, wp_copy, pagep) ({ BUG(); 0; })
0159 #endif
0160 #endif
0161
0162 #endif