Received: by 2002:ab2:23c8:0:b0:1f2:fdbc:cb93 with SMTP id a8csp133421lqe; Wed, 27 Mar 2024 00:38:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV7y4mo6yFmBYaCQKSJAC6HwLiSVETT6TXLtejvFrCjQ7nsqDjxJ69hWy9U0aJDZNqIh8eDFIssHfVckPUsmHl0h6u+vpZ8raWlAFvhEQ== X-Google-Smtp-Source: AGHT+IG0lTXP8//k8jkGHIamwfqwlecodLAtvkCj/kbebmI8L6xJyE+OFEjeRi1fgCs7jk2hVgeL X-Received: by 2002:a05:6402:3507:b0:56c:3feb:8898 with SMTP id b7-20020a056402350700b0056c3feb8898mr385642edd.3.1711525125742; Wed, 27 Mar 2024 00:38:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711525125; cv=pass; d=google.com; s=arc-20160816; b=ICLcrkH5buB9kAeoTkGtBpCHpQQuhNLxHQ4X7I4ndjDLK6rK/vxicPmxd1CSbns5yk ePALbxiYSNvFlyp6OA8FBWB7+opThhyJJRw31+dasKir9FZc0yfHim3ylDj5sfi8vsFk oX4dUXj9dcOk3uI/WXYM7o12erX7+EcQfytZ7kGMdExqJLg+P2qMMhMhYtuAvYaTrx1o fJgQmU6OD5injwaocaJhr/YpvAe+9jHlPf3+fGEXfoP1ftfGhY+0XmXxa0xecFVllm1m dj6oaFwre7shWr/Vtqu8gaoMV20B7RwNSXAyOBxi+IaARBrC1DmE7Ip6viF6okd0+WnV WpnQ== 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=7ItZHhOcFyzFOy1l+CkMWr2iKKkEIs5cA1g5tVStj0A=; fh=bmJMP5ZABTubPEgidfBiEdusydDuNG0BjCBCe+D3FK0=; b=f8gni+u16K8pTO9ZbE38a5ODJSj5udVU7tmbun2+KMdJozdlZ5IPEwIpEefpxL940g 1F6HVy/EdKtwv6Aoczj5C4wSVqhmeP02zJUb/P/YkTfc2Me8WHGATAqu1ryzbZZ7fKbM sMyG8G1U4sKo3RSJ68cmq2lLx2IU1op3bv0i0jWsIPK4wXGVvXNN1kAo9Iyks29NJpqj cWWO19Jf6k2OY4ENPKaem8FVGbWN5RDWUsBpvFSobrgMzIg0X9q7HFoRcjR+q2NTJMkJ FlCtJ8PwNPiU/A7zGj9Shehp8S1+PQUFyNkrcxLwmTyqWk/952EEsbd8G5DWi3jI8NX3 9SOw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YhIgEMST; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-120437-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120437-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 r25-20020a50aad9000000b0056b849263c3si4461151edc.438.2024.03.27.00.38.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 00:38:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-120437-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=YhIgEMST; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-120437-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120437-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 7279C1F28F70 for ; Wed, 27 Mar 2024 07:38:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2B6672C195; Wed, 27 Mar 2024 07:38:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YhIgEMST" 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 530281D530 for ; Wed, 27 Mar 2024 07:38:38 +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=1711525119; cv=none; b=qQrY1icYcSmFUhxH/n445kTr+hr29GnHSiqUNkw8vKS2CRn9ej/dQjYYsOG3/1ebyhSr7k5pn6nDtFZrLdec0NJ2n3SHwGBDQeS1+UDMUVoD2RycGmE0FAl1rYkPUO/o2CpITWb5hdDS/szIlfPXifgHe80/SKLFN5rDcTtzhAY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711525119; c=relaxed/simple; bh=vOZBAan2Cx/wF+uoGUYShV+giAfOXpqrqoKkEy8CSw4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Ik3ln5rhkBhqdckqK8inuZw66eRilzIqDPIl63uGg5T4AYOBZF64WCnDfIGKS8PtoLYtgmqsvU/Y6byQRCL6CAI4LqCAc4ITFbVZoP1JH/wT/HKTrn0fVr/BgmbIxfjOECtuzYChZr1IiwH5GBLNGOp+mL+RWApHyrQqzrjQRuU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YhIgEMST; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2177AC433C7; Wed, 27 Mar 2024 07:38:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711525118; bh=vOZBAan2Cx/wF+uoGUYShV+giAfOXpqrqoKkEy8CSw4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=YhIgEMST9xtsM1kuUIFnjNtUlS4bDEW6Xe7XuLJyuMAL4l/C4BzzYnGQMLFFSXifX T56E0U7fOGPEpCT4v+pukG+27VYedgBlhWMHVpQlr93mo0dY/Q+ej62gxaIikCMki8 KhU7sjFmeAmQV36czX5Hn8OXp3TjilAKWrpY3cHVgF0/RBujgNRK5n9iK/g0VuLORF vpEjbeC/UKNdlxboX4DNdbe2e3zVW3wAfYHNwqeS7eNDLVB5B3la2e2Eh4GRddXHSL G6VsUI32rqktTFO3wyhcsxnL3IB36I/CRR2tH+POgAyBYaYrpjp6K2HWktfBvNZqdC +l1RPXcC3DBUw== Message-ID: <0ed07576-256c-4ed7-8ddc-33ed788a45ac@kernel.org> Date: Wed, 27 Mar 2024 15:38:34 +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 Cc: Zhiguo Niu , jaegeuk@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, ke.wang@unisoc.com, hongyu.jin@unisoc.com References: <1711346195-24555-1-git-send-email-zhiguo.niu@unisoc.com> <8a6b2768-8ab6-4275-8c4e-05b4eca83987@kernel.org> Content-Language: en-US From: Chao Yu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2024/3/27 9:26, Zhiguo Niu wrote: > On Tue, Mar 26, 2024 at 7:11 PM Chao Yu wrote: >> >> 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); ? > should be pg_start << PAGE_SHIFT , pg_end << PAGE_SHIFT - 1)?? Oh, yes. :) Thanks, > if range.start=0, pg_start is also 0, lstart in > filemap_write_and_wait_range is 0, > but pg_start << PAGE_SHIFT - 1 will get lstart=-1? > thanks! >> >> 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.