linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: linux-mm@kvack.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>, hughd@google.com
Subject: [PATCH 09/59] shmem: Convert shmem_writepage() to use a folio throughout
Date: Mon,  8 Aug 2022 20:33:37 +0100	[thread overview]
Message-ID: <20220808193430.3378317-10-willy@infradead.org> (raw)
In-Reply-To: <20220808193430.3378317-1-willy@infradead.org>

Even though we will split any large folio that comes in, write the
code to handle large folios so as to not leave a trap for whoever
tries to handle large folios in the swap cache.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 mm/shmem.c | 47 ++++++++++++++++++++++++-----------------------
 1 file changed, 24 insertions(+), 23 deletions(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index de267a23248d..bcd3644eb9c3 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1328,17 +1328,18 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
 	 * "force", drivers/gpu/drm/i915/gem/i915_gem_shmem.c gets huge pages,
 	 * and its shmem_writeback() needs them to be split when swapping.
 	 */
-	if (PageTransCompound(page)) {
+	if (folio_test_large(folio)) {
 		/* Ensure the subpages are still dirty */
-		SetPageDirty(page);
+		folio_test_set_dirty(folio);
 		if (split_huge_page(page) < 0)
 			goto redirty;
-		ClearPageDirty(page);
+		folio = page_folio(page);
+		folio_clear_dirty(folio);
 	}
 
-	BUG_ON(!PageLocked(page));
-	mapping = page->mapping;
-	index = page->index;
+	BUG_ON(!folio_test_locked(folio));
+	mapping = folio->mapping;
+	index = folio->index;
 	inode = mapping->host;
 	info = SHMEM_I(inode);
 	if (info->flags & VM_LOCKED)
@@ -1361,15 +1362,15 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
 	/*
 	 * This is somewhat ridiculous, but without plumbing a SWAP_MAP_FALLOC
 	 * value into swapfile.c, the only way we can correctly account for a
-	 * fallocated page arriving here is now to initialize it and write it.
+	 * fallocated folio arriving here is now to initialize it and write it.
 	 *
-	 * That's okay for a page already fallocated earlier, but if we have
+	 * That's okay for a folio already fallocated earlier, but if we have
 	 * not yet completed the fallocation, then (a) we want to keep track
-	 * of this page in case we have to undo it, and (b) it may not be a
+	 * of this folio in case we have to undo it, and (b) it may not be a
 	 * good idea to continue anyway, once we're pushing into swap.  So
-	 * reactivate the page, and let shmem_fallocate() quit when too many.
+	 * reactivate the folio, and let shmem_fallocate() quit when too many.
 	 */
-	if (!PageUptodate(page)) {
+	if (!folio_test_uptodate(folio)) {
 		if (inode->i_private) {
 			struct shmem_falloc *shmem_falloc;
 			spin_lock(&inode->i_lock);
@@ -1385,9 +1386,9 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
 			if (shmem_falloc)
 				goto redirty;
 		}
-		clear_highpage(page);
-		flush_dcache_page(page);
-		SetPageUptodate(page);
+		folio_zero_range(folio, 0, folio_size(folio));
+		flush_dcache_folio(folio);
+		folio_mark_uptodate(folio);
 	}
 
 	swap = folio_alloc_swap(folio);
@@ -1396,7 +1397,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
 
 	/*
 	 * Add inode to shmem_unuse()'s list of swapped-out inodes,
-	 * if it's not already there.  Do it now before the page is
+	 * if it's not already there.  Do it now before the folio is
 	 * moved to swap cache, when its pagelock no longer protects
 	 * the inode from eviction.  But don't unlock the mutex until
 	 * we've incremented swapped, because shmem_unuse_inode() will
@@ -1406,7 +1407,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
 	if (list_empty(&info->swaplist))
 		list_add(&info->swaplist, &shmem_swaplist);
 
-	if (add_to_swap_cache(page, swap,
+	if (add_to_swap_cache(&folio->page, swap,
 			__GFP_HIGH | __GFP_NOMEMALLOC | __GFP_NOWARN,
 			NULL) == 0) {
 		spin_lock_irq(&info->lock);
@@ -1415,21 +1416,21 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
 		spin_unlock_irq(&info->lock);
 
 		swap_shmem_alloc(swap);
-		shmem_delete_from_page_cache(page, swp_to_radix_entry(swap));
+		shmem_delete_from_page_cache(&folio->page, swp_to_radix_entry(swap));
 
 		mutex_unlock(&shmem_swaplist_mutex);
-		BUG_ON(page_mapped(page));
-		swap_writepage(page, wbc);
+		BUG_ON(folio_mapped(folio));
+		swap_writepage(&folio->page, wbc);
 		return 0;
 	}
 
 	mutex_unlock(&shmem_swaplist_mutex);
-	put_swap_page(page, swap);
+	put_swap_page(&folio->page, swap);
 redirty:
-	set_page_dirty(page);
+	folio_mark_dirty(folio);
 	if (wbc->for_reclaim)
-		return AOP_WRITEPAGE_ACTIVATE;	/* Return with page locked */
-	unlock_page(page);
+		return AOP_WRITEPAGE_ACTIVATE;	/* Return with folio locked */
+	folio_unlock(folio);
 	return 0;
 }
 
-- 
2.35.1



  parent reply	other threads:[~2022-08-08 19:35 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-08 19:33 [PATCH 00/59] MM folio changes for 6.1 Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 01/59] mm: Fix VM_BUG_ON in __delete_from_swap_cache() Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 02/59] shmem: Update folio if shmem_replace_page() updates the page Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 03/59] vmscan: Check folio_test_private(), not folio_get_private() Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 04/59] mm/vmscan: Fix a lot of comments Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 05/59] mm: Add the first tail page to struct folio Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 06/59] mm: Reimplement folio_order() and folio_nr_pages() Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 07/59] mm: Add split_folio() Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 08/59] mm: Add folio_add_lru_vma() Matthew Wilcox (Oracle)
2022-08-08 19:33 ` Matthew Wilcox (Oracle) [this message]
2022-08-08 19:33 ` [PATCH 10/59] shmem: Convert shmem_delete_from_page_cache() to take a folio Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 11/59] shmem: Convert shmem_replace_page() to use folios throughout Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 12/59] mm/swapfile: Remove page_swapcount() Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 13/59] mm/swapfile: Convert try_to_free_swap() to folio_free_swap() Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 14/59] mm/swap: Convert __read_swap_cache_async() to use a folio Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 15/59] mm/swap: Convert add_to_swap_cache() to take " Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 16/59] mm/swap: Convert put_swap_page() to put_swap_folio() Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 17/59] mm: Convert do_swap_page() to use a folio Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 18/59] mm: Convert do_swap_page()'s swapcache variable to " Matthew Wilcox (Oracle)
2022-08-11  2:28   ` Hugh Dickins
2022-08-08 19:33 ` [PATCH 19/59] memcg: Convert mem_cgroup_swapin_charge_page() to mem_cgroup_swapin_charge_folio() Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 20/59] shmem: Convert shmem_mfill_atomic_pte() to use a folio Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 21/59] shmem: Convert shmem_replace_page() to shmem_replace_folio() Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 22/59] swap: Add swap_cache_get_folio() Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 23/59] shmem: Eliminate struct page from shmem_swapin_folio() Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 24/59] shmem: Convert shmem_getpage_gfp() to shmem_get_folio_gfp() Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 25/59] shmem: Convert shmem_fault() to use shmem_get_folio_gfp() Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 26/59] shmem: Convert shmem_read_mapping_page_gfp() " Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 27/59] shmem: Add shmem_get_folio() Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 28/59] shmem: Convert shmem_get_partial_folio() to use shmem_get_folio() Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 29/59] shmem: Convert shmem_write_begin() " Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 30/59] shmem: Convert shmem_file_read_iter() " Matthew Wilcox (Oracle)
2022-08-08 19:33 ` [PATCH 31/59] shmem: Convert shmem_fallocate() to use a folio Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 32/59] shmem: Convert shmem_symlink() " Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 33/59] shmem: Convert shmem_get_link() " Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 34/59] khugepaged: Call shmem_get_folio() Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 35/59] userfaultfd: Convert mcontinue_atomic_pte() to use a folio Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 36/59] shmem: Remove shmem_getpage() Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 37/59] swapfile: Convert try_to_unuse() to use a folio Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 38/59] swapfile: Convert __try_to_reclaim_swap() " Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 39/59] swapfile: Convert unuse_pte_range() " Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 40/59] mm: Convert do_swap_page() to use swap_cache_get_folio() Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 41/59] mm: Remove lookup_swap_cache() Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 42/59] swap_state: Convert free_swap_cache() to use a folio Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 43/59] swap: Convert swap_writepage() " Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 44/59] mm: Convert do_wp_page() " Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 45/59] huge_memory: Convert do_huge_pmd_wp_page() " Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 46/59] madvise: Convert madvise_free_pte_range() " Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 47/59] uprobes: Use folios more widely in __replace_page() Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 48/59] ksm: Use a folio in replace_page() Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 49/59] mm: Convert do_swap_page() to use folio_free_swap() Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 50/59] memcg: Convert mem_cgroup_swap_full() to take a folio Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 51/59] mm: Remove try_to_free_swap() Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 52/59] rmap: Convert page_move_anon_rmap() to use a folio Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 53/59] migrate: Convert __unmap_and_move() to use folios Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 54/59] migrate: Convert unmap_and_move_huge_page() " Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 55/59] huge_memory: Convert split_huge_page_to_list() to use a folio Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 56/59] huge_memory: Convert unmap_page() to unmap_folio() Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 57/59] mm: Convert page_get_anon_vma() to folio_get_anon_vma() Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 58/59] rmap: Remove page_unlock_anon_vma_read() Matthew Wilcox (Oracle)
2022-08-08 19:34 ` [PATCH 59/59] uprobes: Use new_folio in __replace_page() Matthew Wilcox (Oracle)
2022-08-11  2:17 ` [PATCH 00/59] MM folio changes for 6.1 Hugh Dickins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220808193430.3378317-10-willy@infradead.org \
    --to=willy@infradead.org \
    --cc=hughd@google.com \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).