From patchwork Wed Oct 9 10:27:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Han X-Patchwork-Id: 13828122 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 C1387CF0449 for ; Wed, 9 Oct 2024 10:12:05 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1syTfm-00024A-1o; Wed, 09 Oct 2024 10:12:02 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1syTfj-00023t-UE for linux-f2fs-devel@lists.sourceforge.net; Wed, 09 Oct 2024 10:11:59 +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=goUSf55hgllp3OjqMieU1ZUpPQF/HnlAaNUU6I/ZMMU=; b=Sl16B7LfuuOkg463EQpbC7zbb4 KAVMwUbf/JKd4KKnWvQb9uV1kJ4a1eo557AaUS6RLJkj3T/KOIo05yR7NSCy+t/CBwZ7fwcudABt4 l1F7bXEw/qQSxUCVSfDvBFoeUpuN/dGqaGsKkvSk/tMX2rnzst2vrl3LZ38bdKm/Z1yk=; 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=goUSf55hgllp3OjqMieU1ZUpPQF/HnlAaNUU6I/ZMMU=; b=A WGwiBp07nIauLIYbcRSaowDBlNfgRf06RY4uHjnwfLNjwStsU8H1K71uxy0cPWa1FVANlhLs8HReC 2QVQh1fpecfd3htK8vvcGbs7DawaWjf9c8CQWmjf4Zz+Xf16edrOenKmJoCDwOZDRYpkpZKSmAtGe vALOWWDlgc608pcc=; Received: from mail-tyzapc01on2041.outbound.protection.outlook.com ([40.107.117.41] 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 1syTfj-0001U7-4J for linux-f2fs-devel@lists.sourceforge.net; Wed, 09 Oct 2024 10:11:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XRWawf4Nst3EdlOcP6F2NE6Yt0jzoOmvYn0kPgJYqoBRsezUtgJTxSh6/WxCMxDEaeDnVFfJM4rvHoTE3I0k6ZGr1u8DKCQ2Ib7EuStAO1HOTt+JdBm62xm9MDDy+2tfk3NN7MgcAH5lrnW5Bw3sLGvzbZ4nqaSP5jG6QLtQgCAojv5KOgAYqxGF4epkhlfj6pbZnHDhrkkb1caS+sOa+11V98MvPACoC+Sq5afyg9mPp//esoc5vV9WOZtejC7meC0HT8iFWmja/2ZrvhkGRibaKaLcuACkc5Mk29dJwz0DZv2NXPUGHQad3/SilRQtm3LoMk9TWqXNytPT9vmwxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=goUSf55hgllp3OjqMieU1ZUpPQF/HnlAaNUU6I/ZMMU=; b=o7zxao5GXFpZUHsXnh4/PKT8wzFNOyGMpKqBp68KA2Tv3J7FYaJvs7FHIRoEjxLPSa5t0fu1zZ8Vv6tmldp+fZDNkWkxzNxC2DSJJcS8XbOA5nmtsmXUVtEX9asv1HoK2W1IICs9LZY/QDs0jaUCmX5zaBnCsdUw3QqZdmXTpVq3HbM8RVYpdloHdFouWrsejwKYkaNnoddJauXUXD06qSCayfcAEPhRrk7JmcD+WvyCj6ip0/kWSwrqCXWgDH+GCPxJFWHe/EGnkOOy5F/xbvg5urd4MHlnIvEH9zMhxJcGDuxI0ep6F/XJcdLItAqP87b0/Tb2xlHznfadgqM1Kw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=goUSf55hgllp3OjqMieU1ZUpPQF/HnlAaNUU6I/ZMMU=; b=HAA0Lzucx41ZFyGcc/+Pd6cQDA9KN6iLE1HpXgwIYgKRcQSCeESqYOeaMknEOnqaZ2iv8G1TDIDlccbPMhw+MhK9mBoH5ASObVNWOm8D6A8Fuf0pC85QMH8vFASSwuSUeBOi/jYSwQw4ZHjtWDXZkk1C4j5qeRCfp2x6D/uhyteUw13sVQzdOSGDfhBMQ9yDKofsCen4yTKJBLhKN40+JN4FqS1y/pv5Q6bge2m1XrnuWmS6Um077RlIKLBCfSc0MzsjtubQpmh7uASaHueLADKrvaX9rtuOTs+RusJJAB0v4TSzf5HfjSZEpG6Ay35JRRgVIywiPNnr5xN9XV80Fw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SEZPR06MB7140.apcprd06.prod.outlook.com (2603:1096:101:228::14) by SEZPR06MB5119.apcprd06.prod.outlook.com (2603:1096:101:4e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.17; Wed, 9 Oct 2024 10:11:46 +0000 Received: from SEZPR06MB7140.apcprd06.prod.outlook.com ([fe80::9eaf:17a9:78b4:67c0]) by SEZPR06MB7140.apcprd06.prod.outlook.com ([fe80::9eaf:17a9:78b4:67c0%5]) with mapi id 15.20.8048.013; Wed, 9 Oct 2024 10:11:46 +0000 To: jaegeuk@kernel.org, chao@kernel.org Date: Wed, 9 Oct 2024 04:27:45 -0600 Message-Id: <20241009102745.1390935-1-hanqi@vivo.com> X-Mailer: git-send-email 2.25.1 X-ClientProxiedBy: SI2PR01CA0021.apcprd01.prod.exchangelabs.com (2603:1096:4:192::19) To SEZPR06MB7140.apcprd06.prod.outlook.com (2603:1096:101:228::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB7140:EE_|SEZPR06MB5119:EE_ X-MS-Office365-Filtering-Correlation-Id: 5968b5e9-bb40-4584-d610-08dce84ac857 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|52116014|376014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: 2FwrC1OVACizeBAIG2dddlUuNf6b5s0hLAAkLNt+zvkYr8s6+GopQaGM9kylSEYaJVWndrU0OsIfsZUAWl0E/JmvplEqV26wNjrZv389IEUuKJ2V/9HUmIDLfOJh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mogDUJ5/SFliJ+NoWaqc9BcpsjVtFf2vsGwT9qz7X7itgKx721xjRvdfTYOlLtAe6wr0zExfj2fSNxVbFhOPviIATb+fDyIHwJCRFZfUCnBraPZDtONeJn+FZGhXDQZooxglN+9FsUDdBFNWYL5fJ1I68pM X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEZPR06MB7140.apcprd06.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(52116014)(376014)(1800799024)(366016)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1Ufkfb9MtvvJZiqfVpiRzKTLp6z+fOIVDO17ilSbYZKu/ZVQfvcIIibjSY1cSJ5c1I6RrdIbge4hmAsIXxZtZrEEGAXfzY6jG/I9jkpl0LRr0epbMxg3h0/jEqQqLxrKP0/FwQvRGFKm2YNkH3aLWkFAtk+HcKLUYtksUWj6lV38m6dw/PxsmrNdd36AMy0bWVueBmjIfVGiwGpSr4SitXmdL27zwhUMkGUO8Bnao0pmZGdKH8pvGpN1ZzkgqyZX/NAUEqSgUS5R7y7zC3823nPGh+mc5z7wWYGes25o+Jd2IM4ldiQmE17Houq1wGKXVq14Z7/sJr5HlZ3MRpQWQ7jgi/hPlHLVoCbXu1AXKgZWozHRI7kNg5r++oI1B/0tSXf/FD6p1d1H/khnBOkXu8uFN1PzFq51F4n3woMIxlOBfjlt42LWIURdWkql+D9lEeiVKE4jiPrpVglMAVKUPGPSOFYcXNeLpsUYnxcf/NAgbp/QCCsyqx2PV6+oH5EiokHfNTAmj7thVGxIK24/5WYnt5GvVqiBCWQ4u8paChtQNLac6Mg5NKAEGnPUc1X0LmzJ8fd+zpnaGPhYstjh6eOC9l/PQUAI4pc/8UgaqTXMQESOdy+CpIgUpPe4Enbkv9JUQyv2UruPujg2s1sSJZBp2AkBkCuxnvya6a1m92T4Rp9I23I+j1Pfpq4UHl3JQrnjQ6cCElSoC1s59em/MbZR0GT9NXzirtY7iQhZPPx/Y56ma5DIQn+VS7kyPoxk186DLLtw5IEI9Ag13oxrT/GStCN27yK8g7X+6K4/XPgV7FoMGJqJSDR2h3d0PAsAwRo95MD097HuRTu7dnkPfM7MMvL4ctzNFdi8wlLGkCQfajCJ17ugAaG+HTMxAp5nvpgvo45dOhL+ZaeIWCzWHiqiox+VFJq6iSghVqqmb+8jf5E4fXsJXctBsQVDBJW98UfxqpiFj0f9mhlNk0YQkrM5g7/vvMbwZZee3mNeMlDIfHc7qezU9J0MShFBWMX5QpeMPHjGJ5O1Je0gmttNX+9WM5A0t/CpsTzKkb/Em8DKFSg6X9+jrm4HWHiYVbJYBu6sdLUMHkq3OMWjEQQSLajev5YGxDBjn6cfV1kJSYgetNumlPYW2KyJzzzOyR+3bWw+N2i1x7EAmXOFWwlaevzQiPMcuGXVP7MQGWMqGnqhLU0gjoPrtgjRi0Gc3vIXsomhr9oHxtP1QC8e98yjk0bkIhK5cRfVqBKvU/AzI5WLzBIb8sXBPAHeW3eW1ovMAESda6UBBR483qtECwkxzfz4xN48AmfzPasb/K0g6njU6BL/ZDuGfhtxj5DFdgUv4AwsbICGlV9FOf4T3x3wwpXC8QVheOSq1E2ITQT3Rh5RD7ecyruNEIrcCW66RtYHY7q+TdwMf3twHKpH9adhL1+zGj5XTN6YkFuzE0qAWX+VK6Mf0YGP557OYiLNog0rwckKPPclMrB9n/b4+HpQ2ntY0C58yafFsEDIp3iMUB542FjIMFMYylRIBoa73Ztz08eyV1xOzYUWnmpgznh3s+hXWsLMa1oyK+nKhaeVC9TyfS8s1EzkI/qFXgJI9c+8 X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5968b5e9-bb40-4584-d610-08dce84ac857 X-MS-Exchange-CrossTenant-AuthSource: SEZPR06MB7140.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2024 10:11:46.7583 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Ingu+5c5PH+kB3/qtq8UNvPZEq0UXGnGN6FcMQKY0TrhoDM+kYTzc9QIpwtxTwpbb3g2wQy3abqpiuc3J0w1RQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR06MB5119 X-Headers-End: 1syTfj-0001U7-4J Subject: [f2fs-dev] [PATCH] f2fs: modify f2fs_is_checkpoint_ready logic to allow more data to be written with the CP disable 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: Qi Han via Linux-f2fs-devel From: Qi Han Reply-To: Qi Han Cc: Qi Han , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net When the free segment is used up during CP disable, many write or ioctl operations will get ENOSPC error codes, even if there are still many blocks available. We can reproduce it in the following steps: dd if=/dev/zero of=f2fs.img bs=1M count=55 mkfs.f2fs -f f2fs.img mount f2fs.img f2fs_dir -o checkpoint=disable:10% cd f2fs_dir dd if=/dev/zero of=bigfile bs=1M count=50 sync rm bigfile i=1; while [[ $i -lt 10000000 ]]; do (file_name=./file$i; dd \ if=/dev/random of=$file_name bs=1M count=0); i=$((i+1)); done stat -f ./ In f2fs_need_SSR() function, it is allowed to use SSR to allocate blocks when CP is disabled, so in f2fs_is_checkpoint_ready function, can we judge the number of invalid blocks when free segment is not enough, and return ENOSPC only if the number of invalid blocks is also not enough? Signed-off-by: Qi Han Signed-off-by: Chao Yu --- fs/f2fs/segment.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index 71adb4a43bec..9bf0cf3a6a31 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h @@ -637,12 +637,33 @@ static inline bool has_enough_free_secs(struct f2fs_sb_info *sbi, return !has_not_enough_free_secs(sbi, freed, needed); } +static inline bool has_enough_available_blocks(struct f2fs_sb_info *sbi) +{ + unsigned int total_free_blocks = sbi->user_block_count - + valid_user_blocks(sbi) - + sbi->current_reserved_blocks; + + if (total_free_blocks <= sbi->unusable_block_count) + total_free_blocks = 0; + else + total_free_blocks -= sbi->unusable_block_count; + + if (total_free_blocks > F2FS_OPTION(sbi).root_reserved_blocks) + total_free_blocks -= F2FS_OPTION(sbi).root_reserved_blocks; + else + total_free_blocks = 0; + + return (total_free_blocks > 0) ? true : false; +} + static inline bool f2fs_is_checkpoint_ready(struct f2fs_sb_info *sbi) { if (likely(!is_sbi_flag_set(sbi, SBI_CP_DISABLED))) return true; if (likely(has_enough_free_secs(sbi, 0, 0))) return true; + if (likely(has_enough_available_blocks(sbi))) + return true; return false; }