Skip to content

Commit 68189fe

Browse files
author
Matthew Wilcox (Oracle)
committed
fs: Change try_to_free_buffers() to take a folio
All but two of the callers already have a folio; pass a folio into try_to_free_buffers(). This removes the last user of cancel_dirty_page() so remove that wrapper function too. Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Reviewed-by: Jeff Layton <[email protected]>
1 parent 7312225 commit 68189fe

File tree

16 files changed

+37
-41
lines changed

16 files changed

+37
-41
lines changed

fs/buffer.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ grow_dev_page(struct block_device *bdev, sector_t block,
955955
size);
956956
goto done;
957957
}
958-
if (!try_to_free_buffers(page))
958+
if (!try_to_free_buffers(page_folio(page)))
959959
goto failed;
960960
}
961961

@@ -3155,20 +3155,20 @@ int sync_dirty_buffer(struct buffer_head *bh)
31553155
EXPORT_SYMBOL(sync_dirty_buffer);
31563156

31573157
/*
3158-
* try_to_free_buffers() checks if all the buffers on this particular page
3158+
* try_to_free_buffers() checks if all the buffers on this particular folio
31593159
* are unused, and releases them if so.
31603160
*
31613161
* Exclusion against try_to_free_buffers may be obtained by either
3162-
* locking the page or by holding its mapping's private_lock.
3162+
* locking the folio or by holding its mapping's private_lock.
31633163
*
3164-
* If the page is dirty but all the buffers are clean then we need to
3165-
* be sure to mark the page clean as well. This is because the page
3164+
* If the folio is dirty but all the buffers are clean then we need to
3165+
* be sure to mark the folio clean as well. This is because the folio
31663166
* may be against a block device, and a later reattachment of buffers
3167-
* to a dirty page will set *all* buffers dirty. Which would corrupt
3167+
* to a dirty folio will set *all* buffers dirty. Which would corrupt
31683168
* filesystem data on the same device.
31693169
*
3170-
* The same applies to regular filesystem pages: if all the buffers are
3171-
* clean then we set the page clean and proceed. To do that, we require
3170+
* The same applies to regular filesystem folios: if all the buffers are
3171+
* clean then we set the folio clean and proceed. To do that, we require
31723172
* total exclusion from block_dirty_folio(). That is obtained with
31733173
* private_lock.
31743174
*
@@ -3207,40 +3207,40 @@ drop_buffers(struct page *page, struct buffer_head **buffers_to_free)
32073207
return 0;
32083208
}
32093209

3210-
int try_to_free_buffers(struct page *page)
3210+
bool try_to_free_buffers(struct folio *folio)
32113211
{
3212-
struct address_space * const mapping = page->mapping;
3212+
struct address_space * const mapping = folio->mapping;
32133213
struct buffer_head *buffers_to_free = NULL;
3214-
int ret = 0;
3214+
bool ret = 0;
32153215

3216-
BUG_ON(!PageLocked(page));
3217-
if (PageWriteback(page))
3218-
return 0;
3216+
BUG_ON(!folio_test_locked(folio));
3217+
if (folio_test_writeback(folio))
3218+
return false;
32193219

32203220
if (mapping == NULL) { /* can this still happen? */
3221-
ret = drop_buffers(page, &buffers_to_free);
3221+
ret = drop_buffers(&folio->page, &buffers_to_free);
32223222
goto out;
32233223
}
32243224

32253225
spin_lock(&mapping->private_lock);
3226-
ret = drop_buffers(page, &buffers_to_free);
3226+
ret = drop_buffers(&folio->page, &buffers_to_free);
32273227

32283228
/*
32293229
* If the filesystem writes its buffers by hand (eg ext3)
3230-
* then we can have clean buffers against a dirty page. We
3231-
* clean the page here; otherwise the VM will never notice
3230+
* then we can have clean buffers against a dirty folio. We
3231+
* clean the folio here; otherwise the VM will never notice
32323232
* that the filesystem did any IO at all.
32333233
*
32343234
* Also, during truncate, discard_buffer will have marked all
3235-
* the page's buffers clean. We discover that here and clean
3236-
* the page also.
3235+
* the folio's buffers clean. We discover that here and clean
3236+
* the folio also.
32373237
*
32383238
* private_lock must be held over this entire operation in order
32393239
* to synchronise against block_dirty_folio and prevent the
32403240
* dirty bit from being lost.
32413241
*/
32423242
if (ret)
3243-
cancel_dirty_page(page);
3243+
folio_cancel_dirty(folio);
32443244
spin_unlock(&mapping->private_lock);
32453245
out:
32463246
if (buffers_to_free) {

fs/ext4/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3255,7 +3255,7 @@ static bool ext4_release_folio(struct folio *folio, gfp_t wait)
32553255
if (journal)
32563256
return jbd2_journal_try_to_free_buffers(journal, folio);
32573257
else
3258-
return try_to_free_buffers(&folio->page);
3258+
return try_to_free_buffers(folio);
32593259
}
32603260

32613261
static bool ext4_inode_datasync_dirty(struct inode *inode)

fs/gfs2/aops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ bool gfs2_release_folio(struct folio *folio, gfp_t gfp_mask)
757757
} while (bh != head);
758758
gfs2_log_unlock(sdp);
759759

760-
return try_to_free_buffers(&folio->page);
760+
return try_to_free_buffers(folio);
761761

762762
cannot_release:
763763
gfs2_log_unlock(sdp);

fs/hfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static bool hfs_release_folio(struct folio *folio, gfp_t mask)
124124
} while (--i && nidx < tree->node_count);
125125
spin_unlock(&tree->hash_lock);
126126
}
127-
return res ? try_to_free_buffers(&folio->page) : false;
127+
return res ? try_to_free_buffers(folio) : false;
128128
}
129129

130130
static ssize_t hfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)

fs/hfsplus/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static bool hfsplus_release_folio(struct folio *folio, gfp_t mask)
121121
} while (--i && nidx < tree->node_count);
122122
spin_unlock(&tree->hash_lock);
123123
}
124-
return res ? try_to_free_buffers(&folio->page) : false;
124+
return res ? try_to_free_buffers(folio) : false;
125125
}
126126

127127
static ssize_t hfsplus_direct_IO(struct kiocb *iocb, struct iov_iter *iter)

fs/jbd2/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static void release_buffer_page(struct buffer_head *bh)
8282

8383
folio_get(folio);
8484
__brelse(bh);
85-
try_to_free_buffers(&folio->page);
85+
try_to_free_buffers(folio);
8686
folio_unlock(folio);
8787
folio_put(folio);
8888
return;

fs/jbd2/transaction.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,7 +2175,7 @@ bool jbd2_journal_try_to_free_buffers(journal_t *journal, struct folio *folio)
21752175
goto busy;
21762176
} while ((bh = bh->b_this_page) != head);
21772177

2178-
ret = try_to_free_buffers(&folio->page);
2178+
ret = try_to_free_buffers(folio);
21792179
busy:
21802180
return ret;
21812181
}
@@ -2482,7 +2482,7 @@ int jbd2_journal_invalidate_folio(journal_t *journal, struct folio *folio,
24822482
} while (bh != head);
24832483

24842484
if (!partial_page) {
2485-
if (may_free && try_to_free_buffers(&folio->page))
2485+
if (may_free && try_to_free_buffers(folio))
24862486
J_ASSERT(!folio_buffers(folio));
24872487
}
24882488
return 0;

fs/mpage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ static void clean_buffers(struct page *page, unsigned first_unmapped)
431431
* disk before we reach the platter.
432432
*/
433433
if (buffer_heads_over_limit && PageUptodate(page))
434-
try_to_free_buffers(page);
434+
try_to_free_buffers(page_folio(page));
435435
}
436436

437437
/*

fs/ocfs2/aops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ static bool ocfs2_release_folio(struct folio *folio, gfp_t wait)
502502
{
503503
if (!folio_buffers(folio))
504504
return false;
505-
return try_to_free_buffers(&folio->page);
505+
return try_to_free_buffers(folio);
506506
}
507507

508508
static void ocfs2_figure_cluster_boundaries(struct ocfs2_super *osb,

fs/reiserfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3234,7 +3234,7 @@ static bool reiserfs_release_folio(struct folio *folio, gfp_t unused_gfp_flags)
32343234
bh = bh->b_this_page;
32353235
} while (bh != head);
32363236
if (ret)
3237-
ret = try_to_free_buffers(&folio->page);
3237+
ret = try_to_free_buffers(folio);
32383238
spin_unlock(&j->j_dirty_buffers_lock);
32393239
return ret;
32403240
}

0 commit comments

Comments
 (0)