mm/writeback: Add folio_mark_dirty()
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Tue, 27 Apr 2021 03:53:10 +0000 (23:53 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Mon, 18 Oct 2021 11:49:39 +0000 (07:49 -0400)
Reimplement set_page_dirty() as a wrapper around folio_mark_dirty().
There is no change to filesystems as they were already being called
with the compound_head of the page being marked dirty.  We avoid
several calls to compound_head(), both statically (through
using folio_test_dirty() instead of PageDirty() and dynamically by
calling folio_mapping() instead of page_mapping().

Also return bool instead of int to show the range of values actually
returned, and add kernel-doc.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: David Howells <dhowells@redhat.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
include/linux/mm.h
mm/folio-compat.c
mm/page-writeback.c

index 93d5fbe2e4e3c179ab5f5e67ab4056102346d156..00510b02ffe1ea77df9ec2475c75f30228fa975d 100644 (file)
@@ -2008,7 +2008,8 @@ int redirty_page_for_writepage(struct writeback_control *wbc,
                                struct page *page);
 void account_page_cleaned(struct page *page, struct address_space *mapping,
                          struct bdi_writeback *wb);
-int set_page_dirty(struct page *page);
+bool folio_mark_dirty(struct folio *folio);
+bool set_page_dirty(struct page *page);
 int set_page_dirty_lock(struct page *page);
 void __cancel_dirty_page(struct page *page);
 static inline void cancel_dirty_page(struct page *page)
index 10ce5582d86987a266fb300d8000dfbc994fad4b..2c2b3917b5dc95b83cec2415b1dbd8287d5bc1cc 100644 (file)
@@ -77,3 +77,9 @@ bool set_page_writeback(struct page *page)
        return folio_start_writeback(page_folio(page));
 }
 EXPORT_SYMBOL(set_page_writeback);
+
+bool set_page_dirty(struct page *page)
+{
+       return folio_mark_dirty(page_folio(page));
+}
+EXPORT_SYMBOL(set_page_dirty);
index 82938b0371030fbc4d7666cb47373fe8acdb2402..c79801656f5b2c26311b0691dd715148d60f89cf 100644 (file)
@@ -2581,18 +2581,21 @@ int redirty_page_for_writepage(struct writeback_control *wbc, struct page *page)
 }
 EXPORT_SYMBOL(redirty_page_for_writepage);
 
-/*
- * Dirty a page.
+/**
+ * folio_mark_dirty - Mark a folio as being modified.
+ * @folio: The folio.
+ *
+ * For folios with a mapping this should be done under the page lock
+ * for the benefit of asynchronous memory errors who prefer a consistent
+ * dirty state. This rule can be broken in some special cases,
+ * but should be better not to.
  *
- * For pages with a mapping this should be done under the page lock for the
- * benefit of asynchronous memory errors who prefer a consistent dirty state.
- * This rule can be broken in some special cases, but should be better not to.
+ * Return: True if the folio was newly dirtied, false if it was already dirty.
  */
-int set_page_dirty(struct page *page)
+bool folio_mark_dirty(struct folio *folio)
 {
-       struct address_space *mapping = page_mapping(page);
+       struct address_space *mapping = folio_mapping(folio);
 
-       page = compound_head(page);
        if (likely(mapping)) {
                /*
                 * readahead/lru_deactivate_page could remain
@@ -2604,17 +2607,17 @@ int set_page_dirty(struct page *page)
                 * it will confuse readahead and make it restart the size rampup
                 * process. But it's a trivial problem.
                 */
-               if (PageReclaim(page))
-                       ClearPageReclaim(page);
-               return mapping->a_ops->set_page_dirty(page);
+               if (folio_test_reclaim(folio))
+                       folio_clear_reclaim(folio);
+               return mapping->a_ops->set_page_dirty(&folio->page);
        }
-       if (!PageDirty(page)) {
-               if (!TestSetPageDirty(page))
-                       return 1;
+       if (!folio_test_dirty(folio)) {
+               if (!folio_test_set_dirty(folio))
+                       return true;
        }
-       return 0;
+       return false;
 }
-EXPORT_SYMBOL(set_page_dirty);
+EXPORT_SYMBOL(folio_mark_dirty);
 
 /*
  * set_page_dirty() is racy if the caller has no reference against