{"id":2215726,"url":"http://patchwork.ozlabs.org/api/patches/2215726/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ext4/patch/20260325072850.3997161-9-yi.zhang@huaweicloud.com/","project":{"id":8,"url":"http://patchwork.ozlabs.org/api/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":"<20260325072850.3997161-9-yi.zhang@huaweicloud.com>","list_archive_url":null,"date":"2026-03-25T07:28:47","name":"[v2,08/10] ext4: pass allocate range as loff_t to ext4_alloc_file_blocks()","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"54f9b0ae02f6cc7d77466161e0def3fe82e4a97b","submitter":{"id":85428,"url":"http://patchwork.ozlabs.org/api/people/85428/?format=json","name":"Zhang Yi","email":"yi.zhang@huaweicloud.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-ext4/patch/20260325072850.3997161-9-yi.zhang@huaweicloud.com/mbox/","series":[{"id":497391,"url":"http://patchwork.ozlabs.org/api/series/497391/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ext4/list/?series=497391","date":"2026-03-25T07:28:44","name":"ext4: refactor partial block zero-out for iomap conversion","version":2,"mbox":"http://patchwork.ozlabs.org/series/497391/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2215726/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2215726/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <SRS0=RDt0=BZ=vger.kernel.org=linux-ext4+bounces-15333-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 spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org\n (client-ip=150.107.74.76; helo=mail.ozlabs.org;\n envelope-from=srs0=rdt0=bz=vger.kernel.org=linux-ext4+bounces-15333-patchwork-incoming=ozlabs.org@ozlabs.org;\n receiver=patchwork.ozlabs.org)","gandalf.ozlabs.org;\n arc=pass smtp.remote-ip=172.234.253.10 arc.chain=subspace.kernel.org","gandalf.ozlabs.org;\n dmarc=none (p=none dis=none) header.from=huaweicloud.com","gandalf.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=172.234.253.10; helo=sea.lore.kernel.org;\n envelope-from=linux-ext4+bounces-15333-patchwork-incoming=ozlabs.org@vger.kernel.org;\n receiver=ozlabs.org)","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=45.249.212.56","smtp.subspace.kernel.org;\n dmarc=none (p=none dis=none) header.from=huaweicloud.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=huaweicloud.com"],"Received":["from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76])\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 4fgdyk6N8dz1y1G\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 25 Mar 2026 18:37:02 +1100 (AEDT)","from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3])\n\tby gandalf.ozlabs.org (Postfix) with ESMTP id 4fgdyk5xbFz4wHj\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 25 Mar 2026 18:37:02 +1100 (AEDT)","by gandalf.ozlabs.org (Postfix)\n\tid 4fgdyk5qs7z4wHf; Wed, 25 Mar 2026 18:37:02 +1100 (AEDT)","from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])\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 4fgdyg3G69z4wH2\n\tfor <patchwork-incoming@ozlabs.org>; Wed, 25 Mar 2026 18:36:59 +1100 (AEDT)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id 8D3E930CAAAA\n\tfor <patchwork-incoming@ozlabs.org>; Wed, 25 Mar 2026 07:34:20 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id C33B7372B39;\n\tWed, 25 Mar 2026 07:33:49 +0000 (UTC)","from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com\n [45.249.212.56])\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 3FECC351C24;\n\tWed, 25 Mar 2026 07:33:47 +0000 (UTC)","from mail.maildlp.com (unknown [172.19.163.177])\n\tby dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4fgdt53V7dzKHMZg;\n\tWed, 25 Mar 2026 15:33:01 +0800 (CST)","from mail02.huawei.com (unknown [10.116.40.112])\n\tby mail.maildlp.com (Postfix) with ESMTP id CFA5D40539;\n\tWed, 25 Mar 2026 15:33:39 +0800 (CST)","from huaweicloud.com (unknown [10.50.85.155])\n\tby APP1 (Coremail) with SMTP id cCh0CgAHC9vFj8NpuR6cCA--.49898S12;\n\tWed, 25 Mar 2026 15:33:39 +0800 (CST)"],"ARC-Seal":["i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1774424222; cv=pass;\n\tb=yUQrJAUHR2AUcM1JJwm56Xz2fkJBp88nIjRSKYvAXnuj2XyoGZZmd5r0N0ndW3fRUO/HhDGM2VtyaiaiqtuQ9OrOKb2J3Int9SBGTdYGosHxsGGMLwQS6KRThkC/ByFYMxSDpJfjoJQmMsKOcpAnsVxHaBIecV0+2X9/Z/QjmS+8Om2fW7eZqXfCv4l9rZ1e5TrJftWTGNS1oww2lwkcvF5j+CY7dM0sfYJjj6yfuGlPAmigZsE5fuk6BQ7F4BuyFo745h8L2xnHGF4jHzHNDT9lO7xJrmOquH0zSpF7mFupP/Le7MKyMs6d0iRp9hWtF+J2tCw3AJmq25hy9aNUSQ==","i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1774424029; cv=none;\n b=DZmAXdZRpqWnHnDJ1WFUuAA/FOwaCx/JGhUGA/BVAZ8RZr+sstPDaksQws5Mgkd8ILUF0H/kxzI9X5SaDNYwFyq8tSphW6piEZG8yqw5zvCQanUZs79DYyRZKQJffjPbIV5VBqWV6H1LfpQfv6XRvoSFLUV50E+Hv+P6W8k66Yw="],"ARC-Message-Signature":["i=2; a=rsa-sha256; d=ozlabs.org; s=201707;\n\tt=1774424222; c=relaxed/relaxed;\n\tbh=7Nt4YZbJcOVe5o7x11uh9j0TCspFsj1RrbnDXVGo/pw=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=SkaXH+JEnTO9oGbh5+52q0uYjnhkAfqYDBGZlsUg1XqwS6ehnpHHX/Sxt1IyBFuWF24W6JxJeeoPDCmpp9eOj2iHENLPePkaEadAEfhuFBv5J6npMaTaB6uVMn9e5XYCBG+6nrb+SXKRBDrl7rhAMnEMYViGW6eOiY94j7ZLQRPSRlKU35TFZj/JRLWPnnhjnqOO5eky1CHTt7NDd3CAaBdi6m7Cy3thltz6QZABxCXohjARuyAPIgnOxQIM54Sa77lMCaeHHVrNMM43/+fsNJctw0Lcb7v25MFGRwGXQo0S6t3LBBNc6fz0OYfMPxe/OSZ+OQuoeDqvciXNj78Bkg==","i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1774424029; c=relaxed/simple;\n\tbh=XmFUjlxOZHR+uzDYaPjlfunzjAttkhEg3O4QZ+98J+A=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=k4hprNNqfktlRT4ki7qsuuZm/KchTOOzQ6FH5GeT+gJ9zbpazBDCt0+ESzfTjq+kXP7vSjAdvxbxxZN4QVpjlVVUl+vmww+VrM++bj/H/+u0jMMyverNJpPdoqngBoRk3KCL8wDNLFhappgQvk2fH9Ix0RRaMs813fG7bsAjhu0="],"ARC-Authentication-Results":["i=2; gandalf.ozlabs.org;\n dmarc=none (p=none dis=none) header.from=huaweicloud.com;\n spf=pass (client-ip=172.234.253.10; helo=sea.lore.kernel.org;\n envelope-from=linux-ext4+bounces-15333-patchwork-incoming=ozlabs.org@vger.kernel.org;\n receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org","i=1; smtp.subspace.kernel.org;\n dmarc=none (p=none dis=none) header.from=huaweicloud.com;\n spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56"],"From":"Zhang Yi <yi.zhang@huaweicloud.com>","To":"linux-ext4@vger.kernel.org","Cc":"linux-fsdevel@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org,\n\ttytso@mit.edu,\n\tadilger.kernel@dilger.ca,\n\tjack@suse.cz,\n\tojaswin@linux.ibm.com,\n\tritesh.list@gmail.com,\n\tlibaokun@linux.alibaba.com,\n\tyi.zhang@huawei.com,\n\tyi.zhang@huaweicloud.com,\n\tyizhang089@gmail.com,\n\tyangerkun@huawei.com,\n\tyukuai@fnnas.com","Subject":"[PATCH v2 08/10] ext4: pass allocate range as loff_t to\n ext4_alloc_file_blocks()","Date":"Wed, 25 Mar 2026 15:28:47 +0800","Message-ID":"<20260325072850.3997161-9-yi.zhang@huaweicloud.com>","X-Mailer":"git-send-email 2.52.0","In-Reply-To":"<20260325072850.3997161-1-yi.zhang@huaweicloud.com>","References":"<20260325072850.3997161-1-yi.zhang@huaweicloud.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-CM-TRANSID":"cCh0CgAHC9vFj8NpuR6cCA--.49898S12","X-Coremail-Antispam":"1UD129KBjvJXoWxtrWfuF1kCryUKFyUZrW5Wrg_yoW7tFWrpF\n\tZ8Zr15GF4fWFyv9w40kwsrXr1fK3ZrKrWUXryagryFqa4DtF1xtan0yFW0gFySgrZ7Zrs0\n\tvF4Ykry7Ga1UG3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2\n\t9KBjDU0xBIdaVrnRJUUUmS14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0\n\trVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI\n\tkIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2\n\tz4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F\n\t4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq\n\t3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7\n\tIYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U\n\tM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2\n\tkIc2xKxwCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkE\n\tbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67\n\tAF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI\n\t42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF\n\t4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBI\n\tdaVFxhVjvjDU0xZFpf9x0JUWMKtUUUUU=","X-CM-SenderInfo":"d1lo6xhdqjqx5xdzvxpfor3voofrz/","X-Spam-Status":"No, score=-1.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,\n\tDMARC_MISSING,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,\n\tSPF_HELO_NONE,SPF_PASS autolearn=disabled version=4.0.1","X-Spam-Checker-Version":"SpamAssassin 4.0.1 (2024-03-25) on gandalf.ozlabs.org"},"content":"From: Zhang Yi <yi.zhang@huawei.com>\n\nChange ext4_alloc_file_blocks() to accept offset and len in byte\ngranularity instead of block granularity. This allows callers to pass\nbyte offsets and lengths directly, and this prepares for moving the\next4_zero_partial_blocks() call from the while(len) loop for unaligned\nappend writes, where it only needs to be invoked once before doing block\nallocation.\n\nSigned-off-by: Zhang Yi <yi.zhang@huawei.com>\nReviewed-by: Jan Kara <jack@suse.cz>\n---\n fs/ext4/extents.c | 53 ++++++++++++++++++++---------------------------\n 1 file changed, 22 insertions(+), 31 deletions(-)","diff":"diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c\nindex 753a0f3418a4..57a686b600d9 100644\n--- a/fs/ext4/extents.c\n+++ b/fs/ext4/extents.c\n@@ -4542,15 +4542,15 @@ int ext4_ext_truncate(handle_t *handle, struct inode *inode)\n \treturn err;\n }\n \n-static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,\n-\t\t\t\t  ext4_lblk_t len, loff_t new_size,\n-\t\t\t\t  int flags)\n+static int ext4_alloc_file_blocks(struct file *file, loff_t offset, loff_t len,\n+\t\t\t\t  loff_t new_size, int flags)\n {\n \tstruct inode *inode = file_inode(file);\n \thandle_t *handle;\n \tint ret = 0, ret2 = 0, ret3 = 0;\n \tint retries = 0;\n \tint depth = 0;\n+\text4_lblk_t len_lblk;\n \tstruct ext4_map_blocks map;\n \tunsigned int credits;\n \tloff_t epos, old_size = i_size_read(inode);\n@@ -4558,14 +4558,14 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,\n \tbool alloc_zero = false;\n \n \tBUG_ON(!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS));\n-\tmap.m_lblk = offset;\n-\tmap.m_len = len;\n+\tmap.m_lblk = offset >> blkbits;\n+\tmap.m_len = len_lblk = EXT4_MAX_BLOCKS(len, offset, blkbits);\n \t/*\n \t * Don't normalize the request if it can fit in one extent so\n \t * that it doesn't get unnecessarily split into multiple\n \t * extents.\n \t */\n-\tif (len <= EXT_UNWRITTEN_MAX_LEN)\n+\tif (len_lblk <= EXT_UNWRITTEN_MAX_LEN)\n \t\tflags |= EXT4_GET_BLOCKS_NO_NORMALIZE;\n \n \t/*\n@@ -4582,16 +4582,16 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,\n \t/*\n \t * credits to insert 1 extent into extent tree\n \t */\n-\tcredits = ext4_chunk_trans_blocks(inode, len);\n+\tcredits = ext4_chunk_trans_blocks(inode, len_lblk);\n \tdepth = ext_depth(inode);\n \n retry:\n-\twhile (len) {\n+\twhile (len_lblk) {\n \t\t/*\n \t\t * Recalculate credits when extent tree depth changes.\n \t\t */\n \t\tif (depth != ext_depth(inode)) {\n-\t\t\tcredits = ext4_chunk_trans_blocks(inode, len);\n+\t\t\tcredits = ext4_chunk_trans_blocks(inode, len_lblk);\n \t\t\tdepth = ext_depth(inode);\n \t\t}\n \n@@ -4648,7 +4648,7 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,\n \t\t}\n \n \t\tmap.m_lblk += ret;\n-\t\tmap.m_len = len = len - ret;\n+\t\tmap.m_len = len_lblk = len_lblk - ret;\n \t}\n \tif (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))\n \t\tgoto retry;\n@@ -4665,11 +4665,9 @@ static long ext4_zero_range(struct file *file, loff_t offset,\n {\n \tstruct inode *inode = file_inode(file);\n \thandle_t *handle = NULL;\n-\tloff_t new_size = 0;\n+\tloff_t align_start, align_end, new_size = 0;\n \tloff_t end = offset + len;\n-\text4_lblk_t start_lblk, end_lblk;\n \tunsigned int blocksize = i_blocksize(inode);\n-\tunsigned int blkbits = inode->i_blkbits;\n \tint ret, flags, credits;\n \n \ttrace_ext4_zero_range(inode, offset, len, mode);\n@@ -4690,11 +4688,8 @@ static long ext4_zero_range(struct file *file, loff_t offset,\n \tflags = EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT;\n \t/* Preallocate the range including the unaligned edges */\n \tif (!IS_ALIGNED(offset | end, blocksize)) {\n-\t\text4_lblk_t alloc_lblk = offset >> blkbits;\n-\t\text4_lblk_t len_lblk = EXT4_MAX_BLOCKS(len, offset, blkbits);\n-\n-\t\tret = ext4_alloc_file_blocks(file, alloc_lblk, len_lblk,\n-\t\t\t\t\t     new_size, flags);\n+\t\tret = ext4_alloc_file_blocks(file, offset, len, new_size,\n+\t\t\t\t\t     flags);\n \t\tif (ret)\n \t\t\treturn ret;\n \t}\n@@ -4709,18 +4704,17 @@ static long ext4_zero_range(struct file *file, loff_t offset,\n \t\treturn ret;\n \n \t/* Zero range excluding the unaligned edges */\n-\tstart_lblk = EXT4_B_TO_LBLK(inode, offset);\n-\tend_lblk = end >> blkbits;\n-\tif (end_lblk > start_lblk) {\n-\t\text4_lblk_t zero_blks = end_lblk - start_lblk;\n-\n+\talign_start = round_up(offset, blocksize);\n+\talign_end = round_down(end, blocksize);\n+\tif (align_end > align_start) {\n \t\tif (mode & FALLOC_FL_WRITE_ZEROES)\n \t\t\tflags = EXT4_GET_BLOCKS_CREATE_ZERO | EXT4_EX_NOCACHE;\n \t\telse\n \t\t\tflags |= (EXT4_GET_BLOCKS_CONVERT_UNWRITTEN |\n \t\t\t\t  EXT4_EX_NOCACHE);\n-\t\tret = ext4_alloc_file_blocks(file, start_lblk, zero_blks,\n-\t\t\t\t\t     new_size, flags);\n+\t\tret = ext4_alloc_file_blocks(file, align_start,\n+\t\t\t\t\t     align_end - align_start, new_size,\n+\t\t\t\t\t     flags);\n \t\tif (ret)\n \t\t\treturn ret;\n \t}\n@@ -4768,15 +4762,11 @@ static long ext4_do_fallocate(struct file *file, loff_t offset,\n \tstruct inode *inode = file_inode(file);\n \tloff_t end = offset + len;\n \tloff_t new_size = 0;\n-\text4_lblk_t start_lblk, len_lblk;\n \tint ret;\n \n \ttrace_ext4_fallocate_enter(inode, offset, len, mode);\n \tWARN_ON_ONCE(!inode_is_locked(inode));\n \n-\tstart_lblk = offset >> inode->i_blkbits;\n-\tlen_lblk = EXT4_MAX_BLOCKS(len, offset, inode->i_blkbits);\n-\n \t/* We only support preallocation for extent-based files only. */\n \tif (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) {\n \t\tret = -EOPNOTSUPP;\n@@ -4791,7 +4781,7 @@ static long ext4_do_fallocate(struct file *file, loff_t offset,\n \t\t\tgoto out;\n \t}\n \n-\tret = ext4_alloc_file_blocks(file, start_lblk, len_lblk, new_size,\n+\tret = ext4_alloc_file_blocks(file, offset, len, new_size,\n \t\t\t\t     EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT);\n \tif (ret)\n \t\tgoto out;\n@@ -4801,7 +4791,8 @@ static long ext4_do_fallocate(struct file *file, loff_t offset,\n \t\t\t\t\tEXT4_I(inode)->i_sync_tid);\n \t}\n out:\n-\ttrace_ext4_fallocate_exit(inode, offset, len_lblk, ret);\n+\ttrace_ext4_fallocate_exit(inode, offset,\n+\t\t\tEXT4_MAX_BLOCKS(len, offset, inode->i_blkbits), ret);\n \treturn ret;\n }\n \n","prefixes":["v2","08/10"]}