From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753076AbbCWF2g (ORCPT ); Mon, 23 Mar 2015 01:28:36 -0400 Received: from mail-qg0-f44.google.com ([209.85.192.44]:34237 "EHLO mail-qg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752303AbbCWFZ6 (ORCPT ); Mon, 23 Mar 2015 01:25:58 -0400 From: Tejun Heo To: axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, jack@suse.cz, hch@infradead.org, hannes@cmpxchg.org, linux-fsdevel@vger.kernel.org, vgoyal@redhat.com, lizefan@huawei.com, cgroups@vger.kernel.org, linux-mm@kvack.org, mhocko@suse.cz, clm@fb.com, fengguang.wu@intel.com, david@fromorbit.com, gthelen@google.com, Tejun Heo Subject: [PATCH 4/8] truncate: swap the order of conditionals in cancel_dirty_page() Date: Mon, 23 Mar 2015 01:25:40 -0400 Message-Id: <1427088344-17542-5-git-send-email-tj@kernel.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1427088344-17542-1-git-send-email-tj@kernel.org> References: <1427088344-17542-1-git-send-email-tj@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org cancel_dirty_page() currently performs TestClearPageDirty() and then tests whether the mapping exists and has cap_account_dirty. This patch swaps the order so that it performs the mapping tests first. If the mapping tests fail, the dirty is cleared with ClearPageDirty(). The order or the conditionals is swapped but the end result is the same. This will help inode foreign cgroup wb switching. Signed-off-by: Tejun Heo Cc: Jens Axboe Cc: Jan Kara Cc: Wu Fengguang Cc: Greg Thelen --- mm/truncate.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mm/truncate.c b/mm/truncate.c index fe2d769..9d40cd4 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -108,13 +108,13 @@ void do_invalidatepage(struct page *page, unsigned int offset, */ void cancel_dirty_page(struct page *page, unsigned int account_size) { - struct mem_cgroup *memcg; + struct address_space *mapping = page->mapping; - memcg = mem_cgroup_begin_page_stat(page); - if (TestClearPageDirty(page)) { - struct address_space *mapping = page->mapping; + if (mapping && mapping_cap_account_dirty(mapping)) { + struct mem_cgroup *memcg; - if (mapping && mapping_cap_account_dirty(mapping)) { + memcg = mem_cgroup_begin_page_stat(page); + if (TestClearPageDirty(page)) { struct bdi_writeback *wb = inode_to_wb(mapping->host); mem_cgroup_dec_page_stat(memcg, MEM_CGROUP_STAT_DIRTY); @@ -123,8 +123,10 @@ void cancel_dirty_page(struct page *page, unsigned int account_size) if (account_size) task_io_account_cancelled_write(account_size); } + mem_cgroup_end_page_stat(memcg); + } else { + ClearPageDirty(page); } - mem_cgroup_end_page_stat(memcg); } EXPORT_SYMBOL(cancel_dirty_page); -- 2.1.0 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tejun Heo Subject: [PATCH 4/8] truncate: swap the order of conditionals in cancel_dirty_page() Date: Mon, 23 Mar 2015 01:25:40 -0400 Message-ID: <1427088344-17542-5-git-send-email-tj@kernel.org> References: <1427088344-17542-1-git-send-email-tj@kernel.org> Cc: linux-kernel@vger.kernel.org, jack@suse.cz, hch@infradead.org, hannes@cmpxchg.org, linux-fsdevel@vger.kernel.org, vgoyal@redhat.com, lizefan@huawei.com, cgroups@vger.kernel.org, linux-mm@kvack.org, mhocko@suse.cz, clm@fb.com, fengguang.wu@intel.com, david@fromorbit.com, gthelen@google.com, Tejun Heo To: axboe@kernel.dk Return-path: In-Reply-To: <1427088344-17542-1-git-send-email-tj@kernel.org> Sender: owner-linux-mm@kvack.org List-Id: linux-fsdevel.vger.kernel.org cancel_dirty_page() currently performs TestClearPageDirty() and then tests whether the mapping exists and has cap_account_dirty. This patch swaps the order so that it performs the mapping tests first. If the mapping tests fail, the dirty is cleared with ClearPageDirty(). The order or the conditionals is swapped but the end result is the same. This will help inode foreign cgroup wb switching. Signed-off-by: Tejun Heo Cc: Jens Axboe Cc: Jan Kara Cc: Wu Fengguang Cc: Greg Thelen --- mm/truncate.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mm/truncate.c b/mm/truncate.c index fe2d769..9d40cd4 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -108,13 +108,13 @@ void do_invalidatepage(struct page *page, unsigned int offset, */ void cancel_dirty_page(struct page *page, unsigned int account_size) { - struct mem_cgroup *memcg; + struct address_space *mapping = page->mapping; - memcg = mem_cgroup_begin_page_stat(page); - if (TestClearPageDirty(page)) { - struct address_space *mapping = page->mapping; + if (mapping && mapping_cap_account_dirty(mapping)) { + struct mem_cgroup *memcg; - if (mapping && mapping_cap_account_dirty(mapping)) { + memcg = mem_cgroup_begin_page_stat(page); + if (TestClearPageDirty(page)) { struct bdi_writeback *wb = inode_to_wb(mapping->host); mem_cgroup_dec_page_stat(memcg, MEM_CGROUP_STAT_DIRTY); @@ -123,8 +123,10 @@ void cancel_dirty_page(struct page *page, unsigned int account_size) if (account_size) task_io_account_cancelled_write(account_size); } + mem_cgroup_end_page_stat(memcg); + } else { + ClearPageDirty(page); } - mem_cgroup_end_page_stat(memcg); } EXPORT_SYMBOL(cancel_dirty_page); -- 2.1.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org