From patchwork Wed Apr 10 15:03:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624739 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 A94C1CD128A for ; Wed, 10 Apr 2024 15:11:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 28D3A6B00BE; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 215B26B00BF; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 042666B00C1; Wed, 10 Apr 2024 11:11:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D3D3C6B00BE for ; Wed, 10 Apr 2024 11:11:56 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 92547140816 for ; Wed, 10 Apr 2024 15:11:56 +0000 (UTC) X-FDA: 81993962232.18.875EB83 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf02.hostedemail.com (Postfix) with ESMTP id 3C8BD80009 for ; Wed, 10 Apr 2024 15:11:52 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf02.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712761914; 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=RZrNAfKqPKEAjMF5Y3M7foneYQpwHm5h4BORCNdEvbw=; b=7nA2Ld1rny0LZvChuauOG4PwVf18n5eLg524tpRI2FabsH2gNa6qPctqTYAplLrrQBaPj3 Aw3JxAdFaMw99/j1kQsVIWZC5tZRlu4aBsrRRVtOkGCHchBW8LyLpeKz+txGrFh5yeqWpe X7j99fvzCGHqIEbqvFJWD/wsmy3Lu4U= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf02.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712761914; a=rsa-sha256; cv=none; b=QtMkbxFhiQkifg+hkjm4xrLAs9+ziETWMK1OoG+L6iiw+wgkcR/jf99qbONf85DAvq9OGu /XRnpQE2MzEngzbEk2QG9D3s+beGZ0m48KZCa55p9wpdgeIoekeZT5dh2mBAZbDuODK5Ms O/igmnv10mM0PQ1g8RrHJRp0ob5CXUE= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF5rw5SZHz4f3kKp for ; Wed, 10 Apr 2024 23:11:44 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 308CC1A016E for ; Wed, 10 Apr 2024 23:11:49 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn9g4orBZmFSt+Jg--.51485S5; Wed, 10 Apr 2024 23:11:48 +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, david@fromorbit.com, 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 v4 30/34] ext4: partial enable iomap for regular file's buffered IO path Date: Wed, 10 Apr 2024 23:03:09 +0800 Message-Id: <20240410150313.2820364-2-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn9g4orBZmFSt+Jg--.51485S5 X-Coremail-Antispam: 1UD129KBjvJXoWxGw1kKrWrCw1DtF43GFW7Jwb_yoWrGr4UpF ZIkryrJr4Y93s29a1ftF48Zr1Sv3WxKw4UG3yS9wn5XFy8J34SqF1jyF15A3WrJrZ5ua4S qF4jkr1Uuw43urDanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUdEb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0V AKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUAVWUtwAv7VC2z280aVAF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pPjfzPvUIhT5kGy+H3B/Vmrn6XzYipAP1/KMgQ5MAzxkImS8tIB2VxvEfykZI7aRXR4nfZfExPoIxn0LKxp9aWFpW+HanSGow/dgBxZRc76IhiVuf5XDVOIEYku9jus7V+vFdYlyEmSitgCV0fmIBNitp7xfaRXzNsj2jiyAr/X1R219xuOZhWaNQqmpWaY4A6dZ5PzVFuD/5qXOX1O+/wgWcsnXF7gPI//HSkjUYXQIOpmiuKDA5ztmN+FyWqtbOM/q4dSmeWDWBGo+DLtstk9WzUbnbwu8KasQ00utgic4RAKE06abWNAjhXbrbH9b5dDtiApGflOgXvYq0Vhj2tVS0fXKrdBTHMlgex0J84mj1RmbIAhJvoVmB17l+u1+3hcUbUww9wZ8dOYyJkedFQGUobWUCcDwzHWpgIMrsPjFQlCUGU9xHje81cLjkNTgyj8cDHPnk5io+ixc1N/ZvwC56LGL00etdE0lDpG8d7+hhHUKCnFlBGkFxYrTLktwfpeue31s5dubLgqnneXpDhj4yio11a6PzcOzBHNzizLbpKgIZutWmxySJ1DxeZxEqxYUFTzRZ1juNt3sJyW84GFgYYrBPBRZBD4QbmCeiVU auAiJsRY B7Uh3 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 Partial enable iomap for regular file's buffered IO path on default mount option, support default filesystem features and bigalloc feature, doesn't support inline data, fs_verity, fs_crypt, defrag and data=journal mode yet (these would be supported gradually in the future). ext4 will fallback to buffered_head path automatically if these options or features are enable. Signed-off-by: Zhang Yi --- fs/ext4/ext4.h | 1 + fs/ext4/ialloc.c | 3 +++ fs/ext4/inode.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 2ec6c7884e9a..4e7667b21c2f 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2972,6 +2972,7 @@ int ext4_walk_page_buffers(handle_t *handle, struct buffer_head *bh)); int do_journal_get_write_access(handle_t *handle, struct inode *inode, struct buffer_head *bh); +bool ext4_should_use_buffered_iomap(struct inode *inode); int ext4_nonda_switch(struct super_block *sb); #define FALL_BACK_TO_NONDELALLOC 1 #define CONVERT_INLINE_DATA 2 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index e9bbb1da2d0a..956b9d69c559 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c @@ -1336,6 +1336,9 @@ struct inode *__ext4_new_inode(struct mnt_idmap *idmap, } } + if (ext4_should_use_buffered_iomap(inode)) + ext4_set_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + if (ext4_handle_valid(handle)) { ei->i_sync_tid = handle->h_transaction->t_tid; ei->i_datasync_tid = handle->h_transaction->t_tid; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 5af3b8acf1b9..624eac0cc705 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -770,6 +770,8 @@ static int _ext4_get_block(struct inode *inode, sector_t iblock, if (ext4_has_inline_data(inode)) return -ERANGE; + if (WARN_ON(ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP))) + return -EINVAL; map.m_lblk = iblock; map.m_len = bh->b_size >> inode->i_blkbits; @@ -2567,6 +2569,9 @@ static int ext4_do_writepages(struct mpage_da_data *mpd) trace_ext4_writepages(inode, wbc); + if (WARN_ON(ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP))) + return -EINVAL; + /* * No pages to write? This is mainly a kludge to avoid starting * a transaction for special inodes like journal inode on last iput() @@ -5107,6 +5112,30 @@ static const char *check_igot_inode(struct inode *inode, ext4_iget_flags flags) return NULL; } +bool ext4_should_use_buffered_iomap(struct inode *inode) +{ + struct super_block *sb = inode->i_sb; + + if (ext4_has_feature_inline_data(sb)) + return false; + if (ext4_has_feature_verity(sb)) + return false; + if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) + return false; + if (!S_ISREG(inode->i_mode)) + return false; + if (IS_DAX(inode)) + return false; + if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) + return false; + if (ext4_test_inode_flag(inode, EXT4_INODE_EA_INODE)) + return false; + if (ext4_test_inode_flag(inode, EXT4_INODE_ENCRYPT)) + return false; + + return true; +} + struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, ext4_iget_flags flags, const char *function, unsigned int line) @@ -5371,6 +5400,9 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, if (ret) goto bad_inode; + if (ext4_should_use_buffered_iomap(inode)) + ext4_set_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + if (S_ISREG(inode->i_mode)) { inode->i_op = &ext4_file_inode_operations; inode->i_fop = &ext4_file_operations;