Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3248940lqp; Tue, 26 Mar 2024 04:12:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVfoka4N4rL5BdwoaS8ytnVED0RfvC7j7H6YLa/+zeio5vix5fjEQjZrD5Ifyun/IUJ+U07zmlGWDojo1Xr6YiqkylrTc3+xoTJWjEgVw== X-Google-Smtp-Source: AGHT+IEpev8SJD2CxVnk25pnWfZuo2X3quva07JUZdpJV5i/n3B95AiOph6BsgOCqkBJ66Fflnsc X-Received: by 2002:a2e:9f17:0:b0:2d6:d043:f6fc with SMTP id u23-20020a2e9f17000000b002d6d043f6fcmr5740736ljk.48.1711451522004; Tue, 26 Mar 2024 04:12:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711451521; cv=pass; d=google.com; s=arc-20160816; b=PWYDeAriqSLnpBbJ6AlbQZw9q24Qh6g0xOokoIzauZew+13U6jaJHd8x87aSHw7Va6 vxrOi0aoHplNYHVbQuuwd3zJQV5LOn1EScfz2Te0LXvjbnzEP0QBePHwzGHgJRFJ6qD/ bdMLQcwdwsFz6hGS1oMIQ1bSruA7OhXqAOJm7he2gLBM4n9k6NPQ0N9exzqGaPAqb5sd O8HMXt1wQjgShtfXFN1u3xuYbcrDvDsjn+6E7T7YzunqXwizaQgv4wp2Qo6TU62jxLgK Wig4XBt9cCO7gmxwkGGUDNMScD74lA/9B1o+/x8Ip5+pOoye5yUnha03Qnreq2NrM28J pqsQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=4Tk6DS2QAq6koFHYij25bP5TbhpaX6EhVX5UwuXE/YQ=; fh=W6COFBd4BX4Q4YpnsinfP4Lifuq45kIfChsHXFM1YEQ=; b=YAlyxs1OKNHUkbXmC8Qka5vyhpHxPwzkRjF4c/mIjuSPtpJBq/NxpyoagyaEIYcnO3 4qnMTBZCd282aFZ8JvAqAwNynxV4qkbSK8YyzGPDSvgrsDSHsGa6uWvKYBmpCLeuw8WF PgPx00wAkXRZSxHd/0RyvTqjVVUhAhUisnojcm5V3UyiBxDcYpfzedJNEIHCX9d9TQe7 tsKROjcA5hF8x4K8Bnlt5iOw5tCA4YLr5JBmDr3Wtr9pK+UnxS3tXgvVXJAEtp6jBUgd c1kvh6WwsxFvnL+neoJFn9GOYoqckB22p2uKAJXfMW1kRM3TjFCpK15Oc+TI9t1R7MDW tRJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UZUDLLRu; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-118853-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118853-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id u17-20020a1709064ad100b00a4df0612177si708383ejt.343.2024.03.26.04.12.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 04:12:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-118853-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UZUDLLRu; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-118853-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118853-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id B4B291F25BD0 for ; Tue, 26 Mar 2024 11:12:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 85BE3481DE; Tue, 26 Mar 2024 11:11:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UZUDLLRu" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE65114AB8 for ; Tue, 26 Mar 2024 11:11:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711451515; cv=none; b=tGBdxaHFHmSBqgD+p3S3rfyGbMKetzTAmrQ1sF2ycM3GiKZwd0+bJVxWSBIbMeUHHaCUTMQpvAQ8N26zYBHPnOfH6OMqTlqT/2r9BnpdFehzzliZQJJnAzpA1ozuHUgfeM9Jr8wp16dAkQ/0T36fLHGrJ1IpAHz4vcTT2ndf/6g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711451515; c=relaxed/simple; bh=XOachr2WIaie8cJhl/lzaSmTxBP/4J3wqYR/eRLBdO8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Z70Ma0CHYVy8FvBXdDITqoQ/hGqoPx4ei449CD3acqP1j+yt9s+TYghX5tlvlOa4ZQpTwd1j3s3wx3yLW74b0H9GzJFxBPNQ6f9shXYSJjyrHzwIsWZBrNIGYYyDO5cBYwHSyiBizisZ9dTbjsHcG7nyD8nW+L8QPJprSNoHMMc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UZUDLLRu; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51EACC433F1; Tue, 26 Mar 2024 11:11:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711451515; bh=XOachr2WIaie8cJhl/lzaSmTxBP/4J3wqYR/eRLBdO8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=UZUDLLRuPSnii715EPgehEkwLpc2bCCpy55jaWgGp7uH9FxbqW6+vaJAhstkh64Ho Gp2OkGWlSF8rL6b5MobYtUjhJ33VzlDTeB+jQlCNoOyHba2er/P6yvjlddDKuq9CI0 SwiMQlt4FBmRFGIXM3Str9hGkUeWkCbme/wd5mNGTkAZHewRFc1hjyZuB1v9fUijfn bhvkzlyOaCdIkKuEaHm5LXOWbNoBoljVZn2jRggs8ETEQ07HIcP/PwN0OanHRA6oFr h6AymSgN3MVLdAhMD2Eu6CjqbXrt4UkovwTTKET5xqQx7IlY+/YbJjZGSJRgTo6rGn t4GxWigrJrzwA== Message-ID: <8a6b2768-8ab6-4275-8c4e-05b4eca83987@kernel.org> Date: Tue, 26 Mar 2024 19:11:50 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH V2] f2fs: fix to adjust appropirate defragment pg_end To: Zhiguo Niu , jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, niuzhiguo84@gmail.com, ke.wang@unisoc.com, hongyu.jin@unisoc.com References: <1711346195-24555-1-git-send-email-zhiguo.niu@unisoc.com> Content-Language: en-US From: Chao Yu In-Reply-To: <1711346195-24555-1-git-send-email-zhiguo.niu@unisoc.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024/3/25 13:56, Zhiguo Niu wrote: > A length that exceeds the real size of the inode may be > specified from user, although these out-of-range areas > are not mapped, but they still need to be check in > while loop, which is unnecessary. > > Signed-off-by: Zhiguo Niu > --- > v2: check i_size within inode lock according to Chao's suggestions > --- > --- > fs/f2fs/file.c | 11 +++++++---- > 1 file changed, 7 insertions(+), 4 deletions(-) > > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > index 128e53d..cf63db7 100644 > --- a/fs/f2fs/file.c > +++ b/fs/f2fs/file.c > @@ -2608,9 +2608,6 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, > bool fragmented = false; > int err; > > - pg_start = range->start >> PAGE_SHIFT; > - pg_end = (range->start + range->len) >> PAGE_SHIFT; > - > f2fs_balance_fs(sbi, true); > > inode_lock(inode); > @@ -2629,10 +2626,16 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, pg_start = range->start >> PAGE_SHIFT; pg_end = min_t(pgoff_t, (range->start + range->len) >> PAGE_SHIFT, DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE)); > > /* writeback all dirty pages in the range */ > err = filemap_write_and_wait_range(inode->i_mapping, range->start, > - range->start + range->len - 1); > + min_t(loff_t, range->start + range->len - 1, > + i_size_read(inode) - 1)); , pg_start << PAGE_SHIFT - 1, pg_end << PAGE_SHIFT - 1); ? Thanks, > if (err) > goto out; > > + pg_start = range->start >> PAGE_SHIFT; > + pg_end = min_t(pgoff_t, > + (range->start + range->len) >> PAGE_SHIFT, > + DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE)); > + > /* > * lookup mapping info in extent cache, skip defragmenting if physical > * block addresses are continuous.