From 525f84b69939ae799bcb9369a7d1822b7e830d21 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 29 Dec 2006 10:00:58 -0800 Subject: [PATCH] --- yaml --- r: 45019 b: refs/heads/master c: 7658cc289288b8ae7dd2c2224549a048431222b3 h: refs/heads/master i: 45017: 846c46b8436e3e578defe234a1b149a1ea43c612 45015: 7e279e19414ab05c9cd734b69d6976aa6571d7c2 v: v3 --- [refs] | 2 +- trunk/mm/page-writeback.c | 45 ++++++++++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/[refs] b/[refs] index 9c6b249f3108..b388af14ce29 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 3bf8ba38f38d3647368e4edcf7d019f9f8d9184a +refs/heads/master: 7658cc289288b8ae7dd2c2224549a048431222b3 diff --git a/trunk/mm/page-writeback.c b/trunk/mm/page-writeback.c index b3a198c9248d..1d2fc89ca56d 100644 --- a/trunk/mm/page-writeback.c +++ b/trunk/mm/page-writeback.c @@ -862,17 +862,46 @@ int clear_page_dirty_for_io(struct page *page) { struct address_space *mapping = page_mapping(page); - if (!mapping) - return TestClearPageDirty(page); - - if (TestClearPageDirty(page)) { - if (mapping_cap_account_dirty(mapping)) { - page_mkclean(page); + if (mapping && mapping_cap_account_dirty(mapping)) { + /* + * Yes, Virginia, this is indeed insane. + * + * We use this sequence to make sure that + * (a) we account for dirty stats properly + * (b) we tell the low-level filesystem to + * mark the whole page dirty if it was + * dirty in a pagetable. Only to then + * (c) clean the page again and return 1 to + * cause the writeback. + * + * This way we avoid all nasty races with the + * dirty bit in multiple places and clearing + * them concurrently from different threads. + * + * Note! Normally the "set_page_dirty(page)" + * has no effect on the actual dirty bit - since + * that will already usually be set. But we + * need the side effects, and it can help us + * avoid races. + * + * We basically use the page "master dirty bit" + * as a serialization point for all the different + * threads doing their things. + * + * FIXME! We still have a race here: if somebody + * adds the page back to the page tables in + * between the "page_mkclean()" and the "TestClearPageDirty()", + * we might have it mapped without the dirty bit set. + */ + if (page_mkclean(page)) + set_page_dirty(page); + if (TestClearPageDirty(page)) { dec_zone_page_state(page, NR_FILE_DIRTY); + return 1; } - return 1; + return 0; } - return 0; + return TestClearPageDirty(page); } EXPORT_SYMBOL(clear_page_dirty_for_io);