xref: /openbmc/linux/mm/folio-compat.c (revision 56b5b1c7)
1 /*
2  * Compatibility functions which bloat the callers too much to make inline.
3  * All of the callers of these functions should be converted to use folios
4  * eventually.
5  */
6 
7 #include <linux/migrate.h>
8 #include <linux/pagemap.h>
9 #include <linux/swap.h>
10 
11 struct address_space *page_mapping(struct page *page)
12 {
13 	return folio_mapping(page_folio(page));
14 }
15 EXPORT_SYMBOL(page_mapping);
16 
17 void unlock_page(struct page *page)
18 {
19 	return folio_unlock(page_folio(page));
20 }
21 EXPORT_SYMBOL(unlock_page);
22 
23 void end_page_writeback(struct page *page)
24 {
25 	return folio_end_writeback(page_folio(page));
26 }
27 EXPORT_SYMBOL(end_page_writeback);
28 
29 void wait_on_page_writeback(struct page *page)
30 {
31 	return folio_wait_writeback(page_folio(page));
32 }
33 EXPORT_SYMBOL_GPL(wait_on_page_writeback);
34 
35 void wait_for_stable_page(struct page *page)
36 {
37 	return folio_wait_stable(page_folio(page));
38 }
39 EXPORT_SYMBOL_GPL(wait_for_stable_page);
40 
41 bool page_mapped(struct page *page)
42 {
43 	return folio_mapped(page_folio(page));
44 }
45 EXPORT_SYMBOL(page_mapped);
46 
47 void mark_page_accessed(struct page *page)
48 {
49 	folio_mark_accessed(page_folio(page));
50 }
51 EXPORT_SYMBOL(mark_page_accessed);
52 
53 #ifdef CONFIG_MIGRATION
54 int migrate_page_move_mapping(struct address_space *mapping,
55 		struct page *newpage, struct page *page, int extra_count)
56 {
57 	return folio_migrate_mapping(mapping, page_folio(newpage),
58 					page_folio(page), extra_count);
59 }
60 EXPORT_SYMBOL(migrate_page_move_mapping);
61 
62 void migrate_page_states(struct page *newpage, struct page *page)
63 {
64 	folio_migrate_flags(page_folio(newpage), page_folio(page));
65 }
66 EXPORT_SYMBOL(migrate_page_states);
67 
68 void migrate_page_copy(struct page *newpage, struct page *page)
69 {
70 	folio_migrate_copy(page_folio(newpage), page_folio(page));
71 }
72 EXPORT_SYMBOL(migrate_page_copy);
73 #endif
74 
75 bool set_page_writeback(struct page *page)
76 {
77 	return folio_start_writeback(page_folio(page));
78 }
79 EXPORT_SYMBOL(set_page_writeback);
80 
81 bool set_page_dirty(struct page *page)
82 {
83 	return folio_mark_dirty(page_folio(page));
84 }
85 EXPORT_SYMBOL(set_page_dirty);
86 
87 int __set_page_dirty_nobuffers(struct page *page)
88 {
89 	return filemap_dirty_folio(page_mapping(page), page_folio(page));
90 }
91 EXPORT_SYMBOL(__set_page_dirty_nobuffers);
92 
93 bool clear_page_dirty_for_io(struct page *page)
94 {
95 	return folio_clear_dirty_for_io(page_folio(page));
96 }
97 EXPORT_SYMBOL(clear_page_dirty_for_io);
98 
99 bool redirty_page_for_writepage(struct writeback_control *wbc,
100 		struct page *page)
101 {
102 	return folio_redirty_for_writepage(wbc, page_folio(page));
103 }
104 EXPORT_SYMBOL(redirty_page_for_writepage);
105 
106 void lru_cache_add(struct page *page)
107 {
108 	folio_add_lru(page_folio(page));
109 }
110 EXPORT_SYMBOL(lru_cache_add);
111 
112 int add_to_page_cache_lru(struct page *page, struct address_space *mapping,
113 		pgoff_t index, gfp_t gfp)
114 {
115 	return filemap_add_folio(mapping, page_folio(page), index, gfp);
116 }
117 EXPORT_SYMBOL(add_to_page_cache_lru);
118 
119 noinline
120 struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index,
121 		int fgp_flags, gfp_t gfp)
122 {
123 	struct folio *folio;
124 
125 	folio = __filemap_get_folio(mapping, index, fgp_flags, gfp);
126 	if ((fgp_flags & FGP_HEAD) || !folio || xa_is_value(folio))
127 		return &folio->page;
128 	return folio_file_page(folio, index);
129 }
130 EXPORT_SYMBOL(pagecache_get_page);
131 
132 struct page *grab_cache_page_write_begin(struct address_space *mapping,
133 					pgoff_t index, unsigned flags)
134 {
135 	unsigned fgp_flags = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE;
136 
137 	if (flags & AOP_FLAG_NOFS)
138 		fgp_flags |= FGP_NOFS;
139 	return pagecache_get_page(mapping, index, fgp_flags,
140 			mapping_gfp_mask(mapping));
141 }
142 EXPORT_SYMBOL(grab_cache_page_write_begin);
143 
144 void delete_from_page_cache(struct page *page)
145 {
146 	return filemap_remove_folio(page_folio(page));
147 }
148 
149 int try_to_release_page(struct page *page, gfp_t gfp)
150 {
151 	return filemap_release_folio(page_folio(page), gfp);
152 }
153 EXPORT_SYMBOL(try_to_release_page);
154