From patchwork Thu Apr 16 15:46:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 11493255 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A55381392 for ; Thu, 16 Apr 2020 15:46:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 65D5F22246 for ; Thu, 16 Apr 2020 15:46:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="txZtTD7m" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 65D5F22246 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7BF228E0001; Thu, 16 Apr 2020 11:46:09 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 75ED28E00BF; Thu, 16 Apr 2020 11:46:09 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4EC8F8E0001; Thu, 16 Apr 2020 11:46:09 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0054.hostedemail.com [216.40.44.54]) by kanga.kvack.org (Postfix) with ESMTP id 2B0DC8E00BC for ; Thu, 16 Apr 2020 11:46:09 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E2EC78245571 for ; Thu, 16 Apr 2020 15:46:08 +0000 (UTC) X-FDA: 76714144416.23.steam01_8cf2327bec462 X-Spam-Summary: 2,0,0,579d5d2c4d51563d,d41d8cd98f00b204,willy@infradead.org,,RULES_HIT:41:69:355:379:541:800:960:966:968:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1544:1711:1730:1747:1777:1792:2196:2199:2393:2553:2559:2562:2901:3138:3139:3140:3141:3142:3355:3865:3866:3867:3868:3871:3872:3874:4117:4385:4423:4605:5007:6261:6653:7576:8957:9040:9592:10004:10226:11026:11473:11658:11914:12043:12114:12291:12295:12296:12297:12438:12555:12683:12895:13161:13229:13868:13894:14096:14181:14394:14721:21080:21324:21450:21451:21627:21990:30012:30045:30054:30064:30090,0,RBL:198.137.202.133:@infradead.org:.lbl8.mailshell.net-64.201.201.201 62.8.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: steam01_8cf2327bec462 X-Filterd-Recvd-Size: 6530 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Thu, 16 Apr 2020 15:46:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=oWl7Bo+ZEaJmJs40/6QIbxDCr3XNJEbNu8oUFCyylaw=; b=txZtTD7m3BQq354s1srWGlcQkK 4xMPB74sf9g2nvHsBTgyUwTFBs6EMyBJvDZ0zLZ5LsOS5AfDjWburOtaBj1Qgm1+5QsqEZyS/GdG9 F+QwJowd05Cas9Ps2oKwAiHSgEec3KN5tAB/K+DLQtxOl2Hr0yRRCThZWQ6DX1AAozEkolsFwKnZc TTX+DYST6sUP6ck5g/5PVvKaUmXQIpdbpM1QXQXY76Y9gb32E4cjiWYNeUuGUSzdQZm2Txv4HE0Pn iPM0w/f6HIseGgLyHDlJ7qRC/4M89JSkciR7FJStRPdchyri12D6yRQ6U7pMj/JWqdRBzAr4NWeaG ixO4kXuA==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jP6iN-00006b-H2; Thu, 16 Apr 2020 15:46:07 +0000 From: Matthew Wilcox To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , William Kucharski Subject: [PATCH v2 4/5] mm: Use clear_bit_unlock_is_negative_byte for PageWriteback Date: Thu, 16 Apr 2020 08:46:05 -0700 Message-Id: <20200416154606.306-5-willy@infradead.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200416154606.306-1-willy@infradead.org> References: <20200416154606.306-1-willy@infradead.org> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: "Matthew Wilcox (Oracle)" We can use clear_bit_unlock_is_negative_byte() for writeback as well as the lock bit. wake_up_page() then has no more callers and can be removed. Given the other code being executed between the clear and the test, this is not going to be as dramatic a win as it was for PageLocked, but symmetry between the two is nice and lets us remove some code. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Jan Kara Reviewed-by: William Kucharski --- include/linux/page-flags.h | 2 +- mm/filemap.c | 12 ++---------- mm/page-writeback.c | 37 ++++++++++++++++++++----------------- 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index af7c0ff5f517..96c7d220c8cf 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -545,7 +545,7 @@ static __always_inline void SetPageUptodate(struct page *page) CLEARPAGEFLAG(Uptodate, uptodate, PF_NO_TAIL) -int test_clear_page_writeback(struct page *page); +bool __clear_page_writeback(struct page *page); int __test_set_page_writeback(struct page *page, bool keep_write); #define test_set_page_writeback(page) \ diff --git a/mm/filemap.c b/mm/filemap.c index 401b24d980ba..c704d333d3bf 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1084,13 +1084,6 @@ static void wake_up_page_bit(struct page *page, int bit_nr) spin_unlock_irqrestore(&q->lock, flags); } -static void wake_up_page(struct page *page, int bit) -{ - if (!PageWaiters(page)) - return; - wake_up_page_bit(page, bit); -} - /* * A choice of three behaviors for wait_on_page_bit_common(): */ @@ -1293,9 +1286,8 @@ void end_page_writeback(struct page *page) rotate_reclaimable_page(page); } - test_clear_page_writeback(page); - smp_mb__after_atomic(); - wake_up_page(page, PG_writeback); + if (__clear_page_writeback(page)) + wake_up_page_bit(page, PG_writeback); } EXPORT_SYMBOL(end_page_writeback); diff --git a/mm/page-writeback.c b/mm/page-writeback.c index ebaf0d8263a6..d019d86fc21f 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -595,7 +595,7 @@ static void wb_domain_writeout_inc(struct wb_domain *dom, /* * Increment @wb's writeout completion count and the global writeout - * completion count. Called from test_clear_page_writeback(). + * completion count. */ static inline void __wb_writeout_inc(struct bdi_writeback *wb) { @@ -2711,12 +2711,19 @@ int clear_page_dirty_for_io(struct page *page) } EXPORT_SYMBOL(clear_page_dirty_for_io); -int test_clear_page_writeback(struct page *page) +#define clear_writeback_bit(page) \ + clear_bit_unlock_is_negative_byte(PG_writeback, &page->flags) + +/* + * The return value is whether there are waiters pending, not whether + * the flag was set. + */ +bool __clear_page_writeback(struct page *page) { struct address_space *mapping = page_mapping(page); struct mem_cgroup *memcg; struct lruvec *lruvec; - int ret; + bool ret; if (WARN_ON(!PageWriteback(page))) { dump_page(page, "!writeback"); @@ -2731,16 +2738,14 @@ int test_clear_page_writeback(struct page *page) unsigned long flags; xa_lock_irqsave(&mapping->i_pages, flags); - ret = TestClearPageWriteback(page); - if (ret) { - __xa_clear_mark(&mapping->i_pages, page_index(page), + ret = clear_writeback_bit(page); + __xa_clear_mark(&mapping->i_pages, page_index(page), PAGECACHE_TAG_WRITEBACK); - if (bdi_cap_account_writeback(bdi)) { - struct bdi_writeback *wb = inode_to_wb(inode); + if (bdi_cap_account_writeback(bdi)) { + struct bdi_writeback *wb = inode_to_wb(inode); - dec_wb_stat(wb, WB_WRITEBACK); - __wb_writeout_inc(wb); - } + dec_wb_stat(wb, WB_WRITEBACK); + __wb_writeout_inc(wb); } if (mapping->host && !mapping_tagged(mapping, @@ -2749,7 +2754,7 @@ int test_clear_page_writeback(struct page *page) xa_unlock_irqrestore(&mapping->i_pages, flags); } else { - ret = TestClearPageWriteback(page); + ret = clear_writeback_bit(page); } /* * NOTE: Page might be free now! Writeback doesn't hold a page @@ -2757,11 +2762,9 @@ int test_clear_page_writeback(struct page *page) * the clearing of PG_writeback. The below can only access * page state that is static across allocation cycles. */ - if (ret) { - dec_lruvec_state(lruvec, NR_WRITEBACK); - dec_zone_page_state(page, NR_ZONE_WRITE_PENDING); - inc_node_page_state(page, NR_WRITTEN); - } + dec_lruvec_state(lruvec, NR_WRITEBACK); + dec_zone_page_state(page, NR_ZONE_WRITE_PENDING); + inc_node_page_state(page, NR_WRITTEN); __unlock_page_memcg(memcg); return ret; }