提交 b5e84594 编写于 作者: M Matthew Wilcox (Oracle)

mm/writeback: Add folio_mark_dirty()

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: NMatthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: NChristoph Hellwig <hch@lst.de>
Reviewed-by: NDavid Howells <dhowells@redhat.com>
Acked-by: NVlastimil Babka <vbabka@suse.cz>
上级 f143f1ea
...@@ -2008,7 +2008,8 @@ int redirty_page_for_writepage(struct writeback_control *wbc, ...@@ -2008,7 +2008,8 @@ int redirty_page_for_writepage(struct writeback_control *wbc,
struct page *page); struct page *page);
void account_page_cleaned(struct page *page, struct address_space *mapping, void account_page_cleaned(struct page *page, struct address_space *mapping,
struct bdi_writeback *wb); 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); int set_page_dirty_lock(struct page *page);
void __cancel_dirty_page(struct page *page); void __cancel_dirty_page(struct page *page);
static inline void cancel_dirty_page(struct page *page) static inline void cancel_dirty_page(struct page *page)
......
...@@ -77,3 +77,9 @@ bool set_page_writeback(struct page *page) ...@@ -77,3 +77,9 @@ bool set_page_writeback(struct page *page)
return folio_start_writeback(page_folio(page)); return folio_start_writeback(page_folio(page));
} }
EXPORT_SYMBOL(set_page_writeback); EXPORT_SYMBOL(set_page_writeback);
bool set_page_dirty(struct page *page)
{
return folio_mark_dirty(page_folio(page));
}
EXPORT_SYMBOL(set_page_dirty);
...@@ -2581,18 +2581,21 @@ int redirty_page_for_writepage(struct writeback_control *wbc, struct page *page) ...@@ -2581,18 +2581,21 @@ int redirty_page_for_writepage(struct writeback_control *wbc, struct page *page)
} }
EXPORT_SYMBOL(redirty_page_for_writepage); 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 * Return: True if the folio was newly dirtied, false if it was already dirty.
* 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.
*/ */
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)) { if (likely(mapping)) {
/* /*
* readahead/lru_deactivate_page could remain * readahead/lru_deactivate_page could remain
...@@ -2604,17 +2607,17 @@ int set_page_dirty(struct page *page) ...@@ -2604,17 +2607,17 @@ int set_page_dirty(struct page *page)
* it will confuse readahead and make it restart the size rampup * it will confuse readahead and make it restart the size rampup
* process. But it's a trivial problem. * process. But it's a trivial problem.
*/ */
if (PageReclaim(page)) if (folio_test_reclaim(folio))
ClearPageReclaim(page); folio_clear_reclaim(folio);
return mapping->a_ops->set_page_dirty(page); return mapping->a_ops->set_page_dirty(&folio->page);
} }
if (!PageDirty(page)) { if (!folio_test_dirty(folio)) {
if (!TestSetPageDirty(page)) if (!folio_test_set_dirty(folio))
return 1; 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 * set_page_dirty() is racy if the caller has no reference against
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册