Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752158AbcDRE02 (ORCPT ); Mon, 18 Apr 2016 00:26:28 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:55477 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751879AbcDREZE (ORCPT ); Mon, 18 Apr 2016 00:25:04 -0400 From: Jens Axboe To: , , CC: , , Jens Axboe Subject: [PATCH 5/8] writeback: increment page wait count when waiting Date: Sun, 17 Apr 2016 23:24:44 -0500 Message-ID: <1460953487-3430-6-git-send-email-axboe@fb.com> X-Mailer: git-send-email 2.8.0.rc4.6.g7e4ba36 In-Reply-To: <1460953487-3430-1-git-send-email-axboe@fb.com> References: <1460953487-3430-1-git-send-email-axboe@fb.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [192.168.54.13] X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-04-18_04:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2364 Lines: 91 If we end up waiting on a page that is dirty or marked writeback, then increment the corresponding bdi_writeback counter. Signed-off-by: Jens Axboe --- mm/filemap.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index f2479af09da9..a8854a083b71 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -764,37 +764,73 @@ wait_queue_head_t *page_waitqueue(struct page *page) } EXPORT_SYMBOL(page_waitqueue); +static bool inc_dirty_wait(struct page *page) +{ + if (!page->mapping || !PageDirty(page) || !PageWriteback(page)) + return false; + else { + struct bdi_writeback *wb = inode_to_wb(page->mapping->host); + + atomic_inc(&wb->dirty_sleeping); + return true; + } +} + +static void dec_dirty_wait(struct page *page) +{ + struct bdi_writeback *wb = inode_to_wb(page->mapping->host); + + atomic_dec(&wb->dirty_sleeping); +} + void wait_on_page_bit(struct page *page, int bit_nr) { DEFINE_WAIT_BIT(wait, &page->flags, bit_nr); - if (test_bit(bit_nr, &page->flags)) + if (test_bit(bit_nr, &page->flags)) { + bool did_inc = inc_dirty_wait(page); __wait_on_bit(page_waitqueue(page), &wait, bit_wait_io, TASK_UNINTERRUPTIBLE); + if (did_inc) + dec_dirty_wait(page); + } } EXPORT_SYMBOL(wait_on_page_bit); int wait_on_page_bit_killable(struct page *page, int bit_nr) { DEFINE_WAIT_BIT(wait, &page->flags, bit_nr); + bool did_inc; + int ret; if (!test_bit(bit_nr, &page->flags)) return 0; - return __wait_on_bit(page_waitqueue(page), &wait, + did_inc = inc_dirty_wait(page); + ret = __wait_on_bit(page_waitqueue(page), &wait, bit_wait_io, TASK_KILLABLE); + if (did_inc) + dec_dirty_wait(page); + return ret; } int wait_on_page_bit_killable_timeout(struct page *page, int bit_nr, unsigned long timeout) { DEFINE_WAIT_BIT(wait, &page->flags, bit_nr); + bool did_inc; + int ret; wait.key.timeout = jiffies + timeout; if (!test_bit(bit_nr, &page->flags)) return 0; - return __wait_on_bit(page_waitqueue(page), &wait, + + did_inc = inc_dirty_wait(page); + ret = __wait_on_bit(page_waitqueue(page), &wait, bit_wait_io_timeout, TASK_KILLABLE); + if (did_inc) + dec_dirty_wait(page); + return ret; } EXPORT_SYMBOL_GPL(wait_on_page_bit_killable_timeout); -- 2.8.0.rc4.6.g7e4ba36