{"id":2234984,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2234984/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ext4/patch/20260508121539.4174601-16-libaokun@linux.alibaba.com/","project":{"id":8,"url":"http://patchwork.ozlabs.org/api/1.2/projects/8/?format=json","name":"Linux ext4 filesystem development","link_name":"linux-ext4","list_id":"linux-ext4.vger.kernel.org","list_email":"linux-ext4@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260508121539.4174601-16-libaokun@linux.alibaba.com>","list_archive_url":null,"date":"2026-05-08T12:15:37","name":"[RFC,15/17] ext4: use fast incremental CRC update in __ext4_new_inode()","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"aec33ca159b1d3730e2072828731476d52974675","submitter":{"id":92757,"url":"http://patchwork.ozlabs.org/api/1.2/people/92757/?format=json","name":"Baokun Li","email":"libaokun@linux.alibaba.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-ext4/patch/20260508121539.4174601-16-libaokun@linux.alibaba.com/mbox/","series":[{"id":503377,"url":"http://patchwork.ozlabs.org/api/1.2/series/503377/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ext4/list/?series=503377","date":"2026-05-08T12:15:22","name":"ext4/lib-crc: LBS performance part 1 - incremental CRC32c for bitmap checksums","version":1,"mbox":"http://patchwork.ozlabs.org/series/503377/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2234984/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2234984/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <SRS0=0She=DF=vger.kernel.org=linux-ext4+bounces-16380-patchwork-incoming=ozlabs.org@ozlabs.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-ext4@vger.kernel.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","patchwork-incoming@ozlabs.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com\n header.a=rsa-sha256 header.s=default header.b=tjgu8Aa9;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org\n (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org;\n envelope-from=srs0=0she=df=vger.kernel.org=linux-ext4+bounces-16380-patchwork-incoming=ozlabs.org@ozlabs.org;\n receiver=patchwork.ozlabs.org)","gandalf.ozlabs.org;\n arc=pass smtp.remote-ip=\"2600:3c15:e001:75::12fc:5321\"\n arc.chain=subspace.kernel.org","gandalf.ozlabs.org;\n dmarc=pass (p=none dis=none) header.from=linux.alibaba.com","gandalf.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com\n header.a=rsa-sha256 header.s=default header.b=tjgu8Aa9;\n\tdkim-atps=neutral","gandalf.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c15:e001:75::12fc:5321; helo=sin.lore.kernel.org;\n envelope-from=linux-ext4+bounces-16380-patchwork-incoming=ozlabs.org@vger.kernel.org;\n receiver=ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (1024-bit key) header.d=linux.alibaba.com\n header.i=@linux.alibaba.com header.b=\"tjgu8Aa9\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=115.124.30.98","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=linux.alibaba.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=linux.alibaba.com"],"Received":["from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4gBp5d6cRYz1yJq\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 08 May 2026 22:17:09 +1000 (AEST)","from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3])\n\tby gandalf.ozlabs.org (Postfix) with ESMTP id 4gBp5d65z2z4wCG\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 08 May 2026 22:17:09 +1000 (AEST)","by gandalf.ozlabs.org (Postfix)\n\tid 4gBp5d62jTz4wKS; Fri, 08 May 2026 22:17:09 +1000 (AEST)","from sin.lore.kernel.org (sin.lore.kernel.org\n [IPv6:2600:3c15:e001:75::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby gandalf.ozlabs.org (Postfix) with ESMTPS id 4gBp5Z3Cmwz4wCG\n\tfor <patchwork-incoming@ozlabs.org>; Fri, 08 May 2026 22:17:06 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sin.lore.kernel.org (Postfix) with ESMTP id DACE53003836\n\tfor <patchwork-incoming@ozlabs.org>; Fri,  8 May 2026 12:16:32 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 885C93DC4CB;\n\tFri,  8 May 2026 12:16:22 +0000 (UTC)","from out30-98.freemail.mail.aliyun.com\n (out30-98.freemail.mail.aliyun.com [115.124.30.98])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 01E4E3D5244;\n\tFri,  8 May 2026 12:16:17 +0000 (UTC)","from\n x31h02109.sqa.na131.tbsite.net(mailfrom:libaokun@linux.alibaba.com\n fp:SMTPD_---0X2XQgrP_1778242570 cluster:ay36)\n          by smtp.aliyun-inc.com;\n          Fri, 08 May 2026 20:16:11 +0800"],"ARC-Seal":["i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1778242629; cv=pass;\n\tb=XS31E9ujkdW/B/TCsZnQZ+fE6KE0Qt5djmBbnsUCFgChRpd+r4ik59gK38BAyv+JIZQES0nxRY+xHp5E+yLeFs2geuldbQ6qDguQ5Jm+EnXFfFnGwC7sGRCb28heePpuTGrUlMzEqE3zjXUD6LBGUIhaQdD0WYH3be6ZHEMLgR/lQksfoCpn3SRBp6SSAtEHp2NpooGCm4KpU13qlH4ntLWM367g6Tofb4zCgl6UOkGvdWbC/3u1G+0/XLzLq17DmBzv5QeklXgKNrbCvhXz4VklcmseXhfR2ZFMJTykEqccDXYd4NioAT2tbBGVItdzvj6prvUb+Eg9QAaQseBZDg==","i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1778242582; cv=none;\n b=OdBps8L+tL6BKlsBYUaSerlAV7acwNzqFYIZ6h8GvGaccmbFFDNgC+ow80XlZVs3Bf4rrfi2OpvK5TnLVjXx8PYxysNiZ2cSLylrkWK5TGbC/rG4um6GA6L1ZQaJAnTCiGbsgBMQbLeqUd3DAgOtew3i4Uaj8xawaCUyc5Y2hnE="],"ARC-Message-Signature":["i=2; a=rsa-sha256; d=ozlabs.org; s=201707;\n\tt=1778242629; c=relaxed/relaxed;\n\tbh=rBO8Eie88UmrTBPFytczv1QUExFDkjPYiN01+iCNxl8=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=SU90Eoe+BXG6pQyYCPh9pvJHgEvXzpY/lQCTXA8BQ0WPvxQG1DG9EtzrHrigRRCCOPJaT4lTXCjQSM7GLlbm7Z75Me1vd9MU0yjvvZElIZRcY/KKVS88/R8JGANxF7V9oD7d1CfuogJaGnK/06OOHohfffgrycbxLS30KASEcAM1aVAQcY/3ODabumL4xoZw4kTOKjJjcie81sE5C2jIJHaAQf6yW8eMHXYXdgQLqQPpdPBVu4bJfGlmN98QgG/8XLWSizUhIJSe30wMCD4+TNoPFD25hmpr7fdvbuxtyGttvNHUvRZDlZMVdWs8ZDoCd0LICmSmDwUErsULK6FL0w==","i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1778242582; c=relaxed/simple;\n\tbh=ru7eSD7FE1o2zyOuZ/OIwiAjOXqgGwTWmXfp8+TDFjs=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=YEtKwVmCmUqvbuBZYK9kdBoyQ1uBzp9jkpG6uxJtYR0wR0cIRldAXqkWggkAtBPMryTOZyGkFxgCdUbvIK65ZNX4Vo48Y0kvs962oLt40Aju7Y2TwRoVPUnppJAFewElAOdWT5gPE3ESl+2O3MZuEEznVVXPXbLWxBQZZG18dI8="],"ARC-Authentication-Results":["i=2; gandalf.ozlabs.org;\n dmarc=pass (p=none dis=none) header.from=linux.alibaba.com;\n dkim=pass (1024-bit key;\n unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com\n header.a=rsa-sha256 header.s=default header.b=tjgu8Aa9; dkim-atps=neutral;\n spf=pass (client-ip=2600:3c15:e001:75::12fc:5321; helo=sin.lore.kernel.org;\n envelope-from=linux-ext4+bounces-16380-patchwork-incoming=ozlabs.org@vger.kernel.org;\n receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org","i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=linux.alibaba.com;\n spf=pass smtp.mailfrom=linux.alibaba.com;\n dkim=pass (1024-bit key) header.d=linux.alibaba.com\n header.i=@linux.alibaba.com header.b=tjgu8Aa9;\n arc=none smtp.client-ip=115.124.30.98"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=linux.alibaba.com; s=default;\n\tt=1778242572; h=From:To:Subject:Date:Message-ID:MIME-Version;\n\tbh=rBO8Eie88UmrTBPFytczv1QUExFDkjPYiN01+iCNxl8=;\n\tb=tjgu8Aa9zc2a6556hUC7phsd//b5zRVUlcwfgIjNFQcWiPBFmV9RTjMLaBuDSgImkhq3N88njUSBBryFCf8TPey0SdC1jR4cvR8DPeFbL3Jwne0N4bQzsSA0CHZDm63wqpdgwribyAq5qNfxASwTwb4OmClYUMSyhHa0akhTDFA=","X-Alimail-AntiSpam":"\n AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037026112;MF=libaokun@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0X2XQgrP_1778242570;","From":"Baokun Li <libaokun@linux.alibaba.com>","To":"linux-ext4@vger.kernel.org","Cc":"linux-crypto@vger.kernel.org,\n\tebiggers@kernel.org,\n\tardb@kernel.org,\n\ttytso@mit.edu,\n\tadilger.kernel@dilger.ca,\n\tjack@suse.cz,\n\tyi.zhang@huawei.com,\n\tojaswin@linux.ibm.com,\n\tritesh.list@gmail.com,\n\tBaokun Li <libaokun@linux.alibaba.com>","Subject":"[PATCH RFC 15/17] ext4: use fast incremental CRC update in\n __ext4_new_inode()","Date":"Fri,  8 May 2026 20:15:37 +0800","Message-ID":"<20260508121539.4174601-16-libaokun@linux.alibaba.com>","X-Mailer":"git-send-email 2.43.7","In-Reply-To":"<20260508121539.4174601-1-libaokun@linux.alibaba.com>","References":"<20260508121539.4174601-1-libaokun@linux.alibaba.com>","Precedence":"bulk","X-Mailing-List":"linux-ext4@vger.kernel.org","List-Id":"<linux-ext4.vger.kernel.org>","List-Subscribe":"<mailto:linux-ext4+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-ext4+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-Spam-Status":"No, score=-8.7 required=5.0 tests=ARC_SIGNED,ARC_VALID,\n\tDKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DMARC_PASS,\n\tHEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,\n\tSPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_DKIM_WL autolearn=disabled\n\tversion=4.0.1","X-Spam-Checker-Version":"SpamAssassin 4.0.1 (2024-03-25) on gandalf.ozlabs.org"},"content":"Merge the bitmap modification and group descriptor update into a single\ngroup lock acquisition in __ext4_new_inode(). Previously the bitmap bit\nwas set under one lock/unlock pair, and the GDP fields (UNINIT,\nitable_unused, free_inodes, dirs, csum) were updated under a separate\nlock/unlock pair with a gap in between. Another thread could modify the\nbitmap and update the checksum during that gap, making incremental CRC\nincorrect.\n\nNow the full sequence -- set bit, update free inodes, clear UNINIT,\nupdate itable_unused, and compute checksum -- happens atomically under\nthe same ext4_lock_group(). The alloc_sem is acquired before the group\nlock to maintain correct locking order with itable lazyinit.\n\nUse ext4_inode_bitmap_csum_set_fast() for the normal path where the\nstored checksum is valid. When EXT4_BG_INODE_UNINIT is set, fall back\nto ext4_inode_bitmap_csum_set() for a full recalculation to establish\na correct baseline (mkfs leaves the checksum as zero for UNINIT groups).\n\nSigned-off-by: Baokun Li <libaokun@linux.alibaba.com>\n---\n fs/ext4/ialloc.c | 129 +++++++++++++++++++++++------------------------\n 1 file changed, 63 insertions(+), 66 deletions(-)","diff":"diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c\nindex 8b75b331b26e..9dd1cdb367ba 100644\n--- a/fs/ext4/ialloc.c\n+++ b/fs/ext4/ialloc.c\n@@ -1135,7 +1135,25 @@ struct inode *__ext4_new_inode(struct mnt_idmap *idmap,\n \t\t\text4_std_error(sb, err);\n \t\t\tgoto out;\n \t\t}\n+\n+\t\tBUFFER_TRACE(group_desc_bh, \"get_write_access\");\n+\t\terr = ext4_journal_get_write_access(handle, sb, group_desc_bh,\n+\t\t\t\t\t\t    EXT4_JTR_NONE);\n+\t\tif (err) {\n+\t\t\text4_std_error(sb, err);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\t/* We may have to initialize the block bitmap if it isn't already */\n+\t\terr = ext4_might_init_block_bitmap(handle, sb, group, gdp);\n+\t\tif (err)\n+\t\t\tgoto out;\n+\n+\t\tif (ext4_has_group_desc_csum(sb) &&\n+\t\t    !(sbi->s_mount_state & EXT4_FC_REPLAY))\n+\t\t\tdown_read(&grp->alloc_sem);\n \t\text4_lock_group(sb, group);\n+\n \t\tret2 = ext4_test_and_set_bit(bit, inode_bitmap_bh->b_data);\n \t\tif (ret2) {\n \t\t\t/* Someone already took the bit. Repeat the search\n@@ -1147,9 +1165,54 @@ struct inode *__ext4_new_inode(struct mnt_idmap *idmap,\n \t\t\t\tret2 = 0;\n \t\t\t} else {\n \t\t\t\tret2 = 1; /* we didn't grab the inode */\n+\t\t\t\tgoto unlock_group;\n+\t\t\t}\n+\t\t}\n+\n+\t\t/* Update the relevant bg descriptor fields */\n+\t\text4_free_inodes_set(sb, gdp,\n+\t\t\t\t     ext4_free_inodes_count(sb, gdp) - 1);\n+\t\tif (S_ISDIR(mode)) {\n+\t\t\text4_used_dirs_set(sb, gdp,\n+\t\t\t\t\t   ext4_used_dirs_count(sb, gdp) + 1);\n+\t\t\tif (sbi->s_log_groups_per_flex) {\n+\t\t\t\text4_group_t f = ext4_flex_group(sbi, group);\n+\t\t\t\tatomic_inc(&sbi_array_rcu_deref(sbi, s_flex_groups,\n+\t\t\t\t\t\t\t\tf)->used_dirs);\n+\t\t\t}\n+\t\t}\n+\n+\t\tif (ext4_has_group_desc_csum(sb)) {\n+\t\t\tbool fast_crc = true;\n+\t\t\tint free = EXT4_INODES_PER_GROUP(sb) -\n+\t\t\t\t\text4_itable_unused_count(sb, gdp);\n+\n+\t\t\tif (gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT)) {\n+\t\t\t\tgdp->bg_flags &= cpu_to_le16(~EXT4_BG_INODE_UNINIT);\n+\t\t\t\tfree = 0;\n+\t\t\t\t/* Incremental CRC needs a valid csum baseline */\n+\t\t\t\tfast_crc = false;\n \t\t\t}\n+\t\t\t/*\n+\t\t\t * Check the relative inode number against the\n+\t\t\t * last used relative inode number in this group.\n+\t\t\t * If it is greater we need to update the\n+\t\t\t * bg_itable_unused count.\n+\t\t\t */\n+\t\t\tif (bit >= free)\n+\t\t\t\text4_itable_unused_set(sb, gdp,\n+\t\t\t\t\tEXT4_INODES_PER_GROUP(sb) - bit - 1);\n+\t\t\tif (fast_crc)\n+\t\t\t\text4_inode_bitmap_csum_set_fast(sb, gdp, bit);\n+\t\t\telse\n+\t\t\t\text4_inode_bitmap_csum_set(sb, gdp, inode_bitmap_bh);\n+\t\t\text4_group_desc_csum_set(sb, group, gdp);\n \t\t}\n+unlock_group:\n \t\text4_unlock_group(sb, group);\n+\t\tif (ext4_has_group_desc_csum(sb) &&\n+\t\t    !(sbi->s_mount_state & EXT4_FC_REPLAY))\n+\t\t\tup_read(&grp->alloc_sem);\n \t\tif (!ret2)\n \t\t\tgoto got; /* we grabbed the inode! */\n \n@@ -1168,72 +1231,6 @@ struct inode *__ext4_new_inode(struct mnt_idmap *idmap,\n \t\tgoto out;\n \t}\n \n-\tBUFFER_TRACE(group_desc_bh, \"get_write_access\");\n-\terr = ext4_journal_get_write_access(handle, sb, group_desc_bh,\n-\t\t\t\t\t    EXT4_JTR_NONE);\n-\tif (err) {\n-\t\text4_std_error(sb, err);\n-\t\tgoto out;\n-\t}\n-\n-\t/* We may have to initialize the block bitmap if it isn't already */\n-\terr = ext4_might_init_block_bitmap(handle, sb, group, gdp);\n-\tif (err)\n-\t\tgoto out;\n-\n-\t/* Update the relevant bg descriptor fields */\n-\tif (ext4_has_group_desc_csum(sb)) {\n-\t\tint free;\n-\t\tstruct ext4_group_info *grp = NULL;\n-\n-\t\tif (!(sbi->s_mount_state & EXT4_FC_REPLAY)) {\n-\t\t\tgrp = ext4_get_group_info(sb, group);\n-\t\t\tif (!grp) {\n-\t\t\t\terr = -EFSCORRUPTED;\n-\t\t\t\tgoto out;\n-\t\t\t}\n-\t\t\tdown_read(&grp->alloc_sem); /*\n-\t\t\t\t\t\t     * protect vs itable\n-\t\t\t\t\t\t     * lazyinit\n-\t\t\t\t\t\t     */\n-\t\t}\n-\t\text4_lock_group(sb, group); /* while we modify the bg desc */\n-\t\tfree = EXT4_INODES_PER_GROUP(sb) -\n-\t\t\text4_itable_unused_count(sb, gdp);\n-\t\tif (gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT)) {\n-\t\t\tgdp->bg_flags &= cpu_to_le16(~EXT4_BG_INODE_UNINIT);\n-\t\t\tfree = 0;\n-\t\t}\n-\t\t/*\n-\t\t * Check the relative inode number against the last used\n-\t\t * relative inode number in this group. if it is greater\n-\t\t * we need to update the bg_itable_unused count\n-\t\t */\n-\t\tif (bit >= free)\n-\t\t\text4_itable_unused_set(sb, gdp,\n-\t\t\t\t\t(EXT4_INODES_PER_GROUP(sb) - bit - 1));\n-\t\tif (!(sbi->s_mount_state & EXT4_FC_REPLAY))\n-\t\t\tup_read(&grp->alloc_sem);\n-\t} else {\n-\t\text4_lock_group(sb, group);\n-\t}\n-\n-\text4_free_inodes_set(sb, gdp, ext4_free_inodes_count(sb, gdp) - 1);\n-\tif (S_ISDIR(mode)) {\n-\t\text4_used_dirs_set(sb, gdp, ext4_used_dirs_count(sb, gdp) + 1);\n-\t\tif (sbi->s_log_groups_per_flex) {\n-\t\t\text4_group_t f = ext4_flex_group(sbi, group);\n-\n-\t\t\tatomic_inc(&sbi_array_rcu_deref(sbi, s_flex_groups,\n-\t\t\t\t\t\t\tf)->used_dirs);\n-\t\t}\n-\t}\n-\tif (ext4_has_group_desc_csum(sb)) {\n-\t\text4_inode_bitmap_csum_set(sb, gdp, inode_bitmap_bh);\n-\t\text4_group_desc_csum_set(sb, group, gdp);\n-\t}\n-\text4_unlock_group(sb, group);\n-\n \tBUFFER_TRACE(group_desc_bh, \"call ext4_handle_dirty_metadata\");\n \terr = ext4_handle_dirty_metadata(handle, NULL, group_desc_bh);\n \tif (err) {\n","prefixes":["RFC","15/17"]}