xref: /openbmc/linux/mm/folio-compat.c (revision ffc143db)
12f52578fSMatthew Wilcox (Oracle) /*
22f52578fSMatthew Wilcox (Oracle)  * Compatibility functions which bloat the callers too much to make inline.
32f52578fSMatthew Wilcox (Oracle)  * All of the callers of these functions should be converted to use folios
42f52578fSMatthew Wilcox (Oracle)  * eventually.
52f52578fSMatthew Wilcox (Oracle)  */
62f52578fSMatthew Wilcox (Oracle) 
73417013eSMatthew Wilcox (Oracle) #include <linux/migrate.h>
82f52578fSMatthew Wilcox (Oracle) #include <linux/pagemap.h>
94d510f3dSMatthew Wilcox (Oracle) #include <linux/rmap.h>
1076580b65SMatthew Wilcox (Oracle) #include <linux/swap.h>
11d1d8a3b4SMatthew Wilcox (Oracle) #include "internal.h"
122f52578fSMatthew Wilcox (Oracle) 
page_mapping(struct page * page)132f52578fSMatthew Wilcox (Oracle) struct address_space *page_mapping(struct page *page)
142f52578fSMatthew Wilcox (Oracle) {
152f52578fSMatthew Wilcox (Oracle) 	return folio_mapping(page_folio(page));
162f52578fSMatthew Wilcox (Oracle) }
172f52578fSMatthew Wilcox (Oracle) EXPORT_SYMBOL(page_mapping);
184e136428SMatthew Wilcox (Oracle) 
unlock_page(struct page * page)194e136428SMatthew Wilcox (Oracle) void unlock_page(struct page *page)
204e136428SMatthew Wilcox (Oracle) {
214e136428SMatthew Wilcox (Oracle) 	return folio_unlock(page_folio(page));
224e136428SMatthew Wilcox (Oracle) }
234e136428SMatthew Wilcox (Oracle) EXPORT_SYMBOL(unlock_page);
244268b480SMatthew Wilcox (Oracle) 
end_page_writeback(struct page * page)254268b480SMatthew Wilcox (Oracle) void end_page_writeback(struct page *page)
264268b480SMatthew Wilcox (Oracle) {
274268b480SMatthew Wilcox (Oracle) 	return folio_end_writeback(page_folio(page));
284268b480SMatthew Wilcox (Oracle) }
294268b480SMatthew Wilcox (Oracle) EXPORT_SYMBOL(end_page_writeback);
30490e016fSMatthew Wilcox (Oracle) 
wait_on_page_writeback(struct page * page)31490e016fSMatthew Wilcox (Oracle) void wait_on_page_writeback(struct page *page)
32490e016fSMatthew Wilcox (Oracle) {
33490e016fSMatthew Wilcox (Oracle) 	return folio_wait_writeback(page_folio(page));
34490e016fSMatthew Wilcox (Oracle) }
35490e016fSMatthew Wilcox (Oracle) EXPORT_SYMBOL_GPL(wait_on_page_writeback);
36a49d0c50SMatthew Wilcox (Oracle) 
wait_for_stable_page(struct page * page)37a49d0c50SMatthew Wilcox (Oracle) void wait_for_stable_page(struct page *page)
38a49d0c50SMatthew Wilcox (Oracle) {
39a49d0c50SMatthew Wilcox (Oracle) 	return folio_wait_stable(page_folio(page));
40a49d0c50SMatthew Wilcox (Oracle) }
41a49d0c50SMatthew Wilcox (Oracle) EXPORT_SYMBOL_GPL(wait_for_stable_page);
42dd10ab04SMatthew Wilcox (Oracle) 
mark_page_accessed(struct page * page)4376580b65SMatthew Wilcox (Oracle) void mark_page_accessed(struct page *page)
4476580b65SMatthew Wilcox (Oracle) {
4576580b65SMatthew Wilcox (Oracle) 	folio_mark_accessed(page_folio(page));
4676580b65SMatthew Wilcox (Oracle) }
4776580b65SMatthew Wilcox (Oracle) EXPORT_SYMBOL(mark_page_accessed);
483417013eSMatthew Wilcox (Oracle) 
set_page_writeback(struct page * page)49f143f1eaSMatthew Wilcox (Oracle) bool set_page_writeback(struct page *page)
50f143f1eaSMatthew Wilcox (Oracle) {
51f143f1eaSMatthew Wilcox (Oracle) 	return folio_start_writeback(page_folio(page));
52f143f1eaSMatthew Wilcox (Oracle) }
53f143f1eaSMatthew Wilcox (Oracle) EXPORT_SYMBOL(set_page_writeback);
54b5e84594SMatthew Wilcox (Oracle) 
set_page_dirty(struct page * page)55b5e84594SMatthew Wilcox (Oracle) bool set_page_dirty(struct page *page)
56b5e84594SMatthew Wilcox (Oracle) {
57b5e84594SMatthew Wilcox (Oracle) 	return folio_mark_dirty(page_folio(page));
58b5e84594SMatthew Wilcox (Oracle) }
59b5e84594SMatthew Wilcox (Oracle) EXPORT_SYMBOL(set_page_dirty);
6085d4d2ebSMatthew Wilcox (Oracle) 
__set_page_dirty_nobuffers(struct page * page)6185d4d2ebSMatthew Wilcox (Oracle) int __set_page_dirty_nobuffers(struct page *page)
6285d4d2ebSMatthew Wilcox (Oracle) {
6385d4d2ebSMatthew Wilcox (Oracle) 	return filemap_dirty_folio(page_mapping(page), page_folio(page));
6485d4d2ebSMatthew Wilcox (Oracle) }
6585d4d2ebSMatthew Wilcox (Oracle) EXPORT_SYMBOL(__set_page_dirty_nobuffers);
669350f20aSMatthew Wilcox (Oracle) 
clear_page_dirty_for_io(struct page * page)679350f20aSMatthew Wilcox (Oracle) bool clear_page_dirty_for_io(struct page *page)
689350f20aSMatthew Wilcox (Oracle) {
699350f20aSMatthew Wilcox (Oracle) 	return folio_clear_dirty_for_io(page_folio(page));
709350f20aSMatthew Wilcox (Oracle) }
719350f20aSMatthew Wilcox (Oracle) EXPORT_SYMBOL(clear_page_dirty_for_io);
72cd78ab11SMatthew Wilcox (Oracle) 
redirty_page_for_writepage(struct writeback_control * wbc,struct page * page)73cd78ab11SMatthew Wilcox (Oracle) bool redirty_page_for_writepage(struct writeback_control *wbc,
74cd78ab11SMatthew Wilcox (Oracle) 		struct page *page)
75cd78ab11SMatthew Wilcox (Oracle) {
76cd78ab11SMatthew Wilcox (Oracle) 	return folio_redirty_for_writepage(wbc, page_folio(page));
77cd78ab11SMatthew Wilcox (Oracle) }
78cd78ab11SMatthew Wilcox (Oracle) EXPORT_SYMBOL(redirty_page_for_writepage);
790d31125dSMatthew Wilcox (Oracle) 
lru_cache_add_inactive_or_unevictable(struct page * page,struct vm_area_struct * vma)80681ecf63SMatthew Wilcox (Oracle) void lru_cache_add_inactive_or_unevictable(struct page *page,
81681ecf63SMatthew Wilcox (Oracle) 		struct vm_area_struct *vma)
82681ecf63SMatthew Wilcox (Oracle) {
83681ecf63SMatthew Wilcox (Oracle) 	folio_add_lru_vma(page_folio(page), vma);
84681ecf63SMatthew Wilcox (Oracle) }
85681ecf63SMatthew Wilcox (Oracle) 
add_to_page_cache_lru(struct page * page,struct address_space * mapping,pgoff_t index,gfp_t gfp)869dd3d069SMatthew Wilcox (Oracle) int add_to_page_cache_lru(struct page *page, struct address_space *mapping,
879dd3d069SMatthew Wilcox (Oracle) 		pgoff_t index, gfp_t gfp)
889dd3d069SMatthew Wilcox (Oracle) {
899dd3d069SMatthew Wilcox (Oracle) 	return filemap_add_folio(mapping, page_folio(page), index, gfp);
909dd3d069SMatthew Wilcox (Oracle) }
919dd3d069SMatthew Wilcox (Oracle) EXPORT_SYMBOL(add_to_page_cache_lru);
923f0c6a07SMatthew Wilcox (Oracle) 
93b27652d9SMatthew Wilcox (Oracle) noinline
pagecache_get_page(struct address_space * mapping,pgoff_t index,fgf_t fgp_flags,gfp_t gfp)943f0c6a07SMatthew Wilcox (Oracle) struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index,
95*ffc143dbSMatthew Wilcox (Oracle) 		fgf_t fgp_flags, gfp_t gfp)
963f0c6a07SMatthew Wilcox (Oracle) {
973f0c6a07SMatthew Wilcox (Oracle) 	struct folio *folio;
983f0c6a07SMatthew Wilcox (Oracle) 
993f0c6a07SMatthew Wilcox (Oracle) 	folio = __filemap_get_folio(mapping, index, fgp_flags, gfp);
10066dabbb6SChristoph Hellwig 	if (IS_ERR(folio))
10148c9d113SChristoph Hellwig 		return NULL;
1023f0c6a07SMatthew Wilcox (Oracle) 	return folio_file_page(folio, index);
1033f0c6a07SMatthew Wilcox (Oracle) }
1043f0c6a07SMatthew Wilcox (Oracle) EXPORT_SYMBOL(pagecache_get_page);
105b27652d9SMatthew Wilcox (Oracle) 
grab_cache_page_write_begin(struct address_space * mapping,pgoff_t index)106b27652d9SMatthew Wilcox (Oracle) struct page *grab_cache_page_write_begin(struct address_space *mapping,
107b7446e7cSMatthew Wilcox (Oracle) 					pgoff_t index)
108b27652d9SMatthew Wilcox (Oracle) {
109e999a5c5SMatthew Wilcox 	return pagecache_get_page(mapping, index, FGP_WRITEBEGIN,
110b27652d9SMatthew Wilcox (Oracle) 			mapping_gfp_mask(mapping));
111b27652d9SMatthew Wilcox (Oracle) }
112b27652d9SMatthew Wilcox (Oracle) EXPORT_SYMBOL(grab_cache_page_write_begin);
113452e9e69SMatthew Wilcox (Oracle) 
isolate_lru_page(struct page * page)114f7f9c00dSBaolin Wang bool isolate_lru_page(struct page *page)
115d1d8a3b4SMatthew Wilcox (Oracle) {
116d1d8a3b4SMatthew Wilcox (Oracle) 	if (WARN_RATELIMIT(PageTail(page), "trying to isolate tail page"))
117f7f9c00dSBaolin Wang 		return false;
118f7f9c00dSBaolin Wang 	return folio_isolate_lru((struct folio *)page);
119d1d8a3b4SMatthew Wilcox (Oracle) }
120ca6d60f3SMatthew Wilcox (Oracle) 
putback_lru_page(struct page * page)121ca6d60f3SMatthew Wilcox (Oracle) void putback_lru_page(struct page *page)
122ca6d60f3SMatthew Wilcox (Oracle) {
123ca6d60f3SMatthew Wilcox (Oracle) 	folio_putback_lru(page_folio(page));
124ca6d60f3SMatthew Wilcox (Oracle) }
1254d510f3dSMatthew Wilcox (Oracle) 
1264d510f3dSMatthew Wilcox (Oracle) #ifdef CONFIG_MMU
page_add_new_anon_rmap(struct page * page,struct vm_area_struct * vma,unsigned long address)1274d510f3dSMatthew Wilcox (Oracle) void page_add_new_anon_rmap(struct page *page, struct vm_area_struct *vma,
1284d510f3dSMatthew Wilcox (Oracle) 		unsigned long address)
1294d510f3dSMatthew Wilcox (Oracle) {
1304d510f3dSMatthew Wilcox (Oracle) 	VM_BUG_ON_PAGE(PageTail(page), page);
1314d510f3dSMatthew Wilcox (Oracle) 
1324d510f3dSMatthew Wilcox (Oracle) 	return folio_add_new_anon_rmap((struct folio *)page, vma, address);
1334d510f3dSMatthew Wilcox (Oracle) }
1344d510f3dSMatthew Wilcox (Oracle) #endif
135