From patchwork Wed Oct 4 16:53:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13409076 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7BEDE7C4E6 for ; Wed, 4 Oct 2023 16:53:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B4B66B028A; Wed, 4 Oct 2023 12:53:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 765E76B028C; Wed, 4 Oct 2023 12:53:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 604E46B028D; Wed, 4 Oct 2023 12:53:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 46A786B028A for ; Wed, 4 Oct 2023 12:53:35 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1D60E1A03A4 for ; Wed, 4 Oct 2023 16:53:35 +0000 (UTC) X-FDA: 81308375190.16.CA6A26B Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf25.hostedemail.com (Postfix) with ESMTP id 74AB4A001A for ; Wed, 4 Oct 2023 16:53:33 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=XKrwcSOW; dmarc=none; spf=none (imf25.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696438413; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=KV8LjVnp8SrGIYzPBzTmbRSPvfzlFJYoh9EV/UdX1VU=; b=AEAcQl80KmccFdw/Ox264+cRH/j7I+j1bIy3uooZBu2hT9dSoXQOm2zXf+GY8LuoWIVyH4 muYDjdoLcC483aNYxa2suxVnQjS+pjjvP3yW7MPn68J7NMVg6P4+0prHz1kKxiibyngvxc fLuygOil0xIfJXasJLFUxvS1j0EaCG4= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=XKrwcSOW; dmarc=none; spf=none (imf25.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696438413; a=rsa-sha256; cv=none; b=NDqXQgq/T+aXlbYxvW4ngOCxRFRpeU7vGX/p11I5FUGs3iuVRIHcD1EXeAeUDT+Bh/ot8o /ox22C3wPPP5baPAiMTZQ5MK4KS+7kHXwg4ekVG0QsDezsQflHFKPGRvfmYRpTL1/ztQJ6 4oXQLTRrPfAWvSHGGcof/OclxsfwbpM= 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=KV8LjVnp8SrGIYzPBzTmbRSPvfzlFJYoh9EV/UdX1VU=; b=XKrwcSOWaQs6f+lvNnjqWsQNeA tgWGSVcwUcSUK+ppxTN6wCxuM6QU4zpdWpMiV6KVrIp0r98Vydm6CI9x3+M231XCLbvBHeUsTq1Ls +eZkvGGQwfurJSHA3nMDjyfvsg3VWB1w7Wx3V3DziFeKyn/pTJoHxUMnw/Y0g1ZbGCod0NlutrX1u figIDtFZopRavwvsxs9+1eC5eeKlB+YwkNGYdG+6yHXeWhuaeNGxlKiTUBIQrV/JCqNxwxPBkUPJ4 ygOewt9UVPVSMnaPp9qvSI+NvRcESnTW6dPLxrxNb6Il9rZ36q3vUjsCZiCcnR1NwTo+eprsm+LCY ab+q/3Xg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qo57f-004SEt-6o; Wed, 04 Oct 2023 16:53:19 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, torvalds@linux-foundation.org, npiggin@gmail.com Subject: [PATCH v2 01/17] iomap: Hold state_lock over call to ifs_set_range_uptodate() Date: Wed, 4 Oct 2023 17:53:01 +0100 Message-Id: <20231004165317.1061855-2-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20231004165317.1061855-1-willy@infradead.org> References: <20231004165317.1061855-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 74AB4A001A X-Stat-Signature: 7eymgbaeqkztj5hoyjz1krgtcqudi6gk X-HE-Tag: 1696438413-805769 X-HE-Meta: U2FsdGVkX180lA1diPHrkyzibudTVi4wj7jbtZUhTNIqGqxdDVxd7TC+GtVA/g2CLgNShGPFH29aWQQ09Pi9Y4TsvtnKOL0CU4C3AqAOsSbfAXLYOtSp9gdlFV7ePOg4S83FriDM9RcsMgiZXJNErOxt2HhDEZP3+rJzxHltwtcZV6p4Uy6W5bXKSJE4OvMV1/ZbyXkhqAUKZYkAKwGtv3MlWAq6JY+4L7xuZjweehp7GqGi+4U4AfAhmiiIsUX98YXGrCEMuyNF+WpSqSAPuOwqcgFTEotDwKSVqo0sVOAVsv2rzWg3zd6RaihzMeosPII58mQ2MGZeKXElfd70KEs5D/CjZ2QmOsaQ8mcmGVOJOzSSmvyriW/ZeIDhl7E16uoaitaTFyDxBHJdKPIUu1X54RS1LLERK0LQncwezh5S7p6uH5GNFXjAGKPnqY8foZFNLAbAfNmoJeB53FC03fplz057Edp6On06RnW2ExP0K0DxWaSZqijvL8eCD+LvTQiDJH1Ewhkp9Id0E8tgNVKhsv/w3ipk7cdraLQuUhTqfxGMFQTt6zCxJKhw5fmV19m+8415UM9yPBFYbSwbnMaVTaDb+yZ77JHkjvVPyB+zn40k+ClP+0XPHOraLKMVZwvijbgf5rOMpkbjB4rvHJeDCRdudRER9/oqljCY1kF8dGxtmrC4pGaQlRRWyDAe/JDVe4Dmq0I72JLR4wulP2f/fzXoFMMGwjS2EfZui7ABkqjmIKNrCC83GVT8Jsba6Ag0ATyJFiQ0PJ9YsiVITrOknJWMWy7tyD4OwDK2dgI7b2yRmVYGQYnbMoELMrS7VtUTm8ETGniIsW1qI17BE4EMuSGGB32AeISQPKv2OHawxJ9hLFwzwzyhD1WJ8ZhrmDLaVfJHk0aBCSMhK8vtJUXksc28QGpZDFgK/ECAC/skzneeygYUFBOCfmVYErMSsW8D1O+5//5QYYKXZoh xgrVYLlD lJPl6e4ajxkDgt/R7KNmV2xzTs6mTAEVteJiygIxXzZPza1zMyBs8UXhlnBUiyJD8kZtJcnEOmonk2lYIOy4nhRSIK9RwcznLwUAxyGwpXedEV/8HGVMEOMC9ilMwxG5GWB2EGvcsS4WhewCyFoxXP/kdOD+zwYGwD2ZMxXbgclBjS9ORwh3IVW6baDqkoB5MPnmRO5jBEcInzb0Ul+mbMVPjfA7cH6Bzxk7L 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: This is really preparation for the next patch, but it lets us call folio_mark_uptodate() in just one place instead of two. Signed-off-by: Matthew Wilcox (Oracle) --- fs/iomap/buffered-io.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 5db54ca29a35..6e780ca64ce3 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -57,30 +57,32 @@ static inline bool ifs_block_is_uptodate(struct iomap_folio_state *ifs, return test_bit(block, ifs->state); } -static void ifs_set_range_uptodate(struct folio *folio, +static bool ifs_set_range_uptodate(struct folio *folio, struct iomap_folio_state *ifs, size_t off, size_t len) { struct inode *inode = folio->mapping->host; unsigned int first_blk = off >> inode->i_blkbits; unsigned int last_blk = (off + len - 1) >> inode->i_blkbits; unsigned int nr_blks = last_blk - first_blk + 1; - unsigned long flags; - spin_lock_irqsave(&ifs->state_lock, flags); bitmap_set(ifs->state, first_blk, nr_blks); - if (ifs_is_fully_uptodate(folio, ifs)) - folio_mark_uptodate(folio); - spin_unlock_irqrestore(&ifs->state_lock, flags); + return ifs_is_fully_uptodate(folio, ifs); } static void iomap_set_range_uptodate(struct folio *folio, size_t off, size_t len) { struct iomap_folio_state *ifs = folio->private; + unsigned long flags; + bool uptodate = true; - if (ifs) - ifs_set_range_uptodate(folio, ifs, off, len); - else + if (ifs) { + spin_lock_irqsave(&ifs->state_lock, flags); + uptodate = ifs_set_range_uptodate(folio, ifs, off, len); + spin_unlock_irqrestore(&ifs->state_lock, flags); + } + + if (uptodate) folio_mark_uptodate(folio); }