Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _MM_SWAP_H
0003 #define _MM_SWAP_H
0004 
0005 #ifdef CONFIG_SWAP
0006 #include <linux/blk_types.h> /* for bio_end_io_t */
0007 
0008 /* linux/mm/page_io.c */
0009 int sio_pool_init(void);
0010 struct swap_iocb;
0011 int swap_readpage(struct page *page, bool do_poll,
0012           struct swap_iocb **plug);
0013 void __swap_read_unplug(struct swap_iocb *plug);
0014 static inline void swap_read_unplug(struct swap_iocb *plug)
0015 {
0016     if (unlikely(plug))
0017         __swap_read_unplug(plug);
0018 }
0019 void swap_write_unplug(struct swap_iocb *sio);
0020 int swap_writepage(struct page *page, struct writeback_control *wbc);
0021 void end_swap_bio_write(struct bio *bio);
0022 int __swap_writepage(struct page *page, struct writeback_control *wbc,
0023              bio_end_io_t end_write_func);
0024 
0025 /* linux/mm/swap_state.c */
0026 /* One swap address space for each 64M swap space */
0027 #define SWAP_ADDRESS_SPACE_SHIFT    14
0028 #define SWAP_ADDRESS_SPACE_PAGES    (1 << SWAP_ADDRESS_SPACE_SHIFT)
0029 extern struct address_space *swapper_spaces[];
0030 #define swap_address_space(entry)               \
0031     (&swapper_spaces[swp_type(entry)][swp_offset(entry) \
0032         >> SWAP_ADDRESS_SPACE_SHIFT])
0033 
0034 void show_swap_cache_info(void);
0035 bool add_to_swap(struct folio *folio);
0036 void *get_shadow_from_swap_cache(swp_entry_t entry);
0037 int add_to_swap_cache(struct page *page, swp_entry_t entry,
0038               gfp_t gfp, void **shadowp);
0039 void __delete_from_swap_cache(struct folio *folio,
0040                   swp_entry_t entry, void *shadow);
0041 void delete_from_swap_cache(struct folio *folio);
0042 void clear_shadow_from_swap_cache(int type, unsigned long begin,
0043                   unsigned long end);
0044 struct page *lookup_swap_cache(swp_entry_t entry,
0045                    struct vm_area_struct *vma,
0046                    unsigned long addr);
0047 struct page *find_get_incore_page(struct address_space *mapping, pgoff_t index);
0048 
0049 struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
0050                    struct vm_area_struct *vma,
0051                    unsigned long addr,
0052                    bool do_poll,
0053                    struct swap_iocb **plug);
0054 struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
0055                      struct vm_area_struct *vma,
0056                      unsigned long addr,
0057                      bool *new_page_allocated);
0058 struct page *swap_cluster_readahead(swp_entry_t entry, gfp_t flag,
0059                     struct vm_fault *vmf);
0060 struct page *swapin_readahead(swp_entry_t entry, gfp_t flag,
0061                   struct vm_fault *vmf);
0062 
0063 static inline unsigned int folio_swap_flags(struct folio *folio)
0064 {
0065     return page_swap_info(&folio->page)->flags;
0066 }
0067 #else /* CONFIG_SWAP */
0068 struct swap_iocb;
0069 static inline int swap_readpage(struct page *page, bool do_poll,
0070                 struct swap_iocb **plug)
0071 {
0072     return 0;
0073 }
0074 static inline void swap_write_unplug(struct swap_iocb *sio)
0075 {
0076 }
0077 
0078 static inline struct address_space *swap_address_space(swp_entry_t entry)
0079 {
0080     return NULL;
0081 }
0082 
0083 static inline void show_swap_cache_info(void)
0084 {
0085 }
0086 
0087 static inline struct page *swap_cluster_readahead(swp_entry_t entry,
0088                 gfp_t gfp_mask, struct vm_fault *vmf)
0089 {
0090     return NULL;
0091 }
0092 
0093 static inline struct page *swapin_readahead(swp_entry_t swp, gfp_t gfp_mask,
0094             struct vm_fault *vmf)
0095 {
0096     return NULL;
0097 }
0098 
0099 static inline int swap_writepage(struct page *p, struct writeback_control *wbc)
0100 {
0101     return 0;
0102 }
0103 
0104 static inline struct page *lookup_swap_cache(swp_entry_t swp,
0105                          struct vm_area_struct *vma,
0106                          unsigned long addr)
0107 {
0108     return NULL;
0109 }
0110 
0111 static inline
0112 struct page *find_get_incore_page(struct address_space *mapping, pgoff_t index)
0113 {
0114     return find_get_page(mapping, index);
0115 }
0116 
0117 static inline bool add_to_swap(struct folio *folio)
0118 {
0119     return false;
0120 }
0121 
0122 static inline void *get_shadow_from_swap_cache(swp_entry_t entry)
0123 {
0124     return NULL;
0125 }
0126 
0127 static inline int add_to_swap_cache(struct page *page, swp_entry_t entry,
0128                     gfp_t gfp_mask, void **shadowp)
0129 {
0130     return -1;
0131 }
0132 
0133 static inline void __delete_from_swap_cache(struct folio *folio,
0134                     swp_entry_t entry, void *shadow)
0135 {
0136 }
0137 
0138 static inline void delete_from_swap_cache(struct folio *folio)
0139 {
0140 }
0141 
0142 static inline void clear_shadow_from_swap_cache(int type, unsigned long begin,
0143                 unsigned long end)
0144 {
0145 }
0146 
0147 static inline unsigned int folio_swap_flags(struct folio *folio)
0148 {
0149     return 0;
0150 }
0151 #endif /* CONFIG_SWAP */
0152 #endif /* _MM_SWAP_H */