From nobody Sat Feb 7 06:39:32 2026 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) (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 09C2F4DA11 for ; Wed, 27 Mar 2024 08:54:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529678; cv=none; b=uxMykUqZtN2kyrJD4MXHYJEdH765Qk2ahWnH6E6lLM9WDv8eW8zrnYeYdQmYTl/j3iAvJeVXo73I9koZVOig3AXJ6bTelhj1Uz6TfDu3rUToh7sCYKBEHX7NVrA/kNICc9lnSnMMck79bN+M+/mrpW+bEKn5uoW5i+JB9Ote6OM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529678; c=relaxed/simple; bh=8qeOhLgDp4B6NSdcFUTzjGxs/APrSCobmWoiOp9La28=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Gsx7MKawyPs1PtQ+nX37c9H0YuHJ0bv4kDFhjZ7ilIZwCAAVGywzmhlCyq2m/i1PMj271QeupD66BTjTMSSZeQSbTQwHYHbA6G7dapuGDrXfwIxelEAfAo+0fxyZeBK7rwqEUJw75++wuSmMo89l9VSdwFTnNjRaEpVoPr3YL/A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 42R8rtpk037904; Wed, 27 Mar 2024 16:53:55 +0800 (+08) (envelope-from Zhiguo.Niu@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4V4L5S56V1z2Lt7c3; Wed, 27 Mar 2024 16:52:12 +0800 (CST) Received: from bj08434pcu.spreadtrum.com (10.0.73.87) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 27 Mar 2024 16:53:53 +0800 From: Zhiguo Niu To: , CC: , , , , , Subject: [PATCH V3] f2fs: fix to adjust appropirate defragment pg_end Date: Wed, 27 Mar 2024 16:53:40 +0800 Message-ID: <1711529620-17576-1-git-send-email-zhiguo.niu@unisoc.com> X-Mailer: git-send-email 1.9.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com 42R8rtpk037904 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Chao Yu --- v3: adjust code positions according to Chao's suggestions v2: check i_size within inode lock according to Chao's suggestions --- --- fs/f2fs/file.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index bc190d5..9908017 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -2627,12 +2627,13 @@ static int f2fs_defragment_range(struct f2fs_sb_inf= o *sbi, bool fragmented =3D false; int err; =20 - pg_start =3D range->start >> PAGE_SHIFT; - pg_end =3D (range->start + range->len) >> PAGE_SHIFT; - f2fs_balance_fs(sbi, true); =20 inode_lock(inode); + pg_start =3D range->start >> PAGE_SHIFT; + pg_end =3D min_t(pgoff_t, + (range->start + range->len) >> PAGE_SHIFT, + DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE)); =20 if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { err =3D -EINVAL; @@ -2647,8 +2648,9 @@ static int f2fs_defragment_range(struct f2fs_sb_info = *sbi, } =20 /* writeback all dirty pages in the range */ - err =3D filemap_write_and_wait_range(inode->i_mapping, range->start, - range->start + range->len - 1); + err =3D filemap_write_and_wait_range(inode->i_mapping, + pg_start << PAGE_SHIFT, + pg_end << PAGE_SHIFT - 1); if (err) goto out; =20 --=20 1.9.1