From patchwork Mon Apr 18 04:24:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 8867821 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 81361BF440 for ; Mon, 18 Apr 2016 04:26:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9A63020138 for ; Mon, 18 Apr 2016 04:26:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AEF10201ED for ; Mon, 18 Apr 2016 04:26:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751278AbcDRE01 (ORCPT ); Mon, 18 Apr 2016 00:26:27 -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 Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.0.11/8.16.0.11) with SMTP id u3I4MTb8028690; Sun, 17 Apr 2016 21:25:00 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=cUmtWCuo/xqs5Pb0zw9hYGEKMahvsprmCp9yUvdyufA=; b=kgkuXUf/+23AuoKg5JglYIM74B+4ntGbMb3QLDAdv9niUpgY29GFbrnMhm+F/vZRswgN bAAlh3C5FbbwM2ZWqDo0NXi0ObT7Byl21uR6QxYE+m3xtXN0AHxC96qAQf4NehV7T4l0 4EuTPg/WmyNzSzaQOpuhLUzIhqiymTQta/0= Received: from mail.thefacebook.com ([199.201.64.23]) by m0089730.ppops.net with ESMTP id 22c24h2rgg-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Sun, 17 Apr 2016 21:25:00 -0700 Received: from localhost.localdomain (192.168.54.13) by mail.thefacebook.com (192.168.16.19) with Microsoft SMTP Server (TLS) id 14.3.248.2; Sun, 17 Apr 2016 21:24:58 -0700 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 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-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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);