Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp5357242rdb; Sat, 16 Sep 2023 13:22:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFObjGw/KNy6gV3a/ZTkvfe026VoFVxzWbmEtMOyVu6YttAYrn5l3E8KPCvvSE0Xi6+bl/3 X-Received: by 2002:a05:6870:64a7:b0:19f:aee0:e169 with SMTP id cz39-20020a05687064a700b0019faee0e169mr6743411oab.30.1694895731844; Sat, 16 Sep 2023 13:22:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694895731; cv=none; d=google.com; s=arc-20160816; b=wOBOMKp7piuqFWMx7KToypTVMWFO51vhCWwCA73Wd1mIqcYByJ9vXbWGkOimEAX2+j TpEediTRkUrE9BNYOl+jPQ8G2mg+Ij5sgOFnf4yZyjGJ5rBzoGaUGBxaxeAnuhBYt45h 1/m8l6tBNk6qAcVD5v2Q8c+VkCzZSiO903U82FZTTUzGmY5S1vZd1e3AEbUvh6qY/7TI OojKqHx3TzndbbXN3ktOqlE4SBvAX7YdXjTzxfFZwCCetHrTFV3Z01HQ3l7HMChppfnc BraQPULC1kU4PHxR9pURBDU4+xKpT8ASRGamDjrI642P2XSTVrVZ56kIsQjnWv2t0OZP Jo5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=q9NosZnRxeft56oj4p2r/NWATsovvrHRZyqFuy7rBbo=; fh=xzc49AGP2UuUySg4emyxVK77JVslpo47pwHCiiC+VqY=; b=EJN54BM9GIo1tK2C/kSwtxsUWdGhO/0XX+q9vyze/epPOLLScl3UcZBzs121yEVY+R 2Qv/VzzhxvGAncL50Tyji3gKkdksqCqz/qkheZ0kOHRL9AKmkY7+udOp7WJ4rvW1iHBQ KHa5Q4SSBKn6rtZX8C9jJr9HIVs9Fp2p/4zfr9SMEYboRqbqllTLZjOvah3NvD0OlqN7 C17ETbRq1Bhj7BEgnUjkqhB7l1oaO5ekocjF3G25wmyUgAMCITON0GWTgZPUDfLEfy7o kYUjW7tiT3HIjr7DkbzVTTbUdX64Rr/NelChpymsvOGMI118i7ZQkfl9EwgEi3DLoWB2 /Sfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=HygmhOnB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id i71-20020a636d4a000000b0056379ae7b03si5258100pgc.71.2023.09.16.13.22.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 13:22:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=HygmhOnB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id E103C825AC10; Sat, 16 Sep 2023 08:52:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238756AbjIPPvS (ORCPT + 99 others); Sat, 16 Sep 2023 11:51:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238407AbjIPPvA (ORCPT ); Sat, 16 Sep 2023 11:51:00 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32199F7; Sat, 16 Sep 2023 08:50:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=q9NosZnRxeft56oj4p2r/NWATsovvrHRZyqFuy7rBbo=; b=HygmhOnBUvsHJeiHPubdfb6ZLL hrfrPa1q2R2TpeY5Ad9/H0TbJtEgaTml9EaeGSj21539hAQJqfKtMQOJ9r2F2KnqPGhePdSCJyR0s ZMgMGUgWo+sLl4xPf3Omm+XgP1gXCJirGlrJp9oiHhOMZacR/s+44GBXYUuDh0Ci/b+qZ00nx+raO oLFtCGoCxtIrvnOXjFdY1f3NhsgMUYB+obMrsjscvx0EHfezQAh3qHadIVrejW2o6A2vAUWuoeM2Y BM6Grx2D+H9d1C32e/gNSxNTNorwHumwKS+bDZvXb80Li/a3gGdpkY330aynHXUPuZXxrtET18XSK lEyjgYEQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qhXZL-00H0DC-O8; Sat, 16 Sep 2023 15:50:51 +0000 Date: Sat, 16 Sep 2023 16:50:51 +0100 From: Matthew Wilcox To: Linus Torvalds Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, Nicholas Piggin Subject: Re: [PATCH 02/17] iomap: Protect read_bytes_pending with the state_lock Message-ID: References: <20230915183707.2707298-1-willy@infradead.org> <20230915183707.2707298-3-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Sat, 16 Sep 2023 08:52:25 -0700 (PDT) On Fri, Sep 15, 2023 at 05:11:55PM -0700, Linus Torvalds wrote: > I think it ends up looking like this: > > static void iomap_finish_folio_read(struct folio *folio, size_t off, > size_t len, int error) > { > struct iomap_folio_state *ifs = folio->private; > bool uptodate = true; > bool finished = true; > > if (ifs) { > unsigned long flags; > > spin_lock_irqsave(&ifs->state_lock, flags); > > if (!error) > uptodate = ifs_set_range_uptodate(folio, ifs, > off, len); > > ifs->read_bytes_pending -= len; > finished = !ifs->read_bytes_pending; > spin_unlock_irqrestore(&ifs->state_lock, flags); > } > > if (unlikely(error)) > folio_set_error(folio); > else if (uptodate) > folio_mark_uptodate(folio); > if (finished) > folio_unlock(folio); > } > > but that was just a quick hack-work by me (the above does, for > example, depend on folio_mark_uptodate() not needing the > ifs->state_lock, so the shared parts then got moved out). I really like this. One tweak compared to your version: bool uptodate = !error; ... if (error) folio_set_error(folio); if (uptodate) folio_mark_uptodate(folio); if (finished) folio_unlock(folio); ... and then the later patch becomes if (finished) folio_end_read(folio, uptodate);