Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp5037431rdb; Fri, 15 Sep 2023 23:42:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHPmEpU9BNbjpo7qYPe15eAxj6QjGqG8gl9GFUFHfwxEm6ZGxsyKptH8SPsck7EX063w3yY X-Received: by 2002:a17:902:e5c8:b0:1c3:868f:5958 with SMTP id u8-20020a170902e5c800b001c3868f5958mr9359409plf.20.1694846570434; Fri, 15 Sep 2023 23:42:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694846570; cv=none; d=google.com; s=arc-20160816; b=wTt0tKvvCnWpUl7YrcXqizrZ4L08TgamSb4Kl0G3aZEuGXRp0f5kJ/WIZKOSTSgnZL reHI/IrVx19sx4/QFd3AM9t6iCs35hlEcDZB283pKAEisNAJxY+3k73XscGbEmFdv6YI ydBK0m7m5lJwVfvfP/0/sXkQNLEeOo+hDMBoooaMd6nEbu3qkP1t2DWrKBV7/yL9tTd7 dmRbKm1vM3OQPeiDaXN5a7oIsEHFiYYsrrACPTN95yA5fyc1PXzC1VxSoZmfgIrxrSij K/H5GgT0ncGxwZaaKh0CfDyub70OpQ2/RhemTENBqwpITQhuombISMNF7pcJ2FAXT7eO orPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=I/mcxM9CcPo8xWIB8wMPmyQcFOb+eL3EOkmPufsZvNw=; fh=Exu8p2J0bt/MoYkEByA/Woj5EWTdUoRsvJYmK88z1hY=; b=Gu3zwHsMoVPzm55TQCH5N3c6D2dFnhjFdywO6ghNhxkEEZkTwXUrl7RSK/FUww866t Qh7fhtc+gEqmQG96azPNynoFvWwIHK3z5uQUVfm5u8yyVcsEcDdy++LERjTSuCFTVfmr njJ7HcFSZbMhBBlIfv5G/N/yJQh15HxCV5xqH43bPfJ7Pp+4fkb3eX6A8GmTfcgLhyKX TvWyyrHInBQ7NTEqL+SOP6DwRf/PHte+F2f9gJz/GntPT+8wawO+YhooJKy0gmkU73dG 7ennssEgpkYXKrLX3Q5hM3iTsJsYSPUlomIR/PvUDw73mMYVFwk6WUzaVHSYK9kalyqm Rh5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=algmUIsk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id s8-20020a170902ea0800b001bc7a4b5c6dsi4645291plg.622.2023.09.15.23.42.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 23:42:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=algmUIsk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A81D2833E870; Fri, 15 Sep 2023 11:38:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236639AbjIOShz (ORCPT + 99 others); Fri, 15 Sep 2023 14:37:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236592AbjIOShY (ORCPT ); Fri, 15 Sep 2023 14:37:24 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1B701A8; Fri, 15 Sep 2023 11:37:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=I/mcxM9CcPo8xWIB8wMPmyQcFOb+eL3EOkmPufsZvNw=; b=algmUIskdAyoKr4qTO12fn4nRP fWLPKU3eyRF4p6Wl8lL1WBSLrQnHyYX2LVbQ31kpdJwdCDcjOUlPKUaKt5ioI+pkE+HwdXlzdg7zO lZ3FlU/oq2TQ7lGaqRCMeQg62X7pIhANT4NOvAuIfVm3/PmOzSbaTsPT2AXa39N2sxzwaecBCw6Gz Vlcid+5xzcrq03Ytu2JU2xoHSwAg5Zy6EcHen3aVwRFhMHGfhzM7GIyZQ69/80pCOjI9w/aW0QYIw oH6FkDmIYQ8sHKn/4STyq1ufRrC9MrZsk89jtRUNrePxRD43t9kJK1s8MAFRelCd8ti9WHeBfluuo DPIGfbzg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qhDgk-00BMJ4-Bx; Fri, 15 Sep 2023 18:37:10 +0000 From: "Matthew Wilcox (Oracle)" To: linux-kernel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, torvalds@linux-foundation.org, Nicholas Piggin Subject: [PATCH 16/17] mm: Make __end_folio_writeback() return void Date: Fri, 15 Sep 2023 19:37:06 +0100 Message-Id: <20230915183707.2707298-17-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230915183707.2707298-1-willy@infradead.org> References: <20230915183707.2707298-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 15 Sep 2023 11:38:21 -0700 (PDT) Rather than check the result of test-and-clear, just check that we have the writeback bit set at the start. This wouldn't catch every case, but it's good enough (and enables the next patch). Signed-off-by: Matthew Wilcox (Oracle) --- mm/filemap.c | 9 +++++++-- mm/internal.h | 2 +- mm/page-writeback.c | 38 ++++++++++++++++---------------------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 8262b85593be..53c0d71aae8e 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1595,9 +1595,15 @@ EXPORT_SYMBOL(folio_wait_private_2_killable); /** * folio_end_writeback - End writeback against a folio. * @folio: The folio. + * + * The folio must actually be under writeback. + * + * Context: May be called from process or interrupt context. */ void folio_end_writeback(struct folio *folio) { + VM_BUG_ON_FOLIO(!folio_test_writeback(folio), folio); + /* * folio_test_clear_reclaim() could be used here but it is an * atomic operation and overkill in this particular case. Failing @@ -1617,8 +1623,7 @@ void folio_end_writeback(struct folio *folio) * reused before the folio_wake(). */ folio_get(folio); - if (!__folio_end_writeback(folio)) - BUG(); + __folio_end_writeback(folio); smp_mb__after_atomic(); folio_wake(folio, PG_writeback); diff --git a/mm/internal.h b/mm/internal.h index 30cf724ddbce..ccb08dd9b5ec 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -105,7 +105,7 @@ static inline void wake_throttle_isolated(pg_data_t *pgdat) vm_fault_t do_swap_page(struct vm_fault *vmf); void folio_rotate_reclaimable(struct folio *folio); -bool __folio_end_writeback(struct folio *folio); +void __folio_end_writeback(struct folio *folio); void deactivate_file_folio(struct folio *folio); void folio_activate(struct folio *folio); diff --git a/mm/page-writeback.c b/mm/page-writeback.c index b8d3d7040a50..410b53e888e3 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2940,11 +2940,10 @@ static void wb_inode_writeback_end(struct bdi_writeback *wb) spin_unlock_irqrestore(&wb->work_lock, flags); } -bool __folio_end_writeback(struct folio *folio) +void __folio_end_writeback(struct folio *folio) { long nr = folio_nr_pages(folio); struct address_space *mapping = folio_mapping(folio); - bool ret; folio_memcg_lock(folio); if (mapping && mapping_use_writeback_tags(mapping)) { @@ -2953,19 +2952,16 @@ bool __folio_end_writeback(struct folio *folio) unsigned long flags; xa_lock_irqsave(&mapping->i_pages, flags); - ret = folio_test_clear_writeback(folio); - if (ret) { - __xa_clear_mark(&mapping->i_pages, folio_index(folio), - PAGECACHE_TAG_WRITEBACK); - if (bdi->capabilities & BDI_CAP_WRITEBACK_ACCT) { - struct bdi_writeback *wb = inode_to_wb(inode); - - wb_stat_mod(wb, WB_WRITEBACK, -nr); - __wb_writeout_add(wb, nr); - if (!mapping_tagged(mapping, - PAGECACHE_TAG_WRITEBACK)) - wb_inode_writeback_end(wb); - } + folio_test_clear_writeback(folio); + __xa_clear_mark(&mapping->i_pages, folio_index(folio), + PAGECACHE_TAG_WRITEBACK); + if (bdi->capabilities & BDI_CAP_WRITEBACK_ACCT) { + struct bdi_writeback *wb = inode_to_wb(inode); + + wb_stat_mod(wb, WB_WRITEBACK, -nr); + __wb_writeout_add(wb, nr); + if (!mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK)) + wb_inode_writeback_end(wb); } if (mapping->host && !mapping_tagged(mapping, @@ -2974,15 +2970,13 @@ bool __folio_end_writeback(struct folio *folio) xa_unlock_irqrestore(&mapping->i_pages, flags); } else { - ret = folio_test_clear_writeback(folio); - } - if (ret) { - lruvec_stat_mod_folio(folio, NR_WRITEBACK, -nr); - zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, -nr); - node_stat_mod_folio(folio, NR_WRITTEN, nr); + folio_test_clear_writeback(folio); } + + lruvec_stat_mod_folio(folio, NR_WRITEBACK, -nr); + zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, -nr); + node_stat_mod_folio(folio, NR_WRITTEN, nr); folio_memcg_unlock(folio); - return ret; } bool __folio_start_writeback(struct folio *folio, bool keep_write) -- 2.40.1