Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2702555lqp; Mon, 25 Mar 2024 07:06:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVxJ/MqYRMM7tYRKK2UqCc5qMB5LFEz8dmwJ0SVOJS9tF0o6dN2siZj5kvbc3g8LcaO/BiWAmibv7JqlNmPJGEc7fWm2cpRAq0yL61MDw== X-Google-Smtp-Source: AGHT+IHQ8v2uqYId0487uHIZ6i5hF4KVoPO1iAwyw9V3hg5h2C6kebPCYegrvRLyNJcdY450gKnN X-Received: by 2002:a05:6a20:258c:b0:1a3:c38d:3faa with SMTP id k12-20020a056a20258c00b001a3c38d3faamr3585882pzd.42.1711375563625; Mon, 25 Mar 2024 07:06:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711375563; cv=pass; d=google.com; s=arc-20160816; b=tzW6lS15qU3CLc6IDNMysgJjN4Hhabj5r7U91xr7eEQ/ltpb2bxAdQO8P8CMa9IM2j XpupED3GCpMc4XYpCyotG+AZEddX3S7GxNEbFwnj4zhR9t5mk0M01+jzMyPFUKziRlDJ 9PIHUymJwTRXfWI152PtVGxVk2r+ijbOqMpIUgz3zZytJaNzB8Rqr9y2aVjZC0reeX0j kM5tT1CnsdanztpGQMuyWqUtCooTrKS9gwvQzPviQvzFvO4We3tK7jolvu4uDltI5c1a D5t/TEr1ZB4WU1IxvSl0A1U0on3hbMZt/2278L/bK1oKLacYrL2P7/LSRvOYuicW7qpe cyFg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:subject:cc:to:from; bh=71ksiVuQJfLauOg/uDmrYfOhTXM+ciIwcjHvu+Z1JXY=; fh=r88ULmOhzmh3DE8RgcUXK+PF5Q+3czCYkx5yGhGfkR0=; b=NJZtD/Q57fJVCnjBg93o84aGGBnqeiFft5Or7ipPE8Soqtp/IGZsnSp3tAz7CTUbwS O05sbLj2Niw+YcPMRvcFzha6rWQYvlzN2p2rw6Yjj/M5nRll5YRUhOO3aXaXfPX4xw5J v4A8bBpZ1R6x0fekGFcLtrdKMURISywKUkX3M3QicpAG5EG6LV/Khrj7VyeEIMrNhwOU 4jNckP8/iR6GAA8VEfwGVeXDTiXVoU4zyOftC0dzmD/aYLQvaNpBSQdXpvamZdSyaNn0 2qiAix2ajdOmFpt1PR8+6oyxGGnfPzl66tIcHHcBGW8irJGRz+1OxM4cotZ6aR7LivnO o+Lg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-116563-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116563-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id p7-20020a631e47000000b005e838ab0edfsi7718304pgm.542.2024.03.25.07.06.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 07:06:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116563-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-116563-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116563-linux.lists.archive=gmail.com@vger.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id A7699B3A21E for ; Mon, 25 Mar 2024 12:17:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9BAD814D446; Mon, 25 Mar 2024 08:17:30 +0000 (UTC) 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 CEB6D14D441 for ; Mon, 25 Mar 2024 05:57:29 +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=1711346253; cv=none; b=oT35Y8a9rVnLlVyjx1ERUCe1gain54FrlEbypDGzogi+UqLDjRN9G2E/m/9R09nhOQNPt8porvlsB5StzuWH+Ae9l9MHcAQLUOUwQm9r6AAlnQv3FesYmXZJRYGEiWvC7tF4ijlBY81FIMfWmCWxOolxJH0jaCaP0ogMdaUUbRE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711346253; c=relaxed/simple; bh=hct+CG+K49mQ7e/gs5Egxa90nVS7OdjNK08fkPwVO7E=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ciH92jGgEXBWdqifSj8CmRbEcAzU6q3uO631LQbxZbJLMv8ZQN7YucAImsn3WymEKchy+kHYKdCy5N9sgiYCGmbEQXKqZcGstxiJS5VhCsVrAzRyZ8OnvR1tyrVUoEOFKUrmLnAn7tm2o2Tz1/xj17SBFvjtDtFyHtkl6i2M7UQ= 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 42P5uic2078365; Mon, 25 Mar 2024 13:56:44 +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 4V32G14BRMz2KXJwC; Mon, 25 Mar 2024 13:55:05 +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; Mon, 25 Mar 2024 13:56:42 +0800 From: Zhiguo Niu To: , CC: , , , , , Subject: [PATCH V2] f2fs: fix to adjust appropirate defragment pg_end Date: Mon, 25 Mar 2024 13:56:35 +0800 Message-ID: <1711346195-24555-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 Content-Type: text/plain X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL:SHSQR01.spreadtrum.com 42P5uic2078365 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, /* 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)); 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. -- 1.9.1