From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 744012EA749; Fri, 21 Nov 2025 09:16:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716610; cv=none; b=KHlZjSgGuDbE8j+bFF9D1o1GH6n0G7rSonqP0+8uTLOppRHseeUpbjcESZNf8CR0c6mB8UgeSCIEMGiAMKg8f9Cyfgm4oTFPeQ1UYm8YWoYJ5hPcTTqIiAIJG4qh5ryqKteHSPZpZDARkwoiNhGDYcNMu9f/3q99wY2vXGTw890= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716610; c=relaxed/simple; bh=JdhqQ7ElDQWQRGAwHRwuVueaZCVisYEGz/PhfYBlF1o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WHwDzKsXCKof0geugKYds7zOIiV3/uITVtBJv2UID2VTqh+2ITQz5sOTFTRILM7uReqpyRhwowCY4833dWtJQ4iSLuXrHpKUJMVtjBQvHcqxKfg4iK+HeWRofoKfTET61IzSFzjoMKimzm1nGGc0IP8QRctD1M6rHT9DYb9vD5c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dCV2M4wppzKHMtc; Fri, 21 Nov 2025 17:16:11 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id A54141A1449; Fri, 21 Nov 2025 17:16:42 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S5; Fri, 21 Nov 2025 17:16:42 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 01/24] ext4: remove page offset calculation in ext4_block_zero_page_range() Date: Fri, 21 Nov 2025 17:06:31 +0800 Message-Id: <20251121090654.631996-2-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S5 X-Coremail-Antispam: 1UD129KBjvdXoWrZFW5uw1fAr1rZr1UZF1UJrb_yoWkWwb_A3 yv9w4rWw1rJrnakwn8A3yYqr1vka18Cr15uFn8tryrXFWrZFs5J3WvgryY9rs8WF47urs8 ArykXF43Kr9F9jkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbP8FF20E14v26rWj6s0DM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGwA2048vs2IY02 0Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM2 8EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AI xVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20x vE14v26r1Y6r17McIj6I8E87Iv67AKxVW8Jr0_Cr1UMcvjeVCFs4IE7xkEbVWUJVW8JwAC jcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2Y2ka0x kIwI1lw4CEc2x0rVAKj4xxMxkF7I0En4kS14v26r1q6r43MxAIw28IcxkI7VAKI48JMxC2 0s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI 0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE 14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20x vaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8 JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUjIztUUUUUU== X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQATBWkf35kfDwAAs3 Content-Type: text/plain; charset="utf-8" From: Zhihao Cheng For bs <=3D ps scenarios, calculating the offset within the block is sufficient. For bs > ps, an initial page offset calculation can lead to incorrect behavior. Thus this redundant calculation has been removed. Signed-off-by: Zhihao Cheng Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo --- fs/ext4/inode.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 32d9f0b36c33..dd8726a9046b 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4165,9 +4165,8 @@ static int ext4_block_zero_page_range(handle_t *handl= e, struct address_space *mapping, loff_t from, loff_t length) { struct inode *inode =3D mapping->host; - unsigned offset =3D from & (PAGE_SIZE-1); unsigned blocksize =3D inode->i_sb->s_blocksize; - unsigned max =3D blocksize - (offset & (blocksize - 1)); + unsigned int max =3D blocksize - (from & (blocksize - 1)); =20 /* * correct length if it does not fall between --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58C512E7166; Fri, 21 Nov 2025 09:16:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716611; cv=none; b=FpyGx1QFqJh3qkXlD9MyyGkq2XoT3O2V4YjYPsPen0nVO+xLpM9xtTBVZBeaOxYn0OS8QMiIiDiAZZiSqb+QL4CGy4/KF1SCN5V4nMULc6pgRN1tvKt6UmuOeqvyhIlE77bXyDE6q4pYKiF42jh1A/viw8yj5CykWOjxdy6iBxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716611; c=relaxed/simple; bh=zcTOqT/cXe7/nFM0ZCqng0W4nnTJQN3tMQx1KphzHIY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EdrbXpiDPRcq/mlphnXMQRf6gZ+WzZOUmpYUg1DsoFZ7Iui1PUggiYgbqoQuGHmB7qMQWGVn8Z+uN+jlGUkVEl8DcrGreocJuEn+SZkxuEhKRx2MLibrTSFgBimtuAbdHbMdSHPA3Yvw+8shIpQMT5virvJJOz9jsz4uDqUg1Xk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dCV273XQczYQvFy; Fri, 21 Nov 2025 17:15:59 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id BDFEB1A07BB; Fri, 21 Nov 2025 17:16:42 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S6; Fri, 21 Nov 2025 17:16:42 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 02/24] ext4: remove page offset calculation in ext4_block_truncate_page() Date: Fri, 21 Nov 2025 17:06:32 +0800 Message-Id: <20251121090654.631996-3-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S6 X-Coremail-Antispam: 1UD129KBjvJXoW7Kw1fJFy7WrWfAr1kJr48Xrb_yoW8Gry7pF yUK3y8ur17uFyjga1IvF1DXryxK3ZrGFWUXFWjq345WryIqF1fKrnrKwsYqF4jqrWxXayD XF4YyrWxZa1UA3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQj14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2 IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxGrwCF x2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14 v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY 67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2 IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdManUUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQATBWkf35kfEAAAso Content-Type: text/plain; charset="utf-8" From: Baokun Li For bs <=3D ps scenarios, calculating the offset within the block is sufficient. For bs > ps, an initial page offset calculation can lead to incorrect behavior. Thus this redundant calculation has been removed. Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo --- fs/ext4/inode.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index dd8726a9046b..c956aff677ac 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4191,7 +4191,6 @@ static int ext4_block_zero_page_range(handle_t *handl= e, static int ext4_block_truncate_page(handle_t *handle, struct address_space *mapping, loff_t from) { - unsigned offset =3D from & (PAGE_SIZE-1); unsigned length; unsigned blocksize; struct inode *inode =3D mapping->host; @@ -4200,8 +4199,8 @@ static int ext4_block_truncate_page(handle_t *handle, if (IS_ENCRYPTED(inode) && !fscrypt_has_encryption_key(inode)) return 0; =20 - blocksize =3D inode->i_sb->s_blocksize; - length =3D blocksize - (offset & (blocksize - 1)); + blocksize =3D i_blocksize(inode); + length =3D blocksize - (from & (blocksize - 1)); =20 return ext4_block_zero_page_range(handle, mapping, from, length); } --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D40F2DC761; Fri, 21 Nov 2025 09:16:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716609; cv=none; b=lh6IhGaic2pCemH3gJr8KNPp+c4i1fTDoxcKJqF7p8B9/rDt4oo5gBW5jISq2IbALi5Sm12JVzyYAqJ3jUSDrscieU4I147rrzYqpPoN4/Ko3yZ/n0JxqyY7hJPrMalt2qrAJ4yzpr+i8iDpfi65jcULUTu01x53qI2+ro+N2oE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716609; c=relaxed/simple; bh=Jx+c1in1ewd1Dt2A5qNro6tjPX49d1cFqnt8faG1Alg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Pa29VYH930YB8CPhaWCo+os9v2m3tc9kgBq9sqLSY7d1PaDk5VtBQLEamd9jH0xta9kZBK7S7+cVqiotcPT4Hq9PBgAAF5JTueVlHsuasAcCBzQi91tVkObu+ZIQYZVZApW3bZxnkoYi0sV9At4cTJ28NVgXQqZ21PUV7XSlAOc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dCV274PcxzYQvGF; Fri, 21 Nov 2025 17:15:59 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id DB9E11A01A3; Fri, 21 Nov 2025 17:16:42 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S7; Fri, 21 Nov 2025 17:16:42 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 03/24] ext4: remove PAGE_SIZE checks for rec_len conversion Date: Fri, 21 Nov 2025 17:06:33 +0800 Message-Id: <20251121090654.631996-4-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S7 X-Coremail-Antispam: 1UD129KBjvJXoW7AFW3CFW8GFW5JFy5Jr1UZFb_yoW8ArW3pF 43GryUGrWYvF1Uuay2qF4rGa4Ikw1fKw1UJa9xW3yrWFy7Xr4fXr9agFyFqFW8tFZaqFWU Xan8JFWftr43AaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQ014x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JrWl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2 IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxGrwCF x2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14 v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY 67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI 8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v2 6r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUo6wZDUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgATBWkf34sfEgADs4 Content-Type: text/plain; charset="utf-8" From: Baokun Li Previously, ext4_rec_len_(to|from)_disk only performed complex rec_len conversions when PAGE_SIZE >=3D 65536 to reduce complexity. However, we are soon to support file system block sizes greater than page size, which makes these conditional checks unnecessary. Thus, these checks are now removed. Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo --- fs/ext4/ext4.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 9f127aedbaee..3d18e6bf43cf 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2475,28 +2475,19 @@ static inline unsigned int ext4_dir_rec_len(__u8 na= me_len, return (rec_len & ~EXT4_DIR_ROUND); } =20 -/* - * If we ever get support for fs block sizes > page_size, we'll need - * to remove the #if statements in the next two functions... - */ static inline unsigned int ext4_rec_len_from_disk(__le16 dlen, unsigned blocksize) { unsigned len =3D le16_to_cpu(dlen); =20 -#if (PAGE_SIZE >=3D 65536) if (len =3D=3D EXT4_MAX_REC_LEN || len =3D=3D 0) return blocksize; return (len & 65532) | ((len & 3) << 16); -#else - return len; -#endif } =20 static inline __le16 ext4_rec_len_to_disk(unsigned len, unsigned blocksize) { BUG_ON((len > blocksize) || (blocksize > (1 << 18)) || (len & 3)); -#if (PAGE_SIZE >=3D 65536) if (len < 65536) return cpu_to_le16(len); if (len =3D=3D blocksize) { @@ -2506,9 +2497,6 @@ static inline __le16 ext4_rec_len_to_disk(unsigned le= n, unsigned blocksize) return cpu_to_le16(0); } return cpu_to_le16((len & 65532) | ((len >> 16) & 3)); -#else - return cpu_to_le16(len); -#endif } =20 /* --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A5572E8B66; Fri, 21 Nov 2025 09:16:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716608; cv=none; b=k10+YQjHZgC7FQ9U33R82EL1iuN2Ip9Zs3HFu3liIW/xGPnRAnKgN71rfVvkPEiKDvFn+HWH4w/wA/kqfWFWvrJtBDDBRSU8wLM1kPSYVKG9RRGJ1mz99IA/pSolT/9c39UxZwpQnApUBQE2+uChopMnmkOP8nCvAVuhTy0kjbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716608; c=relaxed/simple; bh=XgQvpJ6GqS3mrzphP4vfzaJL3vWA0LYD80eFbI67RuI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HJFokTMRqbrc9ZVV0uChqsWBnknLrpz/k7X1EYc+kccDXOB7MuNZtJEUEcdZNWD1JT9N3N7j0qLngGKKLT+Yv/YekJuZhPLCoUkpIUDEIOIOBnXcPsUH9jAVu3pWOEwvmhD0Ts96vpfctPXu7Um1m4K2hE09W0/srOtqVShC+s8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dCV274p6dzYQvGT; Fri, 21 Nov 2025 17:15:59 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id E72231A0BC1; Fri, 21 Nov 2025 17:16:42 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S8; Fri, 21 Nov 2025 17:16:42 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 04/24] ext4: make ext4_punch_hole() support large block size Date: Fri, 21 Nov 2025 17:06:34 +0800 Message-Id: <20251121090654.631996-5-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S8 X-Coremail-Antispam: 1UD129KBjvJXoW7WrWxWw4xXryDGw17WF1xZrb_yoW8Xw1kpr y3G348urWUWayqkF4jg3W8Zw1xtana9w4UXFWUZr4UJr98Ja4Skr12gry0qa1vyrZ2yryF qrsrtryfZF13A3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQ214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK8V AvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E 14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUo0PSUUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgATBWkf34sfEwAAs6 Content-Type: text/plain; charset="utf-8" From: Baokun Li When preparing for bs > ps support, clean up unnecessary PAGE_SIZE references in ext4_punch_hole(). Previously, when a hole extended beyond i_size, we aligned the hole end upwards to PAGE_SIZE to handle partial folio invalidation. Now that truncate_inode_pages_range() already handles partial folio invalidation correctly, this alignment is no longer required. However, to save pointless tail block zeroing, we still keep rounding up to the block size here. In addition, as Honza pointed out, when the hole end equals i_size, it should also be rounded up to the block size. This patch fixes that as well. Suggested-by: Jan Kara Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo --- fs/ext4/inode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index c956aff677ac..d11df0f4c546 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4406,10 +4406,10 @@ int ext4_punch_hole(struct file *file, loff_t offse= t, loff_t length) =20 /* * If the hole extends beyond i_size, set the hole to end after - * the page that contains i_size. + * the block that contains i_size to save pointless tail block zeroing. */ - if (end > inode->i_size) - end =3D round_up(inode->i_size, PAGE_SIZE); + if (end >=3D inode->i_size) + end =3D round_up(inode->i_size, sb->s_blocksize); if (end > max_end) end =3D max_end; length =3D end - offset; --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 745922EF65B; Fri, 21 Nov 2025 09:16:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716608; cv=none; b=XjpgxPdPe/CMtuB3fJ2qvfIQ+9VXDkp+aT4cJSr454xbR/7Fq7IHFw3V6PwO+T/L4/cE7PsEciiehWhyNx00tfZUKKLBN4F/SmaaDalx/QNc4buk+J+i5QcqtYW70YQWy6o6yZJEw2dnx3YHrL09l4RLZDyDAVAo7lttM7J0VuE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716608; c=relaxed/simple; bh=hWC3P5vWjbyLSQ/0WYv8l+fw09eD6kixda6WLpVgMK8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HTMQJ8JZE2WfImKE3D8OAuKyBZn5w+GCKLgu7Oq02bY9nkE8ZcaKB3FoSOq9d7w1NYkmaM7SD9xQNh2MHZSvkGvbm3msu+SXsPoaUlIEvwcLkTuEqOZP8feH5DKxfWB7RtCZYyOpkAhrKdaCpmbY700GKy0W21j8Qw/KurBmqHI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dCV2N0F9JzKHMvC; Fri, 21 Nov 2025 17:16:12 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 0093D1A1449; Fri, 21 Nov 2025 17:16:42 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S9; Fri, 21 Nov 2025 17:16:42 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 05/24] ext4: enable DIOREAD_NOLOCK by default for BS > PS as well Date: Fri, 21 Nov 2025 17:06:35 +0800 Message-Id: <20251121090654.631996-6-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S9 X-Coremail-Antispam: 1UD129KBjvdXoW7XF18GFWrWFykGry8Kr47twb_yoWftrcEvF WfJrW7Gr4rJw1S9a4rua1UJFs0kw4I9r1rGws5tr15X3ZIqrWxX34qqrZ5GF15uF4rXrWf Ars5XF13KryagjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbm8FF20E14v26rWj6s0DM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAVCq3wA2048vs2 IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28E F7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr 1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVW8Jr0_Cr1UMcvjeVCFs4IE7xkEbVWUJVW8 JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2Y2 ka0xkIwI1lw4CEc2x0rVAKj4xxMxkF7I0En4kS14v26r1q6r43MxAIw28IcxkI7VAKI48J MxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwV AFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv2 0xvE14v26r1I6r4UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF04k26c xKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAF wI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdsqAUUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgATBWkf34sfFAAAs9 Content-Type: text/plain; charset="utf-8" From: Baokun Li The dioread_nolock related processes already support large folio, so dioread_nolock is enabled by default regardless of whether the blocksize is less than, equal to, or greater than PAGE_SIZE. Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo --- fs/ext4/super.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 707f890d674e..f39679892e71 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -4392,8 +4392,7 @@ static void ext4_set_def_opts(struct super_block *sb, ((def_mount_opts & EXT4_DEFM_NODELALLOC) =3D=3D 0)) set_opt(sb, DELALLOC); =20 - if (sb->s_blocksize <=3D PAGE_SIZE) - set_opt(sb, DIOREAD_NOLOCK); + set_opt(sb, DIOREAD_NOLOCK); } =20 static int ext4_handle_clustersize(struct super_block *sb) --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAF372727ED; Fri, 21 Nov 2025 09:16:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716610; cv=none; b=gv6yAHagZ0QlSgHDMe2ctT47JlAkYYQ7I0sXXmalYJ6emdwYFWTk91x4gI7tbZoQPzsNeVUvGQiaP5vIVNMvpuzeKlxVpoGfoJdhOG1Q+U/BKQ4MXj0GnMLkIFFEzPGw6MHRPzFsqW1ffFR7vvHgzqrSE7/BACxMRUxlnJ/UNkg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716610; c=relaxed/simple; bh=iXC0/0xQeXYSMuZnKkDHPcsnq9rffMXGb7xGo5Rz7hE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=p9U3lgHwXxJvKPbCYibuoyepG7t670/q/nz4b6qDf246Z7Gkdy9ciir/WfE3JGl8rfKF9aWorJoA87I7fFyVxTzdgnMEMsw4OD+B2CqHYNDGd37LRtyTL4WPouP6TdfisPr5YgxCvrPSga0bXvoB+GNj71Zalzm5dbkmg+S2lNQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dCV2N0tF9zKHMvH; Fri, 21 Nov 2025 17:16:12 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 1666B1A195F; Fri, 21 Nov 2025 17:16:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S10; Fri, 21 Nov 2025 17:16:42 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com, Pankaj Raghav Subject: [PATCH v4 06/24] ext4: introduce s_min_folio_order for future BS > PS support Date: Fri, 21 Nov 2025 17:06:36 +0800 Message-Id: <20251121090654.631996-7-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S10 X-Coremail-Antispam: 1UD129KBjvJXoWxJrWfJFyxtr4xKFyrCw13CFg_yoW8Kw45pF nxCFyfGFW8Zry8uFs2gFsrX34rKay8KayUXrWav3W5urWaq3409r1DtF15AFWYqrW8XFWS qF1UKry7Cr13CrDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQ214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK8V AvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E 14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUo0PSUUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQATBWkf35kfEgAAsq Content-Type: text/plain; charset="utf-8" From: Baokun Li This commit introduces the s_min_folio_order field to the ext4_sb_info structure. This field will store the minimum folio order required by the current filesystem, laying groundwork for future support of block sizes greater than PAGE_SIZE. Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Pankaj Raghav Reviewed-by: Ojaswin Mujoo --- fs/ext4/ext4.h | 3 +++ fs/ext4/inode.c | 3 ++- fs/ext4/super.c | 10 +++++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 3d18e6bf43cf..6fe8cc3bf9a5 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1688,6 +1688,9 @@ struct ext4_sb_info { /* record the last minlen when FITRIM is called. */ unsigned long s_last_trim_minblks; =20 + /* minimum folio order of a page cache allocation */ + unsigned int s_min_folio_order; + /* Precomputed FS UUID checksum for seeding other checksums */ __u32 s_csum_seed; =20 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index d11df0f4c546..e8da685ede49 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5181,7 +5181,8 @@ void ext4_set_inode_mapping_order(struct inode *inode) if (!ext4_should_enable_large_folio(inode)) return; =20 - mapping_set_folio_order_range(inode->i_mapping, 0, + mapping_set_folio_order_range(inode->i_mapping, + EXT4_SB(inode->i_sb)->s_min_folio_order, EXT4_MAX_PAGECACHE_ORDER(inode)); } =20 diff --git a/fs/ext4/super.c b/fs/ext4/super.c index f39679892e71..2286cd1e3cb8 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5109,11 +5109,8 @@ static int ext4_load_super(struct super_block *sb, e= xt4_fsblk_t *lsb, * If the default block size is not the same as the real block size, * we need to reload it. */ - if (sb->s_blocksize =3D=3D blocksize) { - *lsb =3D logical_sb_block; - sbi->s_sbh =3D bh; - return 0; - } + if (sb->s_blocksize =3D=3D blocksize) + goto success; =20 /* * bh must be released before kill_bdev(), otherwise @@ -5144,6 +5141,9 @@ static int ext4_load_super(struct super_block *sb, ex= t4_fsblk_t *lsb, ext4_msg(sb, KERN_ERR, "Magic mismatch, very weird!"); goto out; } + +success: + sbi->s_min_folio_order =3D get_order(blocksize); *lsb =3D logical_sb_block; sbi->s_sbh =3D bh; return 0; --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F33B23E325; Fri, 21 Nov 2025 09:16:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716612; cv=none; b=StiLuEYsP5ApQ2Y5Su904rOuQzyiZW8+FEVF7FyFvvZKBe/vHrRPLvIhToQXhVDx9TahopHlV45fbt4Bf16tycaTLfcORoDLlrQExTOSwDtKW5a/kUHu8bwsHzoyrs/R+w4SwbJ6HylZ/UsCS/eXPSqqv4iFfII19cjCgLnIi+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716612; c=relaxed/simple; bh=CjAZGCBsF0Gl5HD+1R0WQsk0tmGxw4N/8p/Heky+Ukg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LNqxq16dZM0lZx1Kn0F5Jnfdbv4y2GuMPT9xgxubUEaCFiDp53wH2g37EQPl/08Qn79PHgxo2STqZzvWxD+f8JRQHa3hg8COMsj0JJ2tU/7cvLx6BTjKBASly+B+6Wyu+z7hHoTBpmgQ2YrW6ih6AEbyKk1bwSl7PXIQjTg98o4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dCV2N1JzRzKHMvS; Fri, 21 Nov 2025 17:16:12 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 25CB61A07BB; Fri, 21 Nov 2025 17:16:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S11; Fri, 21 Nov 2025 17:16:42 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 07/24] ext4: support large block size in ext4_calculate_overhead() Date: Fri, 21 Nov 2025 17:06:37 +0800 Message-Id: <20251121090654.631996-8-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S11 X-Coremail-Antispam: 1UD129KBjvJXoW7uw4DZw47ZFWUuFW5Kw1kAFb_yoW8Wryrp3 Z3WryxArWruFWDuanruFZrJF48K3WxCFyUKFWa9343Zry7tw1fury3KFyYqr4xXFWxuryS v3WUKrWxZr15J3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQa14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x02 67AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdsqAUUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQATBWkf35kfEwAAsr Content-Type: text/plain; charset="utf-8" From: Baokun Li ext4_calculate_overhead() used a single page for its bitmap buffer, which worked fine when PAGE_SIZE >=3D block size. However, with block size greater than page size (BS > PS) support, the bitmap can exceed a single page. To address this, we now use kvmalloc() to allocate memory of the filesystem block size, to properly support BS > PS. Suggested-by: Jan Kara Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo --- fs/ext4/super.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 2286cd1e3cb8..998ddce49093 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -4191,7 +4191,7 @@ int ext4_calculate_overhead(struct super_block *sb) unsigned int j_blocks, j_inum =3D le32_to_cpu(es->s_journal_inum); ext4_group_t i, ngroups =3D ext4_get_groups_count(sb); ext4_fsblk_t overhead =3D 0; - char *buf =3D (char *) get_zeroed_page(GFP_NOFS); + char *buf =3D kvmalloc(sb->s_blocksize, GFP_NOFS | __GFP_ZERO); =20 if (!buf) return -ENOMEM; @@ -4216,7 +4216,7 @@ int ext4_calculate_overhead(struct super_block *sb) blks =3D count_overhead(sb, i, buf); overhead +=3D blks; if (blks) - memset(buf, 0, PAGE_SIZE); + memset(buf, 0, sb->s_blocksize); cond_resched(); } =20 @@ -4239,7 +4239,7 @@ int ext4_calculate_overhead(struct super_block *sb) } sbi->s_overhead =3D overhead; smp_wmb(); - free_page((unsigned long) buf); + kvfree(buf); return 0; } =20 --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D4DB2DF146; Fri, 21 Nov 2025 09:16:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716609; cv=none; b=BEccCUScZkDsDmpTjwzsLBhiZB45UWlfM8LQDtCjL1P7evnfpAtj9UXfNxSSC5ass52su5skqNcESRtUNBmD16vbSaMtUQevHkdi/FFTS2PP8xNKpIuRu7FxWVgvXP2omtNTuw8b/Bw2TZ/wRhbxaQC4zmhGaQco78ezRIbIBPU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716609; c=relaxed/simple; bh=nbLlr4pz10EzMDk4blvgn3Zk/K6kyFcZwM8fWlL40uw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=F+ns7JhiN2jtaL6GxRZumM4i9cAU+Mesy9khbou2VE+lv1/peN4CXSQrJHBc5HnguiO7C6Qqe20y+okzoB+V9zgiKBwXw8nDMPJwXACGLfsqeyq4VUCoBhnel1xTzBZbXHw28J7HCfS4KfHwE6osSQsVXeFfobBrmemDv3zAIjI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dCV276tQdzYQvGn; Fri, 21 Nov 2025 17:15:59 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 3A8251A084B; Fri, 21 Nov 2025 17:16:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S12; Fri, 21 Nov 2025 17:16:43 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com, Pankaj Raghav Subject: [PATCH v4 08/24] ext4: support large block size in ext4_readdir() Date: Fri, 21 Nov 2025 17:06:38 +0800 Message-Id: <20251121090654.631996-9-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S12 X-Coremail-Antispam: 1UD129KBjvJXoW7KF15KF1fWw1rZry8CrWktFb_yoW8Gw1rpa 9Ig3WvkFy09r40939rtFy7ZFWY9a97GFWUWrWYy345W3s3X3sakr9xtF1jvF1DW3yxAa4f ZF12kFy3GF15J3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQa14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x02 67AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdsqAUUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQATBWkf35kfFAAAss Content-Type: text/plain; charset="utf-8" From: Baokun Li In ext4_readdir(), page_cache_sync_readahead() is used to readahead mapped physical blocks. With LBS support, this can lead to a negative right shift. To fix this, the page index is now calculated by first converting the physical block number (pblk) to a file position (pos) before converting it to a page index. Also, the correct number of pages to readahead is now passed. Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Pankaj Raghav Reviewed-by: Ojaswin Mujoo --- fs/ext4/dir.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c index d4164c507a90..256fe2c1d4c1 100644 --- a/fs/ext4/dir.c +++ b/fs/ext4/dir.c @@ -192,13 +192,13 @@ static int ext4_readdir(struct file *file, struct dir= _context *ctx) continue; } if (err > 0) { - pgoff_t index =3D map.m_pblk >> - (PAGE_SHIFT - inode->i_blkbits); + pgoff_t index =3D map.m_pblk << inode->i_blkbits >> + PAGE_SHIFT; if (!ra_has_index(&file->f_ra, index)) page_cache_sync_readahead( sb->s_bdev->bd_mapping, - &file->f_ra, file, - index, 1); + &file->f_ra, file, index, + 1 << EXT4_SB(sb)->s_min_folio_order); file->f_ra.prev_pos =3D (loff_t)index << PAGE_SHIFT; bh =3D ext4_bread(NULL, inode, map.m_lblk, 0); if (IS_ERR(bh)) { --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 790B133BBDB; Fri, 21 Nov 2025 09:16:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716615; cv=none; b=ETw2tkJCl4emvNSWKaY+Ro62X81aMzcfjGEr//k1dfh1JHqT4MRsEqz2I4dd+EYVeAMJaeIxZR8RvdRNZVLZSbFGSErV+FjVTKrPi3DDP+EKl2e3TurxK0eKzTHAEwvKccHZ0Kl0Oa0yKCFbE+NwwGL/7gt5bOnaEMd3mBKShXI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716615; c=relaxed/simple; bh=YrykeLcgX4JHiuiCkTkDHn+PsZ01hXsMjuKDqOGcAYA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lDwuHfzlsAN6LJ5YRhiDioBvWA/yAQQiZp6hk+hf0mh8uIB1XMja95ugldMcjyv5cTh0WJRjIWcBInpXvNTN8kAng4zwefg1CF1oqEiCpVAAoudrWKU7O07trLpjL/RFdKAO7oZbYjFDASk2gsS8ldhMEbXN+VAYsk0/q7ZA2dc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dCV280X4HzYQvH3; Fri, 21 Nov 2025 17:16:00 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 526F21A0BC1; Fri, 21 Nov 2025 17:16:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S13; Fri, 21 Nov 2025 17:16:43 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 09/24] ext4: add EXT4_LBLK_TO_B macro for logical block to bytes conversion Date: Fri, 21 Nov 2025 17:06:39 +0800 Message-Id: <20251121090654.631996-10-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S13 X-Coremail-Antispam: 1UD129KBjvJXoW3Ar4rKryxZw43ZF43ZFWDArb_yoWxCw43pF Z09F18GF409Fyj9r48KrWDZr12g3W7K3yUXFWru34Ygas7tr1FqF1ktF1fZa45trWxZ3ZI vF45K347Ww43GrDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQa14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x02 67AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdsqAUUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgATBWkf34sfFQAEs4 Content-Type: text/plain; charset="utf-8" From: Baokun Li No functional changes. Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo --- fs/ext4/ext4.h | 1 + fs/ext4/extents.c | 2 +- fs/ext4/inode.c | 20 +++++++++----------- fs/ext4/namei.c | 8 +++----- fs/ext4/verity.c | 2 +- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 6fe8cc3bf9a5..c00ce6db69f0 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -368,6 +368,7 @@ struct ext4_io_submit { blkbits)) #define EXT4_B_TO_LBLK(inode, offset) \ (round_up((offset), i_blocksize(inode)) >> (inode)->i_blkbits) +#define EXT4_LBLK_TO_B(inode, lblk) ((loff_t)(lblk) << (inode)->i_blkbits) =20 /* Translate a block number to a cluster number */ #define EXT4_B2C(sbi, blk) ((blk) >> (sbi)->s_cluster_bits) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index c7d219e6c6d8..13c3cfeb13bc 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4562,7 +4562,7 @@ static int ext4_alloc_file_blocks(struct file *file, = ext4_lblk_t offset, * allow a full retry cycle for any remaining allocations */ retries =3D 0; - epos =3D (loff_t)(map.m_lblk + ret) << blkbits; + epos =3D EXT4_LBLK_TO_B(inode, map.m_lblk + ret); inode_set_ctime_current(inode); if (new_size) { if (epos > new_size) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index e8da685ede49..65a9c04bc691 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -831,9 +831,8 @@ int ext4_map_blocks(handle_t *handle, struct inode *ino= de, !(flags & EXT4_GET_BLOCKS_ZERO) && !ext4_is_quota_file(inode) && ext4_should_order_data(inode)) { - loff_t start_byte =3D - (loff_t)map->m_lblk << inode->i_blkbits; - loff_t length =3D (loff_t)map->m_len << inode->i_blkbits; + loff_t start_byte =3D EXT4_LBLK_TO_B(inode, map->m_lblk); + loff_t length =3D EXT4_LBLK_TO_B(inode, map->m_len); =20 if (flags & EXT4_GET_BLOCKS_IO_SUBMIT) ret =3D ext4_jbd2_inode_add_wait(handle, inode, @@ -2233,7 +2232,6 @@ static int mpage_process_folio(struct mpage_da_data *= mpd, struct folio *folio, ext4_lblk_t lblk =3D *m_lblk; ext4_fsblk_t pblock =3D *m_pblk; int err =3D 0; - int blkbits =3D mpd->inode->i_blkbits; ssize_t io_end_size =3D 0; struct ext4_io_end_vec *io_end_vec =3D ext4_last_io_end_vec(io_end); =20 @@ -2259,7 +2257,8 @@ static int mpage_process_folio(struct mpage_da_data *= mpd, struct folio *folio, err =3D PTR_ERR(io_end_vec); goto out; } - io_end_vec->offset =3D (loff_t)mpd->map.m_lblk << blkbits; + io_end_vec->offset =3D EXT4_LBLK_TO_B(mpd->inode, + mpd->map.m_lblk); } *map_bh =3D true; goto out; @@ -2269,7 +2268,7 @@ static int mpage_process_folio(struct mpage_da_data *= mpd, struct folio *folio, bh->b_blocknr =3D pblock++; } clear_buffer_unwritten(bh); - io_end_size +=3D (1 << blkbits); + io_end_size +=3D i_blocksize(mpd->inode); } while (lblk++, (bh =3D bh->b_this_page) !=3D head); =20 io_end_vec->size +=3D io_end_size; @@ -2471,7 +2470,7 @@ static int mpage_map_and_submit_extent(handle_t *hand= le, io_end_vec =3D ext4_alloc_io_end_vec(io_end); if (IS_ERR(io_end_vec)) return PTR_ERR(io_end_vec); - io_end_vec->offset =3D ((loff_t)map->m_lblk) << inode->i_blkbits; + io_end_vec->offset =3D EXT4_LBLK_TO_B(inode, map->m_lblk); do { err =3D mpage_map_one_extent(handle, mpd); if (err < 0) { @@ -3511,8 +3510,8 @@ static void ext4_set_iomap(struct inode *inode, struc= t iomap *iomap, iomap->dax_dev =3D EXT4_SB(inode->i_sb)->s_daxdev; else iomap->bdev =3D inode->i_sb->s_bdev; - iomap->offset =3D (u64) map->m_lblk << blkbits; - iomap->length =3D (u64) map->m_len << blkbits; + iomap->offset =3D EXT4_LBLK_TO_B(inode, map->m_lblk); + iomap->length =3D EXT4_LBLK_TO_B(inode, map->m_len); =20 if ((map->m_flags & EXT4_MAP_MAPPED) && !ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) @@ -3686,7 +3685,6 @@ static int ext4_iomap_alloc(struct inode *inode, stru= ct ext4_map_blocks *map, unsigned int flags) { handle_t *handle; - u8 blkbits =3D inode->i_blkbits; int ret, dio_credits, m_flags =3D 0, retries =3D 0; bool force_commit =3D false; =20 @@ -3745,7 +3743,7 @@ static int ext4_iomap_alloc(struct inode *inode, stru= ct ext4_map_blocks *map, * i_disksize out to i_size. This could be beyond where direct I/O is * happening and thus expose allocated blocks to direct I/O reads. */ - else if (((loff_t)map->m_lblk << blkbits) >=3D i_size_read(inode)) + else if (EXT4_LBLK_TO_B(inode, map->m_lblk) >=3D i_size_read(inode)) m_flags =3D EXT4_GET_BLOCKS_CREATE; else if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) m_flags =3D EXT4_GET_BLOCKS_IO_CREATE_EXT; diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 045616033515..c4b5e252af0e 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1076,7 +1076,7 @@ static int htree_dirblock_to_tree(struct file *dir_fi= le, for (; de < top; de =3D ext4_next_entry(de, dir->i_sb->s_blocksize)) { if (ext4_check_dir_entry(dir, NULL, de, bh, bh->b_data, bh->b_size, - (block<i_sb)) + EXT4_LBLK_TO_B(dir, block) + ((char *)de - bh->b_data))) { /* silently ignore the rest of the block */ break; @@ -1630,7 +1630,7 @@ static struct buffer_head *__ext4_find_entry(struct i= node *dir, } set_buffer_verified(bh); i =3D search_dirblock(bh, dir, fname, - block << EXT4_BLOCK_SIZE_BITS(sb), res_dir); + EXT4_LBLK_TO_B(dir, block), res_dir); if (i =3D=3D 1) { EXT4_I(dir)->i_dir_start_lookup =3D block; ret =3D bh; @@ -1710,7 +1710,6 @@ static struct buffer_head * ext4_dx_find_entry(struct= inode *dir, struct ext4_filename *fname, struct ext4_dir_entry_2 **res_dir) { - struct super_block * sb =3D dir->i_sb; struct dx_frame frames[EXT4_HTREE_LEVEL], *frame; struct buffer_head *bh; ext4_lblk_t block; @@ -1729,8 +1728,7 @@ static struct buffer_head * ext4_dx_find_entry(struct= inode *dir, goto errout; =20 retval =3D search_dirblock(bh, dir, fname, - block << EXT4_BLOCK_SIZE_BITS(sb), - res_dir); + EXT4_LBLK_TO_B(dir, block), res_dir); if (retval =3D=3D 1) goto success; brelse(bh); diff --git a/fs/ext4/verity.c b/fs/ext4/verity.c index b0acb0c50313..415d9c4d8a32 100644 --- a/fs/ext4/verity.c +++ b/fs/ext4/verity.c @@ -302,7 +302,7 @@ static int ext4_get_verity_descriptor_location(struct i= node *inode, =20 end_lblk =3D le32_to_cpu(last_extent->ee_block) + ext4_ext_get_actual_len(last_extent); - desc_size_pos =3D (u64)end_lblk << inode->i_blkbits; + desc_size_pos =3D EXT4_LBLK_TO_B(inode, end_lblk); ext4_free_ext_path(path); =20 if (desc_size_pos < sizeof(desc_size_disk)) --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 744D22ED86F; Fri, 21 Nov 2025 09:16:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716608; cv=none; b=bda8YN4PwpFySqR0FrMyA9q+71TK9PSbCYrsZYXsYMSTIq3CoMSgYYibI7BWLdrI1aXXRR77AEZXqq14jN9e8hosfKSfhN7JGqCWGEGAfN7R/k/kNNxySlUsTNJSX854WKu7KZA37nzsM+AgdlEEEgwNtxhU7Mh2NFTkyMLWULc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716608; c=relaxed/simple; bh=hytnSNj7OABxAoBo5+RLLIPiZwGumRxLUvhAxPgmAWs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Yu5eDRjO2GcRaDfFq7mDoeUsuVMVY6wCukKr0FFIQJOq2BSoZ9tl+xceELi1K/DNgnvTlzuNMOehvwfYqMttQwRPH99B0M45rXAS077DolUlfNJxXAYreXtvuX/rSCAHNxfB4x/uLAtLXfE+4zaYQG6lwjOpYRUGE49zE0yc2Zw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dCV2N33jVzKHMvb; Fri, 21 Nov 2025 17:16:12 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 62C951A10F1; Fri, 21 Nov 2025 17:16:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S14; Fri, 21 Nov 2025 17:16:43 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 10/24] ext4: add EXT4_LBLK_TO_PG and EXT4_PG_TO_LBLK for block/page conversion Date: Fri, 21 Nov 2025 17:06:40 +0800 Message-Id: <20251121090654.631996-11-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S14 X-Coremail-Antispam: 1UD129KBjvJXoW7tF4DJrW7uF1DWw17GFW7Jwb_yoW8Gr4Dpr ZxWFyrGr1FvFy8ur1IgFy0vryfGan3GayUX39FvrWY9FyxKr1Sgrs0gr95tFyjg3yrJFWq qFyFkryxWr13C3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQa14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x02 67AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdsqAUUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgATBWkf34sfFQAGs6 Content-Type: text/plain; charset="utf-8" From: Baokun Li As BS > PS support is coming, all block number to page index (and vice-versa) conversions must now go via bytes. Added EXT4_LBLK_TO_PG() and EXT4_PG_TO_LBLK() macros to simplify these conversions and handle both BS <=3D PS and BS > PS scenarios cleanly. Suggested-by: Jan Kara Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo --- fs/ext4/ext4.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index c00ce6db69f0..4bc0b2b7288a 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -370,6 +370,12 @@ struct ext4_io_submit { (round_up((offset), i_blocksize(inode)) >> (inode)->i_blkbits) #define EXT4_LBLK_TO_B(inode, lblk) ((loff_t)(lblk) << (inode)->i_blkbits) =20 +/* Translate a block number to a page index */ +#define EXT4_LBLK_TO_PG(inode, lblk) (EXT4_LBLK_TO_B((inode), (lblk)) >> \ + PAGE_SHIFT) +/* Translate a page index to a block number */ +#define EXT4_PG_TO_LBLK(inode, pnum) (((loff_t)(pnum) << PAGE_SHIFT) >> \ + (inode)->i_blkbits) /* Translate a block number to a cluster number */ #define EXT4_B2C(sbi, blk) ((blk) >> (sbi)->s_cluster_bits) /* Translate a cluster number to a block number */ --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78FAD824A3; Fri, 21 Nov 2025 09:16:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716618; cv=none; b=nTKGZN2mzBk5WwlzqtEWbsU5t/mxT/Q702JPNwyDXq6vUHxqKGCLYltBpIN0v1DKHMUaau4U49loBvgkv0rRINkjBHJKBqCfGxCK1bCxzAzGWwU3Jpk3heQjCHiQ/kMWWzBEruReLgH3soCyugQS4or+ohtdryT1iHroROYeJbU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716618; c=relaxed/simple; bh=Zhn/IogLIgUaBuPIWYgGdBw1sRiR+JtODhQ7+icZ7/M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=ki6ixOSimF9fFYMTaWiAvxnDF4LDmHzotZbHcBO7wmh56z9PpKoJJBShXYANmdL8vlxgA+oBIKLBdVXsBR/2Zq+6v7wXpIp4cb0w73lBIzML0pIWVHoqVOc0JlKkoidWZAUvux7qaOkmjgBfP5q+5rlsjzfK50dqcqyFc0fXXm8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dCV2N3NYjzKHMvf; Fri, 21 Nov 2025 17:16:12 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 6F32B1A19B8; Fri, 21 Nov 2025 17:16:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S15; Fri, 21 Nov 2025 17:16:43 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 11/24] ext4: support large block size in ext4_mb_load_buddy_gfp() Date: Fri, 21 Nov 2025 17:06:41 +0800 Message-Id: <20251121090654.631996-12-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S15 X-Coremail-Antispam: 1UD129KBjvJXoWxArykWFyUGry7JrW7Jr18Krg_yoWrJF48pF srGrn8Gr48WFnxWwsrZa4Sqr1Fgas3uFWUGFWfWF1fZFy3t3WfKFnrK3WUJF1jqa9rJ3Wk XFW5ZryfuF17W3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQa14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x02 67AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdsqAUUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQATBWkf35kfFQAAst From: Baokun Li Currently, ext4_mb_load_buddy_gfp() uses blocks_per_page to calculate the folio index and offset. However, when blocksize is larger than PAGE_SIZE, blocks_per_page becomes zero, leading to a potential division-by-zero bug. To support BS > PS, use bytes to compute folio index and offset within folio to get rid of blocks_per_page. Also, if buddy and bitmap land in the same folio, we get that folio=E2=80= =99s ref instead of looking it up again before updating the buddy. Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo --- fs/ext4/mballoc.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 9087183602e4..143d6ff1fdef 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -1642,17 +1642,15 @@ int ext4_mb_init_group(struct super_block *sb, ext4= _group_t group, gfp_t gfp) =20 /* * Locking note: This routine calls ext4_mb_init_cache(), which takes the - * block group lock of all groups for this page; do not hold the BG lock w= hen + * block group lock of all groups for this folio; do not hold the BG lock = when * calling this routine! */ static noinline_for_stack int ext4_mb_load_buddy_gfp(struct super_block *sb, ext4_group_t group, struct ext4_buddy *e4b, gfp_t gfp) { - int blocks_per_page; int block; int pnum; - int poff; struct folio *folio; int ret; struct ext4_group_info *grp; @@ -1662,7 +1660,6 @@ ext4_mb_load_buddy_gfp(struct super_block *sb, ext4_g= roup_t group, might_sleep(); mb_debug(sb, "load group %u\n", group); =20 - blocks_per_page =3D PAGE_SIZE / sb->s_blocksize; grp =3D ext4_get_group_info(sb, group); if (!grp) return -EFSCORRUPTED; @@ -1690,8 +1687,7 @@ ext4_mb_load_buddy_gfp(struct super_block *sb, ext4_g= roup_t group, * So for each group we need two blocks. */ block =3D group * 2; - pnum =3D block / blocks_per_page; - poff =3D block % blocks_per_page; + pnum =3D EXT4_LBLK_TO_PG(inode, block); =20 /* Avoid locking the folio in the fast path ... */ folio =3D __filemap_get_folio(inode->i_mapping, pnum, FGP_ACCESSED, 0); @@ -1723,7 +1719,8 @@ ext4_mb_load_buddy_gfp(struct super_block *sb, ext4_g= roup_t group, goto err; } mb_cmp_bitmaps(e4b, folio_address(folio) + - (poff * sb->s_blocksize)); + offset_in_folio(folio, + EXT4_LBLK_TO_B(inode, block))); } folio_unlock(folio); } @@ -1739,12 +1736,18 @@ ext4_mb_load_buddy_gfp(struct super_block *sb, ext4= _group_t group, =20 /* Folios marked accessed already */ e4b->bd_bitmap_folio =3D folio; - e4b->bd_bitmap =3D folio_address(folio) + (poff * sb->s_blocksize); + e4b->bd_bitmap =3D folio_address(folio) + + offset_in_folio(folio, EXT4_LBLK_TO_B(inode, block)); =20 block++; - pnum =3D block / blocks_per_page; - poff =3D block % blocks_per_page; + pnum =3D EXT4_LBLK_TO_PG(inode, block); + /* buddy and bitmap are on the same folio? */ + if (folio_contains(folio, pnum)) { + folio_get(folio); + goto update_buddy; + } =20 + /* we need another folio for the buddy */ folio =3D __filemap_get_folio(inode->i_mapping, pnum, FGP_ACCESSED, 0); if (IS_ERR(folio) || !folio_test_uptodate(folio)) { if (!IS_ERR(folio)) @@ -1779,9 +1782,11 @@ ext4_mb_load_buddy_gfp(struct super_block *sb, ext4_= group_t group, goto err; } =20 +update_buddy: /* Folios marked accessed already */ e4b->bd_buddy_folio =3D folio; - e4b->bd_buddy =3D folio_address(folio) + (poff * sb->s_blocksize); + e4b->bd_buddy =3D folio_address(folio) + + offset_in_folio(folio, EXT4_LBLK_TO_B(inode, block)); =20 return 0; =20 --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5263433ADB9; Fri, 21 Nov 2025 09:16:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716615; cv=none; b=K/sY5iMIewHH2mfCtuTyeo6b7Glf5CRWhVFY0Iq4y7/VU7OGPh/rksW1/f7Mvkq9SMJV+DutlAxco5z2jzDtpwjnTGscdOEDlvsvZtaeUxqzXBv1ZNQd/MQhHvm+kRTy9digeMMQnP/Ya9mYIdsojhviVfK/Oi6giMHEaMkY+os= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716615; c=relaxed/simple; bh=zru6h0tSducD5Q4JGP0Z7AO61CNXM4NKMumOKOKELBk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DyJ1mrnGLAeHDfc6lIjEw1tGW7tv67IeSRO9DM8LroAomBjeT1MLwXNxrblNCYvzS9q6N35QrPHTt0DrBjeMjy7DMLWGUqE6w0wo1/ZIxynAr/HbSTx3ORWPigC7E3gLXCvNa1aZx5+Dev+4J3ZqGkA19jo+wPVcJ3GZhSPxk3Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dCV281dQxzYQvGw; Fri, 21 Nov 2025 17:16:00 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 7C8671A0359; Fri, 21 Nov 2025 17:16:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S16; Fri, 21 Nov 2025 17:16:43 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 12/24] ext4: support large block size in ext4_mb_get_buddy_page_lock() Date: Fri, 21 Nov 2025 17:06:42 +0800 Message-Id: <20251121090654.631996-13-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S16 X-Coremail-Antispam: 1UD129KBjvJXoWxJF13CF47GF4xuFyDGF1rWFg_yoWrZF48pa y7Cwn8Jr4kWasrursrZ3saq3WFkas5Zay7A3yIgr13uFy3J34IkFy0k3WUXF1UtFWxGFs5 XF45Zry3WF1UX3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQa14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x02 67AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdsqAUUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQATBWkf35kfFgAAsu Content-Type: text/plain; charset="utf-8" From: Baokun Li Currently, ext4_mb_get_buddy_page_lock() uses blocks_per_page to calculate folio index and offset. However, when blocksize is larger than PAGE_SIZE, blocks_per_page becomes zero, leading to a potential division-by-zero bug. To support BS > PS, use bytes to compute folio index and offset within folio to get rid of blocks_per_page. Also, since ext4_mb_get_buddy_page_lock() already fully supports folio, rename it to ext4_mb_get_buddy_folio_lock(). Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo --- fs/ext4/mballoc.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 143d6ff1fdef..b454a41dd6c1 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -1510,50 +1510,52 @@ static int ext4_mb_init_cache(struct folio *folio, = char *incore, gfp_t gfp) } =20 /* - * Lock the buddy and bitmap pages. This make sure other parallel init_gro= up - * on the same buddy page doesn't happen whild holding the buddy page lock. - * Return locked buddy and bitmap pages on e4b struct. If buddy and bitmap - * are on the same page e4b->bd_buddy_folio is NULL and return value is 0. + * Lock the buddy and bitmap folios. This makes sure other parallel init_g= roup + * on the same buddy folio doesn't happen while holding the buddy folio lo= ck. + * Return locked buddy and bitmap folios on e4b struct. If buddy and bitmap + * are on the same folio e4b->bd_buddy_folio is NULL and return value is 0. */ -static int ext4_mb_get_buddy_page_lock(struct super_block *sb, +static int ext4_mb_get_buddy_folio_lock(struct super_block *sb, ext4_group_t group, struct ext4_buddy *e4b, gfp_t gfp) { struct inode *inode =3D EXT4_SB(sb)->s_buddy_cache; - int block, pnum, poff; - int blocks_per_page; + int block, pnum; struct folio *folio; =20 e4b->bd_buddy_folio =3D NULL; e4b->bd_bitmap_folio =3D NULL; =20 - blocks_per_page =3D PAGE_SIZE / sb->s_blocksize; /* * the buddy cache inode stores the block bitmap * and buddy information in consecutive blocks. * So for each group we need two blocks. */ block =3D group * 2; - pnum =3D block / blocks_per_page; - poff =3D block % blocks_per_page; + pnum =3D EXT4_LBLK_TO_PG(inode, block); folio =3D __filemap_get_folio(inode->i_mapping, pnum, FGP_LOCK | FGP_ACCESSED | FGP_CREAT, gfp); if (IS_ERR(folio)) return PTR_ERR(folio); BUG_ON(folio->mapping !=3D inode->i_mapping); + WARN_ON_ONCE(folio_size(folio) < sb->s_blocksize); e4b->bd_bitmap_folio =3D folio; - e4b->bd_bitmap =3D folio_address(folio) + (poff * sb->s_blocksize); + e4b->bd_bitmap =3D folio_address(folio) + + offset_in_folio(folio, EXT4_LBLK_TO_B(inode, block)); =20 - if (blocks_per_page >=3D 2) { - /* buddy and bitmap are on the same page */ + block++; + pnum =3D EXT4_LBLK_TO_PG(inode, block); + if (folio_contains(folio, pnum)) { + /* buddy and bitmap are on the same folio */ return 0; } =20 - /* blocks_per_page =3D=3D 1, hence we need another page for the buddy */ - folio =3D __filemap_get_folio(inode->i_mapping, block + 1, + /* we need another folio for the buddy */ + folio =3D __filemap_get_folio(inode->i_mapping, pnum, FGP_LOCK | FGP_ACCESSED | FGP_CREAT, gfp); if (IS_ERR(folio)) return PTR_ERR(folio); BUG_ON(folio->mapping !=3D inode->i_mapping); + WARN_ON_ONCE(folio_size(folio) < sb->s_blocksize); e4b->bd_buddy_folio =3D folio; return 0; } @@ -1592,14 +1594,14 @@ int ext4_mb_init_group(struct super_block *sb, ext4= _group_t group, gfp_t gfp) =20 /* * This ensures that we don't reinit the buddy cache - * page which map to the group from which we are already + * folio which map to the group from which we are already * allocating. If we are looking at the buddy cache we would * have taken a reference using ext4_mb_load_buddy and that - * would have pinned buddy page to page cache. - * The call to ext4_mb_get_buddy_page_lock will mark the - * page accessed. + * would have pinned buddy folio to page cache. + * The call to ext4_mb_get_buddy_folio_lock will mark the + * folio accessed. */ - ret =3D ext4_mb_get_buddy_page_lock(sb, group, &e4b, gfp); + ret =3D ext4_mb_get_buddy_folio_lock(sb, group, &e4b, gfp); if (ret || !EXT4_MB_GRP_NEED_INIT(this_grp)) { /* * somebody initialized the group --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6FEC42882AA; Fri, 21 Nov 2025 09:16:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716615; cv=none; b=cMOjiifnTL5l40wG1zxvwXqdpsrxIEl6u4aWlIAPZoJjdHh/PrbWnnYG2DQWZ0C7f6yeeN6Fp574x74hIqZxxi4wD4cUh3geKGn3+h7SzD5cwJsZfcUj3+b096oEcLoKZmWwjg9Z7c++xjUi3RxbFA6VinB89DzWiY37DNIOvI8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716615; c=relaxed/simple; bh=8z07ORJLuvNM84vCR2wCkKmp4t1hudpgLUW5sLQvkow=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TX6XEkGazo0n5GgVHu5162y/4Dm8cTq1JnMrf217c5ofULfipQvjgpFmHtCZ8jl2pWRFm9chej0N8ltmnBOsjHRMMFFFfH1Xvd5wuX4s/l+zTIi4J1MsdiNyUwByroY8BkaKZsQZM8hKicVDBXjPtqtyKMFUSFe3NELa/1lN/Ew= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dCV282B1QzYQvHD; Fri, 21 Nov 2025 17:16:00 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 906A21A084E; Fri, 21 Nov 2025 17:16:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S17; Fri, 21 Nov 2025 17:16:43 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 13/24] ext4: support large block size in ext4_mb_init_cache() Date: Fri, 21 Nov 2025 17:06:43 +0800 Message-Id: <20251121090654.631996-14-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S17 X-Coremail-Antispam: 1UD129KBjvJXoWxZw1ktr1DWw4UKFyfKr4UArb_yoWruw4Dpa 9xKr15Gr18Wa9rW3ZrWayvvF1fG34xZF47GFWxXr1xCFy7Xw1FgFnrtr18JryUtFZrJF95 XF15Ar13ZF1UXw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQa14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x02 67AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdsqAUUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQATBWkf35kfFwABsu Content-Type: text/plain; charset="utf-8" From: Baokun Li Currently, ext4_mb_init_cache() uses blocks_per_page to calculate the folio index and offset. However, when blocksize is larger than PAGE_SIZE, blocks_per_page becomes zero, leading to a potential division-by-zero bug. Since we now have the folio, we know its exact size. This allows us to convert {blocks, groups}_per_page to {blocks, groups}_per_folio, thus supporting block sizes greater than page size. Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo --- fs/ext4/mballoc.c | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index b454a41dd6c1..3f10c64ab2b1 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -1329,26 +1329,25 @@ static void mb_regenerate_buddy(struct ext4_buddy *= e4b) * block bitmap and buddy information. The information are * stored in the inode as * - * { page } + * { folio } * [ group 0 bitmap][ group 0 buddy] [group 1][ group 1]... * * * one block each for bitmap and buddy information. - * So for each group we take up 2 blocks. A page can - * contain blocks_per_page (PAGE_SIZE / blocksize) blocks. - * So it can have information regarding groups_per_page which - * is blocks_per_page/2 + * So for each group we take up 2 blocks. A folio can + * contain blocks_per_folio (folio_size / blocksize) blocks. + * So it can have information regarding groups_per_folio which + * is blocks_per_folio/2 * * Locking note: This routine takes the block group lock of all groups - * for this page; do not hold this lock when calling this routine! + * for this folio; do not hold this lock when calling this routine! */ - static int ext4_mb_init_cache(struct folio *folio, char *incore, gfp_t gfp) { ext4_group_t ngroups; unsigned int blocksize; - int blocks_per_page; - int groups_per_page; + int blocks_per_folio; + int groups_per_folio; int err =3D 0; int i; ext4_group_t first_group, group; @@ -1365,27 +1364,24 @@ static int ext4_mb_init_cache(struct folio *folio, = char *incore, gfp_t gfp) sb =3D inode->i_sb; ngroups =3D ext4_get_groups_count(sb); blocksize =3D i_blocksize(inode); - blocks_per_page =3D PAGE_SIZE / blocksize; + blocks_per_folio =3D folio_size(folio) / blocksize; + WARN_ON_ONCE(!blocks_per_folio); + groups_per_folio =3D DIV_ROUND_UP(blocks_per_folio, 2); =20 mb_debug(sb, "init folio %lu\n", folio->index); =20 - groups_per_page =3D blocks_per_page >> 1; - if (groups_per_page =3D=3D 0) - groups_per_page =3D 1; - /* allocate buffer_heads to read bitmaps */ - if (groups_per_page > 1) { - i =3D sizeof(struct buffer_head *) * groups_per_page; + if (groups_per_folio > 1) { + i =3D sizeof(struct buffer_head *) * groups_per_folio; bh =3D kzalloc(i, gfp); if (bh =3D=3D NULL) return -ENOMEM; } else bh =3D &bhs; =20 - first_group =3D folio->index * blocks_per_page / 2; - /* read all groups the folio covers into the cache */ - for (i =3D 0, group =3D first_group; i < groups_per_page; i++, group++) { + first_group =3D EXT4_PG_TO_LBLK(inode, folio->index) / 2; + for (i =3D 0, group =3D first_group; i < groups_per_folio; i++, group++) { if (group >=3D ngroups) break; =20 @@ -1393,7 +1389,7 @@ static int ext4_mb_init_cache(struct folio *folio, ch= ar *incore, gfp_t gfp) if (!grinfo) continue; /* - * If page is uptodate then we came here after online resize + * If folio is uptodate then we came here after online resize * which added some new uninitialized group info structs, so * we must skip all initialized uptodate buddies on the folio, * which may be currently in use by an allocating task. @@ -1413,7 +1409,7 @@ static int ext4_mb_init_cache(struct folio *folio, ch= ar *incore, gfp_t gfp) } =20 /* wait for I/O completion */ - for (i =3D 0, group =3D first_group; i < groups_per_page; i++, group++) { + for (i =3D 0, group =3D first_group; i < groups_per_folio; i++, group++) { int err2; =20 if (!bh[i]) @@ -1423,8 +1419,8 @@ static int ext4_mb_init_cache(struct folio *folio, ch= ar *incore, gfp_t gfp) err =3D err2; } =20 - first_block =3D folio->index * blocks_per_page; - for (i =3D 0; i < blocks_per_page; i++) { + first_block =3D EXT4_PG_TO_LBLK(inode, folio->index); + for (i =3D 0; i < blocks_per_folio; i++) { group =3D (first_block + i) >> 1; if (group >=3D ngroups) break; @@ -1501,7 +1497,7 @@ static int ext4_mb_init_cache(struct folio *folio, ch= ar *incore, gfp_t gfp) =20 out: if (bh) { - for (i =3D 0; i < groups_per_page; i++) + for (i =3D 0; i < groups_per_folio; i++) brelse(bh[i]); if (bh !=3D &bhs) kfree(bh); --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C158633D6E8; Fri, 21 Nov 2025 09:16:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716617; cv=none; b=kyxbdw0s4pUBwi4XH+xnFwlQy9FK23Q9rotZXf3fmEUu+Zi8GHbD+SxMJEqq9F7JMP8+/dC7zhxsvLWaMs0aXW263y+jiwuQlmoAXGGF0MHqtFcLzqFgT2f5gPseB09FeZKsxIx59CraJaythLfsekH1niwxcygTsDdjDtbYd4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716617; c=relaxed/simple; bh=/XgSakDfjLXFQZ0fNtaKp9PDSIuKVtLaor6BRknOcXs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QtcAlPCzN9BXqZdxc1bYMlJxUWCECrbpNYwA4vgPl0cZhSnlLzeuMDdhacQOeVdEM6xWo8D2/HIkzxNTJyWgaQySk1NLAce5cASnzBkXFfRAYZU4rhWXClujrmqgodEaaAI7SYq/Q2Ok1D4v/sCwX3s278aMq7/g801sDYFKboo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dCV2N4hnLzKHMvp; Fri, 21 Nov 2025 17:16:12 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 9BCD41A110B; Fri, 21 Nov 2025 17:16:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S18; Fri, 21 Nov 2025 17:16:43 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 14/24] ext4: prepare buddy cache inode for BS > PS with large folios Date: Fri, 21 Nov 2025 17:06:44 +0800 Message-Id: <20251121090654.631996-15-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S18 X-Coremail-Antispam: 1UD129KBjvJXoW7AFWxXFy3WF4kCw4DtrWxXrb_yoW8JFWfpa 17GF18Gr18Way5CF4xGFy8Xa4xKa1xWay7JrZ29w1jvF9rWFyFkFsrtry29FW8AFWfAayf XF47uw13ur45GaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQa14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x02 67AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdsqAUUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQATBWkf35kfGAAAsg Content-Type: text/plain; charset="utf-8" From: Baokun Li We use EXT4_BAD_INO for the buddy cache inode number. This inode is not accessed via __ext4_new_inode() or __ext4_iget(), meaning ext4_set_inode_mapping_order() is not called to set its folio order range. However, future block size greater than page size support requires this inode to support large folios, and the buddy cache code already handles BS > PS. Therefore, ext4_set_inode_mapping_order() is now explicitly called for this specific inode to set its folio order range. Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo --- fs/ext4/mballoc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 3f10c64ab2b1..102c6439eb11 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -3493,6 +3493,8 @@ static int ext4_mb_init_backend(struct super_block *s= b) * this will avoid confusion if it ever shows up during debugging. */ sbi->s_buddy_cache->i_ino =3D EXT4_BAD_INO; EXT4_I(sbi->s_buddy_cache)->i_disksize =3D 0; + ext4_set_inode_mapping_order(sbi->s_buddy_cache); + for (i =3D 0; i < ngroups; i++) { cond_resched(); desc =3D ext4_get_group_desc(sb, i, NULL); --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DEDD2D949E; Fri, 21 Nov 2025 09:16:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716617; cv=none; b=QFaK7JxzxvGOiB0wcYu97OMRxd62Yrbqj6vOYvUq7pqGGAvbr8Dqm7rOUiHUPv/vH+wcIvhCBbCl7rc+lTGYMk25OuJl9h/rJDtIMwAA+Oro8Bt6seJ3/UeVIAIs638jnKk45rxxd9RS96AcygU+4qyy5y0H92+xgAZEg4UT0R8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716617; c=relaxed/simple; bh=CH9HLTPmVFSNaz8/r/KKhntfMnEOzlpfmi7EXRjONvs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QmtqPfAZreMK1fMohuFsDKUZrcef+NZKIP7IFuXpL5Rvin5Sikd/9784U3EFI20cycfzvoslBUzSCwdKVIBzX+oEMMej/AHCjVgHaRFe5984vrcWSgVntYbypoSTrQXILTQ4+o4Sb5o2vf+PE4geGMBW3fsnKs+H+Q0EvjBKTtY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dCV2835yJzYQvHR; Fri, 21 Nov 2025 17:16:00 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id AECE71A10FD; Fri, 21 Nov 2025 17:16:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S19; Fri, 21 Nov 2025 17:16:43 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 15/24] ext4: rename 'page' references to 'folio' in multi-block allocator Date: Fri, 21 Nov 2025 17:06:45 +0800 Message-Id: <20251121090654.631996-16-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S19 X-Coremail-Antispam: 1UD129KBjvJXoWxCFy7GF15AF45JF1rXF48Xrb_yoWrGFy8pF sxCw15Cr1kWrn8u3Zruayj9w1Sy3yv9FWkCrWxWr18Zr9xXryIgFnrtF1UtFy0gFZ3AFn5 ZF4avF13ur17J3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQa14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x02 67AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdsqAUUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQATBWkf35kfGQABsg Content-Type: text/plain; charset="utf-8" From: Zhihao Cheng The ext4 multi-block allocator now fully supports folio objects. Update all variable names, function names, and comments to replace legacy 'page' terminology with 'folio', improving clarity and consistency. No functional changes. Signed-off-by: Zhihao Cheng Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo --- fs/ext4/mballoc.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 102c6439eb11..0fbd4c5fffc0 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -98,14 +98,14 @@ * block bitmap and buddy information. The information are stored in the * inode as: * - * { page } + * { folio } * [ group 0 bitmap][ group 0 buddy] [group 1][ group 1]... * * * one block each for bitmap and buddy information. So for each group we - * take up 2 blocks. A page can contain blocks_per_page (PAGE_SIZE / - * blocksize) blocks. So it can have information regarding groups_per_page - * which is blocks_per_page/2 + * take up 2 blocks. A folio can contain blocks_per_folio (folio_size / + * blocksize) blocks. So it can have information regarding groups_per_fol= io + * which is blocks_per_folio/2 * * The buddy cache inode is not stored on disk. The inode is thrown * away when the filesystem is unmounted. @@ -1556,7 +1556,7 @@ static int ext4_mb_get_buddy_folio_lock(struct super_= block *sb, return 0; } =20 -static void ext4_mb_put_buddy_page_lock(struct ext4_buddy *e4b) +static void ext4_mb_put_buddy_folio_lock(struct ext4_buddy *e4b) { if (e4b->bd_bitmap_folio) { folio_unlock(e4b->bd_bitmap_folio); @@ -1570,7 +1570,7 @@ static void ext4_mb_put_buddy_page_lock(struct ext4_b= uddy *e4b) =20 /* * Locking note: This routine calls ext4_mb_init_cache(), which takes the - * block group lock of all groups for this page; do not hold the BG lock w= hen + * block group lock of all groups for this folio; do not hold the BG lock = when * calling this routine! */ static noinline_for_stack @@ -1618,7 +1618,7 @@ int ext4_mb_init_group(struct super_block *sb, ext4_g= roup_t group, gfp_t gfp) if (e4b.bd_buddy_folio =3D=3D NULL) { /* * If both the bitmap and buddy are in - * the same page we don't need to force + * the same folio we don't need to force * init the buddy */ ret =3D 0; @@ -1634,7 +1634,7 @@ int ext4_mb_init_group(struct super_block *sb, ext4_g= roup_t group, gfp_t gfp) goto err; } err: - ext4_mb_put_buddy_page_lock(&e4b); + ext4_mb_put_buddy_folio_lock(&e4b); return ret; } =20 @@ -2227,7 +2227,7 @@ static void ext4_mb_use_best_found(struct ext4_alloca= tion_context *ac, ac->ac_buddy =3D ret >> 16; =20 /* - * take the page reference. We want the page to be pinned + * take the folio reference. We want the folio to be pinned * so that we don't get a ext4_mb_init_cache_call for this * group until we update the bitmap. That would mean we * double allocate blocks. The reference is dropped @@ -2933,7 +2933,7 @@ static int ext4_mb_scan_group(struct ext4_allocation_= context *ac, if (cr < CR_ANY_FREE && spin_is_locked(ext4_group_lock_ptr(sb, group))) return 0; =20 - /* This now checks without needing the buddy page */ + /* This now checks without needing the buddy folio */ ret =3D ext4_mb_good_group_nolock(ac, group, cr); if (ret <=3D 0) { if (!ac->ac_first_err) @@ -4725,7 +4725,7 @@ static void ext4_discard_allocated_blocks(struct ext4= _allocation_context *ac) "ext4: mb_load_buddy failed (%d)", err)) /* * This should never happen since we pin the - * pages in the ext4_allocation_context so + * folios in the ext4_allocation_context so * ext4_mb_load_buddy() should never fail. */ return; --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B40233BBDE; Fri, 21 Nov 2025 09:16:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716618; cv=none; b=VXgC3p9gYI9bsyarkl14IAG5IwwdM8uPc3B4lxt5gAnCZ8kXbVq/ifx6pC5Ib/TTrAhT3ZoOSCwY0EwGKZGDatjkr7a9IH3H56NzcTSafyf4RIH6dGDsKiSUEEA1dtsY4aV9C8zIL5MSZFdmh1NHZPIUbJ7Oc66ev9pkaXtSUBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716618; c=relaxed/simple; bh=qOpeQrUWEZr22pjL+quL4xX6rvFnH2QQqyJQo9YuSQk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pWgmULg7Estw/vzeP0WCJR2uGh5lS9xqJTuucbty/0LIKwO6yTh0xdK8yUIfwcUojmZlDCEZboKYiN5bT80+aRec9ZLCy332rJgpooCvUQMIvJ/bDBtTY/7SUfPTu8w1zAkDbCYSXW6A//0WEtfMv0EEOMMqt/BYI9Of7D+Z7ac= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dCV2N5bvlzKHMvr; Fri, 21 Nov 2025 17:16:12 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id B97501A1B37; Fri, 21 Nov 2025 17:16:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S20; Fri, 21 Nov 2025 17:16:43 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 16/24] ext4: support large block size in ext4_mpage_readpages() Date: Fri, 21 Nov 2025 17:06:46 +0800 Message-Id: <20251121090654.631996-17-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S20 X-Coremail-Antispam: 1UD129KBjvJXoWxJryDZFyxGrykZF45tF4Dtwb_yoW8XrWrpa 93K3WkKFn7WryfuanxXF1kZrn5Ka47CayUXFZ3Xry3WFy7trySkwnFqas5XF4jqrsxZr93 XF1fWry7AF45XrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQa14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x02 67AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdsqAUUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgATBWkf34sfFwABs- Content-Type: text/plain; charset="utf-8" From: Baokun Li Use the EXT4_PG_TO_LBLK() macro to convert folio indexes to blocks to avoid negative left shifts after supporting blocksize greater than PAGE_SIZE. Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo --- fs/ext4/readpage.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c index f329daf6e5c7..e7f2350c725b 100644 --- a/fs/ext4/readpage.c +++ b/fs/ext4/readpage.c @@ -213,9 +213,7 @@ int ext4_mpage_readpages(struct inode *inode, { struct bio *bio =3D NULL; sector_t last_block_in_bio =3D 0; - const unsigned blkbits =3D inode->i_blkbits; - const unsigned blocks_per_page =3D PAGE_SIZE >> blkbits; const unsigned blocksize =3D 1 << blkbits; sector_t next_block; sector_t block_in_file; @@ -251,9 +249,8 @@ int ext4_mpage_readpages(struct inode *inode, =20 blocks_per_folio =3D folio_size(folio) >> blkbits; first_hole =3D blocks_per_folio; - block_in_file =3D next_block =3D - (sector_t)folio->index << (PAGE_SHIFT - blkbits); - last_block =3D block_in_file + nr_pages * blocks_per_page; + block_in_file =3D next_block =3D EXT4_PG_TO_LBLK(inode, folio->index); + last_block =3D EXT4_PG_TO_LBLK(inode, folio->index + nr_pages); last_block_in_file =3D (ext4_readpage_limit(inode) + blocksize - 1) >> blkbits; if (last_block > last_block_in_file) --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E4F42309BE; Fri, 21 Nov 2025 09:16:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716621; cv=none; b=rdIpFoGrBpZSnfne2RGtqaE/7x+9fq5TTcpfe5Od/CiWr4EY1r6h1pLPksSn4wg32QYoukDYxwql1D/9/uh+bohFiSx7krnn6flIDeDGVK8BKqnMys1vEKfKCnWQ9V8M2lFT3uYpar7LYwtBrVbbS+mJ4D3wcPbUfyq7C5XL2hA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716621; c=relaxed/simple; bh=5W3Z0XNee6raDH58/A7nkZPv+mwSM+TuZmYuKDXaQzo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=u6fHOJFG7yIfA/kzHLE1+QyKxfucQ7Aiq13VMpHESUJ5I6KWNG24zuNRhfBQTEiRN8Z09uCz6PYgtb33X5bx8SYtfx9odasQGn1bOI3KYvgseWV470aunEql1tYGUOk+/XTC1IQjQN8cGS+m767Yhj4sfxbFhofxVfJfmeS6Jiw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dCV283y4kzYQvHP; Fri, 21 Nov 2025 17:16:00 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id CA9A61A07BD; Fri, 21 Nov 2025 17:16:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S21; Fri, 21 Nov 2025 17:16:43 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 17/24] ext4: support large block size in ext4_block_write_begin() Date: Fri, 21 Nov 2025 17:06:47 +0800 Message-Id: <20251121090654.631996-18-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S21 X-Coremail-Antispam: 1UD129KBjvJXoWxJryDZFyxGrykZF4rXrWxXrb_yoW8XF4Dpr y5K3s7GrsF9rWj93W7WFn3Xr1xKa4DWF4UCFW3Zry5XFy8trnagr1kt3s5XF4jqayxZFyk XF1FyryxW3W7ArJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQa14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x02 67AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdsqAUUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgATBWkf34sfFwADs9 Content-Type: text/plain; charset="utf-8" From: Baokun Li Use the EXT4_PG_TO_LBLK() macro to convert folio indexes to blocks to avoid negative left shifts after supporting blocksize greater than PAGE_SIZE. Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo --- fs/ext4/inode.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 65a9c04bc691..9259d08d4a59 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1168,8 +1168,7 @@ int ext4_block_write_begin(handle_t *handle, struct f= olio *folio, unsigned block_start, block_end; sector_t block; int err =3D 0; - unsigned blocksize =3D inode->i_sb->s_blocksize; - unsigned bbits; + unsigned int blocksize =3D i_blocksize(inode); struct buffer_head *bh, *head, *wait[2]; int nr_wait =3D 0; int i; @@ -1178,12 +1177,12 @@ int ext4_block_write_begin(handle_t *handle, struct= folio *folio, BUG_ON(!folio_test_locked(folio)); BUG_ON(to > folio_size(folio)); BUG_ON(from > to); + WARN_ON_ONCE(blocksize > folio_size(folio)); =20 head =3D folio_buffers(folio); if (!head) head =3D create_empty_buffers(folio, blocksize, 0); - bbits =3D ilog2(blocksize); - block =3D (sector_t)folio->index << (PAGE_SHIFT - bbits); + block =3D EXT4_PG_TO_LBLK(inode, folio->index); =20 for (bh =3D head, block_start =3D 0; bh !=3D head || !block_start; block++, block_start =3D block_end, bh =3D bh->b_this_page) { --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B4D433C198; Fri, 21 Nov 2025 09:16:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716615; cv=none; b=VAWSeP1AUiD2J8ZLb5YVHPbU6GNw/oUZGcRendFquLtRi0z2Pgx2r9J4NfzVdmy9tNfV7VbIO2s6cDQ2CJFOEPJCOJpLiQ22BqMzgKz8sJMvPPxUTcjoyRknw0J8czF9o7nBHiMjo3bYji5oUkw2RFYAyv75VtpYgBIcfXTItkg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716615; c=relaxed/simple; bh=Aopa93A2ifOFU7kiqiHr69ihdKUaiB7RUenoyxcKqEk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P6+TR0pbSgQn2uVp1pAmeP15A+8GGVgyTanaYL5EdlMhEAAKyvg7qhJqHZSvtszVed5o3n5UBLBsatLMEvU4ucw8apmeXn5hefHq2q+oYLA3ZItGKvqf8dTa7lizU9Se69blG50V0bn86ywnkI9pX8sG3y1Qqv6zygAPJz9pSsE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dCV2N6PXqzKHMw5; Fri, 21 Nov 2025 17:16:12 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id D61FF1A111D; Fri, 21 Nov 2025 17:16:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S22; Fri, 21 Nov 2025 17:16:43 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 18/24] ext4: support large block size in mpage_map_and_submit_buffers() Date: Fri, 21 Nov 2025 17:06:48 +0800 Message-Id: <20251121090654.631996-19-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S22 X-Coremail-Antispam: 1UD129KBjvJXoW7CF4rWFW3XF4xGw15Cw45Jrb_yoW8Xw1xpF W5W395WFs5urWI9F40qF1DZrnrKayIqa1UXFWFvryYqFyUKr10krn5t3W8Zas8JFWxJrW8 XF1SkryxW3W3ArJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQa14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x02 67AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdsqAUUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgATBWkf34sfFwAFs7 Content-Type: text/plain; charset="utf-8" From: Baokun Li Use the EXT4_PG_TO_LBLK/EXT4_LBLK_TO_PG macros to complete the conversion between folio indexes and blocks to avoid negative left/right shifts after supporting blocksize greater than PAGE_SIZE. Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo --- fs/ext4/inode.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 9259d08d4a59..f076477e2cf8 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2297,15 +2297,14 @@ static int mpage_map_and_submit_buffers(struct mpag= e_da_data *mpd) struct folio_batch fbatch; unsigned nr, i; struct inode *inode =3D mpd->inode; - int bpp_bits =3D PAGE_SHIFT - inode->i_blkbits; pgoff_t start, end; ext4_lblk_t lblk; ext4_fsblk_t pblock; int err; bool map_bh =3D false; =20 - start =3D mpd->map.m_lblk >> bpp_bits; - end =3D (mpd->map.m_lblk + mpd->map.m_len - 1) >> bpp_bits; + start =3D EXT4_LBLK_TO_PG(inode, mpd->map.m_lblk); + end =3D EXT4_LBLK_TO_PG(inode, mpd->map.m_lblk + mpd->map.m_len - 1); pblock =3D mpd->map.m_pblk; =20 folio_batch_init(&fbatch); @@ -2316,7 +2315,7 @@ static int mpage_map_and_submit_buffers(struct mpage_= da_data *mpd) for (i =3D 0; i < nr; i++) { struct folio *folio =3D fbatch.folios[i]; =20 - lblk =3D folio->index << bpp_bits; + lblk =3D EXT4_PG_TO_LBLK(inode, folio->index); err =3D mpage_process_folio(mpd, folio, &lblk, &pblock, &map_bh); /* --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DBEB2D739F; Fri, 21 Nov 2025 09:16:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716620; cv=none; b=EYhnT7R2b6P8Kt4lan/dLdpHiEht9V/YF9zhL0CYNX+YIkOaVPV7eKyW9e3P0+eEUuqc/OsFuLwHI7N+lOlkWdDRFwAI1w7LjN0z8cm4fdeJ0PmlzcH3NDSnR1q/bWkB4HblMMjGMYPZ8j5RV6J43ZsPzCXhYSWbGFa8DH2wxf4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716620; c=relaxed/simple; bh=x7mmQ4rl+dwpRTv8LX97qc42tEMEmyb92PE9kqtnaBA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=q7tl6u1fRI3N9HyrCFOgFeYz60+nWaXbafZIOo6MAoxLOQ3zFrcDaaLsINQAdnjlTQiT6Yzr97L2Hnncmvf6NIUx+T3cL723ppvxvPGJwF4VDsRtNG1ap3PVQ0MXPhUG5oExRophvRVedMV86hmEpuUVhav86MWSEfZw6Esx4GA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dCV284lcGzYQvHk; Fri, 21 Nov 2025 17:16:00 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id E3F3F1A129F; Fri, 21 Nov 2025 17:16:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S23; Fri, 21 Nov 2025 17:16:43 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 19/24] ext4: support large block size in mpage_prepare_extent_to_map() Date: Fri, 21 Nov 2025 17:06:49 +0800 Message-Id: <20251121090654.631996-20-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S23 X-Coremail-Antispam: 1UD129KBjvJXoW7CF4rWFW3XF4xGw15Cw45Jrb_yoW8WrWfpF W5W3ykCr4fX342gFWSgF1DZwsFka4fGayUJFW5tryYva45Kr95uryUtFnYvFn5tFWIyryr XF4Skryfua17JFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQa14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x02 67AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdsqAUUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQATBWkf35kfGgABsj Content-Type: text/plain; charset="utf-8" From: Baokun Li Use the EXT4_PG_TO_LBLK/EXT4_LBLK_TO_PG macros to complete the conversion between folio indexes and blocks to avoid negative left/right shifts after supporting blocksize greater than PAGE_SIZE. Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo --- fs/ext4/inode.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index f076477e2cf8..2a8a31a2b29e 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2618,7 +2618,6 @@ static int mpage_prepare_extent_to_map(struct mpage_d= a_data *mpd) pgoff_t end =3D mpd->end_pos >> PAGE_SHIFT; xa_mark_t tag; int i, err =3D 0; - int blkbits =3D mpd->inode->i_blkbits; ext4_lblk_t lblk; struct buffer_head *head; handle_t *handle =3D NULL; @@ -2657,7 +2656,7 @@ static int mpage_prepare_extent_to_map(struct mpage_d= a_data *mpd) */ if (mpd->wbc->sync_mode =3D=3D WB_SYNC_NONE && mpd->wbc->nr_to_write <=3D - mpd->map.m_len >> (PAGE_SHIFT - blkbits)) + EXT4_LBLK_TO_PG(mpd->inode, mpd->map.m_len)) goto out; =20 /* If we can't merge this page, we are done. */ @@ -2735,8 +2734,7 @@ static int mpage_prepare_extent_to_map(struct mpage_d= a_data *mpd) mpage_folio_done(mpd, folio); } else { /* Add all dirty buffers to mpd */ - lblk =3D ((ext4_lblk_t)folio->index) << - (PAGE_SHIFT - blkbits); + lblk =3D EXT4_PG_TO_LBLK(mpd->inode, folio->index); head =3D folio_buffers(folio); err =3D mpage_process_page_bufs(mpd, head, head, lblk); --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9EFA305E18; Fri, 21 Nov 2025 09:16:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716625; cv=none; b=b1YgEYxjgqpH9a2Ohmv6aYPxO3ngJjaLK0lH9w9q/X/f005BJtqOaCi0+kg027GRj17NdNeRkidMiDsEN+2r3lWBFU4TCoAOA3glqwb3CShOsD1dZ8gN7/KjVX2kTD7SI2NVSDkW5BFnWqczfYhs6JvGVbyzt3sqcXxXx6bQE9k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716625; c=relaxed/simple; bh=fjCWSMb4W8yBys3EG1WjhzsghzWnwGO7O0H3N2c/aRk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dVNxZ9Dvt5I/2vyKt6e2bst4KUOBJGbi9Eijo6/acG1eY4OonW7Kg/CBi/tIOyckzFmQYzAUq7I0jf2lPInbZeZnNgEZ3GOwA+xvDKhD+HlRyz4sMYgs4Y52ZjRaW/B8pJ3jCcAC0JbiW/vZnLO35cY9n/qspV0u36nZwzR3sn4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dCV2P07wBzKHMwH; Fri, 21 Nov 2025 17:16:13 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id F40FC1A12AD; Fri, 21 Nov 2025 17:16:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S24; Fri, 21 Nov 2025 17:16:43 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 20/24] ext4: support large block size in __ext4_block_zero_page_range() Date: Fri, 21 Nov 2025 17:06:50 +0800 Message-Id: <20251121090654.631996-21-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S24 X-Coremail-Antispam: 1UD129KBjvdXoW7Xw45Wr1fWFWrCF4fCr48Zwb_yoWfurcEkF W8Xr4rXw4rXFn3Za95Aan0qan2k3WrCFn8ur13Gr1rZFykXFZ5G3yDtrWYyr4qgFsrW3y5 ArZ7XFWYyFy7WjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbmkFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAVCq3wA2048vs2 IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28E F7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr 1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVW8Jr0_Cr1UMcvjeVCFs4IE7xkEbVWUJVW8 JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2Y2 ka0xkIwI1lw4CEc2x0rVAKj4xxMxkF7I0En4kS14v26r1q6r43MxAIw28IcxkI7VAKI48J MxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwV AFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv2 0xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UMIIF0xvE42xK8V AvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E 14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUbG-e7UUUUU== X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgATBWkf34sfGQABsx Content-Type: text/plain; charset="utf-8" From: Zhihao Cheng Use the EXT4_PG_TO_LBLK() macro to convert folio indexes to blocks to avoid negative left shifts after supporting blocksize greater than PAGE_SIZE. Signed-off-by: Zhihao Cheng Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo --- fs/ext4/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 2a8a31a2b29e..5499b2856f9e 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4074,7 +4074,7 @@ static int __ext4_block_zero_page_range(handle_t *han= dle, =20 blocksize =3D inode->i_sb->s_blocksize; =20 - iblock =3D folio->index << (PAGE_SHIFT - inode->i_sb->s_blocksize_bits); + iblock =3D EXT4_PG_TO_LBLK(inode, folio->index); =20 bh =3D folio_buffers(folio); if (!bh) --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E1683019D7; Fri, 21 Nov 2025 09:16:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716622; cv=none; b=Pzpm0Pf4fkXc0eMWF3lUhfi9sdOtPZFDZHadcQ3deDQ2XcLchlePgJkmsS5Dawg99SnPBqPDjTWLBols9smrbK1ClHQ774nl7RzKjAFGmQD91PDHhVvqQ/3ewb1kU5JKDlRAWBTgFA2lbYj0DH3GiHh4q6dMgrM3RVjsa/NUJV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716622; c=relaxed/simple; bh=5nRH6C9HPbHrAAAWo8bVZIj+b7lLZlXDwmXnibyUFPg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GL459QYREg4sVf8ts+n4reeo9X1m5qGhfNv7lddP8UP3q/ASl3y+nQXiHQohpEPail1EG+qaNXsor2GpUJ7K/JRyVRHaR9GaG8kGxQr8EbJFzjaP2Io4AqB284Q//yWNRp1e3Getm52CRuROSSYQtw7qimSKw/6GMy83XZDvN2c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dCV2P0qPxzKHMw9; Fri, 21 Nov 2025 17:16:13 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 14DCA1A1B41; Fri, 21 Nov 2025 17:16:44 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S25; Fri, 21 Nov 2025 17:16:43 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com, Dan Carpenter Subject: [PATCH v4 21/24] ext4: make data=journal support large block size Date: Fri, 21 Nov 2025 17:06:51 +0800 Message-Id: <20251121090654.631996-22-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S25 X-Coremail-Antispam: 1UD129KBjvJXoW3AF1xWFy3AF47GF4UWF48WFg_yoW7XrWUpr y3Gry8t3ykZFyq9r48ta17Zr1Yg3WxK3yUZ3s3u3Z3Zw1kJ342gF4jyF1xAFWUJrZ3Ww4S qF40yryUCFnIk3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQa14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVW5JVW7JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x02 67AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdsqAUUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQATBWkf35kfGwABsi Content-Type: text/plain; charset="utf-8" From: Baokun Li Currently, ext4_set_inode_mapping_order() does not set max folio order for files with the data journalling flag. For files that already have large folios enabled, ext4_inode_journal_mode() ignores the data journalling flag once max folio order is set. This is not because data journalling cannot work with large folios, but because credit estimates will go through the roof if there are too many blocks per folio. Since the real constraint is blocks-per-folio, to support data=3Djournal under LBS, we now set max folio order to be equal to min folio order for files with the journalling flag. When LBS is disabled, the max folio order remains unset as before. Therefore, before ext4_change_inode_journal_flag() switches the journalling mode, we call truncate_pagecache() to drop all page cache for that inode, and filemap_write_and_wait() is called unconditionally. After that, once the journalling mode has been switched, we can safely reset the inode mapping order, and the mapping_large_folio_support() check in ext4_inode_journal_mode() can be removed. Suggested-by: Jan Kara Suggested-by: Dan Carpenter Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo --- fs/ext4/ext4_jbd2.c | 3 +-- fs/ext4/inode.c | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c index a0e66bc10093..05e5946ed9b3 100644 --- a/fs/ext4/ext4_jbd2.c +++ b/fs/ext4/ext4_jbd2.c @@ -16,8 +16,7 @@ int ext4_inode_journal_mode(struct inode *inode) ext4_test_inode_flag(inode, EXT4_INODE_EA_INODE) || test_opt(inode->i_sb, DATA_FLAGS) =3D=3D EXT4_MOUNT_JOURNAL_DATA || (ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA) && - !test_opt(inode->i_sb, DELALLOC) && - !mapping_large_folio_support(inode->i_mapping))) { + !test_opt(inode->i_sb, DELALLOC))) { /* We do not support data journalling for encrypted data */ if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) return EXT4_INODE_ORDERED_DATA_MODE; /* ordered */ diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 5499b2856f9e..fff059bfeb52 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5152,9 +5152,6 @@ static bool ext4_should_enable_large_folio(struct ino= de *inode) =20 if (!S_ISREG(inode->i_mode)) return false; - if (test_opt(sb, DATA_FLAGS) =3D=3D EXT4_MOUNT_JOURNAL_DATA || - ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA)) - return false; if (ext4_has_feature_verity(sb)) return false; if (ext4_has_feature_encrypt(sb)) @@ -5172,12 +5169,20 @@ static bool ext4_should_enable_large_folio(struct i= node *inode) umin(MAX_PAGECACHE_ORDER, (11 + (i)->i_blkbits - PAGE_SHIFT)) void ext4_set_inode_mapping_order(struct inode *inode) { + u32 max_order; + if (!ext4_should_enable_large_folio(inode)) return; =20 + if (test_opt(inode->i_sb, DATA_FLAGS) =3D=3D EXT4_MOUNT_JOURNAL_DATA || + ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA)) + max_order =3D EXT4_SB(inode->i_sb)->s_min_folio_order; + else + max_order =3D EXT4_MAX_PAGECACHE_ORDER(inode); + mapping_set_folio_order_range(inode->i_mapping, EXT4_SB(inode->i_sb)->s_min_folio_order, - EXT4_MAX_PAGECACHE_ORDER(inode)); + max_order); } =20 struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, @@ -6552,14 +6557,14 @@ int ext4_change_inode_journal_flag(struct inode *in= ode, int val) * dirty data which can be converted only after flushing the dirty * data (and journalled aops don't know how to handle these cases). */ - if (val) { - filemap_invalidate_lock(inode->i_mapping); - err =3D filemap_write_and_wait(inode->i_mapping); - if (err < 0) { - filemap_invalidate_unlock(inode->i_mapping); - return err; - } + filemap_invalidate_lock(inode->i_mapping); + err =3D filemap_write_and_wait(inode->i_mapping); + if (err < 0) { + filemap_invalidate_unlock(inode->i_mapping); + return err; } + /* Before switch the inode journalling mode evict all the page cache. */ + truncate_pagecache(inode, 0); =20 alloc_ctx =3D ext4_writepages_down_write(inode->i_sb); jbd2_journal_lock_updates(journal); @@ -6579,17 +6584,17 @@ int ext4_change_inode_journal_flag(struct inode *in= ode, int val) if (err < 0) { jbd2_journal_unlock_updates(journal); ext4_writepages_up_write(inode->i_sb, alloc_ctx); + filemap_invalidate_unlock(inode->i_mapping); return err; } ext4_clear_inode_flag(inode, EXT4_INODE_JOURNAL_DATA); } ext4_set_aops(inode); + ext4_set_inode_mapping_order(inode); =20 jbd2_journal_unlock_updates(journal); ext4_writepages_up_write(inode->i_sb, alloc_ctx); - - if (val) - filemap_invalidate_unlock(inode->i_mapping); + filemap_invalidate_unlock(inode->i_mapping); =20 /* Finally we can mark the inode as dirty. */ =20 --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75147340A7F; Fri, 21 Nov 2025 09:16:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716621; cv=none; b=psXpkpCzZBSA7bsQ5m6TVz21qR3jpFUCeATRIxOs3EsqvaJU1td8VOYoDffs0Z71MP8/LEU3fiA6HIgQJjLGLU0fK66Mx1m71C3Lyc6S7tnUrLIG9tLhW0P8I9kdmIpiqRM8LPV+c17qP6+zXF8H/oKcV67nU7XBJ0YYEpah8yc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716621; c=relaxed/simple; bh=U/HqwL2F2Q0NTlnPB6nuLFHOK+usstHUVGB8em0BHeI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=O0HF+4qRnYneqtP2Epo4OpY6R7SZ9DMHZ1oBQW7DoMCHTImN0QV4qVT3icx0SCj7vFCW8Avgznyw8JBQvmz6izlGwBCoUTPCXyLsKF1kN0n560G7YB+Nu4FRfYa3XxoRiE3sBLsSqmPazIR+7CxOO6iy7Ap9msoHxBI4qqqgYDo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dCV2860F5zYQvHn; Fri, 21 Nov 2025 17:16:00 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 209161A1C7A; Fri, 21 Nov 2025 17:16:44 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S26; Fri, 21 Nov 2025 17:16:43 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 22/24] ext4: support verifying data from large folios with fs-verity Date: Fri, 21 Nov 2025 17:06:52 +0800 Message-Id: <20251121090654.631996-23-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S26 X-Coremail-Antispam: 1UD129KBjvdXoW7Wry5XF13ZF13trW8Wr18Grg_yoWkJwbE93 4vvw40v3yfKw4IkrW5Ar4aqryv9F48Wr1Uuayaqr1Yvr4fJ39xA3ZrKrs8Aa1DWayUWFZ8 CFsxJFnFyryjvjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbmkFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAVCq3wA2048vs2 IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28E F7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr 1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVW8Jr0_Cr1UMcvjeVCFs4IE7xkEbVWUJVW8 JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2Y2 ka0xkIwI1lw4CEc2x0rVAKj4xxMxkF7I0En4kS14v26r1q6r43MxAIw28IcxkI7VAKI48J MxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwV AFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv2 0xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UMIIF0xvE42xK8V AvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E 14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUbG-e7UUUUU== X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgATBWkf34sfGgABsy Content-Type: text/plain; charset="utf-8" From: Baokun Li Eric Biggers already added support for verifying data from large folios several years ago in commit 5d0f0e57ed90 ("fsverity: support verifying data from large folios"). With ext4 now supporting large block sizes, the fs-verity tests `kvm-xfstests -c ext4/64k -g verity -x encrypt` pass without issues. Therefore, remove the restriction and allow large folios to be enabled together with fs-verity. Cc: Eric Biggers Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo --- fs/ext4/inode.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index fff059bfeb52..d2fa3471f59a 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5152,8 +5152,6 @@ static bool ext4_should_enable_large_folio(struct ino= de *inode) =20 if (!S_ISREG(inode->i_mode)) return false; - if (ext4_has_feature_verity(sb)) - return false; if (ext4_has_feature_encrypt(sb)) return false; =20 --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1AB1721420B; Fri, 21 Nov 2025 09:16:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716621; cv=none; b=MfuShXgtdyzjSuobXVwXXaEppmuZE2gGgHKyOGBWFKg7IRSDjJjy721Y8pLQLKyRTd3YZ+GXun3+HRwnQ3RXBoUzE7hWtbCxamIZbNGHwlornQKK1aKgBUEN/lFXDwVrNmXhfV1OTnHw53S9sf29dL5x5HKZRC7WQBp0u3LQHSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716621; c=relaxed/simple; bh=rpuopjqN2hrjVl7dOeHpWVRyWqrq7RuGyaPKP4JZg1U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Jg6oQp276SEui3Zssu3/zbL/v2DRZmPRWnqIyGFzfnNhz21NrijD9wGBHpgs2QDitk6tHruoz0923n4Z+0ce74xrY0y7JYGkanQbuJfQTdEdk9O3zwk7r1jCvn5FhlVQvV1bf2P75r/n7PZgkEMUo08azQGr0LpQrS4DSDfVfSk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dCV286v3fzYQvHn; Fri, 21 Nov 2025 17:16:00 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 3D0FF1A1B38; Fri, 21 Nov 2025 17:16:44 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S27; Fri, 21 Nov 2025 17:16:43 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com Subject: [PATCH v4 23/24] ext4: add checks for large folio incompatibilities when BS > PS Date: Fri, 21 Nov 2025 17:06:53 +0800 Message-Id: <20251121090654.631996-24-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S27 X-Coremail-Antispam: 1UD129KBjvJXoW3XF4fAw4fXF4fCFWkur45Jrb_yoW7XF15pF W3Cr1fZrW8Zr97Wws7tanrXr1Ykay8tayUJ3yxu3W7J345t34IyFW0vF1ayFyUtrW8Xryx Xa1Utry29wnrGFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQa14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVW5JVW7JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x02 67AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdsqAUUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgATBWkf34sfGgADsw Content-Type: text/plain; charset="utf-8" From: Baokun Li Supporting a block size greater than the page size (BS > PS) requires support for large folios. However, several features (e.g., encrypt) do not yet support large folios. To prevent conflicts, this patch adds checks at mount time to prohibit these features from being used when BS > PS. Since these features cannot be changed on remount, there is no need to check on remount. This patch adds s_max_folio_order, initialized during mount according to filesystem features and mount options. If s_max_folio_order is 0, large folios are disabled. With this in place, ext4_set_inode_mapping_order() can be simplified by checking s_max_folio_order, avoiding redundant checks. Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Zhang Yi Reviewed-by: Ojaswin Mujoo --- fs/ext4/ext4.h | 4 +++- fs/ext4/inode.c | 38 ++++++++++---------------------------- fs/ext4/super.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 29 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 4bc0b2b7288a..79dc231d6e22 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1696,7 +1696,9 @@ struct ext4_sb_info { unsigned long s_last_trim_minblks; =20 /* minimum folio order of a page cache allocation */ - unsigned int s_min_folio_order; + u16 s_min_folio_order; + /* supported maximum folio order, 0 means not supported */ + u16 s_max_folio_order; =20 /* Precomputed FS UUID checksum for seeding other checksums */ __u32 s_csum_seed; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index d2fa3471f59a..61b803a79756 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5146,41 +5146,23 @@ static int check_igot_inode(struct inode *inode, ex= t4_iget_flags flags, return -EFSCORRUPTED; } =20 -static bool ext4_should_enable_large_folio(struct inode *inode) +void ext4_set_inode_mapping_order(struct inode *inode) { struct super_block *sb =3D inode->i_sb; + u16 min_order, max_order; =20 - if (!S_ISREG(inode->i_mode)) - return false; - if (ext4_has_feature_encrypt(sb)) - return false; - - return true; -} - -/* - * Limit the maximum folio order to 2048 blocks to prevent overestimation - * of reserve handle credits during the folio writeback in environments - * where the PAGE_SIZE exceeds 4KB. - */ -#define EXT4_MAX_PAGECACHE_ORDER(i) \ - umin(MAX_PAGECACHE_ORDER, (11 + (i)->i_blkbits - PAGE_SHIFT)) -void ext4_set_inode_mapping_order(struct inode *inode) -{ - u32 max_order; + max_order =3D EXT4_SB(sb)->s_max_folio_order; + if (!max_order) + return; =20 - if (!ext4_should_enable_large_folio(inode)) + min_order =3D EXT4_SB(sb)->s_min_folio_order; + if (!min_order && !S_ISREG(inode->i_mode)) return; =20 - if (test_opt(inode->i_sb, DATA_FLAGS) =3D=3D EXT4_MOUNT_JOURNAL_DATA || - ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA)) - max_order =3D EXT4_SB(inode->i_sb)->s_min_folio_order; - else - max_order =3D EXT4_MAX_PAGECACHE_ORDER(inode); + if (ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA)) + max_order =3D min_order; =20 - mapping_set_folio_order_range(inode->i_mapping, - EXT4_SB(inode->i_sb)->s_min_folio_order, - max_order); + mapping_set_folio_order_range(inode->i_mapping, min_order, max_order); } =20 struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 998ddce49093..3d03a6eb0ea0 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5042,6 +5042,41 @@ static const char *ext4_has_journal_option(struct su= per_block *sb) return NULL; } =20 +/* + * Limit the maximum folio order to 2048 blocks to prevent overestimation + * of reserve handle credits during the folio writeback in environments + * where the PAGE_SIZE exceeds 4KB. + */ +#define EXT4_MAX_PAGECACHE_ORDER(sb) \ + umin(MAX_PAGECACHE_ORDER, (11 + (sb)->s_blocksize_bits - PAGE_SHIFT)) +static void ext4_set_max_mapping_order(struct super_block *sb) +{ + struct ext4_sb_info *sbi =3D EXT4_SB(sb); + + if (test_opt(sb, DATA_FLAGS) =3D=3D EXT4_MOUNT_JOURNAL_DATA) + sbi->s_max_folio_order =3D sbi->s_min_folio_order; + else + sbi->s_max_folio_order =3D EXT4_MAX_PAGECACHE_ORDER(sb); +} + +static int ext4_check_large_folio(struct super_block *sb) +{ + const char *err_str =3D NULL; + + if (ext4_has_feature_encrypt(sb)) + err_str =3D "encrypt"; + + if (!err_str) { + ext4_set_max_mapping_order(sb); + } else if (sb->s_blocksize > PAGE_SIZE) { + ext4_msg(sb, KERN_ERR, "bs(%lu) > ps(%lu) unsupported for %s", + sb->s_blocksize, PAGE_SIZE, err_str); + return -EINVAL; + } + + return 0; +} + static int ext4_load_super(struct super_block *sb, ext4_fsblk_t *lsb, int silent) { @@ -5318,6 +5353,10 @@ static int __ext4_fill_super(struct fs_context *fc, = struct super_block *sb) =20 ext4_apply_options(fc, sb); =20 + err =3D ext4_check_large_folio(sb); + if (err < 0) + goto failed_mount; + err =3D ext4_encoding_init(sb, es); if (err) goto failed_mount; --=20 2.46.1 From nobody Tue Dec 2 01:33:05 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F27D303CA1; Fri, 21 Nov 2025 09:16:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716623; cv=none; b=urenZVuMNh3jo/TICX7hV/UpdQjyf9+/EdkBnOzDswh+WNIHUnaCp4++rAfFoh++xdACVq11n0udY1X4DRkSbXhse7QNS1rA9VZBxwzNJf23OlXoIn0MmiA99V0rjhBN8j7lBaTqfNMQyJjp3ir2h+kpT8HJdYNDkQUsj2WcP40= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763716623; c=relaxed/simple; bh=aF+DbgPYapqeQ+9Sv3+u8mH464IRHeCbCP54ohxIjj0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AWhp7PiELtNVHiwQR1LJUUmEmsUAKhu/vws0DvdOiocqul64digC/yA9FWgflOJJYDU8bu8dW7G15sSI9kS2Cx3NefKSjvVlVkXNq7sdow5HsUqeCQOT6Om7MJWrI7jqjOBp+mgLV45lV6ojlQV2uq54/8KT0MUeNLsIt0mJg6o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dCV2P2X08zKHMwX; Fri, 21 Nov 2025 17:16:13 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 4F5921A0FC0; Fri, 21 Nov 2025 17:16:44 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.87.129]) by APP2 (Coremail) with SMTP id Syh0CgBHpXv4LSBpaLMDBg--.2072S28; Fri, 21 Nov 2025 17:16:44 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, kernel@pankajraghav.com, mcgrof@kernel.org, ebiggers@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, libaokun@huaweicloud.com, Pankaj Raghav Subject: [PATCH v4 24/24] ext4: enable block size larger than page size Date: Fri, 21 Nov 2025 17:06:54 +0800 Message-Id: <20251121090654.631996-25-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20251121090654.631996-1-libaokun@huaweicloud.com> References: <20251121090654.631996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgBHpXv4LSBpaLMDBg--.2072S28 X-Coremail-Antispam: 1UD129KBjvJXoWxAr4fAryUXrWUtF1DZFWUurg_yoW5WrWxp3 WrGFy8Ar15WFyUua9rWFsF9as3Gw1v9FyUXr90gw1UZFZrX34xKrn7tFy5XFyjqrZ3uFWf XF1vyryayr43uaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQa14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7M4kE6xkIj40Ew7xC0wCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVW5JVW7JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x02 67AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdsqAUUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQATBWkf35kfHAAAsk Content-Type: text/plain; charset="utf-8" From: Baokun Li Since block device (See commit 3c20917120ce ("block/bdev: enable large folio support for large logical block sizes")) and page cache (See commit ab95d23bab220ef8 ("filemap: allocate mapping_min_order folios in the page cache")) has the ability to have a minimum order when allocating folio, and ext4 has supported large folio in commit 7ac67301e82f ("ext4: enable large folio for regular file"), now add support for block_size > PAGE_SIZE in ext4. set_blocksize() -> bdev_validate_blocksize() already validates the block size, so ext4_load_super() does not need to perform additional checks. Here we only need to add the FS_LBS bit to fs_flags. In addition, block sizes larger than the page size are currently supported only when CONFIG_TRANSPARENT_HUGEPAGE is enabled. To make this explicit, a blocksize_gt_pagesize entry has been added under /sys/fs/ext4/feature/, indicating whether bs > ps is supported. This allows mke2fs to check the interface and determine whether a warning should be issued when formatting a filesystem with block size larger than the page size. Suggested-by: Theodore Ts'o Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Pankaj Raghav Reviewed-by: Ojaswin Mujoo --- fs/ext4/super.c | 3 ++- fs/ext4/sysfs.c | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 3d03a6eb0ea0..87205660c5d0 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -7453,7 +7453,8 @@ static struct file_system_type ext4_fs_type =3D { .init_fs_context =3D ext4_init_fs_context, .parameters =3D ext4_param_specs, .kill_sb =3D ext4_kill_sb, - .fs_flags =3D FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_MGTIME, + .fs_flags =3D FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_MGTIME | + FS_LBS, }; MODULE_ALIAS_FS("ext4"); =20 diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c index 987bd00f916a..0018e09b867e 100644 --- a/fs/ext4/sysfs.c +++ b/fs/ext4/sysfs.c @@ -332,6 +332,9 @@ EXT4_ATTR_FEATURE(fast_commit); #if IS_ENABLED(CONFIG_UNICODE) && defined(CONFIG_FS_ENCRYPTION) EXT4_ATTR_FEATURE(encrypted_casefold); #endif +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +EXT4_ATTR_FEATURE(blocksize_gt_pagesize); +#endif =20 static struct attribute *ext4_feat_attrs[] =3D { ATTR_LIST(lazy_itable_init), @@ -351,6 +354,9 @@ static struct attribute *ext4_feat_attrs[] =3D { ATTR_LIST(fast_commit), #if IS_ENABLED(CONFIG_UNICODE) && defined(CONFIG_FS_ENCRYPTION) ATTR_LIST(encrypted_casefold), +#endif +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + ATTR_LIST(blocksize_gt_pagesize), #endif NULL, }; --=20 2.46.1