All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Christoph Hellwig <hch@lst.de>
Subject: [PATCH v14 24/39] mm/writeback: Add folio_clear_dirty_for_io()
Date: Thu, 15 Jul 2021 21:00:15 +0100	[thread overview]
Message-ID: <20210715200030.899216-25-willy@infradead.org> (raw)
In-Reply-To: <20210715200030.899216-1-willy@infradead.org>

Transform clear_page_dirty_for_io() into folio_clear_dirty_for_io()
and add a compatibility wrapper.  Also move the declaration to pagemap.h
as this is page cache functionality that doesn't need to be used by the
rest of the kernel.

Increases the size of the kernel by 79 bytes.  While we remove a few
calls to compound_head(), we add a call to folio_nr_pages() to get the
stats correct for the eventual support of multi-page folios.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 include/linux/mm.h      |  1 -
 include/linux/pagemap.h |  2 ++
 mm/folio-compat.c       |  6 ++++
 mm/page-writeback.c     | 63 +++++++++++++++++++++--------------------
 4 files changed, 40 insertions(+), 32 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 07ba22351d15..26883ea28349 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2005,7 +2005,6 @@ int redirty_page_for_writepage(struct writeback_control *wbc,
 bool folio_mark_dirty(struct folio *folio);
 bool set_page_dirty(struct page *page);
 int set_page_dirty_lock(struct page *page);
-int clear_page_dirty_for_io(struct page *page);
 
 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
 
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index a4d0aeaf884d..006de2d84d06 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -797,6 +797,8 @@ static inline void cancel_dirty_page(struct page *page)
 {
 	folio_cancel_dirty(page_folio(page));
 }
+bool folio_clear_dirty_for_io(struct folio *folio);
+bool clear_page_dirty_for_io(struct page *page);
 
 int __set_page_dirty_nobuffers(struct page *page);
 int __set_page_dirty_no_writeback(struct page *page);
diff --git a/mm/folio-compat.c b/mm/folio-compat.c
index dad962b920e5..39f5a8d963b1 100644
--- a/mm/folio-compat.c
+++ b/mm/folio-compat.c
@@ -89,3 +89,9 @@ int __set_page_dirty_nobuffers(struct page *page)
 	return filemap_dirty_folio(page_mapping(page), page_folio(page));
 }
 EXPORT_SYMBOL(__set_page_dirty_nobuffers);
+
+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);
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 0854ef768d06..66060bbf6aad 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2664,25 +2664,25 @@ void __folio_cancel_dirty(struct folio *folio)
 EXPORT_SYMBOL(__folio_cancel_dirty);
 
 /*
- * Clear a page's dirty flag, while caring for dirty memory accounting.
- * Returns true if the page was previously dirty.
- *
- * This is for preparing to put the page under writeout.  We leave the page
- * tagged as dirty in the xarray so that a concurrent write-for-sync
- * can discover it via a PAGECACHE_TAG_DIRTY walk.  The ->writepage
- * implementation will run either set_page_writeback() or set_page_dirty(),
- * at which stage we bring the page's dirty flag and xarray dirty tag
- * back into sync.
- *
- * This incoherency between the page's dirty flag and xarray tag is
- * unfortunate, but it only exists while the page is locked.
+ * Clear a folio's dirty flag, while caring for dirty memory accounting.
+ * Returns true if the folio was previously dirty.
+ *
+ * This is for preparing to put the folio under writeout.  We leave
+ * the folio tagged as dirty in the xarray so that a concurrent
+ * write-for-sync can discover it via a PAGECACHE_TAG_DIRTY walk.
+ * The ->writepage implementation will run either folio_start_writeback()
+ * or folio_mark_dirty(), at which stage we bring the folio's dirty flag
+ * and xarray dirty tag back into sync.
+ *
+ * This incoherency between the folio's dirty flag and xarray tag is
+ * unfortunate, but it only exists while the folio is locked.
  */
-int clear_page_dirty_for_io(struct page *page)
+bool folio_clear_dirty_for_io(struct folio *folio)
 {
-	struct address_space *mapping = page_mapping(page);
-	int ret = 0;
+	struct address_space *mapping = folio_mapping(folio);
+	bool ret = false;
 
-	VM_BUG_ON_PAGE(!PageLocked(page), page);
+	VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
 
 	if (mapping && mapping_can_writeback(mapping)) {
 		struct inode *inode = mapping->host;
@@ -2695,48 +2695,49 @@ int clear_page_dirty_for_io(struct page *page)
 		 * We use this sequence to make sure that
 		 *  (a) we account for dirty stats properly
 		 *  (b) we tell the low-level filesystem to
-		 *      mark the whole page dirty if it was
+		 *      mark the whole folio dirty if it was
 		 *      dirty in a pagetable. Only to then
-		 *  (c) clean the page again and return 1 to
+		 *  (c) clean the folio again and return 1 to
 		 *      cause the writeback.
 		 *
 		 * This way we avoid all nasty races with the
 		 * dirty bit in multiple places and clearing
 		 * them concurrently from different threads.
 		 *
-		 * Note! Normally the "set_page_dirty(page)"
+		 * Note! Normally the "folio_mark_dirty(folio)"
 		 * has no effect on the actual dirty bit - since
 		 * that will already usually be set. But we
 		 * need the side effects, and it can help us
 		 * avoid races.
 		 *
-		 * We basically use the page "master dirty bit"
+		 * We basically use the folio "master dirty bit"
 		 * as a serialization point for all the different
 		 * threads doing their things.
 		 */
-		if (page_mkclean(page))
-			set_page_dirty(page);
+		if (folio_mkclean(folio))
+			folio_mark_dirty(folio);
 		/*
 		 * We carefully synchronise fault handlers against
-		 * installing a dirty pte and marking the page dirty
+		 * installing a dirty pte and marking the folio dirty
 		 * at this point.  We do this by having them hold the
-		 * page lock while dirtying the page, and pages are
+		 * page lock while dirtying the folio, and folios are
 		 * always locked coming in here, so we get the desired
 		 * exclusion.
 		 */
 		wb = unlocked_inode_to_wb_begin(inode, &cookie);
-		if (TestClearPageDirty(page)) {
-			dec_lruvec_page_state(page, NR_FILE_DIRTY);
-			dec_zone_page_state(page, NR_ZONE_WRITE_PENDING);
-			dec_wb_stat(wb, WB_RECLAIMABLE);
-			ret = 1;
+		if (folio_test_clear_dirty(folio)) {
+			long nr = folio_nr_pages(folio);
+			lruvec_stat_mod_folio(folio, NR_FILE_DIRTY, -nr);
+			zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, -nr);
+			wb_stat_mod(wb, WB_RECLAIMABLE, -nr);
+			ret = true;
 		}
 		unlocked_inode_to_wb_end(inode, &cookie);
 		return ret;
 	}
-	return TestClearPageDirty(page);
+	return folio_test_clear_dirty(folio);
 }
-EXPORT_SYMBOL(clear_page_dirty_for_io);
+EXPORT_SYMBOL(folio_clear_dirty_for_io);
 
 bool __folio_end_writeback(struct folio *folio)
 {
-- 
2.30.2


  parent reply	other threads:[~2021-07-15 20:28 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-15 19:59 [PATCH v14c 00/39] Memory folios: Pagecache edition Matthew Wilcox (Oracle)
2021-07-15 19:59 ` [PATCH v14 01/39] mm: Add folio_pfn() Matthew Wilcox (Oracle)
2021-07-15 19:59 ` [PATCH v14 02/39] mm: Add folio_raw_mapping() Matthew Wilcox (Oracle)
2021-07-15 19:59 ` [PATCH v14 03/39] mm: Add flush_dcache_folio() Matthew Wilcox (Oracle)
2021-07-15 19:59 ` [PATCH v14 04/39] mm: Add kmap_local_folio() Matthew Wilcox (Oracle)
2021-07-15 19:59 ` [PATCH v14 05/39] mm: Add arch_make_folio_accessible() Matthew Wilcox (Oracle)
2021-07-15 19:59 ` [PATCH v14 06/39] mm: Add folio_young and folio_idle Matthew Wilcox (Oracle)
2021-07-15 19:59 ` [PATCH v14 07/39] mm/swap: Add folio_activate() Matthew Wilcox (Oracle)
2021-07-15 19:59 ` [PATCH v14 08/39] mm/swap: Add folio_mark_accessed() Matthew Wilcox (Oracle)
2023-10-08 15:34   ` Gregory Price
2023-10-10 18:08     ` Matthew Wilcox
2023-10-13 16:38       ` Gregory Price
2021-07-15 20:00 ` [PATCH v14 09/39] mm/rmap: Add folio_mkclean() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 10/39] mm/migrate: Add folio_migrate_mapping() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 11/39] mm/migrate: Add folio_migrate_flags() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 12/39] mm/migrate: Add folio_migrate_copy() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 13/39] mm/writeback: Rename __add_wb_stat() to wb_stat_mod() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 14/39] flex_proportions: Allow N events instead of 1 Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 15/39] mm/writeback: Change __wb_writeout_inc() to __wb_writeout_add() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 16/39] mm/writeback: Add __folio_end_writeback() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 17/39] mm/writeback: Add folio_start_writeback() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 18/39] mm/writeback: Add folio_mark_dirty() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 19/39] mm/writeback: Add __folio_mark_dirty() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 20/39] mm/writeback: Convert tracing writeback_page_template to folios Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 21/39] mm/writeback: Add filemap_dirty_folio() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 22/39] mm/writeback: Add folio_account_cleaned() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 23/39] mm/writeback: Add folio_cancel_dirty() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` Matthew Wilcox (Oracle) [this message]
2021-07-15 20:00 ` [PATCH v14 25/39] mm/writeback: Add folio_account_redirty() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 26/39] mm/writeback: Add folio_redirty_for_writepage() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 27/39] mm/filemap: Add i_blocks_per_folio() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 28/39] mm/filemap: Add folio_mkwrite_check_truncate() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 29/39] mm/filemap: Add readahead_folio() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 30/39] mm/workingset: Convert workingset_refault() to take a folio Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 31/39] mm: Add folio_evictable() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 32/39] mm/lru: Convert __pagevec_lru_add_fn to take a folio Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 33/39] mm/lru: Add folio_add_lru() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 34/39] mm/page_alloc: Add folio allocation functions Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 35/39] mm/filemap: Add filemap_alloc_folio Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 36/39] mm/filemap: Add filemap_add_folio() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 37/39] mm/filemap: Convert mapping_get_entry to return a folio Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 38/39] mm/filemap: Add filemap_get_folio Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 39/39] mm/filemap: Add FGP_STABLE Matthew Wilcox (Oracle)

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=20210715200030.899216-25-willy@infradead.org \
    --to=willy@infradead.org \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.