blob: 96e970485b6c0d4b6a3b80f1df222b51be1bda35 [file] [log] [blame]
Rik van Rielb2e18532008-10-18 20:26:30 -07001#ifndef LINUX_MM_INLINE_H
2#define LINUX_MM_INLINE_H
3
4/**
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 !0 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 */
17static inline int page_is_file_cache(struct page *page)
18{
19 if (PageSwapBacked(page))
20 return 0;
21
22 /* The page is page cache backed by a normal filesystem. */
23 return 1;
24}
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026static inline void
Christoph Lameterb69408e2008-10-18 20:26:14 -070027add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list l)
28{
29 list_add(&page->lru, &zone->lru[l].list);
30 __inc_zone_state(zone, NR_LRU_BASE + l);
31}
32
33static inline void
34del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list l)
35{
36 list_del(&page->lru);
37 __dec_zone_state(zone, NR_LRU_BASE + l);
38}
39
40static inline void
Linus Torvalds1da177e2005-04-16 15:20:36 -070041add_page_to_active_list(struct zone *zone, struct page *page)
42{
Christoph Lameterb69408e2008-10-18 20:26:14 -070043 add_page_to_lru_list(zone, page, LRU_ACTIVE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044}
45
46static inline void
47add_page_to_inactive_list(struct zone *zone, struct page *page)
48{
Christoph Lameterb69408e2008-10-18 20:26:14 -070049 add_page_to_lru_list(zone, page, LRU_INACTIVE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050}
51
52static inline void
53del_page_from_active_list(struct zone *zone, struct page *page)
54{
Christoph Lameterb69408e2008-10-18 20:26:14 -070055 del_page_from_lru_list(zone, page, LRU_ACTIVE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056}
57
58static inline void
59del_page_from_inactive_list(struct zone *zone, struct page *page)
60{
Christoph Lameterb69408e2008-10-18 20:26:14 -070061 del_page_from_lru_list(zone, page, LRU_INACTIVE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062}
63
64static inline void
65del_page_from_lru(struct zone *zone, struct page *page)
66{
Christoph Lameterb69408e2008-10-18 20:26:14 -070067 enum lru_list l = LRU_INACTIVE;
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 list_del(&page->lru);
70 if (PageActive(page)) {
Nick Piggin67453912006-03-22 00:08:00 -080071 __ClearPageActive(page);
Christoph Lameterb69408e2008-10-18 20:26:14 -070072 l = LRU_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 }
Christoph Lameterb69408e2008-10-18 20:26:14 -070074 __dec_zone_state(zone, NR_LRU_BASE + l);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075}
Christoph Lameter21eac812006-01-08 01:00:45 -080076
Christoph Lameterb69408e2008-10-18 20:26:14 -070077/**
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{
86 enum lru_list lru = LRU_BASE;
87
88 if (PageActive(page))
89 lru += LRU_ACTIVE;
90
91 return lru;
92}
Rik van Rielb2e18532008-10-18 20:26:30 -070093
94#endif