blob: 227fd3e9a9c9370398478005d01344f5a42cb02d [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
Hugh Dickins41113042012-01-12 17:20:01 -080025add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list lru)
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080026{
Johannes Weiner925b7672012-01-12 17:18:15 -080027 struct lruvec *lruvec;
28
Hugh Dickins41113042012-01-12 17:20:01 -080029 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));
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080032}
33
34static inline void
Hugh Dickins41113042012-01-12 17:20:01 -080035del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list lru)
Christoph Lameterb69408e2008-10-18 20:26:14 -070036{
Hugh Dickins41113042012-01-12 17:20:01 -080037 mem_cgroup_lru_del_list(page, lru);
Christoph Lameterb69408e2008-10-18 20:26:14 -070038 list_del(&page->lru);
Hugh Dickins41113042012-01-12 17:20:01 -080039 __mod_zone_page_state(zone, NR_LRU_BASE + lru, -hpage_nr_pages(page));
Christoph Lameterb69408e2008-10-18 20:26:14 -070040}
41
Johannes Weiner401a8e12009-09-21 17:02:58 -070042/**
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
Hugh Dickins1c1c53d2012-01-12 17:20:04 -080057/**
58 * page_off_lru - which LRU list was page on? clearing its lru flags.
59 * @page: the page to test
60 *
61 * Returns the LRU list a page was on, as an index into the array of LRU
62 * lists; and clears its Unevictable or Active flags, ready for freeing.
63 */
64static inline enum lru_list page_off_lru(struct page *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Hugh Dickins41113042012-01-12 17:20:01 -080066 enum lru_list lru;
Christoph Lameterb69408e2008-10-18 20:26:14 -070067
Lee Schermerhorn894bc312008-10-18 20:26:39 -070068 if (PageUnevictable(page)) {
69 __ClearPageUnevictable(page);
Hugh Dickins41113042012-01-12 17:20:01 -080070 lru = LRU_UNEVICTABLE;
Lee Schermerhorn894bc312008-10-18 20:26:39 -070071 } else {
Hugh Dickins41113042012-01-12 17:20:01 -080072 lru = page_lru_base_type(page);
Lee Schermerhorn894bc312008-10-18 20:26:39 -070073 if (PageActive(page)) {
74 __ClearPageActive(page);
Hugh Dickins41113042012-01-12 17:20:01 -080075 lru += LRU_ACTIVE;
Lee Schermerhorn894bc312008-10-18 20:26:39 -070076 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 }
Hugh Dickins1c1c53d2012-01-12 17:20:04 -080078 return lru;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
Christoph Lameter21eac812006-01-08 01:00:45 -080080
Christoph Lameterb69408e2008-10-18 20:26:14 -070081/**
82 * page_lru - which LRU list should a page be on?
83 * @page: the page to test
84 *
85 * Returns the LRU list a page should be on, as an index
86 * into the array of LRU lists.
87 */
88static inline enum lru_list page_lru(struct page *page)
89{
Johannes Weiner401a8e12009-09-21 17:02:58 -070090 enum lru_list lru;
Christoph Lameterb69408e2008-10-18 20:26:14 -070091
Lee Schermerhorn894bc312008-10-18 20:26:39 -070092 if (PageUnevictable(page))
93 lru = LRU_UNEVICTABLE;
94 else {
Johannes Weiner401a8e12009-09-21 17:02:58 -070095 lru = page_lru_base_type(page);
Lee Schermerhorn894bc312008-10-18 20:26:39 -070096 if (PageActive(page))
97 lru += LRU_ACTIVE;
Lee Schermerhorn894bc312008-10-18 20:26:39 -070098 }
Christoph Lameterb69408e2008-10-18 20:26:14 -070099 return lru;
100}
Rik van Rielb2e18532008-10-18 20:26:30 -0700101
102#endif