From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 8E9874F30D7; Tue, 13 Oct 2026 11:59:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791892793; cv=none; b=pZQHCVfVxnQSx8uGQp7LJPsFXrg46BAQD9DUcS0RCx/y20FiEC8h2ukQngEVxIHHfXq87mbd+ihkkWESHASwpWzEMTunOeBA4TbMZSCi+ZJgivAMqR0tyDAawraKPquCtu9AiPP5eW21eLGRrV7MzJ6GPRejqPK7h+R5Sr57uwQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791892793; c=relaxed/simple; bh=YPDomoCrjuqLyaKQWuuimEB3YeiN4pzQf1dT2g2jinI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YR0b1zArwqvtR96CMDiN3kOakBumcFohsQtTe8zlEnP1UqBPJhB3VnmVEe9YXB6xq9BMrmloGbe5wI3XFXgVbUYPW5zgsesjXYaHX6hYZWj1e/km1agWE+UYwOs9nfqbdA1KzVPp3MNcN88CCZdjTt07An+0h+loaBZcHQlD/jQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=JI6CRei6; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="JI6CRei6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E21361F000FF; Tue, 13 Oct 2026 11:59:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1791892792; bh=cdGpWus1bx3WjmpwWOkMB3ToaZ8m0srrs9kHBQf7Ruo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JI6CRei6L6B/vNs7QOjpr2PSo2WyYw8zP1qwoofZsmjXaSrDon+v38v9ik/2Rzq0A 32IWF+51A/PjTtB0pPwqtumghzdUK5jfeqRrNHJkmqhD9XU9HtOmuaVLkFJR1XyHke na5puduqEc9f5umGOH17dcvagoa9vNqL5Yoh/SCk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable@kernel.org, Daeho Jeong , Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 6.18 011/621] f2fs: fix to shrink gc_lock coverage in f2fs_gc_range() Date: Tue, 13 Oct 2026 13:30:06 +0200 Message-ID: <20261013112921.131597730@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261013112920.855194808@linuxfoundation.org> References: <20261013112920.855194808@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chao Yu [ Upstream commit 5d49025a4e596c4c9ac0c519ef9f9a2c91396856 ] In f2fs_allocate_pinning_section(), we will hold gc_lock before calling f2fs_gc_range() to migrate section in conventional zone, we may suffer worse case because we may need to traverse and migrate multiple sections if we failed to move blocks in section due to lot of reasons: ENOMEM, fail to migrate block of pinfile, racing on i_gc_rwsem. To avoid hold gc_lock for long time to block checkpoint, let's hold the lock and only try to migrate one section. Cc: stable@kernel.org Fixes: 9703d69d9d15 ("f2fs: support file pinning for zoned devices") Cc: Daeho Jeong Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim [ Chao Yu: backport to 6.12.y: - drop file.c changes as f2fs_ioc_reserve_dev_alias() is not present in 6.12 - use f2fs_{down,up}_write(&sbi->gc_lock) as 6.12 lacks lock tracing - use IS_CURSEC() in gc.c as cursec pinning is not present in 6.12 ] Signed-off-by: Chao Yu [ Sasha: applied Chao's 6.12.y backport to 6.18.y; gc.c context uses is_cursec(), which 6.18 has ] Signed-off-by: Sasha Levin --- fs/f2fs/f2fs.h | 2 +- fs/f2fs/gc.c | 33 ++++++++++++++++++++++++--------- fs/f2fs/segment.c | 4 +--- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index f14c364cacc55..ec1b9831e5afe 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -4189,7 +4189,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control); void f2fs_build_gc_manager(struct f2fs_sb_info *sbi); int f2fs_gc_range(struct f2fs_sb_info *sbi, unsigned int start_seg, unsigned int end_seg, - bool dry_run, unsigned int dry_run_sections); + bool dry_run, unsigned int dry_run_sections, bool lock); int f2fs_resize_fs(struct file *filp, __u64 block_count); int __init f2fs_create_garbage_collection_cache(void); void f2fs_destroy_garbage_collection_cache(void); diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index ca1c87e147006..07ea51e68d741 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -2121,7 +2121,7 @@ void f2fs_build_gc_manager(struct f2fs_sb_info *sbi) int f2fs_gc_range(struct f2fs_sb_info *sbi, unsigned int start_seg, unsigned int end_seg, - bool dry_run, unsigned int dry_run_sections) + bool dry_run, unsigned int dry_run_sections, bool lock) { unsigned int segno; unsigned int gc_secs = dry_run_sections; @@ -2135,28 +2135,43 @@ int f2fs_gc_range(struct f2fs_sb_info *sbi, .ilist = LIST_HEAD_INIT(gc_list.ilist), .iroot = RADIX_TREE_INIT(gc_list.iroot, GFP_NOFS), }; + int err = 0; + + if (lock) + f2fs_down_write(&sbi->gc_lock); /* * avoid migrating empty section, as it can be allocated by * log in parallel. */ if (!get_valid_blocks(sbi, segno, true)) - continue; + goto next; if (is_cursec(sbi, GET_SEC_FROM_SEG(sbi, segno))) - continue; + goto next; do_garbage_collect(sbi, segno, &gc_list, FG_GC, true, false); put_gc_inode(&gc_list); - if (!dry_run && get_valid_blocks(sbi, segno, true)) - return -EAGAIN; + if (!dry_run && get_valid_blocks(sbi, segno, true)) { + err = -EAGAIN; + goto next; + } if (dry_run && dry_run_sections && - !get_valid_blocks(sbi, segno, true) && --gc_secs == 0) - break; + !get_valid_blocks(sbi, segno, true)) { + --gc_secs; + goto next; + } if (fatal_signal_pending(current)) - return -ERESTARTSYS; + err = -ERESTARTSYS; +next: + if (lock) + f2fs_up_write(&sbi->gc_lock); + if (err) + return err; + if (dry_run && dry_run_sections && !gc_secs) + return 0; } return 0; @@ -2204,7 +2219,7 @@ static int free_segment_range(struct f2fs_sb_info *sbi, } /* do GC to move out valid blocks in the range */ - err = f2fs_gc_range(sbi, start, end, dry_run, 0); + err = f2fs_gc_range(sbi, start, end, dry_run, 0, false); if (err || dry_run) goto out; diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 2fa2a005c384f..510d073f8ec54 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -3359,10 +3359,8 @@ int f2fs_allocate_pinning_section(struct f2fs_sb_info *sbi) f2fs_unlock_op(sbi); if (f2fs_sb_has_blkzoned(sbi) && err == -EAGAIN && gc_required) { - f2fs_down_write(&sbi->gc_lock); err = f2fs_gc_range(sbi, 0, sbi->first_seq_zone_segno - 1, - true, ZONED_PIN_SEC_REQUIRED_COUNT); - f2fs_up_write(&sbi->gc_lock); + true, ZONED_PIN_SEC_REQUIRED_COUNT, true); if (err) return err; err = f2fs_sync_fs(sbi->sb, 1); -- 2.53.0