From patchwork Sat Jan 27 01:58:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13533899 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83837C47422 for ; Sat, 27 Jan 2024 02:03:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9374F6B008C; Fri, 26 Jan 2024 21:02:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 83D316B0098; Fri, 26 Jan 2024 21:02:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41BBA6B0093; Fri, 26 Jan 2024 21:02:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2AB296B0096 for ; Fri, 26 Jan 2024 21:02:51 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0C07D1406D4 for ; Sat, 27 Jan 2024 02:02:51 +0000 (UTC) X-FDA: 81723442542.15.EEBA158 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf19.hostedemail.com (Postfix) with ESMTP id 1103C1A001D for ; Sat, 27 Jan 2024 02:02:47 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706320969; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kATHz1/ug5teIHGhsTsvlMF8lutPolqn5X3kiv7q1y0=; b=r0e+471pppjdjclLFEQiN34Z1oQZWcvou2Z+SCwiwbu30/lRVBX2QydKZ8obQNrjFs41ZN 7sjCjOueFDDAZnrdgUg5em7W6hzhCw5/BdL+mdkKDCxrAeKOEZZ54c657PElTUBjDet4Ja JhGqT/L6Ugo8ltbeG4H9ed9e6PM2xpg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320969; a=rsa-sha256; cv=none; b=duxiwsG+9e+NyNZowG1WZLMiR0hYCJ4g8CcEoFiuuk1SpJAbDQ6nJ8QVpOhvAqplbQA/SD nWF8qjp7X72IDAUEovNReCHMfywStpfMYVQfD2j+YcLi4SwugEdq2Q1UdMVV53ryXJaQA3 QWijKWaCfJTBtBEVVb+hqghLIqUYsyA= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrb3tbrz4f3k5Y for ; Sat, 27 Jan 2024 10:02:39 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id EF3F11A0171 for ; Sat, 27 Jan 2024 10:02:41 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S8; Sat, 27 Jan 2024 10:02:41 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [PATCH v3 04/26] ext4: add a hole extent entry in cache after punch Date: Sat, 27 Jan 2024 09:58:03 +0800 Message-Id: <20240127015825.1608160-5-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S8 X-Coremail-Antispam: 1UD129KBjvJXoW7Ar1kWr15Gr1DXFyrGw4Durg_yoW8Xr4Dp3 98Ca4Sgr1kW34kuan7XFWUXr1293WUGw4UXrW29w1xWFyUA3WI9Fn09F43Z3W8KrW7Xw4F qF48KryY9w1Uu3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPF14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJV W8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUoxhL UUUUU X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 1103C1A001D X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: pir1dzgstaw35dpdgpi8ubim4hxrihcp X-HE-Tag: 1706320967-857375 X-HE-Meta: U2FsdGVkX18X1ob7SwXD9G4xRpeGmhHIffPlASXkLDYzOTZexIEdtWjRqtDuNsjeAimHwLQ1TpK1PbffV0rnFtKeTqQgd4RxjNEf+vlbISTvd28ELAsUD+wJe4fg/xmydmeqLpKCdUjK8NNiA+wb9jc0gdn+/ZCTFqT/wyyfv7B1KpTcAKe6VJkLYLAjcd1S/sl49qac1SqUrdgqymnx7y9ugVbIhkfdzq/vlAlW0bbLiIGITBMIEt7bPXxfW8fbNrTqLgaTzqJ3ndq6yu1g8+MGrY6ihuQjEDlhUqvvVaUfHLs9prHLH7G/O4au3cyW1dmd1Gs/3uiIzs2p9N7vvJTbeHg26GIrdEBqEWgsffe6US8YFdYPqLweGE2UFWEQEUG3As5yOKOW9jWqncFZDg0AET6NqJTdyn7xAco8zqtKmFK5B2h1Cu2Q6FvPvKjdMqujQwfFqLx2HzPkNpKAZDAyBzHPtSeuFFKfCqb+VRrBeOBpSmn+jnEeIOQjXU5xoSC/Zcom6zBXnpJrJBWSAFjKNDzKm4yEIScK0a9aA0N3BL+DcKFzWtt6Q55WYfMd57ZYHhpXVE8uRk61f44vyUD8JVLCTa/awdx005A3yumpUgnPz7+ROSf1KreZM2dUdF4SQOQTJZmbFqU7zCU1Cd0PoJaSOhoEKcbgXMB3U6TmsaUjqezXkfEjYCEFOgAlbmwGD7uGzlMf7ccImoJMqK5M/Yn3xnRw/LvWttbBX6+BVw8m9v2pzWwsBljOp/ztLo118BzIXraw4FrNVaTilnrHYLNuCa7QsVsK53Fv2738W+zOM9/FJrkKKvWjtJD5s01A12AVmyNo9wpz0H9EutY4w6FRWRNRf17IqvSpZ9jXG0N9Z7VKhV1Z0a6GPfJw+hIg1lHKD+HJY3KkCVt9nsmjM7J4H+CRqKy+8g8PRs31Tku78YhFT6bzPRv9XZRA7DLtSZrpkpS4TVURLil bp+5BGhI Up1EyHyQxFKaZN2538CKMUuCDYmFTVjC/CMOYso7AYL1hjHRew7Ch2yFVcY3NYngAwJ4XBzmnqHTnpReoehfdWvhOlqNj5Ji1UxZeAuOfFZ8HGLmi1i/Yc17zZlQvizP3IaYl6b18zuCwdOUIw5EkgDC/AtyQmp6aaQNWVa+ehA9JMEqlz+aOlwwdaJSrQIby65YTnbdTXV/RVTZ0eHPlnuCd2idpTcBOS+KZiuWYN4K5RlTHO8UdwXgeH5BoPZYA8xVy X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi In order to cache hole extents in the extent status tree and keep the hole length as long as possible, re-add a hole entry to the cache just after punching a hole. Signed-off-by: Zhang Yi Reviewed-by: Jan Kara --- fs/ext4/inode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 142c67f5c7fc..1b5e6409f958 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4000,12 +4000,12 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length) /* If there are blocks to remove, do it */ if (stop_block > first_block) { + ext4_lblk_t hole_len = stop_block - first_block; down_write(&EXT4_I(inode)->i_data_sem); ext4_discard_preallocations(inode, 0); - ext4_es_remove_extent(inode, first_block, - stop_block - first_block); + ext4_es_remove_extent(inode, first_block, hole_len); if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) ret = ext4_ext_remove_space(inode, first_block, @@ -4014,6 +4014,8 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length) ret = ext4_ind_remove_space(handle, inode, first_block, stop_block); + ext4_es_insert_extent(inode, first_block, hole_len, ~0, + EXTENT_STATUS_HOLE); up_write(&EXT4_I(inode)->i_data_sem); } ext4_fc_track_range(handle, inode, first_block, stop_block);