From patchwork Wed Mar 27 08:53:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiguo Niu X-Patchwork-Id: 13605973 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6BD4BC54E67 for ; Wed, 27 Mar 2024 08:54:44 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rpP3S-0002g5-0p; Wed, 27 Mar 2024 08:54:42 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rpP3H-0002bh-FA for linux-f2fs-devel@lists.sourceforge.net; Wed, 27 Mar 2024 08:54:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:MIME-Version:Message-ID:Date:Subject: CC:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=YdtKCLnPzFGUm/lK9M7TwZ51+33mb1qxQgEIbr6UDWk=; b=bqexm2JnVHur8x6UGMD/yzAhQU 0I/+7IYYuGd0iL8aKe9Cghy3Iq8YLr0sOXpLOAID7KmFd1P4jZCBZthPBjD90nHjrIYFqAkMtNc/S ByXiBnkOflT5/gCf5Pn1AxDXyLlGW3sa3asIb7f99cfiWpIVv19AWzmcm/5MAUd5/c8o=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From:Sender: Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=YdtKCLnPzFGUm/lK9M7TwZ51+33mb1qxQgEIbr6UDWk=; b=N y9WSQZxawrKcCvV7lhuXqzG1oj08IqbxznOTml5wJ5Dnvcqu4TsUTvXr7Yo14J2jBWI7cd/dj8fCy onMkk7D1rgM8NL3TaOCB+c5iHvJpWzSTAAqgOiX4I835X7rssYjtjYMH86key9lyHD9ebSH397I2a uJsa/yzaZnyqzNws=; Received: from mx1.unisoc.com ([222.66.158.135] helo=SHSQR01.spreadtrum.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rpP3G-0001bW-8S for linux-f2fs-devel@lists.sourceforge.net; Wed, 27 Mar 2024 08:54:31 +0000 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: , 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 MIME-Version: 1.0 X-Originating-IP: [10.0.73.87] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com 42R8rtpk037904 X-Headers-End: 1rpP3G-0001bW-8S Subject: [f2fs-dev] [PATCH V3] f2fs: fix to adjust appropirate defragment pg_end X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ke.wang@unisoc.com, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, hongyu.jin@unisoc.com, zhiguo.niu@unisoc.com Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net 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_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); + 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)); if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { err = -EINVAL; @@ -2647,8 +2648,9 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, } /* writeback all dirty pages in the range */ - err = filemap_write_and_wait_range(inode->i_mapping, range->start, - range->start + range->len - 1); + err = filemap_write_and_wait_range(inode->i_mapping, + pg_start << PAGE_SHIFT, + pg_end << PAGE_SHIFT - 1); if (err) goto out;