Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp8085810rdb; Thu, 4 Jan 2024 19:33:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IEgu+ZCCqlg2EL+o3wjt1ONmbzEPnXDBhFwZ+gC5VvX78dyhm1loT1bzsyT+SY3MyOho7oQ X-Received: by 2002:a05:6871:460b:b0:204:1d3e:94d with SMTP id nf11-20020a056871460b00b002041d3e094dmr1801908oab.11.1704425615727; Thu, 04 Jan 2024 19:33:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704425615; cv=none; d=google.com; s=arc-20160816; b=F3MADTB1ZVRmPtld5e33VrpigWN231inoVnwpVcTb6ehR5qdF44+LpLU++ipShb8qr 0k7fdOmkeUxhbyRviVtlDhJtaiRfp9d4A9u7KLqNI384HTk/qpyWNxspOSz0u9uTesCN q9jkuQUVCxRfO3VHkSLZ9mxc17bXPYpvVNtNmYfQQZirn0PnBXo+Yw6CFUbEqdgrQQMm 5CWPW/ICScb2xWnNwc78OL3LcBTsyTg0WShUT+PIcXa87dlK3pW3c5TexB/iSGPSiRmu GNR1oMW6ydQ8J6eb2iLy02/zI4kRgYArOr+kgVrZ3V6mi549IxnKcI6OoB0ueUsq6j6X UAEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=kATHz1/ug5teIHGhsTsvlMF8lutPolqn5X3kiv7q1y0=; fh=Uq/HK0tePPZ4uFSrjmAoQ+8fm8HBRKIYZPcFTEYnhm4=; b=FmFuODQnndVZ5Yjs9OqjbwCWwn8ColOyKuGWqyCmjtYEPAS+UlBE/TvistcrRBFFKY c9rmCQ6Rsvvhq4PwvM+NvevYur/p9MHRSSsjYWB42vbUa+7zLiRYHgaNjtPeo259dqmG 7cHPhY5/dM18LsmZ5MuC4GR2/OzWBiNGDZCNDVNcLsGvffBkmXSNe00GEmmdMUxnc0qk lB+r5eRa7xd3vXp+22rEoTPoamkgTWJajKHmC/Gknygt9KWll8EksDpwv1qMoHNSUP6S uB+HSgmSNJ1RAnFyYy1U0XAUhob7lh+Wfh+ZrW3hz9eJSRsPdQKtVSS3hh/wJX4qp3l1 Yy8Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-718-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-ext4+bounces-718-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id cb6-20020a056a02070600b005cd7dd8116bsi635108pgb.89.2024.01.04.19.33.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 19:33:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-718-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-718-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-ext4+bounces-718-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 320682869DC for ; Fri, 5 Jan 2024 03:33:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C4D19525A; Fri, 5 Jan 2024 03:33:24 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout11.his.huawei.com (unknown [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 B05514432 for ; Fri, 5 Jan 2024 03:33:22 +0000 (UTC) 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 ESMTP id 4T5pvF5w1Zz4f3pJD for ; Fri, 5 Jan 2024 11:33:13 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 8C73E1A0A2C for ; Fri, 5 Jan 2024 11:33:19 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgDn6hByeJdlyaRBFg--.23173S8; Fri, 05 Jan 2024 11:33:19 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: [PATCH v3 4/6] ext4: add a hole extent entry in cache after punch Date: Fri, 5 Jan 2024 11:30:16 +0800 Message-Id: <20240105033018.1665752-5-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240105033018.1665752-1-yi.zhang@huaweicloud.com> References: <20240105033018.1665752-1-yi.zhang@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgDn6hByeJdlyaRBFg--.23173S8 X-Coremail-Antispam: 1UD129KBjvJXoW7Ar1kWr15Gr1DXFyrGw4Durg_yoW8Xr4Dp3 98Ca4Sgr1kW34kuan7XFWUXr1293WUGw4UXrW29w1xWFyUA3WI9Fn09F43Z3W8KrW7Xw4F qF48KryY9w1Uu3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9C14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0EwIxGrw CFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE 14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2 IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxK x2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI 0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ 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); -- 2.39.2