From: Jerome Marchand <jmarchan@redhat.com> Date: Tue, 3 Mar 2009 17:27:27 +0100 Subject: [misc] IO accounting: write cancel accounting Message-id: 20090303162957.826242871@dhcp-0-152.brq.redhat.com O-Subject: [RHEL5.4 Patch 05/12] IO accounting: write cancel accounting Bugzilla: 461636 RH-Acked-by: Jiri Pirko <jpirko@redhat.com> bz461636 Account for the number of byte writes which this process caused to not happen after all. Patch is upstream: commit e08748ce01e02f0ec154b141f392ccb9555333f4 diff --git a/fs/buffer.c b/fs/buffer.c index 80c238d..fa218ec 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -3293,8 +3293,13 @@ int try_to_free_buffers(struct page *page) * could encounter a non-uptodate page, which is unresolvable. * This only applies in the rare case where try_to_free_buffers * succeeds but the page is not freed. + * + * Also, during truncate, discard_buffer will have marked all + * the page's buffers clean. We discover that here and clean + * the page also. */ - clear_page_dirty(page); + if (test_clear_page_dirty(page)) + task_io_account_cancelled_write(PAGE_CACHE_SIZE); } out: if (buffers_to_free) { diff --git a/mm/truncate.c b/mm/truncate.c index 7728e45..69394aa 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -12,6 +12,7 @@ #include <linux/module.h> #include <linux/pagemap.h> #include <linux/pagevec.h> +#include <linux/task_io_accounting_ops.h> #include <linux/buffer_head.h> /* grr. try_to_release_page, do_invalidatepage */ @@ -42,7 +43,8 @@ truncate_complete_page(struct address_space *mapping, struct page *page) if (PagePrivate(page)) do_invalidatepage(page, 0); - clear_page_dirty(page); + if (test_clear_page_dirty(page)) + task_io_account_cancelled_write(PAGE_CACHE_SIZE); ClearPageUptodate(page); ClearPageMappedToDisk(page); remove_from_page_cache(page);