blob: 8f7d24712dc115790269442be6f8c245d4cf6145 [file] [log] [blame]
Rik van Rielb2e18532008-10-18 20:26:30 -07001#ifndef LINUX_MM_INLINE_H
2#define LINUX_MM_INLINE_H
3
Rik van Riel2c888cf2011-01-13 15:47:13 -08004#include <linux/huge_mm.h>
5
Rik van Rielb2e18532008-10-18 20:26:30 -07006/**
7 * page_is_file_cache - should the page be on a file LRU or anon LRU?
8 * @page: the page to test
9 *
Johannes Weiner6c0b1352009-09-21 17:02:59 -070010 * Returns 1 if @page is page cache page backed by a regular filesystem,
Rik van Rielb2e18532008-10-18 20:26:30 -070011 * 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{
Johannes Weiner6c0b1352009-09-21 17:02:59 -070021 return !PageSwapBacked(page);
Rik van Rielb2e18532008-10-18 20:26:30 -070022}
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024static inline void
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080025__add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list l,
26 struct list_head *head)
Christoph Lameterb69408e2008-10-18 20:26:14 -070027{
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080028 list_add(&page->lru, head);
Rik van Riel2c888cf2011-01-13 15:47:13 -080029 __mod_zone_page_state(zone, NR_LRU_BASE + l, hpage_nr_pages(page));
KAMEZAWA Hiroyuki08e552c2009-01-07 18:08:01 -080030 mem_cgroup_add_lru_list(page, l);
Christoph Lameterb69408e2008-10-18 20:26:14 -070031}
32
33static inline void
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080034add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list l)
35{
36 __add_page_to_lru_list(zone, page, l, &zone->lru[l].list);
37}
38
39static inline void
Christoph Lameterb69408e2008-10-18 20:26:14 -070040del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list l)
41{
42 list_del(&page->lru);
Rik van Riel2c888cf2011-01-13 15:47:13 -080043 __mod_zone_page_state(zone, NR_LRU_BASE + l, -hpage_nr_pages(page));
KAMEZAWA Hiroyuki08e552c2009-01-07 18:08:01 -080044 mem_cgroup_del_lru_list(page, l);
Christoph Lameterb69408e2008-10-18 20:26:14 -070045}
46
Johannes Weiner401a8e12009-09-21 17:02:58 -070047/**
48 * page_lru_base_type - which LRU list type should a page be on?
49 * @page: the page to test
50 *
51 * Used for LRU list index arithmetic.
52 *
53 * Returns the base LRU type - file or anon - @page should be on.
54 */
55static inline enum lru_list page_lru_base_type(struct page *page)
56{
57 if (page_is_file_cache(page))
58 return LRU_INACTIVE_FILE;
59 return LRU_INACTIVE_ANON;
60}
61
Christoph Lameterb69408e2008-10-18 20:26:14 -070062static inline void
Linus Torvalds1da177e2005-04-16 15:20:36 -070063del_page_from_lru(struct zone *zone, struct page *page)
64{
Johannes Weiner401a8e12009-09-21 17:02:58 -070065 enum lru_list l;
Christoph Lameterb69408e2008-10-18 20:26:14 -070066
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 list_del(&page->lru);
Lee Schermerhorn894bc312008-10-18 20:26:39 -070068 if (PageUnevictable(page)) {
69 __ClearPageUnevictable(page);
70 l = LRU_UNEVICTABLE;
71 } else {
Johannes Weiner401a8e12009-09-21 17:02:58 -070072 l = page_lru_base_type(page);
Lee Schermerhorn894bc312008-10-18 20:26:39 -070073 if (PageActive(page)) {
74 __ClearPageActive(page);
75 l += LRU_ACTIVE;
76 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 }
Rik van Riel2c888cf2011-01-13 15:47:13 -080078 __mod_zone_page_state(zone, NR_LRU_BASE + l, -hpage_nr_pages(page));
KAMEZAWA Hiroyuki08e552c2009-01-07 18:08:01 -080079 mem_cgroup_del_lru_list(page, l);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
Christoph Lameter21eac812006-01-08 01:00:45 -080081
Christoph Lameterb69408e2008-10-18 20:26:14 -070082/**
83 * page_lru - which LRU list should a page be on?
84 * @page: the page to test
85 *
86 * Returns the LRU list a page should be on, as an index
87 * into the array of LRU lists.
88 */
89static inline enum lru_list page_lru(struct page *page)
90{
Johannes Weiner401a8e12009-09-21 17:02:58 -070091 enum lru_list lru;
Christoph Lameterb69408e2008-10-18 20:26:14 -070092
Lee Schermerhorn894bc312008-10-18 20:26:39 -070093 if (PageUnevictable(page))
94 lru = LRU_UNEVICTABLE;
95 else {
Johannes Weiner401a8e12009-09-21 17:02:58 -070096 lru = page_lru_base_type(page);
Lee Schermerhorn894bc312008-10-18 20:26:39 -070097 if (PageActive(page))
98 lru += LRU_ACTIVE;
Lee Schermerhorn894bc312008-10-18 20:26:39 -070099 }
Christoph Lameterb69408e2008-10-18 20:26:14 -0700100
101 return lru;
102}
Rik van Rielb2e18532008-10-18 20:26:30 -0700103
104#endif