{"id":2234983,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2234983/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ext4/patch/20260508121539.4174601-13-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-13-libaokun@linux.alibaba.com>","list_archive_url":null,"date":"2026-05-08T12:15:34","name":"[RFC,12/17] ext4: factor out ext4_might_init_block_bitmap() helper","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"f047a635dda63b85c650f6b995028ee4f7016f80","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-13-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/2234983/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2234983/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <SRS0=mqsm=DF=vger.kernel.org=linux-ext4+bounces-16378-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=e/jNtFAx;\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=mqsm=df=vger.kernel.org=linux-ext4+bounces-16378-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=e/jNtFAx;\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-16378-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=\"e/jNtFAx\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=115.124.30.132","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 4gBp5P0XNWz1yJq\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 08 May 2026 22:16:57 +1000 (AEST)","from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3])\n\tby gandalf.ozlabs.org (Postfix) with ESMTP id 4gBp5N75hnz4wCG\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 08 May 2026 22:16:56 +1000 (AEST)","by gandalf.ozlabs.org (Postfix)\n\tid 4gBp5N72Twz4wJg; Fri, 08 May 2026 22:16:56 +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 4gBp5K4lSYz4wCG\n\tfor <patchwork-incoming@ozlabs.org>; Fri, 08 May 2026 22:16:53 +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 7088A301B718\n\tfor <patchwork-incoming@ozlabs.org>; Fri,  8 May 2026 12:16:28 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 875BE3DDDC3;\n\tFri,  8 May 2026 12:16:20 +0000 (UTC)","from out30-132.freemail.mail.aliyun.com\n (out30-132.freemail.mail.aliyun.com [115.124.30.132])\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 08AD63DA5DC;\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_---0X2XQgqm_1778242568 cluster:ay36)\n          by smtp.aliyun-inc.com;\n          Fri, 08 May 2026 20:16:09 +0800"],"ARC-Seal":["i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1778242616; cv=pass;\n\tb=LP6GlyQfbxKNODxOOB5u0K2WWJfivXbugLG++EB892L9Oxt/NyB967yQ1CEnC9R7Al2dIaPY2GpVIDBEz7CupvIOcZ9NYaHrp2lTLOkxA1/Wen3hbo0WEjAuyfpMByjn7mVnaS0S0lfd14rsKlZvJNXzt7Xequnv3dTrPKNPBFc+MWKY8fhLYSZQ5GlDLlPHJtkIFBEyiuG3GnMt89cH+Ll+ofDsbOigbkGFxgeznJaIDnDddcMG6jnRbCdpuQKHRzPA5o+98RzhUjt0aT+UpvbCC/yv/WALbrigHrvHFFjNi9N/8oLAWwA40A6P5ICezH1J7NKktJBktJE6IneHGw==","i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1778242580; cv=none;\n b=JUdUBAP5OodZ6EgQjWzzANgZ+lyA3Gf8vdElxgZtdSFeP9YIicXISDoJnjRxSZE/oEQD98XnCHTQk/TJYDBdPw4Vo40rQFZDs7OUixebVcbtqavrNN0Pgn2Cac4KJ6fv5RBdX4c58fMgbHarvejuwgzzMEm+UmS2oQ3LP6z+J7Q="],"ARC-Message-Signature":["i=2; a=rsa-sha256; d=ozlabs.org; s=201707;\n\tt=1778242616; c=relaxed/relaxed;\n\tbh=Pyydu/+mSA8+HVaiGjvimdSM19JdEkQ9zUvMzEWmW5w=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=Ol64Zbao/4bPBdtHAZNaXZy12ZtHIMf10kGMSPNL/SbTzXBKP6QlheGMu5dfem6sbCaVAOMxZ1mGGI1r53LDvDfymTqBzV1WbUVVOJtHWvtd7bQQaKehIzXuQMoJQRiWY72ww29OwOdn40Et/IUrYsAW+V68794vkVHEdwzxATfXr1om0/A8lj8dM4bEJjItnhbLJXXO2z+xX/RcBPVFlH8H+t+oaMQ7Zz30hfmRHXfIBpinQAhrRTMtcYvq8spT0bbETEzIHU53IKEdoVstuqRKElq9n9eafSk0VjSUlYIrwIxFnNaMIRg9SF6bVWU4xWyll21yb2Eq9rhTRLgrlQ==","i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1778242580; c=relaxed/simple;\n\tbh=vBNO2Bvyb8M0KvGjxHVE5XxThYzHNdNL1nT/bjDLgeA=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=QqdjcyMakGK8xTAVqHHr+ZD17UFOk2drMxvlfL8rhXQmcbLqIQDoLe1RipQo3IW+UuBFqrEYS/mT0QuOzZSqFOffbKX8pxCHJ5jlJV7LKHyT+7kPnddptDJ0IrgPPWXU9x1PCr2XO7rPjiA0smclJCm1IFG6QZtokrwEyE9dD2c="],"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=e/jNtFAx; 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-16378-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=e/jNtFAx;\n arc=none smtp.client-ip=115.124.30.132"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=linux.alibaba.com; s=default;\n\tt=1778242569; h=From:To:Subject:Date:Message-ID:MIME-Version;\n\tbh=Pyydu/+mSA8+HVaiGjvimdSM19JdEkQ9zUvMzEWmW5w=;\n\tb=e/jNtFAxpfMViYJVnBTmqLtcsE57duadw9Mcs3XIWmQFCs42TddxZu3fuvEXhjx3nlnSGAiXgEQHXvUotC3GaqYxJU6Psn35Fwhc+uI/EljAKGkaB7uKpS9Ya6ZRC8cGDxxALFtswwTFRJ36ycQJky5QqI0Com4r+4K3jiSvTd8=","X-Alimail-AntiSpam":"\n AC=PASS;BC=-1|-1;BR=01201311R611e4;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_---0X2XQgqm_1778242568;","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 12/17] ext4: factor out ext4_might_init_block_bitmap()\n helper","Date":"Fri,  8 May 2026 20:15:34 +0800","Message-ID":"<20260508121539.4174601-13-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":"Extract the BLOCK_UNINIT initialization logic from ext4_mark_inode_used()\nand __ext4_new_inode() into a shared ext4_might_init_block_bitmap() helper.\n\nBoth call sites perform the same sequence: check EXT4_BG_BLOCK_UNINIT,\nread the block bitmap, dirty it, then clear the flag and establish the\ncorrect block bitmap checksum under the group lock.  The only difference\nis whether a journal handle is available (NULL during fast commit replay\nin ext4_mark_inode_used()).\n\nNo functional change.\n\nSigned-off-by: Baokun Li <libaokun@linux.alibaba.com>\n---\n fs/ext4/ialloc.c | 129 +++++++++++++++++++++--------------------------\n 1 file changed, 58 insertions(+), 71 deletions(-)","diff":"diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c\nindex 5896cdfb2ccf..90896b7f8c73 100644\n--- a/fs/ext4/ialloc.c\n+++ b/fs/ext4/ialloc.c\n@@ -756,6 +756,58 @@ static int find_inode_bit(struct super_block *sb, ext4_group_t group,\n \treturn 1;\n }\n \n+/*\n+ * If the block bitmap for @group is not yet initialized (EXT4_BG_BLOCK_UNINIT),\n+ * read it into memory, dirty it, and clear the UNINIT flag under the group lock\n+ * so that the on-disk checksum is established.  @handle may be NULL during fast\n+ * commit replay (no journal credits needed in that path).\n+ */\n+static int ext4_might_init_block_bitmap(handle_t *handle,\n+\t\t\t\t\tstruct super_block *sb,\n+\t\t\t\t\text4_group_t group,\n+\t\t\t\t\tstruct ext4_group_desc *gdp)\n+{\n+\tint err;\n+\tstruct buffer_head *block_bitmap_bh;\n+\n+\tif (!ext4_has_group_desc_csum(sb) ||\n+\t    !(gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)))\n+\t\treturn 0;\n+\n+\tblock_bitmap_bh = ext4_read_block_bitmap(sb, group);\n+\tif (IS_ERR(block_bitmap_bh))\n+\t\treturn PTR_ERR(block_bitmap_bh);\n+\n+\tif (handle) {\n+\t\tBUFFER_TRACE(block_bitmap_bh, \"get block bitmap access\");\n+\t\terr = ext4_journal_get_write_access(handle, sb,\n+\t\t\t\tblock_bitmap_bh, EXT4_JTR_NONE);\n+\t\tif (err)\n+\t\t\tgoto out_brelse;\n+\t}\n+\n+\tBUFFER_TRACE(block_bitmap_bh, \"dirty block bitmap\");\n+\terr = ext4_handle_dirty_metadata(handle, NULL, block_bitmap_bh);\n+\tif (!handle)\n+\t\tsync_dirty_buffer(block_bitmap_bh);\n+\n+\t/* recheck and clear flag under lock if we still need to */\n+\text4_lock_group(sb, group);\n+\tif (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {\n+\t\tgdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT);\n+\t\text4_free_group_clusters_set(sb, gdp,\n+\t\t\text4_free_clusters_after_init(sb, group, gdp));\n+\t\text4_block_bitmap_csum_set(sb, gdp, block_bitmap_bh);\n+\t\text4_group_desc_csum_set(sb, group, gdp);\n+\t}\n+\text4_unlock_group(sb, group);\n+\n+out_brelse:\n+\tbrelse(block_bitmap_bh);\n+\text4_std_error(sb, err);\n+\treturn err;\n+}\n+\n int ext4_mark_inode_used(struct super_block *sb, int ino, umode_t mode)\n {\n \tunsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count);\n@@ -801,38 +853,9 @@ int ext4_mark_inode_used(struct super_block *sb, int ino, umode_t mode)\n \t}\n \n \t/* We may have to initialize the block bitmap if it isn't already */\n-\tif (ext4_has_group_desc_csum(sb) &&\n-\t    gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {\n-\t\tstruct buffer_head *block_bitmap_bh;\n-\n-\t\tblock_bitmap_bh = ext4_read_block_bitmap(sb, group);\n-\t\tif (IS_ERR(block_bitmap_bh)) {\n-\t\t\terr = PTR_ERR(block_bitmap_bh);\n-\t\t\tgoto out;\n-\t\t}\n-\n-\t\tBUFFER_TRACE(block_bitmap_bh, \"dirty block bitmap\");\n-\t\terr = ext4_handle_dirty_metadata(NULL, NULL, block_bitmap_bh);\n-\t\tsync_dirty_buffer(block_bitmap_bh);\n-\n-\t\t/* recheck and clear flag under lock if we still need to */\n-\t\text4_lock_group(sb, group);\n-\t\tif (ext4_has_group_desc_csum(sb) &&\n-\t\t    (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT))) {\n-\t\t\tgdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT);\n-\t\t\text4_free_group_clusters_set(sb, gdp,\n-\t\t\t\text4_free_clusters_after_init(sb, group, gdp));\n-\t\t\text4_block_bitmap_csum_set(sb, gdp, block_bitmap_bh);\n-\t\t\text4_group_desc_csum_set(sb, group, gdp);\n-\t\t}\n-\t\text4_unlock_group(sb, group);\n-\t\tbrelse(block_bitmap_bh);\n-\n-\t\tif (err) {\n-\t\t\text4_std_error(sb, err);\n-\t\t\tgoto out;\n-\t\t}\n-\t}\n+\terr = ext4_might_init_block_bitmap(NULL, 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@@ -1154,45 +1177,9 @@ struct inode *__ext4_new_inode(struct mnt_idmap *idmap,\n \t}\n \n \t/* We may have to initialize the block bitmap if it isn't already */\n-\tif (ext4_has_group_desc_csum(sb) &&\n-\t    gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {\n-\t\tstruct buffer_head *block_bitmap_bh;\n-\n-\t\tblock_bitmap_bh = ext4_read_block_bitmap(sb, group);\n-\t\tif (IS_ERR(block_bitmap_bh)) {\n-\t\t\terr = PTR_ERR(block_bitmap_bh);\n-\t\t\tgoto out;\n-\t\t}\n-\t\tBUFFER_TRACE(block_bitmap_bh, \"get block bitmap access\");\n-\t\terr = ext4_journal_get_write_access(handle, sb, block_bitmap_bh,\n-\t\t\t\t\t\t    EXT4_JTR_NONE);\n-\t\tif (err) {\n-\t\t\tbrelse(block_bitmap_bh);\n-\t\t\text4_std_error(sb, err);\n-\t\t\tgoto out;\n-\t\t}\n-\n-\t\tBUFFER_TRACE(block_bitmap_bh, \"dirty block bitmap\");\n-\t\terr = ext4_handle_dirty_metadata(handle, NULL, block_bitmap_bh);\n-\n-\t\t/* recheck and clear flag under lock if we still need to */\n-\t\text4_lock_group(sb, group);\n-\t\tif (ext4_has_group_desc_csum(sb) &&\n-\t\t    (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT))) {\n-\t\t\tgdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT);\n-\t\t\text4_free_group_clusters_set(sb, gdp,\n-\t\t\t\text4_free_clusters_after_init(sb, group, gdp));\n-\t\t\text4_block_bitmap_csum_set(sb, gdp, block_bitmap_bh);\n-\t\t\text4_group_desc_csum_set(sb, group, gdp);\n-\t\t}\n-\t\text4_unlock_group(sb, group);\n-\t\tbrelse(block_bitmap_bh);\n-\n-\t\tif (err) {\n-\t\t\text4_std_error(sb, err);\n-\t\t\tgoto out;\n-\t\t}\n-\t}\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","prefixes":["RFC","12/17"]}