From patchwork Tue May 7 08:55:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 1932319 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=WegJBcKW; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=mail.ozlabs.org; envelope-from=srs0=yowr=mk=vger.kernel.org=linux-ext4+bounces-2339-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VYXF84TCPz1ymg for ; Tue, 7 May 2024 18:56:12 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4VYXF51r9Kz4x23 for ; Tue, 7 May 2024 18:56:09 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4VYXF51n84z4x2j; Tue, 7 May 2024 18:56:09 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=WegJBcKW; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=139.178.88.99; helo=sv.mirrors.kernel.org; envelope-from=linux-ext4+bounces-2339-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [139.178.88.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4VYXF46dPzz4x23 for ; Tue, 7 May 2024 18:56:08 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AE861282E94 for ; Tue, 7 May 2024 08:56:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B62C514D6EB; Tue, 7 May 2024 08:55:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WegJBcKW" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D8BD14D2B6; Tue, 7 May 2024 08:55:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715072158; cv=none; b=WZlXrecdmLq6vWI+T2TfLF5KfHn4lbTdVgsVxSPE/NLMLtLyVNvgKg3KNaYD8wQE3fDRRW2Vi6UtLpPKGx7jHYtPZtJrrPa36DKb4/5s09GBDxFVWgVI+gqjClVX/O6OgAQYrO+tQmKDn42BvKmn8kfbOvvpsSNof+gtvIBW2BM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715072158; c=relaxed/simple; bh=jFcnH9HqLEggeqAB2KGmVQnYPco7e2fsq97konYOI6s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qTyFqPzjf2bu2Ncw3iFmKCIuIBhxLTgxipwG2vCb3A5X0e7h5mm6T4osaGcFs+6CzmA7Fpb46r2cQbZtdkOECvH/tc7tUGRd2yrCMwlIcupU58MxA0FTyuIZOnzFWFURl9+nGcJ9HrvrNWcQt2xzwgXpgJ8hhLLLUncJkOzUXfo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WegJBcKW; arc=none smtp.client-ip=209.85.215.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-5d8b519e438so2326931a12.1; Tue, 07 May 2024 01:55:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715072156; x=1715676956; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=e57mtgQJCyrMor2wdEaqG/4Lmj2DaZNgeRnrm29BCyg=; b=WegJBcKW8Zcpl0wCdtgI4dcHSS27HrU6dXC0V7mn95HF8JHwRLcONl6tHF0cZyRUIC ttfcTvthPy1XsfRyYNUbWdVxBuPsR1Qa0TOktsDSmgabqDdX1akVUQVwHmOlO409u6kX QwwyTWXD9x+rSmqVM7ZszESll/qqbi6PW79ckwF1LBhmoFsjZZsWR52xcnzVr53Cdl23 FU+/OKPbVWPYeQzBj8PU2qjBDLggCaUmDLD/v5Xj96C9k/2jiFPpqe/XlDfAaNkmAdVQ ++Jwrv83r/YI7GyJEyk6SbQbiFPzzksKpWSZGMNUgqst+v25mcx8SHsQkszf19PTloTy qsMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715072156; x=1715676956; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e57mtgQJCyrMor2wdEaqG/4Lmj2DaZNgeRnrm29BCyg=; b=k/ACvZ1tB/L/4lRzl/DX+T33lb2qFQJSYyQyleGSOOgxSzWO8gbfD/vDhVYbWePeK9 S6KrFjHMmL2Ap74D4ca2ueBjT7EUPwtKcHdel3WLQ4NZKfSgtBZ12v3ImM1RTloF1P5I gTrrs2QupCFcT1hixWBZZLK9VslYEFDVcjM7fjPKFCs9lUN09ibti9sJpNSn83P8KtAd f/cvjrspGkDCC1E60IVjqaWd6s90ZN0++bw435fXn6YZl1yygKoXF2QXawiwvAy0HKei NHQTMu8TnxzgJ0WcepS4MN7+uDy3Nii4eP0i1oRkl5Z3PcPNCjJkylhZbN5e2jz+ZWwu U3Hw== X-Forwarded-Encrypted: i=1; AJvYcCVZr/zVakVDzjukqEYI8b4zHMNa6Y/CZsWDPaZfhYkt/qEr4NJZ7WLrQ2pd4WbLuEIQ4R81FeNFGl2LWNvRBzBc39/lrSKCTwgfGw9x5Q== X-Gm-Message-State: AOJu0Yy3SGwYRmuzO2XcIF/mDeF7hIrYvYSCzfGUE6iUltqw+RVHkmAO LedNL8HnhjkKxg1hvDRIKrxUql71ixwkMiXLV3VLTP8tx0fn+53MeGFeqjGK X-Google-Smtp-Source: AGHT+IEKmuXZ4GNt61aztBB3VJKUSvUF74Re7ukD6WMb3WTHQLEpNms985ob09t25CnALiwpgOvv1A== X-Received: by 2002:a05:6a20:9f9a:b0:1af:93b0:f007 with SMTP id mm26-20020a056a209f9a00b001af93b0f007mr8846151pzb.1.1715072155903; Tue, 07 May 2024 01:55:55 -0700 (PDT) Received: from dw-tp.ibmuc.com ([171.76.81.176]) by smtp.gmail.com with ESMTPSA id kg3-20020a170903060300b001ed53267795sm7262030plb.152.2024.05.07.01.55.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 01:55:55 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linux-xfs@vger.kernel.org Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, Matthew Wilcox , "Darrick J . Wong" , Ojaswin Mujoo , Ritesh Harjani , Jan Kara , Christoph Hellwig Subject: [PATCHv2 1/2] iomap: Fix iomap_adjust_read_range for plen calculation Date: Tue, 7 May 2024 14:25:42 +0530 Message-ID: X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If the extent spans the block that contains i_size, we need to handle both halves separately so that we properly zero data in the page cache for blocks that are entirely outside of i_size. But this is needed only when i_size is within the current folio under processing. "orig_pos + length > isize" can be true for all folios if the mapped extent length is greater than the folio size. That is making plen to break for every folio instead of only the last folio. So use orig_plen for checking if "orig_pos + orig_plen > isize". Signed-off-by: Ritesh Harjani (IBM) cc: Ojaswin Mujoo Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Reviewed-by: Jan Kara --- fs/iomap/buffered-io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.44.0 diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 4e8e41c8b3c0..9f79c82d1f73 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -241,6 +241,7 @@ static void iomap_adjust_read_range(struct inode *inode, struct folio *folio, unsigned block_size = (1 << block_bits); size_t poff = offset_in_folio(folio, *pos); size_t plen = min_t(loff_t, folio_size(folio) - poff, length); + size_t orig_plen = plen; unsigned first = poff >> block_bits; unsigned last = (poff + plen - 1) >> block_bits; @@ -277,7 +278,7 @@ static void iomap_adjust_read_range(struct inode *inode, struct folio *folio, * handle both halves separately so that we properly zero data in the * page cache for blocks that are entirely outside of i_size. */ - if (orig_pos <= isize && orig_pos + length > isize) { + if (orig_pos <= isize && orig_pos + orig_plen > isize) { unsigned end = offset_in_folio(folio, isize - 1) >> block_bits; if (first <= end && last > end) From patchwork Tue May 7 08:55:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 1932320 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ajblN9RE; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=ur/2=mk=vger.kernel.org=linux-ext4+bounces-2340-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VYXFD3gb9z1ymg for ; Tue, 7 May 2024 18:56:16 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4VYXFD3SXQz4x23 for ; Tue, 7 May 2024 18:56:16 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4VYXFD3P0Wz4x2j; Tue, 7 May 2024 18:56:16 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ajblN9RE; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-ext4+bounces-2340-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4VYXFD0Bvvz4x23 for ; Tue, 7 May 2024 18:56:16 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 39DFD1C219B0 for ; Tue, 7 May 2024 08:56:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BCE0514D6FE; Tue, 7 May 2024 08:56:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ajblN9RE" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3483E10E3; Tue, 7 May 2024 08:56:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715072161; cv=none; b=m/ypKVGdJ3HqDjf1Hyj/AHPdDWiNwPGwcBqOdYnyRRdfh3u9TfycTawYSIbl2ONLjSamX9Nm5wn5icMzkZGGEtC9iYXgExrmGL8L+yWikWFbvw9uMe5wziN5IaKlTx8WPfFzKI9JbcZbd61aQ6LHI7xMSuoz63okZVNwlwUvtQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715072161; c=relaxed/simple; bh=Ksf5YxchQflehA0zyL6WfDAHnmrPPcCIXGwNL3c3F50=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qBz26rCKIBR3XabjXVXwO4f2KV40CTonoW1APbUNFVA7A/EMtB35kIn1DT5WhHd4C8MY7ow2PO9nEobwRgZUEShN2v8qDZMsOjtqx1/KM2a31cra1Hh8IL94FDkRVCBVapq0eYkoA0t2Yo/9eyuN4IgXwqRyDT401QqclKYD2uU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ajblN9RE; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1e83a2a4f2cso13466255ad.1; Tue, 07 May 2024 01:56:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715072159; x=1715676959; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BfYxPjYaJ13DzArLzMdBC+xi7YxOzq4F6d2fPzmkmH0=; b=ajblN9RE+4RajUUY0vPep+eM2pJsjtCa69UhcmEQ8Th4tKLG99QYdqC5DIkfWlX0rm i+j2nq4K2O8ZGQRBjvdvQwhLtOTP3RhtwgllA4n2wgZMbmr35/LB9H5opU2ngRblEJy0 nExjw3G9YEQZ9A4rYsGTe0fT09CaEMo7n9yomWcITUInSQbxtmy7suoKNyyzJIXGo2VX 6/DSpTjPFF0WkjCEoUfY3gAd1Rd15P/yMV+M/pBlQvyiERLKfswRbsyHTbCpzKB3FDh4 av5SElzNzGMAJpf9215iRcEcaOoo7vccz6cKU0hJUcqeNBR08mxTnqaw5EPEE0balmkx p9kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715072159; x=1715676959; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BfYxPjYaJ13DzArLzMdBC+xi7YxOzq4F6d2fPzmkmH0=; b=b+0863A7CS9NbazyG7I2xoUqyU63eSl6bEyFWM1JVoc7sWqRXST2x/fs4e5kFJ+KXx 2ZeDBZZ+bvbQEDM0fQwLE7Wfz8PS0WlgPv4qAjGb1RQTo6fOx535cDnODFNWKdOHq0GV K/J8UZZMhjWWeGTkZ4xuBaXxEHBDnzvLvomO2vgM25E7Nl+4mkkHDUDnv7+CfvkzQAqg /B387DIqBwMhuPpOXInTFKgYVzmBQ5LUJcBQLh50/m3YaVasIRHCszO204wm+iz/ApRj 1PJicxT8PfCVvPzEcGlpqyh4fH2GGeXi0E4a2cT5gqZE4tpb/SnRZEgs2s6rX33goBut Y6GQ== X-Forwarded-Encrypted: i=1; AJvYcCWP6YTvCYcjq0F6FFLIgUAfmJZq1Sv+SJZdHvRShoo2IYPWG4exeY7kxSoHz1xbLdVqSfeHpSvIhQ3mfV9+yT1u9fE+IOOVZu1UKLZsAg== X-Gm-Message-State: AOJu0YyeDrnd1SEVpXXygcmJvIh59S+2H7l4WefYoA6iz1F1KHmCJir9 1VosKldrjRvEVEQoFAaMMFBCt8V7UMTgptAD3xGMKhDm0lkPT7nfIZepJGqV X-Google-Smtp-Source: AGHT+IHaTWBvDoyo/xtxNDfUQqoqzNQbOg2X8VVX3v282s4ra57O97EBh+hzkO2JqQ0kdDYvOFzf9A== X-Received: by 2002:a17:902:db0e:b0:1ec:3227:94ea with SMTP id m14-20020a170902db0e00b001ec322794eamr15716088plx.67.1715072159023; Tue, 07 May 2024 01:55:59 -0700 (PDT) Received: from dw-tp.ibmuc.com ([171.76.81.176]) by smtp.gmail.com with ESMTPSA id kg3-20020a170903060300b001ed53267795sm7262030plb.152.2024.05.07.01.55.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 01:55:58 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linux-xfs@vger.kernel.org Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, Matthew Wilcox , "Darrick J . Wong" , Ojaswin Mujoo , Ritesh Harjani , Jan Kara Subject: [PATCHv2 2/2] iomap: Optimize iomap_read_folio Date: Tue, 7 May 2024 14:25:43 +0530 Message-ID: <92ae9f3333c9a7e66214568d08f45664261c899c.1715067055.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 iomap_readpage_iter() handles "uptodate blocks" and "not uptodate blocks" within a folio separately. This makes iomap_read_folio() to call into ->iomap_begin() to request for extent mapping even though it might already have an extent which is not fully processed. This happens when we either have a large folio or with bs < ps. In these cases we can have sub blocks which can be uptodate (say for e.g. due to previous writes). With iomap_read_folio_iter(), this is handled more efficiently by not calling ->iomap_begin() call until all the sub blocks with the current folio are processed. iomap_read_folio_iter() handles multiple sub blocks within a given folio but it's implementation logic is similar to how iomap_readahead_iter() handles multiple folios within a single mapped extent. Both of them iterate over a given range of folio/mapped extent and call iomap_readpage_iter() for reading. Signed-off-by: Ritesh Harjani (IBM) cc: Ojaswin Mujoo Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- fs/iomap/buffered-io.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) -- 2.44.0 diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 9f79c82d1f73..a9bd74ee7870 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -444,6 +444,24 @@ static loff_t iomap_readpage_iter(const struct iomap_iter *iter, return pos - orig_pos + plen; } +static loff_t iomap_read_folio_iter(const struct iomap_iter *iter, + struct iomap_readpage_ctx *ctx) +{ + struct folio *folio = ctx->cur_folio; + size_t offset = offset_in_folio(folio, iter->pos); + loff_t length = min_t(loff_t, folio_size(folio) - offset, + iomap_length(iter)); + loff_t done, ret; + + for (done = 0; done < length; done += ret) { + ret = iomap_readpage_iter(iter, ctx, done); + if (ret <= 0) + return ret; + } + + return done; +} + int iomap_read_folio(struct folio *folio, const struct iomap_ops *ops) { struct iomap_iter iter = { @@ -459,7 +477,7 @@ int iomap_read_folio(struct folio *folio, const struct iomap_ops *ops) trace_iomap_readpage(iter.inode, 1); while ((ret = iomap_iter(&iter, ops)) > 0) - iter.processed = iomap_readpage_iter(&iter, &ctx, 0); + iter.processed = iomap_read_folio_iter(&iter, &ctx); if (ret < 0) folio_set_error(folio);