From patchwork Sat Jan 27 01:58:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13533906 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 5B790C47DA9 for ; Sat, 27 Jan 2024 02:03:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB7AF6B009E; Fri, 26 Jan 2024 21:02:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D409A6B009D; Fri, 26 Jan 2024 21:02:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B6B596B009E; Fri, 26 Jan 2024 21:02:55 -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 A01A96B009D for ; Fri, 26 Jan 2024 21:02:55 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 76BE2140F0F for ; Sat, 27 Jan 2024 02:02:55 +0000 (UTC) X-FDA: 81723442710.09.895D506 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf30.hostedemail.com (Postfix) with ESMTP id F02F580020 for ; Sat, 27 Jan 2024 02:02:52 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 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=1706320973; 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=uC1nS63G2vqggRSn2dOOIt2ysYrZz+B3cJj8p8R4VNQ=; b=Z5E4zAFR708a4iyFIjI2FwwPrfR4SwgX8+184XcCc72SxW0yfxczaSDP3WFX1zP2bjM4vX Tjja8DNjKF9rni9DZFjEV0JsFSvXICUK/rKl0IB9sH6RBQW5yGIj7KzPPOn4NQMHHbqGzA qKeuccyHrJGsB56G316bcAARufWJJLg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320973; a=rsa-sha256; cv=none; b=LSM5vxCaGCz7cirYJcp/VrbXh515fBFbS50k45duaSwuPWutPb0RNTKWOLOYvmNJQzv6bE Fyvb5+8KZkyqHmZxLCfvUqc7yh1LYO0JFIHGJyVThvWoMOi6IUYQjG2aX3a6ouxi4ZYhU4 MIc4YndsT/MgKPi60KGH0PFqmGq2rzg= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TMHrj1tbpz4f3lwb for ; Sat, 27 Jan 2024 10:02:45 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 442B71A016E for ; Sat, 27 Jan 2024 10:02:49 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S19; Sat, 27 Jan 2024 10:02:49 +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: [RFC PATCH v3 15/26] ext4: introduce seq counter for extent entry Date: Sat, 27 Jan 2024 09:58:14 +0800 Message-Id: <20240127015825.1608160-16-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--.7377S19 X-Coremail-Antispam: 1UD129KBjvJXoW3Jw1kZw4xGFy8Jr4DGF15urg_yoW7Zr43pa 97AryUGrZ3Xw4j9a1xXw10qr45Za48urW7Gr9Ig34rXFWftrn0gF1DtFyjvF90qFW0kr17 XFW0kryDAa17WFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: F02F580020 X-Rspam-User: X-Stat-Signature: rjgtwzgmzq4ogieb68gtecf8j1ebnz1e X-Rspamd-Server: rspam03 X-HE-Tag: 1706320972-689495 X-HE-Meta: U2FsdGVkX1+GSscDitjIsmftVx0yz4e4wMCqb1039BjZP4iC8GGrw/7sruvuq+f99bQfy5la+5OThhOAHlxf7n2t1bH5vyBQmbuSPNEetyINWFEANeIyDf26qwUolXA9Cjb1cl8AWxFIRRZplhH4gahOGoIlgFRdgJXk9Zd7gFC48+GQyYB0RAUnsrzIhjJNgOODkfj6krxNSBYYD0OzFyFkj3/V6e5y12DcWM0GnDVu1gZyseY716NATS3b9jP5puOc5LHAXDFkltTsNze8kLw0ZKKjHJa1H6ug3BXOGK3UZDTuccG9Lfkwm+zUuzWKKOevFdIQngONK49OxVZtiaKVboPsd0rcI5GSmjrkiGtE+PrN9waodoPTEaGMD+TxSsPPprCRZo3wj7o6z5p7HxT//HElgT4Pn2wo3cSAjqCOGU1t5w1Ouswi19HyO7qLVu+mqFSzPC/TSGRT3gXk0qgQlKMR9+SEhZhuCk9TjFXye4M+BtUx5r0VfAuiMZ5BgrSsrB7a+d/Dnh0FNAPeHsVKSw77EOdSSPjlvcqE/7clZ0uyn9uDelbv8+owUeN7ZhI/Z57ypyoHFEoSyuqfqjJhHhNQbMJebIzzjaOwkf9tvCTQzX97CHmgowLdr7wtqQpvH0ShxZWcqyTqGKBodsEXzvqjchgvxnB2g1P635LnI/HenDjgoTLdUJ+mTOjgkwB5AR70V9KoHIWN0ByY1RwmEHMPL/ABuNH5xcbALNJcvYTwnrg6vyceQ1sPGMR1kUyDXDQHFoKkj8/1RTYG2NqqV2vFdnGTYm+vCMrUyCzsi3quipUaaKUlBUU3WYKfV/+9fxMxT+QXumKAKw8/GW/V7FWGvM26BocAWG2nO4ynDjbQULFhrbR/W/w1Ta4NbBz1mbBCIQ5Y24W1uAnPqyJrLzFnlZPydEpGfXXbd8ta06jYs0g2gDoXwZfMim0AocYzfB1tBDi1BqcFT2/ XaCoJDsh 97Fn3J40hGzRH+1ym+EOh5VkBjuN6q99L0wayZoqIsrns51l94ie9U0muwJKdHW3dbmnIab5vokO5CDgFJIljPHIO/yQkk/7xtGbK0k1EeOsmguBfPkb+lgCPX4ISDOzOB+W4v1EscoLVppkkx1Tv9mhuPuFwj3ONtL+5gtsMpJxivNgG/Ivh1/4mTHWKhV462JCq3VUgR3s/bIOx+Za7/HSi2Ps686qqhK54r9ETivJKYwAdPsuerrshrIL7lBJJ1yubhZ4ag7rWQR5vvrRRmoAfR5/xBpOjOgv8 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 Add a modify counter for extents to indicate the version of one inode's extent status, increase it once extent changes, it will be used for converting regular file's buffered write path to iomap. Signed-off-by: Zhang Yi --- fs/ext4/ext4.h | 1 + fs/ext4/extents_status.c | 13 ++++++++++++- fs/ext4/super.c | 1 + include/trace/events/ext4.h | 19 +++++++++++++------ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 55195909d32f..287284a3f128 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1115,6 +1115,7 @@ struct ext4_inode_info { ext4_lblk_t i_es_shrink_lblk; /* Offset where we start searching for extents to shrink. Protected by i_es_lock */ + unsigned int i_es_seq; /* modify counter for extents */ /* ialloc */ ext4_group_t i_last_alloc_group; diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 324a6b0a6283..b0a4aa60b311 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -204,6 +204,13 @@ static inline ext4_lblk_t ext4_es_end(struct extent_status *es) return es->es_lblk + es->es_len - 1; } +static inline void ext4_es_inc_seq(struct inode *inode) +{ + struct ext4_inode_info *ei = EXT4_I(inode); + + WRITE_ONCE(ei->i_es_seq, READ_ONCE(ei->i_es_seq) + 1); +} + /* * search through the tree for an delayed extent with a given offset. If * it can't be found, try to find next extent. @@ -876,6 +883,7 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, WARN_ON(1); } + ext4_es_inc_seq(inode); newes.es_lblk = lblk; newes.es_len = len; ext4_es_store_pblock_status(&newes, pblk, status); @@ -1503,13 +1511,15 @@ void ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk, if (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) return; - trace_ext4_es_remove_extent(inode, lblk, len); es_debug("remove [%u/%u) from extent status tree of inode %lu\n", lblk, len, inode->i_ino); if (!len) return; + ext4_es_inc_seq(inode); + trace_ext4_es_remove_extent(inode, lblk, len); + end = lblk + len - 1; BUG_ON(end < lblk); @@ -2080,6 +2090,7 @@ void ext4_es_insert_delayed_extent(struct inode *inode, ext4_lblk_t lblk, if (!len) return; + ext4_es_inc_seq(inode); newes.es_lblk = lblk; newes.es_len = len; ext4_es_store_pblock_status(&newes, ~0, EXTENT_STATUS_DELAYED); diff --git a/fs/ext4/super.c b/fs/ext4/super.c index c5fcf377ab1f..d4afaae8ab38 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1421,6 +1421,7 @@ static struct inode *ext4_alloc_inode(struct super_block *sb) ei->i_es_all_nr = 0; ei->i_es_shk_nr = 0; ei->i_es_shrink_lblk = 0; + ei->i_es_seq = 0; ei->i_reserved_data_blocks = 0; spin_lock_init(&(ei->i_block_reservation_lock)); ext4_init_pending_tree(&ei->i_pending_tree); diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h index 53aa7a7fb3be..6ae504c43de7 100644 --- a/include/trace/events/ext4.h +++ b/include/trace/events/ext4.h @@ -2186,6 +2186,7 @@ DECLARE_EVENT_CLASS(ext4__es_extent, __field( ext4_lblk_t, len ) __field( ext4_fsblk_t, pblk ) __field( char, status ) + __field( unsigned int, seq ) ), TP_fast_assign( @@ -2195,13 +2196,15 @@ DECLARE_EVENT_CLASS(ext4__es_extent, __entry->len = es->es_len; __entry->pblk = ext4_es_show_pblock(es); __entry->status = ext4_es_status(es); + __entry->seq = EXT4_I(inode)->i_es_seq; ), - TP_printk("dev %d,%d ino %lu es [%u/%u) mapped %llu status %s", + TP_printk("dev %d,%d ino %lu es [%u/%u) mapped %llu status %s seq %u", MAJOR(__entry->dev), MINOR(__entry->dev), (unsigned long) __entry->ino, __entry->lblk, __entry->len, - __entry->pblk, show_extent_status(__entry->status)) + __entry->pblk, show_extent_status(__entry->status), + __entry->seq) ); DEFINE_EVENT(ext4__es_extent, ext4_es_insert_extent, @@ -2226,6 +2229,7 @@ TRACE_EVENT(ext4_es_remove_extent, __field( ino_t, ino ) __field( loff_t, lblk ) __field( loff_t, len ) + __field( unsigned int, seq ) ), TP_fast_assign( @@ -2233,12 +2237,13 @@ TRACE_EVENT(ext4_es_remove_extent, __entry->ino = inode->i_ino; __entry->lblk = lblk; __entry->len = len; + __entry->seq = EXT4_I(inode)->i_es_seq; ), - TP_printk("dev %d,%d ino %lu es [%lld/%lld)", + TP_printk("dev %d,%d ino %lu es [%lld/%lld) seq %u", MAJOR(__entry->dev), MINOR(__entry->dev), (unsigned long) __entry->ino, - __entry->lblk, __entry->len) + __entry->lblk, __entry->len, __entry->seq) ); TRACE_EVENT(ext4_es_find_extent_range_enter, @@ -2497,6 +2502,7 @@ TRACE_EVENT(ext4_es_insert_delayed_extent, __field( ext4_fsblk_t, pblk ) __field( char, status ) __field( bool, allocated ) + __field( unsigned int, seq ) ), TP_fast_assign( @@ -2507,15 +2513,16 @@ TRACE_EVENT(ext4_es_insert_delayed_extent, __entry->pblk = ext4_es_show_pblock(es); __entry->status = ext4_es_status(es); __entry->allocated = allocated; + __entry->seq = EXT4_I(inode)->i_es_seq; ), TP_printk("dev %d,%d ino %lu es [%u/%u) mapped %llu status %s " - "allocated %d", + "allocated %d seq %u", MAJOR(__entry->dev), MINOR(__entry->dev), (unsigned long) __entry->ino, __entry->lblk, __entry->len, __entry->pblk, show_extent_status(__entry->status), - __entry->allocated) + __entry->allocated, __entry->seq) ); /* fsmap traces */