]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/linux/mm_inline.h
mm: enum lru_list lru
[mirror_ubuntu-artful-kernel.git] / include / linux / mm_inline.h
CommitLineData
b2e18538
RR
1#ifndef LINUX_MM_INLINE_H
2#define LINUX_MM_INLINE_H
3
2c888cfb
RR
4#include <linux/huge_mm.h>
5
b2e18538
RR
6/**
7 * page_is_file_cache - should the page be on a file LRU or anon LRU?
8 * @page: the page to test
9 *
6c0b1351 10 * Returns 1 if @page is page cache page backed by a regular filesystem,
b2e18538
RR
11 * or 0 if @page is anonymous, tmpfs or otherwise ram or swap backed.
12 * Used by functions that manipulate the LRU lists, to sort a page
13 * onto the right LRU list.
14 *
15 * We would like to get this info without a page flag, but the state
16 * needs to survive until the page is last deleted from the LRU, which
17 * could be as far down as __page_cache_release.
18 */
19static inline int page_is_file_cache(struct page *page)
20{
6c0b1351 21 return !PageSwapBacked(page);
b2e18538
RR
22}
23
71e3aac0 24static inline void
4111304d 25add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list lru)
71e3aac0 26{
925b7673
JW
27 struct lruvec *lruvec;
28
4111304d
HD
29 lruvec = mem_cgroup_lru_add_list(zone, page, lru);
30 list_add(&page->lru, &lruvec->lists[lru]);
31 __mod_zone_page_state(zone, NR_LRU_BASE + lru, hpage_nr_pages(page));
71e3aac0
AA
32}
33
b69408e8 34static inline void
4111304d 35del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list lru)
b69408e8 36{
4111304d 37 mem_cgroup_lru_del_list(page, lru);
b69408e8 38 list_del(&page->lru);
4111304d 39 __mod_zone_page_state(zone, NR_LRU_BASE + lru, -hpage_nr_pages(page));
b69408e8
CL
40}
41
401a8e1c
JW
42/**
43 * page_lru_base_type - which LRU list type should a page be on?
44 * @page: the page to test
45 *
46 * Used for LRU list index arithmetic.
47 *
48 * Returns the base LRU type - file or anon - @page should be on.
49 */
50static inline enum lru_list page_lru_base_type(struct page *page)
51{
52 if (page_is_file_cache(page))
53 return LRU_INACTIVE_FILE;
54 return LRU_INACTIVE_ANON;
55}
56
1da177e4
LT
57static inline void
58del_page_from_lru(struct zone *zone, struct page *page)
59{
4111304d 60 enum lru_list lru;
b69408e8 61
894bc310
LS
62 if (PageUnevictable(page)) {
63 __ClearPageUnevictable(page);
4111304d 64 lru = LRU_UNEVICTABLE;
894bc310 65 } else {
4111304d 66 lru = page_lru_base_type(page);
894bc310
LS
67 if (PageActive(page)) {
68 __ClearPageActive(page);
4111304d 69 lru += LRU_ACTIVE;
894bc310 70 }
1da177e4 71 }
4111304d 72 mem_cgroup_lru_del_list(page, lru);
925b7673 73 list_del(&page->lru);
4111304d 74 __mod_zone_page_state(zone, NR_LRU_BASE + lru, -hpage_nr_pages(page));
1da177e4 75}
21eac81f 76
b69408e8
CL
77/**
78 * page_lru - which LRU list should a page be on?
79 * @page: the page to test
80 *
81 * Returns the LRU list a page should be on, as an index
82 * into the array of LRU lists.
83 */
84static inline enum lru_list page_lru(struct page *page)
85{
401a8e1c 86 enum lru_list lru;
b69408e8 87
894bc310
LS
88 if (PageUnevictable(page))
89 lru = LRU_UNEVICTABLE;
90 else {
401a8e1c 91 lru = page_lru_base_type(page);
894bc310
LS
92 if (PageActive(page))
93 lru += LRU_ACTIVE;
894bc310 94 }
b69408e8
CL
95
96 return lru;
97}
b2e18538
RR
98
99#endif