Skip to content

Commit ecdfc97

Browse files
author
Linus Torvalds
committed
Resurrect 'try_to_free_buffers()' VM hackery
It's not pretty, but it appears that ext3 with data=journal will clean pages without ever actually telling the VM that they are clean. This, in turn, will result in the VM (and balance_dirty_pages() in particular) to never realize that the pages got cleaned, and wait forever for an event that already happened. Technically, this seems to be a problem with ext3 itself, but it used to be hidden by 'try_to_free_buffers()' noticing this situation on its own, and just working around the filesystem problem. This commit re-instates that hack, in order to avoid a regression for the 2.6.20 release. This fixes bugzilla 7844: http://bugzilla.kernel.org/show_bug.cgi?id=7844 Peter Zijlstra points out that we should probably retain the debugging code that this removes from cancel_dirty_page(), and I agree, but for the imminent release we might as well just silence the warning too (since it's not a new bug: anything that triggers that warning has been around forever). Acked-by: Randy Dunlap <rdunlap@xenotime.net> Acked-by: Jens Axboe <jens.axboe@oracle.com> Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 5ad0d38 commit ecdfc97

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

fs/buffer.c

Lines changed: 14 additions & 1 deletion
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 (PageDirty(page) || PageWriteback(page))
2837+
if (PageWriteback(page))
28382838
return 0;
28392839

28402840
if (mapping == NULL) { /* can this still happen? */
@@ -2845,6 +2845,19 @@ 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+
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 the VM will never notice
2853+
* that the filesystem did any IO at all.
2854+
*
2855+
* Also, during truncate, discard_buffer will have marked all
2856+
* the page's buffers clean. We discover that here and clean
2857+
* the page also.
2858+
*/
2859+
if (ret)
2860+
cancel_dirty_page(page, PAGE_CACHE_SIZE);
28482861
out:
28492862
if (buffers_to_free) {
28502863
struct buffer_head *bh = buffers_to_free;

mm/truncate.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,22 @@ static inline void truncate_partial_page(struct page *page, unsigned partial)
5151
do_invalidatepage(page, partial);
5252
}
5353

54+
/*
55+
* This cancels just the dirty bit on the kernel page itself, it
56+
* does NOT actually remove dirty bits on any mmap's that may be
57+
* around. It also leaves the page tagged dirty, so any sync
58+
* activity will still find it on the dirty lists, and in particular,
59+
* clear_page_dirty_for_io() will still look at the dirty bits in
60+
* the VM.
61+
*
62+
* Doing this should *normally* only ever be done when a page
63+
* is truncated, and is not actually mapped anywhere at all. However,
64+
* fs/buffer.c does this when it notices that somebody has cleaned
65+
* out all the buffers on a page without actually doing it through
66+
* the VM. Can you say "ext3 is horribly ugly"? Tought you could.
67+
*/
5468
void cancel_dirty_page(struct page *page, unsigned int account_size)
5569
{
56-
/* If we're cancelling the page, it had better not be mapped any more */
57-
if (page_mapped(page)) {
58-
static unsigned int warncount;
59-
60-
WARN_ON(++warncount < 5);
61-
}
62-
6370
if (TestClearPageDirty(page)) {
6471
struct address_space *mapping = page->mapping;
6572
if (mapping && mapping_cap_account_dirty(mapping)) {

0 commit comments

Comments
 (0)