Skip to content

Commit 7fce207

Browse files
joannekoongMiklos Szeredi
authored andcommitted
mm/writeback: add folio_mark_dirty_lock()
Add a new convenience helper folio_mark_dirty_lock() that grabs the folio lock before calling folio_mark_dirty(). Refactor set_page_dirty_lock() to directly use folio_mark_dirty_lock(). Signed-off-by: Joanne Koong <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent cbe9c11 commit 7fce207

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

include/linux/mm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,6 +2539,7 @@ struct kvec;
25392539
struct page *get_dump_page(unsigned long addr);
25402540

25412541
bool folio_mark_dirty(struct folio *folio);
2542+
bool folio_mark_dirty_lock(struct folio *folio);
25422543
bool set_page_dirty(struct page *page);
25432544
int set_page_dirty_lock(struct page *page);
25442545

mm/folio-compat.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ bool set_page_dirty(struct page *page)
5252
}
5353
EXPORT_SYMBOL(set_page_dirty);
5454

55+
int set_page_dirty_lock(struct page *page)
56+
{
57+
return folio_mark_dirty_lock(page_folio(page));
58+
}
59+
EXPORT_SYMBOL(set_page_dirty_lock);
60+
5561
bool clear_page_dirty_for_io(struct page *page)
5662
{
5763
return folio_clear_dirty_for_io(page_folio(page));

mm/page-writeback.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2914,25 +2914,25 @@ bool folio_mark_dirty(struct folio *folio)
29142914
EXPORT_SYMBOL(folio_mark_dirty);
29152915

29162916
/*
2917-
* set_page_dirty() is racy if the caller has no reference against
2918-
* page->mapping->host, and if the page is unlocked. This is because another
2919-
* CPU could truncate the page off the mapping and then free the mapping.
2917+
* folio_mark_dirty() is racy if the caller has no reference against
2918+
* folio->mapping->host, and if the folio is unlocked. This is because another
2919+
* CPU could truncate the folio off the mapping and then free the mapping.
29202920
*
2921-
* Usually, the page _is_ locked, or the caller is a user-space process which
2921+
* Usually, the folio _is_ locked, or the caller is a user-space process which
29222922
* holds a reference on the inode by having an open file.
29232923
*
2924-
* In other cases, the page should be locked before running set_page_dirty().
2924+
* In other cases, the folio should be locked before running folio_mark_dirty().
29252925
*/
2926-
int set_page_dirty_lock(struct page *page)
2926+
bool folio_mark_dirty_lock(struct folio *folio)
29272927
{
2928-
int ret;
2928+
bool ret;
29292929

2930-
lock_page(page);
2931-
ret = set_page_dirty(page);
2932-
unlock_page(page);
2930+
folio_lock(folio);
2931+
ret = folio_mark_dirty(folio);
2932+
folio_unlock(folio);
29332933
return ret;
29342934
}
2935-
EXPORT_SYMBOL(set_page_dirty_lock);
2935+
EXPORT_SYMBOL(folio_mark_dirty_lock);
29362936

29372937
/*
29382938
* This cancels just the dirty bit on the kernel page itself, it does NOT

0 commit comments

Comments
 (0)