mm/util: Add folio_mapping() and folio_file_mapping()
These are the folio equivalent of page_mapping() and page_file_mapping().
Add an out-of-line page_mapping() wrapper around folio_mapping()
in order to prevent the page_folio() call from bloating every caller
of page_mapping(). Adjust page_file_mapping() and page_mapping_file()
to use folios internally. Rename __page_file_mapping() to
swapcache_mapping() and change it to take a folio.
This ends up saving 122 bytes of text overall. folio_mapping() is
45 bytes shorter than page_mapping() was, but the new page_mapping()
wrapper is 30 bytes. The major reduction is a few bytes less in dozens
of nfs functions (which call page_file_mapping()). Most of these appear
to be a slight change in gcc's register allocation decisions, which allow:
48 8b 56 08 mov 0x8(%rsi),%rdx
48 8d 42 ff lea -0x1(%rdx),%rax
83 e2 01 and $0x1,%edx
48 0f 44 c6 cmove %rsi,%rax
to become:
48 8b 46 08 mov 0x8(%rsi),%rax
48 8d 78 ff lea -0x1(%rax),%rdi
a8 01 test $0x1,%al
48 0f 44 fe cmove %rsi,%rdi
for a reduction of a single byte. Once the NFS client is converted to
use folios, this entire sequence will disappear.
Also add folio_mapping() documentation.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Jeff Layton <jlayton@kernel.org>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
Reviewed-by: David Howells <dhowells@redhat.com>
2020-12-10 15:55:05 +00:00
|
|
|
/*
|
|
|
|
* Compatibility functions which bloat the callers too much to make inline.
|
|
|
|
* All of the callers of these functions should be converted to use folios
|
|
|
|
* eventually.
|
|
|
|
*/
|
|
|
|
|
2021-05-07 11:28:40 +00:00
|
|
|
#include <linux/migrate.h>
|
mm/util: Add folio_mapping() and folio_file_mapping()
These are the folio equivalent of page_mapping() and page_file_mapping().
Add an out-of-line page_mapping() wrapper around folio_mapping()
in order to prevent the page_folio() call from bloating every caller
of page_mapping(). Adjust page_file_mapping() and page_mapping_file()
to use folios internally. Rename __page_file_mapping() to
swapcache_mapping() and change it to take a folio.
This ends up saving 122 bytes of text overall. folio_mapping() is
45 bytes shorter than page_mapping() was, but the new page_mapping()
wrapper is 30 bytes. The major reduction is a few bytes less in dozens
of nfs functions (which call page_file_mapping()). Most of these appear
to be a slight change in gcc's register allocation decisions, which allow:
48 8b 56 08 mov 0x8(%rsi),%rdx
48 8d 42 ff lea -0x1(%rdx),%rax
83 e2 01 and $0x1,%edx
48 0f 44 c6 cmove %rsi,%rax
to become:
48 8b 46 08 mov 0x8(%rsi),%rax
48 8d 78 ff lea -0x1(%rax),%rdi
a8 01 test $0x1,%al
48 0f 44 fe cmove %rsi,%rdi
for a reduction of a single byte. Once the NFS client is converted to
use folios, this entire sequence will disappear.
Also add folio_mapping() documentation.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Jeff Layton <jlayton@kernel.org>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
Reviewed-by: David Howells <dhowells@redhat.com>
2020-12-10 15:55:05 +00:00
|
|
|
#include <linux/pagemap.h>
|
2023-01-11 14:28:54 +00:00
|
|
|
#include <linux/rmap.h>
|
2021-04-27 14:47:39 +00:00
|
|
|
#include <linux/swap.h>
|
2021-12-24 18:26:22 +00:00
|
|
|
#include "internal.h"
|
mm/util: Add folio_mapping() and folio_file_mapping()
These are the folio equivalent of page_mapping() and page_file_mapping().
Add an out-of-line page_mapping() wrapper around folio_mapping()
in order to prevent the page_folio() call from bloating every caller
of page_mapping(). Adjust page_file_mapping() and page_mapping_file()
to use folios internally. Rename __page_file_mapping() to
swapcache_mapping() and change it to take a folio.
This ends up saving 122 bytes of text overall. folio_mapping() is
45 bytes shorter than page_mapping() was, but the new page_mapping()
wrapper is 30 bytes. The major reduction is a few bytes less in dozens
of nfs functions (which call page_file_mapping()). Most of these appear
to be a slight change in gcc's register allocation decisions, which allow:
48 8b 56 08 mov 0x8(%rsi),%rdx
48 8d 42 ff lea -0x1(%rdx),%rax
83 e2 01 and $0x1,%edx
48 0f 44 c6 cmove %rsi,%rax
to become:
48 8b 46 08 mov 0x8(%rsi),%rax
48 8d 78 ff lea -0x1(%rax),%rdi
a8 01 test $0x1,%al
48 0f 44 fe cmove %rsi,%rdi
for a reduction of a single byte. Once the NFS client is converted to
use folios, this entire sequence will disappear.
Also add folio_mapping() documentation.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Jeff Layton <jlayton@kernel.org>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
Reviewed-by: David Howells <dhowells@redhat.com>
2020-12-10 15:55:05 +00:00
|
|
|
|
2020-12-07 20:44:35 +00:00
|
|
|
void unlock_page(struct page *page)
|
|
|
|
{
|
|
|
|
return folio_unlock(page_folio(page));
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(unlock_page);
|
2021-03-03 20:21:55 +00:00
|
|
|
|
|
|
|
void end_page_writeback(struct page *page)
|
|
|
|
{
|
|
|
|
return folio_end_writeback(page_folio(page));
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(end_page_writeback);
|
2021-03-04 16:09:17 +00:00
|
|
|
|
|
|
|
void wait_on_page_writeback(struct page *page)
|
|
|
|
{
|
|
|
|
return folio_wait_writeback(page_folio(page));
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(wait_on_page_writeback);
|
2021-03-04 16:25:25 +00:00
|
|
|
|
|
|
|
void wait_for_stable_page(struct page *page)
|
|
|
|
{
|
|
|
|
return folio_wait_stable(page_folio(page));
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(wait_for_stable_page);
|
2021-04-12 20:45:17 +00:00
|
|
|
|
2021-04-27 14:47:39 +00:00
|
|
|
void mark_page_accessed(struct page *page)
|
|
|
|
{
|
|
|
|
folio_mark_accessed(page_folio(page));
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(mark_page_accessed);
|
2021-05-07 11:28:40 +00:00
|
|
|
|
2023-11-08 20:46:05 +00:00
|
|
|
void set_page_writeback(struct page *page)
|
2021-04-24 16:00:48 +00:00
|
|
|
{
|
2023-11-08 20:46:05 +00:00
|
|
|
folio_start_writeback(page_folio(page));
|
2021-04-24 16:00:48 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(set_page_writeback);
|
2021-04-27 03:53:10 +00:00
|
|
|
|
|
|
|
bool set_page_dirty(struct page *page)
|
|
|
|
{
|
|
|
|
return folio_mark_dirty(page_folio(page));
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(set_page_dirty);
|
2021-05-04 03:30:44 +00:00
|
|
|
|
2024-10-24 17:18:07 +00:00
|
|
|
int set_page_dirty_lock(struct page *page)
|
|
|
|
{
|
|
|
|
return folio_mark_dirty_lock(page_folio(page));
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(set_page_dirty_lock);
|
|
|
|
|
2021-02-28 21:21:20 +00:00
|
|
|
bool clear_page_dirty_for_io(struct page *page)
|
|
|
|
{
|
|
|
|
return folio_clear_dirty_for_io(page_folio(page));
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(clear_page_dirty_for_io);
|
2021-05-03 03:22:52 +00:00
|
|
|
|
|
|
|
bool redirty_page_for_writepage(struct writeback_control *wbc,
|
|
|
|
struct page *page)
|
|
|
|
{
|
|
|
|
return folio_redirty_for_writepage(wbc, page_folio(page));
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(redirty_page_for_writepage);
|
2021-04-29 15:09:31 +00:00
|
|
|
|
2020-12-08 13:56:28 +00:00
|
|
|
int add_to_page_cache_lru(struct page *page, struct address_space *mapping,
|
|
|
|
pgoff_t index, gfp_t gfp)
|
|
|
|
{
|
|
|
|
return filemap_add_folio(mapping, page_folio(page), index, gfp);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(add_to_page_cache_lru);
|
2021-03-08 16:45:35 +00:00
|
|
|
|
2020-12-24 17:55:56 +00:00
|
|
|
noinline
|
2021-03-08 16:45:35 +00:00
|
|
|
struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index,
|
2023-05-26 20:43:23 +00:00
|
|
|
fgf_t fgp_flags, gfp_t gfp)
|
2021-03-08 16:45:35 +00:00
|
|
|
{
|
|
|
|
struct folio *folio;
|
|
|
|
|
|
|
|
folio = __filemap_get_folio(mapping, index, fgp_flags, gfp);
|
2023-03-07 14:34:10 +00:00
|
|
|
if (IS_ERR(folio))
|
2023-03-07 14:34:09 +00:00
|
|
|
return NULL;
|
2021-03-08 16:45:35 +00:00
|
|
|
return folio_file_page(folio, index);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(pagecache_get_page);
|
2020-12-24 17:55:56 +00:00
|
|
|
|
|
|
|
struct page *grab_cache_page_write_begin(struct address_space *mapping,
|
2022-02-22 16:25:12 +00:00
|
|
|
pgoff_t index)
|
2020-12-24 17:55:56 +00:00
|
|
|
{
|
2023-03-24 18:01:01 +00:00
|
|
|
return pagecache_get_page(mapping, index, FGP_WRITEBEGIN,
|
2020-12-24 17:55:56 +00:00
|
|
|
mapping_gfp_mask(mapping));
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(grab_cache_page_write_begin);
|