From patchwork Wed Jul 10 01:26:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13728777 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 EAF33C2BD09 for ; Wed, 10 Jul 2024 01:27:25 +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 1sRM7A-00010o-0M; Wed, 10 Jul 2024 01:27:25 +0000 Received: from [172.30.29.66] (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 1sRM78-00010i-PJ for linux-f2fs-devel@lists.sourceforge.net; Wed, 10 Jul 2024 01:27:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Type:Content-Transfer-Encoding :Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: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=vVgDdArwbVUFcFsjOALigj3LaEaA1Y7fsy+KB2si5r8=; b=bqBXKOSic1XKsotGSYz2HBuP3u vZfNahujR0E440ApA0ycYrIz9SlmJz4HzO09v/AXBDJ1PFY255pzullAY7K3MqhQHdVKgar6j5zAn rkBPl1twX6kJD6VdJqxoi4xdEASkqgxtJo+2rtws7yWaVFIoNFi++VBYadrm08rFJMKQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To: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=vVgDdArwbVUFcFsjOALigj3LaEaA1Y7fsy+KB2si5r8=; b=i AlqHD4D36fIc6jPOCbHTIJ+KmUZgNsevGl0LbErUo6GzOgzIF6jBAcx14ToTjXl1DZfCQh6XzdHMA TXVK+mklKcYhMDyYvfC4K0FTwW7dKeyYl2zFThJN5tZM2CG09FWLCy/1oYwaLPFIv9Ua9aXEeb+LA vIclUGMJVPbz3X1Y=; Received: from mail-tyzapc01on2077.outbound.protection.outlook.com ([40.107.117.77] helo=APC01-TYZ-obe.outbound.protection.outlook.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sRM79-0005C1-DX for linux-f2fs-devel@lists.sourceforge.net; Wed, 10 Jul 2024 01:27:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K5q2IQ1Na49gbLxBiINMnfdyBWHLAILnSmyMlOV0AEuM74bZvbRhJMKyevVQfNizexp18rxeJ5WYppRAwDRIeVTD05k6IRrEU2zNttwUJRE+QbIEap0wUssdarg5K5AorY3eEcisr/nC4p8MiEblvY9MXSEipuBnDJjQyVuCSipgc6r3XgX0uBR/44t5tMepUkrmnaiYwsvI9FYWkDVh/oSBOAsUKncb+1EpOpnsQxfk3qCMVU26vIX1UMQSG36CG6TghYZxIiZXdLXR4ryVYILpa5fwxggApT9EfV9YlrnovVOj4OVYdNzeALHdMgKffhSuxaHmipxeH/lR8ox+Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vVgDdArwbVUFcFsjOALigj3LaEaA1Y7fsy+KB2si5r8=; b=YTE4QFmChh6KApphKkztwROIBurlK/V99vI/3TWZEOJqHfoiKr7/bbuNKkitBSM2vur/JPYh3rABnzTat4hv639Ohs3EJ/UCJsYMi5VCIY9JsxAqYuNUhA+AkDRp9XbrNrCckfPtuaT47is/Aw3JzqkgdtxWBo/HEsdFMcURg/dsne+x4X0d/nmQLzP60Ec0cdBFG1MSo4gjyajxixInH0U9o8UhB+HDyReTqvqbVBiHc+sm7tzhjvXBkPJeXRNqNj7oLRjQMgM1evQwYucBxHBi8LsnsVfBfeOFlr1K+7lQIkm6NxzEq1nvqtHJLkadOK2Jb3/hXAqfN4aYHFQzjw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oppo.com; dmarc=pass action=none header.from=oppo.com; dkim=pass header.d=oppo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vVgDdArwbVUFcFsjOALigj3LaEaA1Y7fsy+KB2si5r8=; b=sv/aR4L0VoSclnJbpreNVe7kvvAauntGqiRd7897RbhoAHJEYOF+Dq0vcDHZOakPas5aMB1N5bx0eCJSn4cBw+AdXFvvbitfHF7IYKc1ooR1Wn8MmmA4WNcGvu1nvlXpDHKf97/6B2+gQ/qMrxF2UXG4SdmXcp30uJmWXXajVzI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oppo.com; Received: from SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) by SEYPR02MB5653.apcprd02.prod.outlook.com (2603:1096:101:56::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.36; Wed, 10 Jul 2024 01:27:14 +0000 Received: from SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796]) by SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796%7]) with mapi id 15.20.7741.033; Wed, 10 Jul 2024 01:27:13 +0000 To: jaegeuk@kernel.org, chao@kernel.org Date: Wed, 10 Jul 2024 09:26:59 +0800 Message-Id: <20240710012659.3415856-1-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 X-ClientProxiedBy: SI1PR02CA0049.apcprd02.prod.outlook.com (2603:1096:4:1f5::18) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SEYPR02MB5653:EE_ X-MS-Office365-Filtering-Correlation-Id: 420ccdec-5c80-4923-1cf4-08dca07f6d3f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|376014|52116014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: +UnWnrcHJSMnt907SGIdUpILAzx0k7+9g7Doa1ZkF6MO0Us3RnUdL6UTfidoLNuRxozOk/tWsF2EpM9FR8gImyTT7fZViNhORkLN0nsEvYuyTcvriRpQ5ye1y6NO0Pq93WuWFL2rGeN1+pFYjFZLqK1Ogcy5ABoSVvyrras4lY9IUgNsVQCY/CLvWAQDrsDMEnhdkO9tlNn002GKQfWNLM+FuKd/7p6qeWnt/FFUVP6XbHABsJAvaxcAtPVoMQ37cP92+fv9gZUdNMHoisfYNY7efrLXD6ug74cIAqyYnFMOACLokZlSJ6WDv+p6YVRsLO6fxnKg1Hh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DkoiixGcJVEzAw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEYPR02MB6014.apcprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(52116014)(1800799024)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /wtIex694UGgHwOEv4Cj63CTEhf0wuP9Tg5rpe+5tF/UBuSfedg7iamY9rg3QgPvER/Vgz65B4sH5XSHX1h2iiCcK7kxC1cBOHF3Sghl4RXR5hOtDaXN6PmfVn8YLjeOxztkTfIzyF4v2kpLrH2YV1Vwrutr4MSMca/8K91m98P1ErqIEMfSn644oJw8fjQ0osVJkWgVBmJn7kfA+0MDktqDDYFYF3m6EEknaY9h8eg+Bkiojq8ouBDpSXE+Lh+0s8btNj+nIynitda5yFdbvSNzIrEJenAkiaYY1HTjwAEAjm//NURf6VS3t9s9feG8twCnAUP8ABrOP/XvNBkx8BlQSdLo7OGLCXIYOGj7tlJn2uRSaUXsl1j8dUAQLx0nWWD7CgZVMaTESu5PaLBJmlSCy6iQR+2fD8jdFRvo6QGIa/RrgVLbYtpGF4Jv52JKoaTwcosb8wZpEObKEQHIiLTm0TfDcWtS6udIsPhSnkSx/zoHhwjbzjFrrCJYvfBxSx+CL+eKMYvEDCRn3/Kx+h6IYcu1Wa1fxJcKgr6rj/r2d+yfn7E/UrCVMKZ6oGBgYLBq7+bVvZIzl7+qhRHLTMP1qrsCuRh0wK9ssvzlv6jPbVwNkLtptUnQahliIatuKUHoy54hHoqh0L71Ry3ll1KblGtLKFViUyxvwuXdKiDtym8snQ0rml86FlCzDx8kxNtVLxuLXVT+SH4U0R7/uPtnnCOzRJt8Q9+ceecMfjSfZxILhzBS4t0umE8Pssnail6DqBZzuS6crvTPAutARPtumOCTuBYf1ZDwd8TcFhKC9QB3cEVJpi7YX67vdCqrIekkyx61JbUcjhCXS/TbwG0kk+HZno1EQXu2Vva2j+MQIz+622CmclVvmgggpSnzTGQgOvmEB77fj14oAEwBxM90HckOXts5bXKtTJhcCRaMSiM8/1P7yXx5J0pEPPCMNwb/GpvFdSc3ccR/ai57S+/bixMf2mZWFoZrNwpmzxABZZ4ZSXjLZCNwhk8RNhKIhrkdsSnifi2sAYC7olqkkgXg8ezBSYIhhfZtrhK8cl2P/zkORq5MLa48TBGOTJbzFCZLcUHFBoZ6t0zzyE6p4LfdEICW/Ry7MElSKtG2bXwh9PE5YTJ6ApTg1NsCqk4yjIkTvliaTHRl9SCltLubTOYN3TBEhOAc95aZxl5x9RAdbrqpFpXqugnredbvwv9HxBe4vluAQU3/U0fUftztphHqlthJqDpyqorOvWMQhJsi5WUJSk25Wm1alLRJyVBwsQ7/gEK1bttav2C45fUqbujDtk0fPSlyfSg6PdzOwvW5Gec1SFi905DsN3ElXXP90jkNVDspIJS76OeLPu3HuuMkLeUYhRrappak0D6H1urMfJX14PTZzO42So2MFJ86EUGMgkCdQeQggWppM8TlDS7J/N9a5+03Ph0+P74fMf3BCNSOLG4CYz0Kdsx+xA3KbRgSZ94IWm7Sx8EGLVRgJOIDoZ7vTCgonN4b9OQtUJ+IOVrzT6+7T9nGRJ13YbB+zZJrE/nLND9qfyCmb7LU26tlxHPb294xARgwflGMR5WqWv3efK67qVNCpFUPCt89 X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 420ccdec-5c80-4923-1cf4-08dca07f6d3f X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jul 2024 01:27:13.6392 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UxWCqdVkgJ8NhrNSD/Ofs2yEzeL9VxveQtEoPrKW7EEn9cD+TAmJX5tLZGqN4f5I3jJ42bys5WWgSwODY4/yAg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR02MB5653 X-Headers-End: 1sRM79-0005C1-DX Subject: [f2fs-dev] [PATCH v3] f2fs: only fragment segment in the same section 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: , X-Patchwork-Original-From: Sheng Yong via Linux-f2fs-devel From: Sheng Yong Reply-To: Sheng Yong Cc: daehojeong@google.com, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net When new_curseg() is allocating a new segment, if mode=fragment:xxx is switched on in large section scenario, __get_next_segno() will select the next segno randomly in the range of [0, maxsegno] in order to fragment segments. If the candidate segno is free, get_new_segment() will use it directly as the new segment. However, if the section of the candidate is not empty, and some other segments have already been used, and have a different type (e.g NODE) with the candidate (e.g DATA), GC will complain inconsistent segment type later. This could be reproduced by the following steps: dd if=/dev/zero of=test.img bs=1M count=10240 mkfs.f2fs -s 128 test.img mount -t f2fs test.img /mnt -o mode=fragment:block echo 1 > /sys/fs/f2fs/loop0/max_fragment_chunk echo 512 > /sys/fs/f2fs/loop0/max_fragment_hole dd if=/dev/zero of=/mnt/testfile bs=4K count=100 umount /mnt F2FS-fs (loop0): Inconsistent segment (4377) type [0, 1] in SSA and SIT In order to allow simulating segment fragmentation in large section scenario, this patch reduces the candidate range: * if curseg is the last segment in the section, return curseg->segno to make get_new_segment() itself find the next free segment. * if curseg is in the middle of the section, select candicate randomly in the range of [curseg + 1, last_seg_in_the_same_section] to keep type consistent. Reviewed-by: Chao Yu Signed-off-by: Sheng Yong --- v3: adjust `if (__is_large_section)' check v2: update commit msg --- fs/f2fs/segment.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index a0ce3d080f80..161aed632278 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2784,11 +2784,19 @@ static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type) unsigned short seg_type = curseg->seg_type; sanity_check_seg_type(sbi, seg_type); - if (f2fs_need_rand_seg(sbi)) - return get_random_u32_below(MAIN_SECS(sbi) * SEGS_PER_SEC(sbi)); + if (__is_large_section(sbi)) { + if (f2fs_need_rand_seg(sbi)) { + unsigned int hint = GET_SEC_FROM_SEG(sbi, curseg->segno); - if (__is_large_section(sbi)) + if (GET_SEC_FROM_SEG(sbi, curseg->segno + 1) != hint) + return curseg->segno; + return get_random_u32_inclusive(curseg->segno + 1, + GET_SEG_FROM_SEC(sbi, hint + 1) - 1); + } return curseg->segno; + } else if (f2fs_need_rand_seg(sbi)) { + return get_random_u32_below(MAIN_SECS(sbi) * SEGS_PER_SEC(sbi)); + } /* inmem log may not locate on any segment after mount */ if (!curseg->inited)