aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/page_ref.h
diff options
context:
space:
mode:
authorJoonsoo Kim <iamjoonsoo.kim@lge.com>2016-03-17 17:19:26 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-03-17 18:09:34 -0400
commitfe896d1878949ea92ba547587bc3075cc688fb8f (patch)
tree582ae505611bafae117c0de8498916485699ac78 /include/linux/page_ref.h
parent444eb2a449ef36fe115431ed7b71467c4563c7f1 (diff)
mm: introduce page reference manipulation functions
The success of CMA allocation largely depends on the success of migration and key factor of it is page reference count. Until now, page reference is manipulated by direct calling atomic functions so we cannot follow up who and where manipulate it. Then, it is hard to find actual reason of CMA allocation failure. CMA allocation should be guaranteed to succeed so finding offending place is really important. In this patch, call sites where page reference is manipulated are converted to introduced wrapper function. This is preparation step to add tracepoint to each page reference manipulation function. With this facility, we can easily find reason of CMA allocation failure. There is no functional change in this patch. In addition, this patch also converts reference read sites. It will help a second step that renames page._count to something else and prevents later attempt to direct access to it (Suggested by Andrew). Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com> Acked-by: Michal Nazarewicz <mina86@mina86.com> Acked-by: Vlastimil Babka <vbabka@suse.cz> Cc: Minchan Kim <minchan@kernel.org> Cc: Mel Gorman <mgorman@techsingularity.net> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> Cc: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/page_ref.h')
-rw-r--r--include/linux/page_ref.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/include/linux/page_ref.h b/include/linux/page_ref.h
new file mode 100644
index 000000000000..30f5817f6b8e
--- /dev/null
+++ b/include/linux/page_ref.h
@@ -0,0 +1,85 @@
1#ifndef _LINUX_PAGE_REF_H
2#define _LINUX_PAGE_REF_H
3
4#include <linux/atomic.h>
5#include <linux/mm_types.h>
6#include <linux/page-flags.h>
7
8static inline int page_ref_count(struct page *page)
9{
10 return atomic_read(&page->_count);
11}
12
13static inline int page_count(struct page *page)
14{
15 return atomic_read(&compound_head(page)->_count);
16}
17
18static inline void set_page_count(struct page *page, int v)
19{
20 atomic_set(&page->_count, v);
21}
22
23/*
24 * Setup the page count before being freed into the page allocator for
25 * the first time (boot or memory hotplug)
26 */
27static inline void init_page_count(struct page *page)
28{
29 set_page_count(page, 1);
30}
31
32static inline void page_ref_add(struct page *page, int nr)
33{
34 atomic_add(nr, &page->_count);
35}
36
37static inline void page_ref_sub(struct page *page, int nr)
38{
39 atomic_sub(nr, &page->_count);
40}
41
42static inline void page_ref_inc(struct page *page)
43{
44 atomic_inc(&page->_count);
45}
46
47static inline void page_ref_dec(struct page *page)
48{
49 atomic_dec(&page->_count);
50}
51
52static inline int page_ref_sub_and_test(struct page *page, int nr)
53{
54 return atomic_sub_and_test(nr, &page->_count);
55}
56
57static inline int page_ref_dec_and_test(struct page *page)
58{
59 return atomic_dec_and_test(&page->_count);
60}
61
62static inline int page_ref_dec_return(struct page *page)
63{
64 return atomic_dec_return(&page->_count);
65}
66
67static inline int page_ref_add_unless(struct page *page, int nr, int u)
68{
69 return atomic_add_unless(&page->_count, nr, u);
70}
71
72static inline int page_ref_freeze(struct page *page, int count)
73{
74 return likely(atomic_cmpxchg(&page->_count, count, 0) == count);
75}
76
77static inline void page_ref_unfreeze(struct page *page, int count)
78{
79 VM_BUG_ON_PAGE(page_count(page) != 0, page);
80 VM_BUG_ON(count == 0);
81
82 atomic_set(&page->_count, count);
83}
84
85#endif