From mboxrd@z Thu Jan 1 00:00:00 1970 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 B2983C5B543 for ; Tue, 10 Jun 2025 12:14:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F3186B009A; Tue, 10 Jun 2025 08:14:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4CB086B009B; Tue, 10 Jun 2025 08:14:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 407986B009C; Tue, 10 Jun 2025 08:14:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 231676B009A for ; Tue, 10 Jun 2025 08:14:17 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BFE41C0155 for ; Tue, 10 Jun 2025 12:14:16 +0000 (UTC) X-FDA: 83539383312.30.2945448 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf20.hostedemail.com (Postfix) with ESMTP id BB5191C000D for ; Tue, 10 Jun 2025 12:14:14 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dBFZLM3M; spf=pass (imf20.hostedemail.com: domain of bfoster@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bfoster@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1749557655; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7M2KXkYboJQV8WZTt83MZ+x4H8up8eCNZ6BOoJSfhd8=; b=fYsJCeJxs9+iJWFetqstcZmDZbr1CdAMjIonGIVQS0qjNjuybPRXDBNO2c8R5MEwoLU8zX WAMsyG96ZNRVcuStqSBtZSDImZjvHIK35OzAZBCilX0zZs/iSXGkoBX9EVrxtDIZ4625tH c+e17AilApVe/JE8I18XC/W/CAk1FxI= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dBFZLM3M; spf=pass (imf20.hostedemail.com: domain of bfoster@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bfoster@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1749557655; a=rsa-sha256; cv=none; b=ZkTNb8jnX6TzM/DbJ+N/QDjiV0sgvXDPg9omgxH4qtqdLjMyyXQ6q9hE/NKkN2GhINFLms SwalpSmBMr9VXnpTVzX4c2WWx2SfzbaDq5PctuqmJiYgk4euaxAKIzzq8rSrr8si6OFZwO KiUABAeYyAsLVRsfBWBrEmPD88SvwHg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749557654; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7M2KXkYboJQV8WZTt83MZ+x4H8up8eCNZ6BOoJSfhd8=; b=dBFZLM3MxNnVD/nEsqrp/4BwyWmROIrk2pS9IAOnTRcnEMm5Dg8GEbaeYAFDHod5Zaw3j8 PPVAOBm6BJqVF6hlv6WWVGpuagWnnFJ2cETyPybPGEWyYFw8uTgnqmFaDzCIKdZk3Ni4nx GkysQ5wk5pMEXOh2SOWG1fbddzPlqgU= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-395-Uc6vkY5tOoe8unqS1MkvTw-1; Tue, 10 Jun 2025 08:14:12 -0400 X-MC-Unique: Uc6vkY5tOoe8unqS1MkvTw-1 X-Mimecast-MFC-AGG-ID: Uc6vkY5tOoe8unqS1MkvTw_1749557651 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 636CD1956080; Tue, 10 Jun 2025 12:14:11 +0000 (UTC) Received: from bfoster (unknown [10.22.80.100]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6A06F19560A3; Tue, 10 Jun 2025 12:14:10 +0000 (UTC) Date: Tue, 10 Jun 2025 08:17:45 -0400 From: Brian Foster To: "Darrick J. Wong" Cc: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 2/7] filemap: add helper to look up dirty folios in a range Message-ID: References: <20250605173357.579720-1-bfoster@redhat.com> <20250605173357.579720-3-bfoster@redhat.com> <20250609154802.GB6156@frogsfrogsfrogs> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250609154802.GB6156@frogsfrogsfrogs> X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Stat-Signature: 1ihjtkhzixmqjku7ybz1jiwrm9qhost8 X-Rspamd-Queue-Id: BB5191C000D X-Rspam-User: X-Rspamd-Server: rspam02 X-HE-Tag: 1749557654-712584 X-HE-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prmwe1LNvyjDNc6y1tNDS7RswjCYVyj0KBlR6+SMhuXJaYyW6bCLcRz+zbp3o7/15wsgdgh6hn14hHs+L9NWxbbvkbrV8mpVdS8FLjmnXu256UGu2kgZp8FlmjIro2qqIvhm9qjLDLjU4sB11Kx6lKHwjsoEuoJPyRGZ2W2pW1IW+MB1l77ObqQWs7ox5Q4fnATXnT2cQ0gQ80D865dlbc6RLcI3xozrJxqdV3w67JoIE+7skyKFXBstD9RNgdVLq35T14WzrsI/2ukKG5l+7JslAkWaC 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: List-Subscribe: List-Unsubscribe: On Mon, Jun 09, 2025 at 08:48:02AM -0700, Darrick J. Wong wrote: > On Thu, Jun 05, 2025 at 01:33:52PM -0400, Brian Foster wrote: > > Add a new filemap_get_folios_dirty() helper to look up existing dirty > > folios in a range and add them to a folio_batch. This is to support > > optimization of certain iomap operations that only care about dirty > > folios in a target range. For example, zero range only zeroes the subset > > of dirty pages over unwritten mappings, seek hole/data may use similar > > logic in the future, etc. > > > > Note that the helper is intended for use under internal fs locks. > > Therefore it trylocks folios in order to filter out clean folios. > > This loosely follows the logic from filemap_range_has_writeback(). > > > > Signed-off-by: Brian Foster > > You might want to cc willy directly on this one... Er yeah, I'll do that for v2. > > --- > > include/linux/pagemap.h | 2 ++ > > mm/filemap.c | 42 +++++++++++++++++++++++++++++++++++++++++ > > 2 files changed, 44 insertions(+) > > ... > > diff --git a/mm/filemap.c b/mm/filemap.c > > index bada249b9fb7..d28e984cdfd4 100644 > > --- a/mm/filemap.c > > +++ b/mm/filemap.c > > @@ -2334,6 +2334,48 @@ unsigned filemap_get_folios_tag(struct address_space *mapping, pgoff_t *start, > > } > > EXPORT_SYMBOL(filemap_get_folios_tag); > > > > +unsigned filemap_get_folios_dirty(struct address_space *mapping, pgoff_t *start, > > + pgoff_t end, struct folio_batch *fbatch) > > This ought to have a comment explaining what the function does. > It identifies every folio starting at @*start and ending before @end > that is dirty and tries to assign them to @fbatch, right? > Yep, or at least every folio that starts before end. I'll add a comment and incorporate all the followup feedback. Thanks. Brian > The code looks reasonable to me; hopefully there aren't some subtleties > that I'm missing here :P > > > +{ > > + XA_STATE(xas, &mapping->i_pages, *start); > > + struct folio *folio; > > + > > + rcu_read_lock(); > > + while ((folio = find_get_entry(&xas, end, XA_PRESENT)) != NULL) { > > + if (xa_is_value(folio)) > > + continue; > > + if (folio_trylock(folio)) { > > + bool clean = !folio_test_dirty(folio) && > > + !folio_test_writeback(folio); > > + folio_unlock(folio); > > + if (clean) { > > + folio_put(folio); > > + continue; > > + } > > + } > > + if (!folio_batch_add(fbatch, folio)) { > > + unsigned long nr = folio_nr_pages(folio); > > + *start = folio->index + nr; > > + goto out; > > + } > > + } > > + /* > > + * We come here when there is no page beyond @end. We take care to not > > ...no folio beyond @end? > > --D > > > + * overflow the index @start as it confuses some of the callers. This > > + * breaks the iteration when there is a page at index -1 but that is > > + * already broke anyway. > > + */ > > + if (end == (pgoff_t)-1) > > + *start = (pgoff_t)-1; > > + else > > + *start = end + 1; > > +out: > > + rcu_read_unlock(); > > + > > + return folio_batch_count(fbatch); > > +} > > +EXPORT_SYMBOL(filemap_get_folios_dirty); > > + > > /* > > * CD/DVDs are error prone. When a medium error occurs, the driver may fail > > * a _large_ part of the i/o request. Imagine the worst scenario: > > -- > > 2.49.0 > > > > >