/include/linux/swap.h

https://github.com/airy09/android_kernel_sony_apq8064 · C Header · 516 lines · 368 code · 71 blank · 77 comment · 4 complexity · 736d44d741b29e966213c1ac63dd2214 MD5 · raw file

  1. #ifndef _LINUX_SWAP_H
  2. #define _LINUX_SWAP_H
  3. #include <linux/spinlock.h>
  4. #include <linux/linkage.h>
  5. #include <linux/mmzone.h>
  6. #include <linux/list.h>
  7. #include <linux/memcontrol.h>
  8. #include <linux/sched.h>
  9. #include <linux/node.h>
  10. #include <linux/atomic.h>
  11. #include <asm/page.h>
  12. struct notifier_block;
  13. struct bio;
  14. #define SWAP_FLAG_PREFER 0x8000 /* set if swap priority specified */
  15. #define SWAP_FLAG_PRIO_MASK 0x7fff
  16. #define SWAP_FLAG_PRIO_SHIFT 0
  17. #define SWAP_FLAG_DISCARD 0x10000 /* discard swap cluster after use */
  18. #define SWAP_FLAGS_VALID (SWAP_FLAG_PRIO_MASK | SWAP_FLAG_PREFER | \
  19. SWAP_FLAG_DISCARD)
  20. static inline int current_is_kswapd(void)
  21. {
  22. return current->flags & PF_KSWAPD;
  23. }
  24. /*
  25. * MAX_SWAPFILES defines the maximum number of swaptypes: things which can
  26. * be swapped to. The swap type and the offset into that swap type are
  27. * encoded into pte's and into pgoff_t's in the swapcache. Using five bits
  28. * for the type means that the maximum number of swapcache pages is 27 bits
  29. * on 32-bit-pgoff_t architectures. And that assumes that the architecture packs
  30. * the type/offset into the pte as 5/27 as well.
  31. */
  32. #define MAX_SWAPFILES_SHIFT 5
  33. /*
  34. * Use some of the swap files numbers for other purposes. This
  35. * is a convenient way to hook into the VM to trigger special
  36. * actions on faults.
  37. */
  38. /*
  39. * NUMA node memory migration support
  40. */
  41. #ifdef CONFIG_MIGRATION
  42. #define SWP_MIGRATION_NUM 2
  43. #define SWP_MIGRATION_READ (MAX_SWAPFILES + SWP_HWPOISON_NUM)
  44. #define SWP_MIGRATION_WRITE (MAX_SWAPFILES + SWP_HWPOISON_NUM + 1)
  45. #else
  46. #define SWP_MIGRATION_NUM 0
  47. #endif
  48. /*
  49. * Handling of hardware poisoned pages with memory corruption.
  50. */
  51. #ifdef CONFIG_MEMORY_FAILURE
  52. #define SWP_HWPOISON_NUM 1
  53. #define SWP_HWPOISON MAX_SWAPFILES
  54. #else
  55. #define SWP_HWPOISON_NUM 0
  56. #endif
  57. #define MAX_SWAPFILES \
  58. ((1 << MAX_SWAPFILES_SHIFT) - SWP_MIGRATION_NUM - SWP_HWPOISON_NUM)
  59. /*
  60. * Magic header for a swap area. The first part of the union is
  61. * what the swap magic looks like for the old (limited to 128MB)
  62. * swap area format, the second part of the union adds - in the
  63. * old reserved area - some extra information. Note that the first
  64. * kilobyte is reserved for boot loader or disk label stuff...
  65. *
  66. * Having the magic at the end of the PAGE_SIZE makes detecting swap
  67. * areas somewhat tricky on machines that support multiple page sizes.
  68. * For 2.5 we'll probably want to move the magic to just beyond the
  69. * bootbits...
  70. */
  71. union swap_header {
  72. struct {
  73. char reserved[PAGE_SIZE - 10];
  74. char magic[10]; /* SWAP-SPACE or SWAPSPACE2 */
  75. } magic;
  76. struct {
  77. char bootbits[1024]; /* Space for disklabel etc. */
  78. __u32 version;
  79. __u32 last_page;
  80. __u32 nr_badpages;
  81. unsigned char sws_uuid[16];
  82. unsigned char sws_volume[16];
  83. __u32 padding[117];
  84. __u32 badpages[1];
  85. } info;
  86. };
  87. /* A swap entry has to fit into a "unsigned long", as
  88. * the entry is hidden in the "index" field of the
  89. * swapper address space.
  90. */
  91. typedef struct {
  92. unsigned long val;
  93. } swp_entry_t;
  94. /*
  95. * current->reclaim_state points to one of these when a task is running
  96. * memory reclaim
  97. */
  98. struct reclaim_state {
  99. unsigned long reclaimed_slab;
  100. };
  101. #ifdef __KERNEL__
  102. struct address_space;
  103. struct sysinfo;
  104. struct writeback_control;
  105. struct zone;
  106. /*
  107. * A swap extent maps a range of a swapfile's PAGE_SIZE pages onto a range of
  108. * disk blocks. A list of swap extents maps the entire swapfile. (Where the
  109. * term `swapfile' refers to either a blockdevice or an IS_REG file. Apart
  110. * from setup, they're handled identically.
  111. *
  112. * We always assume that blocks are of size PAGE_SIZE.
  113. */
  114. struct swap_extent {
  115. struct list_head list;
  116. pgoff_t start_page;
  117. pgoff_t nr_pages;
  118. sector_t start_block;
  119. };
  120. /*
  121. * Max bad pages in the new format..
  122. */
  123. #define __swapoffset(x) ((unsigned long)&((union swap_header *)0)->x)
  124. #define MAX_SWAP_BADPAGES \
  125. ((__swapoffset(magic.magic) - __swapoffset(info.badpages)) / sizeof(int))
  126. enum {
  127. SWP_USED = (1 << 0), /* is slot in swap_info[] used? */
  128. SWP_WRITEOK = (1 << 1), /* ok to write to this swap? */
  129. SWP_DISCARDABLE = (1 << 2), /* swapon+blkdev support discard */
  130. SWP_DISCARDING = (1 << 3), /* now discarding a free cluster */
  131. SWP_SOLIDSTATE = (1 << 4), /* blkdev seeks are cheap */
  132. SWP_CONTINUED = (1 << 5), /* swap_map has count continuation */
  133. SWP_BLKDEV = (1 << 6), /* its a block device */
  134. /* add others here before... */
  135. SWP_SCANNING = (1 << 8), /* refcount in scan_swap_map */
  136. };
  137. #define SWAP_CLUSTER_MAX 32
  138. #define COMPACT_CLUSTER_MAX SWAP_CLUSTER_MAX
  139. /*
  140. * Ratio between the present memory in the zone and the "gap" that
  141. * we're allowing kswapd to shrink in addition to the per-zone high
  142. * wmark, even for zones that already have the high wmark satisfied,
  143. * in order to provide better per-zone lru behavior. We are ok to
  144. * spend not more than 1% of the memory for this zone balancing "gap".
  145. */
  146. #define KSWAPD_ZONE_BALANCE_GAP_RATIO 100
  147. #define SWAP_MAP_MAX 0x3e /* Max duplication count, in first swap_map */
  148. #define SWAP_MAP_BAD 0x3f /* Note pageblock is bad, in first swap_map */
  149. #define SWAP_HAS_CACHE 0x40 /* Flag page is cached, in first swap_map */
  150. #define SWAP_CONT_MAX 0x7f /* Max count, in each swap_map continuation */
  151. #define COUNT_CONTINUED 0x80 /* See swap_map continuation for full count */
  152. #define SWAP_MAP_SHMEM 0xbf /* Owned by shmem/tmpfs, in first swap_map */
  153. /*
  154. * The in-memory structure used to track swap areas.
  155. */
  156. struct swap_info_struct {
  157. unsigned long flags; /* SWP_USED etc: see above */
  158. signed short prio; /* swap priority of this type */
  159. signed char type; /* strange name for an index */
  160. signed char next; /* next type on the swap list */
  161. unsigned int max; /* extent of the swap_map */
  162. unsigned char *swap_map; /* vmalloc'ed array of usage counts */
  163. unsigned int lowest_bit; /* index of first free in swap_map */
  164. unsigned int highest_bit; /* index of last free in swap_map */
  165. unsigned int pages; /* total of usable pages of swap */
  166. unsigned int inuse_pages; /* number of those currently in use */
  167. unsigned int cluster_next; /* likely index for next allocation */
  168. unsigned int cluster_nr; /* countdown to next cluster search */
  169. unsigned int lowest_alloc; /* while preparing discard cluster */
  170. unsigned int highest_alloc; /* while preparing discard cluster */
  171. struct swap_extent *curr_swap_extent;
  172. struct swap_extent first_swap_extent;
  173. struct block_device *bdev; /* swap device or bdev of swap file */
  174. struct file *swap_file; /* seldom referenced */
  175. unsigned int old_block_size; /* seldom referenced */
  176. #ifdef CONFIG_FRONTSWAP
  177. unsigned long *frontswap_map; /* frontswap in-use, one bit per page */
  178. atomic_t frontswap_pages; /* frontswap pages in-use counter */
  179. #endif
  180. };
  181. struct swap_list_t {
  182. int head; /* head of priority-ordered swapfile list */
  183. int next; /* swapfile to be used next */
  184. };
  185. /* Swap 50% full? Release swapcache more aggressively.. */
  186. #define vm_swap_full() (nr_swap_pages*2 < total_swap_pages)
  187. /* linux/mm/page_alloc.c */
  188. extern unsigned long totalram_pages;
  189. extern unsigned long totalreserve_pages;
  190. extern unsigned long dirty_balance_reserve;
  191. extern unsigned int nr_free_buffer_pages(void);
  192. extern unsigned int nr_free_pagecache_pages(void);
  193. /* Definition of global_page_state not available yet */
  194. #define nr_free_pages() global_page_state(NR_FREE_PAGES)
  195. /* linux/mm/swap.c */
  196. extern void __lru_cache_add(struct page *, enum lru_list lru);
  197. extern void lru_cache_add_lru(struct page *, enum lru_list lru);
  198. extern void lru_add_page_tail(struct zone* zone,
  199. struct page *page, struct page *page_tail);
  200. extern void activate_page(struct page *);
  201. extern void mark_page_accessed(struct page *);
  202. extern void lru_add_drain(void);
  203. extern void lru_add_drain_cpu(int cpu);
  204. extern int lru_add_drain_all(void);
  205. extern void rotate_reclaimable_page(struct page *page);
  206. extern void deactivate_page(struct page *page);
  207. extern void swap_setup(void);
  208. extern void add_page_to_unevictable_list(struct page *page);
  209. /**
  210. * lru_cache_add: add a page to the page lists
  211. * @page: the page to add
  212. */
  213. static inline void lru_cache_add_anon(struct page *page)
  214. {
  215. __lru_cache_add(page, LRU_INACTIVE_ANON);
  216. }
  217. static inline void lru_cache_add_file(struct page *page)
  218. {
  219. __lru_cache_add(page, LRU_INACTIVE_FILE);
  220. }
  221. /* linux/mm/vmscan.c */
  222. extern unsigned long try_to_free_pages(struct zonelist *zonelist, int order,
  223. gfp_t gfp_mask, nodemask_t *mask);
  224. extern int __isolate_lru_page(struct page *page, isolate_mode_t mode, int file);
  225. extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem,
  226. gfp_t gfp_mask, bool noswap);
  227. extern unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem,
  228. gfp_t gfp_mask, bool noswap,
  229. struct zone *zone,
  230. unsigned long *nr_scanned);
  231. extern unsigned long shrink_all_memory(unsigned long nr_pages);
  232. extern int vm_swappiness;
  233. extern int remove_mapping(struct address_space *mapping, struct page *page);
  234. extern long vm_total_pages;
  235. #ifdef CONFIG_NUMA
  236. extern int zone_reclaim_mode;
  237. extern int sysctl_min_unmapped_ratio;
  238. extern int sysctl_min_slab_ratio;
  239. extern int zone_reclaim(struct zone *, gfp_t, unsigned int);
  240. #else
  241. #define zone_reclaim_mode 0
  242. static inline int zone_reclaim(struct zone *z, gfp_t mask, unsigned int order)
  243. {
  244. return 0;
  245. }
  246. #endif
  247. extern int page_evictable(struct page *page, struct vm_area_struct *vma);
  248. extern void check_move_unevictable_pages(struct page **, int nr_pages);
  249. extern unsigned long scan_unevictable_pages;
  250. extern int scan_unevictable_handler(struct ctl_table *, int,
  251. void __user *, size_t *, loff_t *);
  252. #ifdef CONFIG_NUMA
  253. extern int scan_unevictable_register_node(struct node *node);
  254. extern void scan_unevictable_unregister_node(struct node *node);
  255. #else
  256. static inline int scan_unevictable_register_node(struct node *node)
  257. {
  258. return 0;
  259. }
  260. static inline void scan_unevictable_unregister_node(struct node *node)
  261. {
  262. }
  263. #endif
  264. extern int kswapd_run(int nid);
  265. extern void kswapd_stop(int nid);
  266. #ifdef CONFIG_CGROUP_MEM_RES_CTLR
  267. extern int mem_cgroup_swappiness(struct mem_cgroup *mem);
  268. #else
  269. static inline int mem_cgroup_swappiness(struct mem_cgroup *mem)
  270. {
  271. return vm_swappiness;
  272. }
  273. #endif
  274. #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
  275. extern void mem_cgroup_uncharge_swap(swp_entry_t ent);
  276. #else
  277. static inline void mem_cgroup_uncharge_swap(swp_entry_t ent)
  278. {
  279. }
  280. #endif
  281. #ifdef CONFIG_SWAP
  282. /* linux/mm/page_io.c */
  283. extern int swap_readpage(struct page *);
  284. extern int swap_writepage(struct page *page, struct writeback_control *wbc);
  285. extern void end_swap_bio_read(struct bio *bio, int err);
  286. /* linux/mm/swap_state.c */
  287. extern struct address_space swapper_space;
  288. #define total_swapcache_pages swapper_space.nrpages
  289. extern void show_swap_cache_info(void);
  290. extern int add_to_swap(struct page *);
  291. extern int add_to_swap_cache(struct page *, swp_entry_t, gfp_t);
  292. extern void __delete_from_swap_cache(struct page *);
  293. extern void delete_from_swap_cache(struct page *);
  294. extern void free_page_and_swap_cache(struct page *);
  295. extern void free_pages_and_swap_cache(struct page **, int);
  296. extern struct page *lookup_swap_cache(swp_entry_t);
  297. extern struct page *read_swap_cache_async(swp_entry_t, gfp_t,
  298. struct vm_area_struct *vma, unsigned long addr);
  299. extern struct page *swapin_readahead(swp_entry_t, gfp_t,
  300. struct vm_area_struct *vma, unsigned long addr);
  301. /* linux/mm/swapfile.c */
  302. extern long nr_swap_pages;
  303. extern long total_swap_pages;
  304. extern void si_swapinfo(struct sysinfo *);
  305. extern swp_entry_t get_swap_page(void);
  306. extern swp_entry_t get_swap_page_of_type(int);
  307. extern int add_swap_count_continuation(swp_entry_t, gfp_t);
  308. extern void swap_shmem_alloc(swp_entry_t);
  309. extern int swap_duplicate(swp_entry_t);
  310. extern int swapcache_prepare(swp_entry_t);
  311. extern void swap_free(swp_entry_t);
  312. extern void swapcache_free(swp_entry_t, struct page *page);
  313. extern int free_swap_and_cache(swp_entry_t);
  314. extern int swap_type_of(dev_t, sector_t, struct block_device **);
  315. extern unsigned int count_swap_pages(int, int);
  316. extern sector_t map_swap_page(struct page *, struct block_device **);
  317. extern sector_t swapdev_block(int, pgoff_t);
  318. extern int reuse_swap_page(struct page *);
  319. extern int try_to_free_swap(struct page *);
  320. struct backing_dev_info;
  321. /* linux/mm/thrash.c */
  322. extern struct mm_struct *swap_token_mm;
  323. extern void grab_swap_token(struct mm_struct *);
  324. extern void __put_swap_token(struct mm_struct *);
  325. extern void disable_swap_token(struct mem_cgroup *memcg);
  326. static inline int has_swap_token(struct mm_struct *mm)
  327. {
  328. return (mm == swap_token_mm);
  329. }
  330. static inline void put_swap_token(struct mm_struct *mm)
  331. {
  332. if (has_swap_token(mm))
  333. __put_swap_token(mm);
  334. }
  335. #ifdef CONFIG_CGROUP_MEM_RES_CTLR
  336. extern void
  337. mem_cgroup_uncharge_swapcache(struct page *page, swp_entry_t ent, bool swapout);
  338. extern int mem_cgroup_count_swap_user(swp_entry_t ent, struct page **pagep);
  339. #else
  340. static inline void
  341. mem_cgroup_uncharge_swapcache(struct page *page, swp_entry_t ent, bool swapout)
  342. {
  343. }
  344. #endif
  345. #else /* CONFIG_SWAP */
  346. #define nr_swap_pages 0L
  347. #define total_swap_pages 0L
  348. #define total_swapcache_pages 0UL
  349. #define si_swapinfo(val) \
  350. do { (val)->freeswap = (val)->totalswap = 0; } while (0)
  351. /* only sparc can not include linux/pagemap.h in this file
  352. * so leave page_cache_release and release_pages undeclared... */
  353. #define free_page_and_swap_cache(page) \
  354. page_cache_release(page)
  355. #define free_pages_and_swap_cache(pages, nr) \
  356. release_pages((pages), (nr), 0);
  357. static inline void show_swap_cache_info(void)
  358. {
  359. }
  360. #define free_swap_and_cache(swp) is_migration_entry(swp)
  361. #define swapcache_prepare(swp) is_migration_entry(swp)
  362. static inline int add_swap_count_continuation(swp_entry_t swp, gfp_t gfp_mask)
  363. {
  364. return 0;
  365. }
  366. static inline void swap_shmem_alloc(swp_entry_t swp)
  367. {
  368. }
  369. static inline int swap_duplicate(swp_entry_t swp)
  370. {
  371. return 0;
  372. }
  373. static inline void swap_free(swp_entry_t swp)
  374. {
  375. }
  376. static inline void swapcache_free(swp_entry_t swp, struct page *page)
  377. {
  378. }
  379. static inline struct page *swapin_readahead(swp_entry_t swp, gfp_t gfp_mask,
  380. struct vm_area_struct *vma, unsigned long addr)
  381. {
  382. return NULL;
  383. }
  384. static inline int swap_writepage(struct page *p, struct writeback_control *wbc)
  385. {
  386. return 0;
  387. }
  388. static inline struct page *lookup_swap_cache(swp_entry_t swp)
  389. {
  390. return NULL;
  391. }
  392. static inline int add_to_swap(struct page *page)
  393. {
  394. return 0;
  395. }
  396. static inline int add_to_swap_cache(struct page *page, swp_entry_t entry,
  397. gfp_t gfp_mask)
  398. {
  399. return -1;
  400. }
  401. static inline void __delete_from_swap_cache(struct page *page)
  402. {
  403. }
  404. static inline void delete_from_swap_cache(struct page *page)
  405. {
  406. }
  407. #define reuse_swap_page(page) (page_mapcount(page) == 1)
  408. static inline int try_to_free_swap(struct page *page)
  409. {
  410. return 0;
  411. }
  412. static inline swp_entry_t get_swap_page(void)
  413. {
  414. swp_entry_t entry;
  415. entry.val = 0;
  416. return entry;
  417. }
  418. /* linux/mm/thrash.c */
  419. static inline void put_swap_token(struct mm_struct *mm)
  420. {
  421. }
  422. static inline void grab_swap_token(struct mm_struct *mm)
  423. {
  424. }
  425. static inline int has_swap_token(struct mm_struct *mm)
  426. {
  427. return 0;
  428. }
  429. static inline void disable_swap_token(struct mem_cgroup *memcg)
  430. {
  431. }
  432. static inline void
  433. mem_cgroup_uncharge_swapcache(struct page *page, swp_entry_t ent)
  434. {
  435. }
  436. #ifdef CONFIG_CGROUP_MEM_RES_CTLR
  437. static inline int
  438. mem_cgroup_count_swap_user(swp_entry_t ent, struct page **pagep)
  439. {
  440. return 0;
  441. }
  442. #endif
  443. #endif /* CONFIG_SWAP */
  444. #endif /* __KERNEL__*/
  445. #endif /* _LINUX_SWAP_H */