shmem_fs.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #ifndef __SHMEM_FS_H
  2. #define __SHMEM_FS_H
  3. #include <linux/file.h>
  4. #include <linux/swap.h>
  5. #include <linux/mempolicy.h>
  6. #include <linux/pagemap.h>
  7. #include <linux/percpu_counter.h>
  8. #include <linux/xattr.h>
  9. /* inode in-kernel data */
  10. struct shmem_inode_info {
  11. spinlock_t lock;
  12. unsigned int seals; /* shmem seals */
  13. unsigned long flags;
  14. unsigned long alloced; /* data pages alloced to file */
  15. unsigned long swapped; /* subtotal assigned to swap */
  16. struct list_head shrinklist; /* shrinkable hpage inodes */
  17. struct list_head swaplist; /* chain of maybes on swap */
  18. struct shared_policy policy; /* NUMA memory alloc policy */
  19. struct simple_xattrs xattrs; /* list of xattrs */
  20. struct inode vfs_inode;
  21. };
  22. struct shmem_sb_info {
  23. unsigned long max_blocks; /* How many blocks are allowed */
  24. struct percpu_counter used_blocks; /* How many are allocated */
  25. unsigned long max_inodes; /* How many inodes are allowed */
  26. unsigned long free_inodes; /* How many are left for allocation */
  27. spinlock_t stat_lock; /* Serialize shmem_sb_info changes */
  28. umode_t mode; /* Mount mode for root directory */
  29. unsigned char huge; /* Whether to try for hugepages */
  30. kuid_t uid; /* Mount uid for root directory */
  31. kgid_t gid; /* Mount gid for root directory */
  32. struct mempolicy *mpol; /* default memory policy for mappings */
  33. spinlock_t shrinklist_lock; /* Protects shrinklist */
  34. struct list_head shrinklist; /* List of shinkable inodes */
  35. unsigned long shrinklist_len; /* Length of shrinklist */
  36. };
  37. static inline struct shmem_inode_info *SHMEM_I(struct inode *inode)
  38. {
  39. return container_of(inode, struct shmem_inode_info, vfs_inode);
  40. }
  41. /*
  42. * Functions in mm/shmem.c called directly from elsewhere:
  43. */
  44. extern int shmem_init(void);
  45. extern int shmem_fill_super(struct super_block *sb, void *data, int silent);
  46. extern struct file *shmem_file_setup(const char *name,
  47. loff_t size, unsigned long flags);
  48. extern struct file *shmem_kernel_file_setup(const char *name, loff_t size,
  49. unsigned long flags);
  50. extern int shmem_zero_setup(struct vm_area_struct *);
  51. extern unsigned long shmem_get_unmapped_area(struct file *, unsigned long addr,
  52. unsigned long len, unsigned long pgoff, unsigned long flags);
  53. extern int shmem_lock(struct file *file, int lock, struct user_struct *user);
  54. extern bool shmem_mapping(struct address_space *mapping);
  55. extern void shmem_unlock_mapping(struct address_space *mapping);
  56. extern struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,
  57. pgoff_t index, gfp_t gfp_mask);
  58. extern void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end);
  59. extern int shmem_unuse(swp_entry_t entry, struct page *page);
  60. extern unsigned long shmem_swap_usage(struct vm_area_struct *vma);
  61. extern unsigned long shmem_partial_swap_usage(struct address_space *mapping,
  62. pgoff_t start, pgoff_t end);
  63. /* Flag allocation requirements to shmem_getpage */
  64. enum sgp_type {
  65. SGP_READ, /* don't exceed i_size, don't allocate page */
  66. SGP_CACHE, /* don't exceed i_size, may allocate page */
  67. SGP_NOHUGE, /* like SGP_CACHE, but no huge pages */
  68. SGP_HUGE, /* like SGP_CACHE, huge pages preferred */
  69. SGP_WRITE, /* may exceed i_size, may allocate !Uptodate page */
  70. SGP_FALLOC, /* like SGP_WRITE, but make existing page Uptodate */
  71. };
  72. extern int shmem_getpage(struct inode *inode, pgoff_t index,
  73. struct page **pagep, enum sgp_type sgp);
  74. static inline struct page *shmem_read_mapping_page(
  75. struct address_space *mapping, pgoff_t index)
  76. {
  77. return shmem_read_mapping_page_gfp(mapping, index,
  78. mapping_gfp_mask(mapping));
  79. }
  80. static inline bool shmem_file(struct file *file)
  81. {
  82. if (!IS_ENABLED(CONFIG_SHMEM))
  83. return false;
  84. if (!file || !file->f_mapping)
  85. return false;
  86. return shmem_mapping(file->f_mapping);
  87. }
  88. extern bool shmem_charge(struct inode *inode, long pages);
  89. extern void shmem_uncharge(struct inode *inode, long pages);
  90. #ifdef CONFIG_TMPFS
  91. extern int shmem_add_seals(struct file *file, unsigned int seals);
  92. extern int shmem_get_seals(struct file *file);
  93. extern long shmem_fcntl(struct file *file, unsigned int cmd, unsigned long arg);
  94. #else
  95. static inline long shmem_fcntl(struct file *f, unsigned int c, unsigned long a)
  96. {
  97. return -EINVAL;
  98. }
  99. #endif
  100. #ifdef CONFIG_TRANSPARENT_HUGE_PAGECACHE
  101. extern bool shmem_huge_enabled(struct vm_area_struct *vma);
  102. #else
  103. static inline bool shmem_huge_enabled(struct vm_area_struct *vma)
  104. {
  105. return false;
  106. }
  107. #endif
  108. #endif