blob: 1397ccf81e91f16d937c3f0b2e7d361104dce5f1 [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
Hugh Dickinsfa9add62012-05-29 15:07:09 -070024static __always_inline void add_page_to_lru_list(struct page *page,
25 struct lruvec *lruvec, enum lru_list lru)
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080026{
Hugh Dickinsfa9add62012-05-29 15:07:09 -070027 int nr_pages = hpage_nr_pages(page);
28 mem_cgroup_update_lru_size(lruvec, lru, nr_pages);
Hugh Dickins41113042012-01-12 17:20:01 -080029 list_add(&page->lru, &lruvec->lists[lru]);
Hugh Dickinsfa9add62012-05-29 15:07:09 -070030 __mod_zone_page_state(lruvec_zone(lruvec), NR_LRU_BASE + lru, nr_pages);
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080031}
32
Hugh Dickinsfa9add62012-05-29 15:07:09 -070033static __always_inline void del_page_from_lru_list(struct page *page,
34 struct lruvec *lruvec, enum lru_list lru)
Christoph Lameterb69408e2008-10-18 20:26:14 -070035{
Hugh Dickinsfa9add62012-05-29 15:07:09 -070036 int nr_pages = hpage_nr_pages(page);
37 mem_cgroup_update_lru_size(lruvec, lru, -nr_pages);
Christoph Lameterb69408e2008-10-18 20:26:14 -070038 list_del(&page->lru);
Hugh Dickinsfa9add62012-05-29 15:07:09 -070039 __mod_zone_page_state(lruvec_zone(lruvec), NR_LRU_BASE + lru, -nr_pages);
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 */
Konstantin Khlebnikov014483b2012-05-29 15:06:53 -070064static __always_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 */
Konstantin Khlebnikov014483b2012-05-29 15:06:53 -070088static __always_inline enum lru_list page_lru(struct page *page)
Christoph Lameterb69408e2008-10-18 20:26:14 -070089{
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