From patchwork Sat Jan 27 01:58:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13533916 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 75DDAC47422 for ; Sat, 27 Jan 2024 02:03:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D91DE6B00A6; Fri, 26 Jan 2024 21:03:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D19916B00A7; Fri, 26 Jan 2024 21:03:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B93616B00A8; Fri, 26 Jan 2024 21:03:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A697E6B00A6 for ; Fri, 26 Jan 2024 21:03:01 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7FC5D140F63 for ; Sat, 27 Jan 2024 02:03:01 +0000 (UTC) X-FDA: 81723442962.10.9491D69 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf11.hostedemail.com (Postfix) with ESMTP id 0C9CF4000A for ; Sat, 27 Jan 2024 02:02:58 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.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=1706320979; 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=5hFbF0KxnHt4vEEsH7/8Qchlvjc2GO7GkzsMdnMu9kI=; b=weVOsyT/tz7nBtctvlQQuUHmcdTB7DQt7lxHwdKdezWYsHT5+nQeBcpbuf1dyXDWJv9W4g sZumscdl0ySLdvzHkgjEoHsXJ94wP3u+gE+CNqOGPHiMvMjeEUSyrpEhRAt9+NFMPynlZi n5t26zCRNVn20+8P6AvzIcOo/yHRt7s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320979; a=rsa-sha256; cv=none; b=5h6VqBGesgrUdaXmUeefBWF4/EwlDZNtkmE70qNladHQt/lL+pERbxhRFVeMgfA01CYyKA W0LuUZfczwN8kTmO6U891kb3V6Wq6KhWo8otNOu2PuVm7IQ5qqjv5QIffJ9NvOap/N07oH 2MBwjJRzxsyKJFjPMjIr23JZnuUbZAA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=pass (imf11.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.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrr5k3hz4f3k6G for ; Sat, 27 Jan 2024 10:02:52 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 3C1951A017A for ; Sat, 27 Jan 2024 10:02:55 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S28; Sat, 27 Jan 2024 10:02:55 +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 24/26] ext4: partially enable iomap for regular file's buffered IO path Date: Sat, 27 Jan 2024 09:58:23 +0800 Message-Id: <20240127015825.1608160-25-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--.7377S28 X-Coremail-Antispam: 1UD129KBjvJXoWxXFyxGFy5GF1xXFy8XFyrWFg_yoWrXw18pF ZIkr1rJr48u3s7ur4ftF48Zr1ava1xK3yUGrWSgwn5JFyrJ3WSqF1FyF1YyF15JrZ5u3WS qF48CF15uw47urDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6r xdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F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BL83ay4oQmxiKf5cNjiJbghiXNjmS6bVpb4G5OnpbN0j6/G/JfxIkTepHEwNBkX8xLbwNAlIzF8PZQ0SeQtQZ+fDIP63B1DLDhA5+v1EyuTnDSKpzHok7WpiLbucYJK0VCVRYJIXoe5iKeFFe81yFYjJqsKHlIcSvqG7ONLWKwfbl3U9U7WlJkvnG9Lg5q9dwzKxIda7cnA1N3mxgG0mjbJYrrDbH6rB31f1mwpjxtFhI4FF60hizUELCDvfNfZcybM6f2wHmYvQlcV3lON+jaMx4cUP3SrFdI3pMChV3+qq1sBx1VQoEqgVIvhr59AviKhxNR31aPr8ATln1cIthE0clYqg6133f8q/mDxUozeJxeyxwcngvq18U2lcl63/8qCL+sR1QAAk/VksleFHQJD3m1S6MJ6Rf9X5/b6Tkr4xdzyAyj+ONNGYEk2DcO+ZGvmg+1WMnF+nUYFazplAAcQ4PcIGHKUetZ7bnFQBWEVEL8CD1k ywX7zDUs TRh5UEBf3MyUPDWfGbg/+qBUNQtTXBZ/+DbqsO/dZxn6OAfs0hfMhtgSC4BpBcKGxuqFUYtpPeVwPCmf8CQ4s8shaGGc/EL4BUPGcxZcJPsYJrghjBBMC9LBPrVXWYiXwxc6nbJoeEK8pzxjP9t8UeH5bbZVp+xoDx9jPxMuiWiXlZOtvItsQNb5oqjBhrysmdmSGF0+vtER2py+X3gB72TwH/bBLjuZR9dSKTU5E10d8xImqcYx+Jw0zVJQs++VzU/JP 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 Partially enable iomap for regular file's buffered IO path on default mount option and default filesystem features. Set inode state flag EXT4_STATE_BUFFERED_IOMAP when creating one inode to indicate that this inode choice the iomap path. Now it still have many limitations, it doesn't support inline data, fs_verity, fs_crypt, defrag, bigalloc, dax and data=journal mode yet, so we have to fallback to buffered_head path if these options/features were enabled. I hope these would be supported gradually in the future. Signed-off-by: Zhang Yi --- fs/ext4/ext4.h | 1 + fs/ext4/ialloc.c | 3 +++ fs/ext4/inode.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index eaf29bade606..16dce8701c5e 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 f8e9f566ef6a..30067775e828 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -774,6 +774,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; @@ -2552,6 +2554,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() @@ -5089,6 +5094,32 @@ 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 (ext4_has_feature_bigalloc(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) @@ -5353,6 +5384,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;