]> www.infradead.org Git - users/willy/pagecache.git/log
users/willy/pagecache.git
3 years agomm/swap: Add release_folios folio
Matthew Wilcox (Oracle) [Thu, 17 Dec 2020 18:13:44 +0000 (13:13 -0500)]
mm/swap: Add release_folios

Turn release_pages() into a wrapper around release_folios().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agoblock: Add folio_nr_vecs
Matthew Wilcox (Oracle) [Wed, 13 Jan 2021 16:57:44 +0000 (11:57 -0500)]
block: Add folio_nr_vecs

Estimate how many iovecs we need in a bio, based on the current folio
we're processing.  Convert iomap to use it.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agofs/writeback: Convert wbc_account_cgroup_owner to take a folio
Matthew Wilcox (Oracle) [Mon, 16 Aug 2021 18:37:08 +0000 (14:37 -0400)]
fs/writeback: Convert wbc_account_cgroup_owner to take a folio

Convert all callers to do the folio conversion instead of doing it in
wbc_account_cgroup_owner().  All callers are in the writeback path,
so they're actually handling head pages and will soon be converted to
use folios.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agofs: Convert aops set_page_dirty to dirty_folio
Matthew Wilcox (Oracle) [Tue, 20 Jul 2021 03:14:33 +0000 (23:14 -0400)]
fs: Convert aops set_page_dirty to dirty_folio

Pass a folio from folio_mark_dirty() to the filesystem.

Include the address_space as a parameter as many implementations of
->dirty_folio want to examine the address space, and several are confused
as to whether ->dirty_folio can race with truncation or not.

Convert the return value from int to bool to reflect what's actually
being communicated.

Rename the helpers:
__set_page_dirty_no_writeback() becomes dirty_folio_no_writeback()
__set_page_dirty_nobuffers() becomes filemap_dirty_folio()
__set_page_dirty_buffers() becomes block_dirty_folio()

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/writeback: Convert set_page_dirty_lock to use folios
Matthew Wilcox (Oracle) [Tue, 27 Apr 2021 04:00:18 +0000 (00:00 -0400)]
mm/writeback: Convert set_page_dirty_lock to use folios

Keep the external API the same, but convert to a folio internally and
use the folio APIs.  Reduces the number of calls to compound_page()
from three to one.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agofs: Convert invalidatepage to work on folios
Matthew Wilcox (Oracle) [Tue, 12 Jan 2021 18:29:42 +0000 (13:29 -0500)]
fs: Convert invalidatepage to work on folios

No existing user of invalidatepage supports compound pages, so all pages
being passed to invalidatepage are folios by definition.  Convert all
the implementations to use folios and also change the offset/length
parameters from unsigned int to size_t to make it clear they're byte
counters and not blocks.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agofs: Convert is_partially_uptodate to folios
Matthew Wilcox (Oracle) [Wed, 30 Dec 2020 22:51:56 +0000 (17:51 -0500)]
fs: Convert is_partially_uptodate to folios

Since the uptodate property is maintained on a per-folio basis, the
is_partially_uptodate method should also take a folio.  Fix the types
at the same time so it's clear that it returns true/false and takes
the count in bytes, not blocks.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agofs: Convert i_blocks_per_page to i_blocks_per_folio
Matthew Wilcox (Oracle) [Thu, 24 Dec 2020 15:33:18 +0000 (10:33 -0500)]
fs: Convert i_blocks_per_page to i_blocks_per_folio

This function already silently required that the page be not a tail page,
so enforce that with the compiler.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agofs: Convert page_mkwrite_check_truncate to folio_mkwrite_check_truncate
Matthew Wilcox (Oracle) [Thu, 24 Dec 2020 04:18:40 +0000 (23:18 -0500)]
fs: Convert page_mkwrite_check_truncate to folio_mkwrite_check_truncate

If a filesystem uses multi-page folios then its ->page_mkwrite() method
may be called with a tail page.  If it is, the filesystem should treat
the entire folio as being made dirty, so it must iterate over every
extent covered by the folio in case it needs to be COWed.

Change both callers to pass the folio of the page.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agodrm: Use folios in drm_gem_get_pages
Matthew Wilcox (Oracle) [Mon, 21 Dec 2020 14:37:16 +0000 (09:37 -0500)]
drm: Use folios in drm_gem_get_pages

Take one refcount per folio instead of per page.  This will be a mild
performance improvement, but the real purpose of this is to only put
head pages in the pagevec in preparation for converting pagevecs to
only containing folios.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agofs: Change readpage to take a folio
Matthew Wilcox (Oracle) [Tue, 15 Dec 2020 15:48:32 +0000 (10:48 -0500)]
fs: Change readpage to take a folio

We track the uptodate state on the entire folio, not individual
pages.  That means the readpage should be passed a folio and told
to update the entire folio.  Filesystems will not have multi-page
folios created for them until they indicate support for them by
setting the FS_MULTI_PAGE_FOLIO flag.  Until they do, they can
assume that the folio being passed in contains a single page.

Also convert filler_t to take a folio as these two are tightly
intertwined.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agofs: Change page refcount rules for readahead
Matthew Wilcox (Oracle) [Mon, 14 Dec 2020 20:16:44 +0000 (15:16 -0500)]
fs: Change page refcount rules for readahead

This brings ->readahead into line with ->readpage for the refcount on
struct page.  It simplifies the various filesystems which implement
readahead and will reduce the number of atomic operations on the page
refcount in the future.  This change is combined with the conversion of
readahead to use the struct folio in order to make unconverted filesystems
fail to compile.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agompage: Convert do_mpage_readpage to take a folio
Matthew Wilcox (Oracle) [Sun, 10 Jan 2021 07:30:22 +0000 (02:30 -0500)]
mpage: Convert do_mpage_readpage to take a folio

This routine is used by both readpage() and readahead(), so it needs to
be converted before either routine which uses it can be converted.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agoafs: Convert afs_page_mkwrite to folios
Matthew Wilcox (Oracle) [Fri, 19 Mar 2021 00:52:12 +0000 (20:52 -0400)]
afs: Convert afs_page_mkwrite to folios

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm: Remove FGP_HEAD
Matthew Wilcox (Oracle) [Tue, 22 Dec 2020 03:59:22 +0000 (22:59 -0500)]
mm: Remove FGP_HEAD

This is no longer used; all callers have been converted to use folios
instead.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/huge_memory: Convert split_huge_pages_in_file to folio
Matthew Wilcox (Oracle) [Wed, 21 Apr 2021 22:24:57 +0000 (18:24 -0400)]
mm/huge_memory: Convert split_huge_pages_in_file to folio

Use __filemap_get_folio() instead of pagecache_get_page().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/swap: Convert __put_page to __folio_put
Matthew Wilcox (Oracle) [Tue, 16 Mar 2021 03:15:30 +0000 (23:15 -0400)]
mm/swap: Convert __put_page to __folio_put

Also change a number of other functions to take folios.  Saves
25 bytes of kernel text, including one check of PageTail on
every page free.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/memory: Use a folio in copy_pte_range
Matthew Wilcox (Oracle) [Mon, 15 Mar 2021 02:47:59 +0000 (22:47 -0400)]
mm/memory: Use a folio in copy_pte_range

Removes three calls to compound_head() and two calls to check if the page
is devmap.  Shrinks the kernel by 121 bytes overall (a few functions which
seem entirely unrelated grow, but copy_pte_range() shrinks by 232 bytes).

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/memory: Turn cow_page into a folio
Matthew Wilcox (Oracle) [Sun, 14 Mar 2021 10:41:59 +0000 (06:41 -0400)]
mm/memory: Turn cow_page into a folio

We always allocate a single page for cow_page, so by definition it's
a folio.  Change its type and update all users.  Saves 57 bytes of
text overall, including 175 bytes from do_cow_fault() and 77 from
do_fault().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Use a folio in filemap_page_mkwrite
Matthew Wilcox (Oracle) [Sat, 13 Mar 2021 04:57:44 +0000 (23:57 -0500)]
mm/filemap: Use a folio in filemap_page_mkwrite

This fixes a bug for tail pages.  They always have a NULL mapping, so
the check would fail and we would never mark the page as dirty.
Ends up growing the kernel by 19 bytes although there will be fewer
calls to compound_head() dynamically.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Convert filemap_map_pmd to take a folio
Matthew Wilcox (Oracle) [Sat, 13 Mar 2021 04:53:02 +0000 (23:53 -0500)]
mm/filemap: Convert filemap_map_pmd to take a folio

Removes an assumption that a multi-order page is necessarily PMD-sized.
Saves a few calls to compound_head(), saving 33 bytes of text.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Use a folio in page_endio
Matthew Wilcox (Oracle) [Sat, 13 Mar 2021 04:20:56 +0000 (23:20 -0500)]
mm/filemap: Use a folio in page_endio

This removes a call to compound_head(), saving 12 bytes of text.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/mlock: Convert __putback_lru_fast_prepare to take a folio
Matthew Wilcox (Oracle) [Thu, 17 Dec 2020 15:23:36 +0000 (10:23 -0500)]
mm/mlock: Convert __putback_lru_fast_prepare to take a folio

The mlock code only uses the pagevecs for order-0 pages, so we can
skip all the compound_head tests by using folios.  Shrinks the
kernel by 81 bytes.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/writeback: Remove account_page_redirty wrapper
Matthew Wilcox (Oracle) [Wed, 5 May 2021 14:04:31 +0000 (10:04 -0400)]
mm/writeback: Remove account_page_redirty wrapper

All users have now been removed, so delete this wrapper.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agobtrfs: Convert run_delalloc_zoned to use a folio
Matthew Wilcox (Oracle) [Mon, 3 May 2021 15:00:48 +0000 (11:00 -0400)]
btrfs: Convert run_delalloc_zoned to use a folio

This removes two uses of page wrappers around functions which
naturally use folios.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agobtrfs: Convert extent_range_redirty_for_io to use a folio
Matthew Wilcox (Oracle) [Wed, 5 May 2021 14:03:29 +0000 (10:03 -0400)]
btrfs: Convert extent_range_redirty_for_io to use a folio

Removes the use of two wrapper functions.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/readahead: Convert page_cache_async_readahead to take a folio
Matthew Wilcox (Oracle) [Thu, 18 Mar 2021 02:38:26 +0000 (22:38 -0400)]
mm/readahead: Convert page_cache_async_readahead to take a folio

Removes a couple of calls to compound_head and saves a few bytes.
Also convert verity's read_file_data_page() to be folio-based.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/readahead: Convert page_cache_ra_unbounded to folios
Matthew Wilcox (Oracle) [Wed, 10 Mar 2021 21:06:51 +0000 (16:06 -0500)]
mm/readahead: Convert page_cache_ra_unbounded to folios

This saves 99 bytes of kernel text.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/swap: Convert find_get_incore_page to use folios
Matthew Wilcox (Oracle) [Mon, 21 Dec 2020 21:46:03 +0000 (16:46 -0500)]
mm/swap: Convert find_get_incore_page to use folios

Eliminates a use of FGP_HEAD and saves 8 bytes of text.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/swap: Convert put_pages_list to use folios
Matthew Wilcox (Oracle) [Tue, 30 Mar 2021 18:35:53 +0000 (14:35 -0400)]
mm/swap: Convert put_pages_list to use folios

Pages on the LRU list cannot be tail pages as ->compound_head is in
a union with one of the words of the list_head, and they cannot be
ZONE_DEVICE pages as ->pgmap is in a union with the same word.  So add
lru_to_folio() and use folio_put() in put_pages_list().  Saves 86 bytes
of text.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/swap: Convert release_pages to use a folio internally
Matthew Wilcox (Oracle) [Thu, 17 Dec 2020 16:21:43 +0000 (11:21 -0500)]
mm/swap: Convert release_pages to use a folio internally

This function was already calling compound_head(), but now it can
cache the result of calling compound_head() and avoid calling it again.
Saves 112 bytes of text by avoiding various calls to compound_page()
and avoiding checks of PageTail.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/swap: Convert try_to_free_swap to use a folio
Matthew Wilcox (Oracle) [Sun, 28 Feb 2021 15:52:57 +0000 (10:52 -0500)]
mm/swap: Convert try_to_free_swap to use a folio

Save a few calls to compound_head by converting the passed page to
a folio.  Reduces kernel text size by 74 bytes.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/swap: Add pagevec_add_and_move()
Matthew Wilcox (Oracle) [Fri, 14 May 2021 14:21:42 +0000 (10:21 -0400)]
mm/swap: Add pagevec_add_and_move()

All but one of the callers of pagevec_add_and_need_flush() conditionally
call pagevec_lru_move_fn().  Simplify by passing the move_fn to
pagevec_add_and_move().  If the move_fn is NULL, then we want to call
__pagevec_lru_add() instead of pagevec_lru_move_fn().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/swap: Pass folios to move functions
Matthew Wilcox (Oracle) [Thu, 1 Jul 2021 03:27:42 +0000 (23:27 -0400)]
mm/swap: Pass folios to move functions

All the move functions now work in terms of folios, so convert the
page from the pagevec into a folio before calling them.  Saves a few
dozen bytes of text.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/swap: Convert mark_page_lazyfree to use folios internally
Matthew Wilcox (Oracle) [Mon, 29 Mar 2021 18:23:54 +0000 (14:23 -0400)]
mm/swap: Convert mark_page_lazyfree to use folios internally

Leave the interface as being struct page for now.  Removes about fifteen
calls to compound_head() for a reduction of XXX bytes of text.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/swap: Convert deactivate_page to use folios internally
Matthew Wilcox (Oracle) [Thu, 17 Dec 2020 04:41:15 +0000 (23:41 -0500)]
mm/swap: Convert deactivate_page to use folios internally

Leave the interface as being struct page for now.  Removes about seven
calls to compound_head() for a total of 98 bytes of text saved.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/swap: Add folio_deactivate_file
Matthew Wilcox (Oracle) [Thu, 17 Dec 2020 04:41:15 +0000 (23:41 -0500)]
mm/swap: Add folio_deactivate_file

Convert deactivate_file_page() to folio_deactivate_file().  We can
use folio_get() instead of folio_try_get() because the only caller of
folio_deactivate_file() definitely has a reference to the folio already.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/migrate: Allocate folios
Matthew Wilcox (Oracle) [Tue, 6 Jul 2021 14:50:39 +0000 (10:50 -0400)]
mm/migrate: Allocate folios

Convert migrate_misplaced_transhuge_page() and alloc_migration_target()
to allocate folios instead of pages.  Probably wants to get split up
and done differently.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/khugepaged: Allocate folios
Matthew Wilcox (Oracle) [Sat, 8 May 2021 03:40:19 +0000 (23:40 -0400)]
mm/khugepaged: Allocate folios

khugepaged only wants to deal in terms of folios, so switch to
using the folio allocation functions.  This eliminates the calls to
prep_transhuge_page() and saves dozens of bytes of text.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agofolio_has_buffers
Matthew Wilcox (Oracle) [Thu, 8 Apr 2021 11:50:58 +0000 (07:50 -0400)]
folio_has_buffers

3 years agofs/writeback: Convert inode_switch_wbs_work_fn to folios
Matthew Wilcox (Oracle) [Fri, 19 Mar 2021 12:58:36 +0000 (08:58 -0400)]
fs/writeback: Convert inode_switch_wbs_work_fn to folios

This gets the statistics correct by modifying the counters by the
number of pages in the folio instead of by 1.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/doc: Add documentation for folio_test_uptodate
Matthew Wilcox (Oracle) [Mon, 3 May 2021 11:29:47 +0000 (07:29 -0400)]
mm/doc: Add documentation for folio_test_uptodate

Move the PG_uptodate documentation to be documentation for
folio_test_uptodate() and expand on it a little.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/shmem: Convert shmem_swapin_page() to produce a folio
Matthew Wilcox (Oracle) [Mon, 17 May 2021 13:51:35 +0000 (09:51 -0400)]
mm/shmem: Convert shmem_swapin_page() to produce a folio

shmem_swapin_page() only brings in order-0 pages, which are folios
by definition.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm: Allow pagevecs to contain a folio
Matthew Wilcox (Oracle) [Mon, 17 May 2021 12:58:51 +0000 (08:58 -0400)]
mm: Allow pagevecs to contain a folio

Use a union to allow pagevecs to contain an array of folios instead of
pages.  Some pagevecs currently contain tail pages, so be sure that all
providers populate with folios before a particular consumer is converted.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/shmem: Convert shmem_getpage_gfp to use a folio
Matthew Wilcox (Oracle) [Sat, 8 May 2021 14:22:02 +0000 (10:22 -0400)]
mm/shmem: Convert shmem_getpage_gfp to use a folio

Rename shmem_alloc_and_acct_page() to shmem_alloc_and_acct_folio() and
have it return a folio, then use a folio throuughout shmem_getpage_gfp().
It continues to return a struct page.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/shmem: Convert shmem_alloc_and_acct_page to use a folio
Matthew Wilcox (Oracle) [Fri, 7 May 2021 21:24:45 +0000 (17:24 -0400)]
mm/shmem: Convert shmem_alloc_and_acct_page to use a folio

Convert shmem_alloc_hugepage() to return the folio that it uses
and use a folio throughout shmem_alloc_and_acct_page().  Continue
to return a page from shmem_alloc_and_acct_page() for now.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/shmem: Turn shmem_alloc_page() into shmem_alloc_folio()
Matthew Wilcox (Oracle) [Thu, 6 May 2021 15:41:34 +0000 (11:41 -0400)]
mm/shmem: Turn shmem_alloc_page() into shmem_alloc_folio()

Call vma_alloc_folio() directly instead of alloc_page_vma().
It's a bit messy in the callers, but they're about to be
cleaned up when they get converted to folios.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/shmem: Turn shmem_should_replace_page into shmem_should_replace_folio
Matthew Wilcox (Oracle) [Thu, 6 May 2021 12:57:44 +0000 (08:57 -0400)]
mm/shmem: Turn shmem_should_replace_page into shmem_should_replace_folio

This is a straightforward conversion.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/shmem: Convert shmem_add_to_page_cache to take a folio
Matthew Wilcox (Oracle) [Thu, 6 May 2021 12:44:40 +0000 (08:44 -0400)]
mm/shmem: Convert shmem_add_to_page_cache to take a folio

Shrinks shmem_add_to_page_cache() by 16 bytes.  All the callers grow,
but this is temporary as they will all be converted to folios soon.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/shmem: Use a folio in shmem_unused_huge_shrink
Matthew Wilcox (Oracle) [Thu, 6 May 2021 12:22:16 +0000 (08:22 -0400)]
mm/shmem: Use a folio in shmem_unused_huge_shrink

When calling split_huge_page() we usually have to find the precise page,
but that's not necessary here because we only need to unlock and put
the folio afterwards.  Saves 231 bytes of text (20% of this function).

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/page_alloc: Convert alloc_pages_vma to vma_alloc_folio
Matthew Wilcox (Oracle) [Tue, 22 Dec 2020 12:55:18 +0000 (07:55 -0500)]
mm/page_alloc: Convert alloc_pages_vma to vma_alloc_folio

Remove the alloc_hugepage_vma() wrapper, and convert all callers to use
a folio.  The callers no longer need to call prep_transhuge_page().
Saves 27 bytes of kernel text (some functions expand, others shrink).

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/swap: Add folio_throttle_swaprate folio-tested
Matthew Wilcox (Oracle) [Thu, 6 May 2021 12:42:34 +0000 (08:42 -0400)]
mm/swap: Add folio_throttle_swaprate

The only use of the page argument to cgroup_throttle_swaprate() is to
get the node ID, and this will be the same for all pages in the folio,
so there's no need to convert the page to a folio before calling it.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agofs: Dump information about bad inodes
Matthew Wilcox (Oracle) [Wed, 26 May 2021 17:05:37 +0000 (13:05 -0400)]
fs: Dump information about bad inodes

If nrpages is still set, call dump_mapping to tell us what kind of inode
is causing problems.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm,fs: Split dump_mapping() out from dump_page()
Matthew Wilcox (Oracle) [Wed, 26 May 2021 17:03:12 +0000 (13:03 -0400)]
mm,fs: Split dump_mapping() out from dump_page()

dump_mapping() is a big chunk of dump_page(), and it'd be handy to be
able to call it when we don't have a struct page.  Split it out and move
it to fs/inode.c.  Take the opportunity to simplify some of the debug
messages a little.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/writeback: Improve __folio_mark_dirty() comment
Matthew Wilcox (Oracle) [Sun, 20 Dec 2020 11:44:51 +0000 (06:44 -0500)]
mm/writeback: Improve __folio_mark_dirty() comment

Add some notes about how this function needs to be called.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agoselftests/vm/transhuge-stress: Support file-backed THPs
Matthew Wilcox (Oracle) [Sun, 25 Jul 2021 03:43:58 +0000 (23:43 -0400)]
selftests/vm/transhuge-stress: Support file-backed THPs

Add a -f <filename> option to test THPs on files

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Support VM_HUGEPAGE for file mappings
Matthew Wilcox (Oracle) [Sun, 25 Jul 2021 03:37:13 +0000 (23:37 -0400)]
mm/filemap: Support VM_HUGEPAGE for file mappings

If the VM_HUGEPAGE flag is set, attempt to allocate PMD-sized THPs
during readahead, even if we have no history of readahead being
successful.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/readahead: Switch to page_cache_ra_order
Matthew Wilcox (Oracle) [Sun, 25 Jul 2021 03:26:14 +0000 (23:26 -0400)]
mm/readahead: Switch to page_cache_ra_order

do_page_cache_ra() was being exposed for the benefit of
do_sync_mmap_readahead().  Switch it over to page_cache_ra_order()
partly because it's a better interface but mostly for the benefit of
the next patch.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/readahead: Align THP mappings for non-DAX
William Kucharski [Sun, 22 Sep 2019 12:43:15 +0000 (08:43 -0400)]
mm/readahead: Align THP mappings for non-DAX

When we have the opportunity to use transparent huge pages to map a
file, we want to follow the same rules as DAX.

Signed-off-by: William Kucharski <william.kucharski@oracle.com>
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/readahead: Add multi-page folio readahead
Matthew Wilcox (Oracle) [Wed, 5 Feb 2020 16:27:01 +0000 (11:27 -0500)]
mm/readahead: Add multi-page folio readahead

If the filesystem supports multi-page folios, allocate larger pages in
the readahead code when it seems worth doing.  The heuristic for choosing
larger page sizes will surely need some tuning, but this aggressive
ramp-up has been good for testing.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/vmscan: Optimise shrink_page_list for smaller THPs
Matthew Wilcox (Oracle) [Sat, 15 Aug 2020 23:28:51 +0000 (19:28 -0400)]
mm/vmscan: Optimise shrink_page_list for smaller THPs

A THP which is smaller than a PMD does not need to do the extra work
in try_to_unmap() of trying to split a PMD entry.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Allow multi-page folios to be added to the page cache
Matthew Wilcox (Oracle) [Thu, 5 Sep 2019 18:03:12 +0000 (14:03 -0400)]
mm/filemap: Allow multi-page folios to be added to the page cache

We return -EEXIST if there are any non-shadow entries in the page
cache in the range covered by the folio.  If there are multiple
shadow entries in the range, we set *shadowp to one of them (currently
the one at the highest index).  If that turns out to be the wrong
answer, we can implement something more complex.  This is mostly
modelled after the equivalent function in the shmem code.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm: Support arbitrary THP sizes
Matthew Wilcox (Oracle) [Sat, 30 May 2020 00:54:38 +0000 (20:54 -0400)]
mm: Support arbitrary THP sizes

Use the compound size of the page instead of assuming PTE or PMD size.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm: Fix READ_ONLY_THP warning
Matthew Wilcox (Oracle) [Sat, 10 Oct 2020 15:47:55 +0000 (11:47 -0400)]
mm: Fix READ_ONLY_THP warning

These counters only exist if CONFIG_READ_ONLY_THP_FOR_FS is defined,
but we do not need to warn if the filesystem natively supports multi-page
folios.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/vmscan: Free non-shmem THPs without splitting them
Matthew Wilcox (Oracle) [Wed, 30 Sep 2020 20:15:46 +0000 (16:15 -0400)]
mm/vmscan: Free non-shmem THPs without splitting them

We have to allocate memory in order to split a file-backed page,
so it's not a good idea to split them.  It also doesn't work for XFS
because pages have an extra reference count from page_has_private() and
split_huge_page() expects that reference to have already been removed.
Unfortunately, we still have to split shmem THPs because we can't handle
swapping out an entire THP yet.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/truncate: Convert invalidate_inode_pages2_range to folios
Matthew Wilcox (Oracle) [Thu, 20 May 2021 12:17:44 +0000 (08:17 -0400)]
mm/truncate: Convert invalidate_inode_pages2_range to folios

If we're going to unmap a folio, we have to be sure to unmap the entire
folio, not just the part of it which lies after the search index.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/truncate: Add invalidate_complete_folio2()
Matthew Wilcox (Oracle) [Wed, 28 Jul 2021 19:52:34 +0000 (15:52 -0400)]
mm/truncate: Add invalidate_complete_folio2()

Convert invalidate_complete_page2() to invalidate_complete_folio2().
Use filemap_free_folio() to free the page instead of calling ->freepage
manually.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Add filemap_release_folio()
Matthew Wilcox (Oracle) [Wed, 28 Jul 2021 19:14:48 +0000 (15:14 -0400)]
mm/filemap: Add filemap_release_folio()

Reimplement try_to_release_page() as a wrapper around
filemap_release_folio().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm: Use multi-index entries in the page cache
Matthew Wilcox (Oracle) [Sun, 28 Jun 2020 02:19:08 +0000 (22:19 -0400)]
mm: Use multi-index entries in the page cache

We currently store order-N THPs as 2^N consecutive entries.  While this
consumes rather more memory than necessary, it also turns out to be buggy.
A writeback operation which starts in the middle of a dirty THP will not
notice as the dirty bit is only set on the head index.  With multi-index
entries, the dirty bit will be found no matter where in the THP the
iteration starts.

This does end up simplifying the page cache slightly, although not as
much as I had hoped.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agoXArray: Add xas_advance()
Matthew Wilcox (Oracle) [Fri, 27 Aug 2021 11:21:49 +0000 (07:21 -0400)]
XArray: Add xas_advance()

Add a new helper function to help iterate over multi-index entries.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Return only head pages from find_get_entries
Matthew Wilcox (Oracle) [Wed, 2 Sep 2020 03:17:50 +0000 (23:17 -0400)]
mm/filemap: Return only head pages from find_get_entries

All callers now expect head (and base) pages, and can handle multiple
head pages in a single batch, so make find_get_entries() behave that way.
Also take the opportunity to make it use the pagevec infrastructure
instead of open-coding how pvecs behave.  This has the side-effect of
being able to append to a pagevec with existing contents, although we
don't make use of that functionality anywhere yet.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
3 years agomm/truncate,shmem: Handle truncates that split THPs
Matthew Wilcox (Oracle) [Wed, 27 May 2020 21:59:22 +0000 (17:59 -0400)]
mm/truncate,shmem: Handle truncates that split THPs

Handle THP splitting in the parts of the truncation functions which
already handle partial pages.  Factor all that code out into a new
function called truncate_inode_partial_page().

We lose the easy 'bail out' path if a truncate or hole punch is entirely
within a single page.  We can add some more complex logic to restore
the optimisation if it proves to be worthwhile.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
3 years agofs: Rename AS_THP_SUPPORT and mapping_thp_support
Matthew Wilcox (Oracle) [Sun, 29 Aug 2021 10:28:19 +0000 (06:28 -0400)]
fs: Rename AS_THP_SUPPORT and mapping_thp_support

These are now indicators of multi-page folio support, not THP support.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agofs: Convert vfs_dedupe_file_range_compare to folios
Matthew Wilcox (Oracle) [Mon, 14 Dec 2020 12:57:07 +0000 (07:57 -0500)]
fs: Convert vfs_dedupe_file_range_compare to folios

We still only operate on a single page of data at a time due to using
kmap().  A more complex implementation would work on each page in a folio,
but it's not clear that such a complex implementation would be worthwhile.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Use a folio in filemap_map_pages
Matthew Wilcox (Oracle) [Sat, 13 Mar 2021 04:46:45 +0000 (23:46 -0500)]
mm/filemap: Use a folio in filemap_map_pages

Saves 61 bytes due to fewer calls to compound_head().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Use folios in next_uptodate_page
Matthew Wilcox (Oracle) [Sat, 13 Mar 2021 04:33:43 +0000 (23:33 -0500)]
mm/filemap: Use folios in next_uptodate_page

This saves 105 bytes of text.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Remove PageHWPoison check from next_uptodate_page()
Matthew Wilcox (Oracle) [Tue, 25 May 2021 14:11:25 +0000 (10:11 -0400)]
mm/filemap: Remove PageHWPoison check from next_uptodate_page()

Pages are individually marked as suffering from hardware poisoning.
Checking that the head page is not hardware poisoned doesn't make
sense; we might be after a subpage.  We check each page individually
before we use it, so this was an optimisation gone wrong.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Convert page_cache_delete_batch to folios
Matthew Wilcox (Oracle) [Sat, 13 Mar 2021 04:13:46 +0000 (23:13 -0500)]
mm/filemap: Convert page_cache_delete_batch to folios

Saves one call to compound_head() and reduces text size by 15 bytes.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Convert filemap_get_pages to use folios
Matthew Wilcox (Oracle) [Wed, 10 Mar 2021 19:01:22 +0000 (14:01 -0500)]
mm/filemap: Convert filemap_get_pages to use folios

This saves a few calls to compound_head(), including one in
filemap_update_page().  Shrinks the kernel by 78 bytes.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Add read_cache_folio and read_mapping_folio
Matthew Wilcox (Oracle) [Wed, 16 Dec 2020 16:45:30 +0000 (11:45 -0500)]
mm/filemap: Add read_cache_folio and read_mapping_folio

Reimplement read_cache_page() as a wrapper around read_cache_folio().
Saves over 400 bytes of text from do_read_cache_folio() which more
thn makes up for the extra 100 bytes of text added to the various
wrapper functions.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Convert filemap_fault to folio
Matthew Wilcox (Oracle) [Wed, 10 Mar 2021 15:46:41 +0000 (10:46 -0500)]
mm/filemap: Convert filemap_fault to folio

Instead of converting back-and-forth between the actual page and
the head page, just convert once at the end of the function where we
set the vmf->page.  Saves 241 bytes of text, or 15% of the size of
filemap_fault().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Convert do_async_mmap_readahead to take a folio
Matthew Wilcox (Oracle) [Thu, 29 Jul 2021 18:57:01 +0000 (14:57 -0400)]
mm/filemap: Convert do_async_mmap_readahead to take a folio

Call page_cache_async_ra() directly instead of indirecting through
page_cache_async_readahead().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/readahead: Convert page_cache_async_ra() to take a folio
Matthew Wilcox (Oracle) [Thu, 27 May 2021 16:30:54 +0000 (12:30 -0400)]
mm/readahead: Convert page_cache_async_ra() to take a folio

Using the folio here avoids checking whether it's a tail page.
This patch mostly just enables some of the following patches.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Convert filemap_range_uptodate to folios
Matthew Wilcox (Oracle) [Wed, 10 Mar 2021 16:04:19 +0000 (11:04 -0500)]
mm/filemap: Convert filemap_range_uptodate to folios

The only caller was already passing a head page, so this simply avoids
a call to compound_head().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Convert filemap_create_page to folio
Matthew Wilcox (Oracle) [Wed, 10 Mar 2021 15:34:00 +0000 (10:34 -0500)]
mm/filemap: Convert filemap_create_page to folio

This is all internal to filemap and saves 100 bytes of text.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Convert filemap_read_page to take a folio
Matthew Wilcox (Oracle) [Wed, 10 Mar 2021 15:19:30 +0000 (10:19 -0500)]
mm/filemap: Convert filemap_read_page to take a folio

One of the callers already had a folio; the other two grow by a few
bytes, but filemap_read_page() shrinks by 50 bytes for a net reduction
of 27 bytes.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Convert find_get_pages_contig to folios
Matthew Wilcox (Oracle) [Sat, 6 Mar 2021 21:38:38 +0000 (16:38 -0500)]
mm/filemap: Convert find_get_pages_contig to folios

None of the callers of find_get_pages_contig() want tail pages.  They all
use order-0 pages today, but if they were converted, they'd want folios.
So just remove the call to find_subpage() instead of replacing it with
folio_page().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Convert filemap_get_read_batch to use folios
Matthew Wilcox (Oracle) [Fri, 5 Mar 2021 15:29:41 +0000 (10:29 -0500)]
mm/filemap: Convert filemap_get_read_batch to use folios

The page cache only stores folios, never tail pages.  Saves 29 bytes
due to removing calls to compound_head().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Convert find_get_entry to return a folio
Matthew Wilcox (Oracle) [Thu, 17 Dec 2020 05:12:26 +0000 (00:12 -0500)]
mm/filemap: Convert find_get_entry to return a folio

Convert callers to cope.  Saves 580 bytes of kernel text; all five
callers are reduced in size.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Add filemap_remove_folio and __filemap_remove_folio
Matthew Wilcox (Oracle) [Sun, 9 May 2021 13:33:42 +0000 (09:33 -0400)]
mm/filemap: Add filemap_remove_folio and __filemap_remove_folio

Reimplement __delete_from_page_cache() as a wrapper around
__filemap_remove_folio() and delete_from_page_cache() as a wrapper
around filemap_remove_folio().  Remove the EXPORT_SYMBOL as
delete_from_page_cache() was not used by any in-tree modules.
Convert page_cache_free_page() into filemap_free_folio().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Convert tracing of page cache operations to folio
Matthew Wilcox (Oracle) [Fri, 23 Jul 2021 13:29:46 +0000 (09:29 -0400)]
mm/filemap: Convert tracing of page cache operations to folio

Pass the folio instead of a page.  The page was already implicitly a
folio as it accessed page->mapping directly.  Add the order of the folio
to the tracepoint, as this is important information.  Also drop printing
the address of the struct page as the pfn provides better information
than the struct page address.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Convert unaccount_page_cache_page to filemap_unaccount_folio
Matthew Wilcox (Oracle) [Sun, 9 May 2021 00:04:05 +0000 (20:04 -0400)]
mm/filemap: Convert unaccount_page_cache_page to filemap_unaccount_folio

Use folios throughout filemap_unaccount_folio(), except for the bug
handling path which would need to use total_mapcount(), which is currently
only defined for builds with THP enabled.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Convert page_cache_delete to take a folio
Matthew Wilcox (Oracle) [Sat, 8 May 2021 04:35:49 +0000 (00:35 -0400)]
mm/filemap: Convert page_cache_delete to take a folio

It was already assuming a head page, so this is a straightforward
conversion.  Convert the one caller to call page_folio(), even though
it must currently be passing in a head page.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/filemap: Add folio_put_wait_locked()
Matthew Wilcox (Oracle) [Tue, 17 Aug 2021 03:36:31 +0000 (23:36 -0400)]
mm/filemap: Add folio_put_wait_locked()

Convert all three callers of put_and_wait_on_page_locked() to
folio_put_wait_locked().  This shrinks the kernel overall by 19 bytes.
filemap_update_page() shrinks by 19 bytes while __migration_entry_wait()
is unchanged.  folio_put_wait_locked() is 14 bytes smaller than
put_and_wait_on_page_locked(), but pmd_migration_entry_wait() grows by
14 bytes.  It removes the assumption from pmd_migration_entry_wait()
that pages cannot be larger than a PMD (which is true today, but
may be interesting to explore in the future).

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomm/memcg: Convert mem_cgroup_css_from_page to folio_memcg_css
Matthew Wilcox (Oracle) [Mon, 16 Aug 2021 16:03:22 +0000 (12:03 -0400)]
mm/memcg: Convert mem_cgroup_css_from_page to folio_memcg_css

Move the hidden page_folio() call from inside mem_cgroup_css_from_page()
to the callers.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agomips: Rename PMD_ORDER to PMD_TABLE_ORDER
Matthew Wilcox (Oracle) [Wed, 30 Jun 2021 12:43:38 +0000 (08:43 -0400)]
mips: Rename PMD_ORDER to PMD_TABLE_ORDER

This is the order of the page table allocation, not the order of a PMD.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agoarm: Rename PMD_ORDER to PMD_BITS
Matthew Wilcox (Oracle) [Wed, 30 Jun 2021 12:43:38 +0000 (08:43 -0400)]
arm: Rename PMD_ORDER to PMD_BITS

This is the number of bits used by a PMD entry, not the order of a PMD.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agoxfs: Support multi-page folios
Matthew Wilcox (Oracle) [Wed, 19 May 2021 22:38:43 +0000 (18:38 -0400)]
xfs: Support multi-page folios

Now that iomap has been converted, XFS is multi-page folio safe.
Indicate to the VFS that it can now create multi-page folios for XFS.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agoiomap: Support multi-page folios in invalidatepage
Matthew Wilcox (Oracle) [Wed, 13 Jan 2021 15:48:49 +0000 (10:48 -0500)]
iomap: Support multi-page folios in invalidatepage

If we're punching a hole in a multi-page folio, we need to remove the
per-folio iomap data as the folio is about to be split and each page will
need its own.  If a dirty folio is only partially-uptodate, the iomap
data contains the information about which blocks cannot be written back,
so assert that a dirty folio is fully uptodate.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
3 years agoiomap: Convert iomap_migrate_page to use folios
Matthew Wilcox (Oracle) [Fri, 7 May 2021 19:08:09 +0000 (15:08 -0400)]
iomap: Convert iomap_migrate_page to use folios

The arguments are still pages for now, but we can use folios internally
and cut out a lot of calls to compound_head().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>