From patchwork Wed Apr 10 13:28:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624584 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 CD0EFCD1299 for ; Wed, 10 Apr 2024 13:38:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 563056B00AC; Wed, 10 Apr 2024 09:37:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4C4F26B00AD; Wed, 10 Apr 2024 09:37:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A0346B00AE; Wed, 10 Apr 2024 09:37:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0CC0A6B00AC for ; Wed, 10 Apr 2024 09:37:17 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C75834061D for ; Wed, 10 Apr 2024 13:37:16 +0000 (UTC) X-FDA: 81993723672.18.28808F1 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf27.hostedemail.com (Postfix) with ESMTP id 5D49C4001F for ; Wed, 10 Apr 2024 13:37:08 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf27.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=1712756230; 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=G63A/1vzHT8HBZ1GnRpYOGjnssd8Ud0KFI6wZDe0IEA=; b=x1bGk7uGysdPogx5++GHG0PN+Abf9AE9EoOrSx/PNqUs9ec81v0v3oDxAPid062bV2nkcO GdGQDivyp2chCMrv7wo6OV2q4GAtNdjQ49MnLA3Rm8wxkhs/qf3yy7IKBErYPb7L8Cy84o Y+Sqlu9QfLaazEcTaKDPub2PhYSY8Kw= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf27.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=1712756230; a=rsa-sha256; cv=none; b=igZrisN91ONVV1YN6vpClLeaP4lIIU2ohsWPKlV7SjGT0q45Zk1cRNH6e+gXAvhpbppiK8 V+8m2daFc3jCE5S+sl6DtpZ/Qnvq0raRLQT3rfCyslTh/zu01tY5aNWiODR6050U67LRg/ 1kJpOIwxjZP0qdOjYul5zx93Mzk3t8c= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lY1btJz4f3n6h for ; Wed, 10 Apr 2024 21:36:57 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id D9CFB1A0568 for ; Wed, 10 Apr 2024 21:37:05 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S33; Wed, 10 Apr 2024 21:37:05 +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 v4 29/34] ext4: fall back to buffer_head path for defrag Date: Wed, 10 Apr 2024 21:28:13 +0800 Message-Id: <20240410132818.2812377-30-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S33 X-Coremail-Antispam: 1UD129KBjvJXoW7uw45KryfZr4UWr15ZF1xuFg_yoW8Kry5pr 9Ikr15Kr4DXas29Fn3ta4UZr1rKa10g3y7urWfW3WxJFWDA34IgFyjkF1UAFW5trZ7JrWa qF40kr17W347G3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6r xdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2 IY04v7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAF wI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc4 0Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AK xVWxJr0_GcWlIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Cr1j6rxdYxBIdaVFxhVjvjDU0xZFpf9x0JUArcfU UUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 5D49C4001F X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: xbyhcb676usdrzkoscsg7mwunohnzju8 X-HE-Tag: 1712756228-201561 X-HE-Meta: U2FsdGVkX19/4DStvoXD+DUrKcvtREdFNK63TgF9wljcaJplSnSzTH76crfM6KrLYPb4sKjSTB6quDJDBS+6EOA0387P56jjKNRaO7KTQVn/4PfnvEYjJ0RimRdm3IPieIY+qPdDhxKQzxYWetqUHx2sP26iHP/E6fgJUfsD+aaWBf5Hunrvlie8KXhCF4U0frDGpmJ0kq4n8l/qWeeaegGU+oNcEZxg2g1IOdHIXcA08QSMgiCdnBBN4T3yB+23pAikhYIUc8H/DjaXcpcYokpM2HG2dzqWKsLMUO0fDFJD/sI9Wy8V1g75ZD8Qzii04ejJTGv3GeR8skWrVfURYcTYYnTqacmL1f/IAO3II+5Yqg9JsjjHBBbQZE6s8SsiXJ3dbpBf2lW+q9VkaQuIl9EeyNE44LMheDuGDUMFgc+O76kaQJygdD+Rcb7OwSQDqDkJ4eZMM+VYGzWVGmz5dSYwRU2pt30DcSKdyoubZe0Ri7HmXD+Fm2eeMO/AT5gAdGt5zgjNGofHHfwaKAZwGwUCFZcVM6cTP3GgDvp+jTJCFPXdLMwgo9Qg3qm91Vj0Sd8kuxCMK6LHhwCM9KVyWnZdJms7vUyBtUDNR+o0Flrn8TJyraaoxUaFCZ9E7OQNYy/7cOQDVoQktQFPFZO+GWNfhEHYN9bhtva4t40X4TFrgUZHGRkho3LswmVsgLkUE9yKUp82zwJgjQFlDkHOLOcrR7ushrgcpavW5MhZ+ouO6klgsVH4elyo9UNEU6CZvhreNDw/9qmhJpalv/YgU+N0NWpk4Qcs+EtVw/iS/vtGE1/1KFa1M0OdyuayoAnUWJ5j5hWZI96M4qvg//Wnqq4jzuD2058v4JOSGF4fzdc5i0DRtKG5y6VjNWhCfhcHck+skVYooHHgwqLCn08ztd6CajcXKFp3TGi9WQp60OAQKM+w3CHhlSU3HrH62SUmKdUnC4XjKMC/soJWMJI RkOSoUNE uav2PeP7I7YvX4GiJWZwxyHh1WiuiF8naDAKeDjCt9RFbnlxd8rvy4HdArMeanyv3B7l1CTsYc9A6Ag/RUQa0jJKgDYNO9sApsR0pfMXWLn6Jg70kft8mk9qNs2fEVOh8C4Empm4T77pM9hQ3rkbxH74GufhobZISCeWBMmfrD8qFaBdKbh2w8FgV2doi8UyzyJB2Z/OYQ2f8B5aRs1N/lf1Jyk6K1ataJWtzZxhWWR3dwr+yiCJUpmg0ElvfYmtXQ5ob/mMkyGVZrquuuUfO4RBFc9LLYHOpOgyafbAVICHLdk6K6uX2EOlRpopuLbTcZwR6DPn4YFDBgnYib2n0J3g+sg== 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 Online defrag doesn't support iomap path yet, we have to fall back to buffer_head path for the inode which has been using iomap. Changing active inode is dangerous, before we start, we must hold the inode lock and the mapping->invalidate_lock, and writeback all dirty folios and drop the inode's pagecache. Signed-off-by: Zhang Yi --- fs/ext4/move_extent.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c index 7cd4afa4de1d..3db255385367 100644 --- a/fs/ext4/move_extent.c +++ b/fs/ext4/move_extent.c @@ -538,6 +538,34 @@ mext_check_arguments(struct inode *orig_inode, return 0; } +/* + * Disable buffered iomap path for the inode that requiring move extents, + * fallback to buffer_head path. + */ +static int ext4_disable_buffered_iomap_aops(struct inode *inode) +{ + int err; + + /* + * The buffered_head aops don't know how to handle folios + * dirtied by iomap, so before falling back, flush all dirty + * folios the inode has. + */ + filemap_invalidate_lock(inode->i_mapping); + err = filemap_write_and_wait(inode->i_mapping); + if (err < 0) { + filemap_invalidate_unlock(inode->i_mapping); + return err; + } + truncate_inode_pages(inode->i_mapping, 0); + + ext4_clear_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + ext4_set_aops(inode); + filemap_invalidate_unlock(inode->i_mapping); + + return 0; +} + /** * ext4_move_extents - Exchange the specified range of a file * @@ -609,6 +637,12 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk, inode_dio_wait(orig_inode); inode_dio_wait(donor_inode); + /* Fallback to buffer_head aops for inodes with buffered iomap aops */ + if (ext4_test_inode_state(orig_inode, EXT4_STATE_BUFFERED_IOMAP)) + ext4_disable_buffered_iomap_aops(orig_inode); + if (ext4_test_inode_state(donor_inode, EXT4_STATE_BUFFERED_IOMAP)) + ext4_disable_buffered_iomap_aops(donor_inode); + /* Protect extent tree against block allocations via delalloc */ ext4_double_down_write_data_sem(orig_inode, donor_inode); /* Check the filesystem environment whether move_extent can be done */