diff options
Diffstat (limited to 'include/linux/mm_inline.h')
-rw-r--r-- | include/linux/mm_inline.h | 98 |
1 files changed, 79 insertions, 19 deletions
diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h index 895bc4e93039..c948350c378e 100644 --- a/include/linux/mm_inline.h +++ b/include/linux/mm_inline.h | |||
@@ -1,40 +1,100 @@ | |||
1 | static inline void | 1 | #ifndef LINUX_MM_INLINE_H |
2 | add_page_to_active_list(struct zone *zone, struct page *page) | 2 | #define LINUX_MM_INLINE_H |
3 | { | ||
4 | list_add(&page->lru, &zone->active_list); | ||
5 | __inc_zone_state(zone, NR_ACTIVE); | ||
6 | } | ||
7 | 3 | ||
8 | static inline void | 4 | /** |
9 | add_page_to_inactive_list(struct zone *zone, struct page *page) | 5 | * page_is_file_cache - should the page be on a file LRU or anon LRU? |
6 | * @page: the page to test | ||
7 | * | ||
8 | * Returns LRU_FILE if @page is page cache page backed by a regular filesystem, | ||
9 | * or 0 if @page is anonymous, tmpfs or otherwise ram or swap backed. | ||
10 | * Used by functions that manipulate the LRU lists, to sort a page | ||
11 | * onto the right LRU list. | ||
12 | * | ||
13 | * We would like to get this info without a page flag, but the state | ||
14 | * needs to survive until the page is last deleted from the LRU, which | ||
15 | * could be as far down as __page_cache_release. | ||
16 | */ | ||
17 | static inline int page_is_file_cache(struct page *page) | ||
10 | { | 18 | { |
11 | list_add(&page->lru, &zone->inactive_list); | 19 | if (PageSwapBacked(page)) |
12 | __inc_zone_state(zone, NR_INACTIVE); | 20 | return 0; |
21 | |||
22 | /* The page is page cache backed by a normal filesystem. */ | ||
23 | return LRU_FILE; | ||
13 | } | 24 | } |
14 | 25 | ||
15 | static inline void | 26 | static inline void |
16 | del_page_from_active_list(struct zone *zone, struct page *page) | 27 | add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list l) |
17 | { | 28 | { |
18 | list_del(&page->lru); | 29 | list_add(&page->lru, &zone->lru[l].list); |
19 | __dec_zone_state(zone, NR_ACTIVE); | 30 | __inc_zone_state(zone, NR_LRU_BASE + l); |
20 | } | 31 | } |
21 | 32 | ||
22 | static inline void | 33 | static inline void |
23 | del_page_from_inactive_list(struct zone *zone, struct page *page) | 34 | del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list l) |
24 | { | 35 | { |
25 | list_del(&page->lru); | 36 | list_del(&page->lru); |
26 | __dec_zone_state(zone, NR_INACTIVE); | 37 | __dec_zone_state(zone, NR_LRU_BASE + l); |
27 | } | 38 | } |
28 | 39 | ||
29 | static inline void | 40 | static inline void |
30 | del_page_from_lru(struct zone *zone, struct page *page) | 41 | del_page_from_lru(struct zone *zone, struct page *page) |
31 | { | 42 | { |
43 | enum lru_list l = LRU_BASE; | ||
44 | |||
32 | list_del(&page->lru); | 45 | list_del(&page->lru); |
33 | if (PageActive(page)) { | 46 | if (PageUnevictable(page)) { |
34 | __ClearPageActive(page); | 47 | __ClearPageUnevictable(page); |
35 | __dec_zone_state(zone, NR_ACTIVE); | 48 | l = LRU_UNEVICTABLE; |
36 | } else { | 49 | } else { |
37 | __dec_zone_state(zone, NR_INACTIVE); | 50 | if (PageActive(page)) { |
51 | __ClearPageActive(page); | ||
52 | l += LRU_ACTIVE; | ||
53 | } | ||
54 | l += page_is_file_cache(page); | ||
55 | } | ||
56 | __dec_zone_state(zone, NR_LRU_BASE + l); | ||
57 | } | ||
58 | |||
59 | /** | ||
60 | * page_lru - which LRU list should a page be on? | ||
61 | * @page: the page to test | ||
62 | * | ||
63 | * Returns the LRU list a page should be on, as an index | ||
64 | * into the array of LRU lists. | ||
65 | */ | ||
66 | static inline enum lru_list page_lru(struct page *page) | ||
67 | { | ||
68 | enum lru_list lru = LRU_BASE; | ||
69 | |||
70 | if (PageUnevictable(page)) | ||
71 | lru = LRU_UNEVICTABLE; | ||
72 | else { | ||
73 | if (PageActive(page)) | ||
74 | lru += LRU_ACTIVE; | ||
75 | lru += page_is_file_cache(page); | ||
38 | } | 76 | } |
77 | |||
78 | return lru; | ||
39 | } | 79 | } |
40 | 80 | ||
81 | /** | ||
82 | * inactive_anon_is_low - check if anonymous pages need to be deactivated | ||
83 | * @zone: zone to check | ||
84 | * | ||
85 | * Returns true if the zone does not have enough inactive anon pages, | ||
86 | * meaning some active anon pages need to be deactivated. | ||
87 | */ | ||
88 | static inline int inactive_anon_is_low(struct zone *zone) | ||
89 | { | ||
90 | unsigned long active, inactive; | ||
91 | |||
92 | active = zone_page_state(zone, NR_ACTIVE_ANON); | ||
93 | inactive = zone_page_state(zone, NR_INACTIVE_ANON); | ||
94 | |||
95 | if (inactive * zone->inactive_ratio < active) | ||
96 | return 1; | ||
97 | |||
98 | return 0; | ||
99 | } | ||
100 | #endif | ||