Skip to content

Commit af7afdc

Browse files
author
Matthew Wilcox (Oracle)
committed
nilfs: Convert nilfs_set_page_dirty() to nilfs_dirty_folio()
The comment about the page always being locked is wrong, so copy the locking protection from __set_page_dirty_buffers(). That means moving the call to nilfs_set_file_dirty() down the function so as to not acquire a new dependency between the mapping->private_lock and the ns_inode_lock. That might be a harmless dependency to add, but it's not necessary. Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Tested-by: Damien Le Moal <[email protected]> Acked-by: Damien Le Moal <[email protected]> Tested-by: Mike Marshall <[email protected]> # orangefs Tested-by: David Howells <[email protected]> # afs
1 parent 7e63df0 commit af7afdc

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

fs/nilfs2/inode.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -199,23 +199,22 @@ static int nilfs_writepage(struct page *page, struct writeback_control *wbc)
199199
return 0;
200200
}
201201

202-
static int nilfs_set_page_dirty(struct page *page)
202+
static bool nilfs_dirty_folio(struct address_space *mapping,
203+
struct folio *folio)
203204
{
204-
struct inode *inode = page->mapping->host;
205-
int ret = __set_page_dirty_nobuffers(page);
205+
struct inode *inode = mapping->host;
206+
struct buffer_head *head;
207+
unsigned int nr_dirty = 0;
208+
bool ret = filemap_dirty_folio(mapping, folio);
206209

207-
if (page_has_buffers(page)) {
208-
unsigned int nr_dirty = 0;
209-
struct buffer_head *bh, *head;
210+
/*
211+
* The page may not be locked, eg if called from try_to_unmap_one()
212+
*/
213+
spin_lock(&mapping->private_lock);
214+
head = folio_buffers(folio);
215+
if (head) {
216+
struct buffer_head *bh = head;
210217

211-
/*
212-
* This page is locked by callers, and no other thread
213-
* concurrently marks its buffers dirty since they are
214-
* only dirtied through routines in fs/buffer.c in
215-
* which call sites of mark_buffer_dirty are protected
216-
* by page lock.
217-
*/
218-
bh = head = page_buffers(page);
219218
do {
220219
/* Do not mark hole blocks dirty */
221220
if (buffer_dirty(bh) || !buffer_mapped(bh))
@@ -224,14 +223,13 @@ static int nilfs_set_page_dirty(struct page *page)
224223
set_buffer_dirty(bh);
225224
nr_dirty++;
226225
} while (bh = bh->b_this_page, bh != head);
227-
228-
if (nr_dirty)
229-
nilfs_set_file_dirty(inode, nr_dirty);
230226
} else if (ret) {
231-
unsigned int nr_dirty = 1 << (PAGE_SHIFT - inode->i_blkbits);
227+
nr_dirty = 1 << (folio_shift(folio) - inode->i_blkbits);
228+
}
229+
spin_unlock(&mapping->private_lock);
232230

231+
if (nr_dirty)
233232
nilfs_set_file_dirty(inode, nr_dirty);
234-
}
235233
return ret;
236234
}
237235

@@ -299,7 +297,7 @@ const struct address_space_operations nilfs_aops = {
299297
.writepage = nilfs_writepage,
300298
.readpage = nilfs_readpage,
301299
.writepages = nilfs_writepages,
302-
.set_page_dirty = nilfs_set_page_dirty,
300+
.dirty_folio = nilfs_dirty_folio,
303301
.readahead = nilfs_readahead,
304302
.write_begin = nilfs_write_begin,
305303
.write_end = nilfs_write_end,

0 commit comments

Comments
 (0)