Skip to content

Commit 46d2277

Browse files
author
Linus Torvalds
committed
Clean up and make try_to_free_buffers() not race with dirty pages
This is preparatory work in our continuing saga on some hard-to-trigger file corruption with shared writable mmap() after the dirty page tracking changes (commit d08b385 etc) were merged. Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 9bfb183 commit 46d2277

File tree

1 file changed

+1
-17
lines changed

1 file changed

+1
-17
lines changed

fs/buffer.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,7 +2834,7 @@ int try_to_free_buffers(struct page *page)
28342834
int ret = 0;
28352835

28362836
BUG_ON(!PageLocked(page));
2837-
if (PageWriteback(page))
2837+
if (PageDirty(page) || PageWriteback(page))
28382838
return 0;
28392839

28402840
if (mapping == NULL) { /* can this still happen? */
@@ -2845,22 +2845,6 @@ int try_to_free_buffers(struct page *page)
28452845
spin_lock(&mapping->private_lock);
28462846
ret = drop_buffers(page, &buffers_to_free);
28472847
spin_unlock(&mapping->private_lock);
2848-
if (ret) {
2849-
/*
2850-
* If the filesystem writes its buffers by hand (eg ext3)
2851-
* then we can have clean buffers against a dirty page. We
2852-
* clean the page here; otherwise later reattachment of buffers
2853-
* could encounter a non-uptodate page, which is unresolvable.
2854-
* This only applies in the rare case where try_to_free_buffers
2855-
* succeeds but the page is not freed.
2856-
*
2857-
* Also, during truncate, discard_buffer will have marked all
2858-
* the page's buffers clean. We discover that here and clean
2859-
* the page also.
2860-
*/
2861-
if (test_clear_page_dirty(page))
2862-
task_io_account_cancelled_write(PAGE_CACHE_SIZE);
2863-
}
28642848
out:
28652849
if (buffers_to_free) {
28662850
struct buffer_head *bh = buffers_to_free;

0 commit comments

Comments
 (0)