From patchwork Thu Mar 16 14:40:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 13177738 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 52324C6FD19 for ; Thu, 16 Mar 2023 14:40:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6E0D900004; Thu, 16 Mar 2023 10:40:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BF81D900002; Thu, 16 Mar 2023 10:40:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7130900004; Thu, 16 Mar 2023 10:40:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 8E9FD900002 for ; Thu, 16 Mar 2023 10:40:39 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 36215161418 for ; Thu, 16 Mar 2023 14:40:39 +0000 (UTC) X-FDA: 80575022598.18.48A4273 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by imf18.hostedemail.com (Postfix) with ESMTP id 43AF21C0012 for ; Thu, 16 Mar 2023 14:40:37 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=KXn5Z5Zz; spf=pass (imf18.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.214.180 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678977637; 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:dkim-signature; bh=OyW2SvG3UTDKocelVyPa5DVOdPH4lrK1qG7JAvJlCt4=; b=johb1bj5dJHEhhb7qErooSgKo6c6DFUnqBdWtMfyUKa1WyGMlbEQnOw5Rahop26aEyTCE0 ktzQtJw+GlmYcX38nekqivgLfxAVkES+/vw6OxDQDmFxqgE2V3AEcyIPj4SAYQiSlapTvS JTJYe1FJz4NNxTeHFTgxk+dZ/NQYxBs= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=KXn5Z5Zz; spf=pass (imf18.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.214.180 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678977637; a=rsa-sha256; cv=none; b=4BUp/NN7FFVqP97LIDGWG8aMXoDlwNJwpM5IU6hb2y9eQmHzzWrKhduNHZxGBG5ilatJXW 4t6TAHR2LzezIrFyE/Hvh2hTK54wynkPACoCjeb/9DpZVAnC/iukk53xYy9oRHIbkzFiMi yz2g4e7idorPBAIbeZU6VWk57i5etHY= Received: by mail-pl1-f180.google.com with SMTP id c18so1957049ple.11 for ; Thu, 16 Mar 2023 07:40:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678977636; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OyW2SvG3UTDKocelVyPa5DVOdPH4lrK1qG7JAvJlCt4=; b=KXn5Z5Zz2m0BEouHiaU7orh8kgiH5oNwjhbmPff045mNOy+nvi2/EqjbTGIF4oA5MI wPRx6MyzafwxjHTxqG/ZwZSzBLQlTS55Pvy5+USXiszPam3wCW96uLggtt58LfPkDDub 1wADiUSbuC8W7r4TFx9QcKizebuG1+qasdCV3YimHRgJQT9eyX4s9i86nIooHSwx0U7D Om2Mtw/fXjULafq+cbSzRPvbXdVz5fGeyij9btA0exHOQpm0Sac/O9MJoxvxyuJ89Pz+ am/fKXg8c4NjO4k8FUVd3Ulf0C67Iu8uBNYfA5WHTCy/vYsIRngTcyg4QdWMPIaMoRta 9J+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678977636; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OyW2SvG3UTDKocelVyPa5DVOdPH4lrK1qG7JAvJlCt4=; b=eMwnYayM4QFlpO4E+ZNJX2zjR7+sDnNck7tQE2TuVLULezUnHpEKyqf9hjXxuXetNx mRq1TPJuFBF11J5eFfDssTigWkZa4Z5Ou0X8UVbg80T17WNUMjuSeDNno2UaBKbyNYR7 K0fTh0fuCDH7YXsfciuq8gXN2zfvz+LLyaDw4ZdvkIypmWiV37KEU23dmjRybZpkBn3T cM3i02ufnLe2Cv+2+TtnH60yV9l40B0EGWskfukoKNtZMQ9hJDDNZyAvzxehHMsdD07V RuxIlX44usaOa2S7crWrcmurKsdIe3uWE/JkE4LF+z31L9ThASc3g9LOddTbHGQdBej0 AX7A== X-Gm-Message-State: AO0yUKUt8gGb4n7P7CxIHpAiExcMFRP8ExSlSO/BOiJg88r9WOVue0m7 BaB2ksJsJCfJIEhi11pCkZw= X-Google-Smtp-Source: AK7set/826oEA2tueYXZwLzCSMlrVyJc9HehZR8zeCuRt8B8KYw0NaLf8dw6IH2Z4mG6trWOME9fKQ== X-Received: by 2002:a17:90b:4d05:b0:237:50b6:9843 with SMTP id mw5-20020a17090b4d0500b0023750b69843mr4142451pjb.0.1678977635896; Thu, 16 Mar 2023 07:40:35 -0700 (PDT) Received: from rh-tp.. ([2406:7400:63:469f:1474:7c59:3a57:aab6]) by smtp.gmail.com with ESMTPSA id f1-20020a17090a654100b0023670dbb82fsm3306736pjs.25.2023.03.16.07.40.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 07:40:35 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: Jan Kara Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, lsf-pc@lists.linux-foundation.org, "Ritesh Harjani (IBM)" Subject: [RFCv1][WIP] ext2: Move direct-io to use iomap Date: Thu, 16 Mar 2023 20:10:29 +0530 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: <87ttz889ns.fsf@doe.com> References: <87ttz889ns.fsf@doe.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 43AF21C0012 X-Rspam-User: X-Stat-Signature: itxh8zkytspacehcc4uoyqu5tmp3ef5s X-HE-Tag: 1678977637-646860 X-HE-Meta: U2FsdGVkX184pKeHhUJGRC/Kl4m3A4fQM6rZVQ0gsI9pv2prAmP/acHs7tK8ZaFzEsi7xB9IE6MdNaPt8wzy06NjBINDL8sAG40aHAHhLdkjZyqdkjmV5WACDtUulKt9Xbc5KKzwaAT+PAlh1gFnHf6R6suLx7SrtFRUGTaVuUx0/JnZ4tG6Fx7CzdJA2BoEIwaDm18md4Zgjpm2a4jVNZeyanPlmpX2tslX1a2aGq6gBLXBF98c+QO8BZQ6osDl4QeEoNVo90cQix7RRNHfI4o1b06KNyCIVdnY6w5OWuNmhwU6vWVvAlPGN0nKPzHJxy2eXWtr/G+e2JK835nAfyu5Yk6tK4TDVxaJjQm+XEBIlnKua6N26vDGJQXKh0sOG5uywnldVK0JDQMPzNA3G9zia4P+o7iGN83KlYFaEUwcdF7XoLJBdpfTmYCPk4jUoH+k0U4cuJ76cLJaisjJwq+2lPks8Hkf8OAewsVG51B3h1wtYOkf/xKi1rkRoS7w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bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: [DO NOT MERGE] [WORK-IN-PROGRESS] Hello Jan, This is an initial version of the patch set which I wanted to share before today's call. This is still work in progress but atleast passes the set of test cases which I had kept for dio testing (except 1 from my list). Looks like there won't be much/any changes required from iomap side to support ext2 moving to iomap apis. I will be doing some more testing specifically test generic/083 which is occassionally failing in my testing. Also once this is stabilized, I can do some performance testing too if you feel so. Last I remembered we saw some performance regressions when ext4 moved to iomap for dio. PS: Please ignore if there are some silly mistakes. As I said, I wanted to get this out before today's discussion. :) Thanks for your help!! Signed-off-by: Ritesh Harjani (IBM) --- fs/ext2/ext2.h | 1 + fs/ext2/file.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/ext2/inode.c | 20 +-------- 3 files changed, 117 insertions(+), 18 deletions(-) -- 2.39.2 diff --git a/fs/ext2/ext2.h b/fs/ext2/ext2.h index cb78d7dcfb95..cb5e309fe040 100644 --- a/fs/ext2/ext2.h +++ b/fs/ext2/ext2.h @@ -753,6 +753,7 @@ extern unsigned long ext2_count_free (struct buffer_head *, unsigned); extern struct inode *ext2_iget (struct super_block *, unsigned long); extern int ext2_write_inode (struct inode *, struct writeback_control *); extern void ext2_evict_inode(struct inode *); +extern void ext2_write_failed(struct address_space *mapping, loff_t to); extern int ext2_get_block(struct inode *, sector_t, struct buffer_head *, int); extern int ext2_setattr (struct mnt_idmap *, struct dentry *, struct iattr *); extern int ext2_getattr (struct mnt_idmap *, const struct path *, diff --git a/fs/ext2/file.c b/fs/ext2/file.c index 6b4bebe982ca..7a8561304559 100644 --- a/fs/ext2/file.c +++ b/fs/ext2/file.c @@ -161,12 +161,123 @@ int ext2_fsync(struct file *file, loff_t start, loff_t end, int datasync) return ret; } +static ssize_t ext2_dio_read_iter(struct kiocb *iocb, struct iov_iter *to) +{ + struct file *file = iocb->ki_filp; + struct inode *inode = file->f_mapping->host; + ssize_t ret; + + inode_lock_shared(inode); + ret = iomap_dio_rw(iocb, to, &ext2_iomap_ops, NULL, 0, NULL, 0); + inode_unlock_shared(inode); + + return ret; +} + +static int ext2_dio_write_end_io(struct kiocb *iocb, ssize_t size, + int error, unsigned int flags) +{ + loff_t pos = iocb->ki_pos; + struct inode *inode = file_inode(iocb->ki_filp); + + if (error) + return error; + + pos += size; + if (pos > i_size_read(inode)) + i_size_write(inode, pos); + + return 0; +} + +static const struct iomap_dio_ops ext2_dio_write_ops = { + .end_io = ext2_dio_write_end_io, +}; + +static ssize_t ext2_dio_write_iter(struct kiocb *iocb, struct iov_iter *from) +{ + struct file *file = iocb->ki_filp; + struct inode *inode = file->f_mapping->host; + ssize_t ret; + unsigned int flags; + unsigned long blocksize = inode->i_sb->s_blocksize; + loff_t offset = iocb->ki_pos; + loff_t count = iov_iter_count(from); + + + inode_lock(inode); + ret = generic_write_checks(iocb, from); + if (ret <= 0) + goto out_unlock; + ret = file_remove_privs(file); + if (ret) + goto out_unlock; + ret = file_update_time(file); + if (ret) + goto out_unlock; + + /* + * We pass IOMAP_DIO_NOSYNC because otherwise iomap_dio_rw() + * calls for generic_write_sync in iomap_dio_complete(). + * Since ext2_fsync nmust be called w/o inode lock, + * hence we pass IOMAP_DIO_NOSYNC and handle generic_write_sync() + * ourselves. + */ + flags = IOMAP_DIO_NOSYNC; + + /* use IOMAP_DIO_FORCE_WAIT for unaligned of extending writes */ + if (iocb->ki_pos + iov_iter_count(from) > i_size_read(inode) || + (!IS_ALIGNED(iocb->ki_pos | iov_iter_alignment(from), blocksize))) + flags |= IOMAP_DIO_FORCE_WAIT; + + ret = iomap_dio_rw(iocb, from, &ext2_iomap_ops, &ext2_dio_write_ops, + flags, NULL, 0); + + if (ret == -ENOTBLK) + ret = 0; + + if (ret < 0 && ret != -EIOCBQUEUED) + ext2_write_failed(inode->i_mapping, offset + count); + + /* handle case for partial write or fallback to buffered write */ + if (ret >= 0 && iov_iter_count(from)) { + loff_t pos, endbyte; + ssize_t status; + ssize_t ret2; + + pos = iocb->ki_pos; + status = generic_perform_write(iocb, from); + if (unlikely(status < 0)) { + ret = status; + goto out_unlock; + } + endbyte = pos + status - 1; + ret2 = filemap_write_and_wait_range(inode->i_mapping, pos, + endbyte); + if (ret2 == 0) { + iocb->ki_pos = endbyte + 1; + ret += status; + invalidate_mapping_pages(inode->i_mapping, + pos >> PAGE_SHIFT, + endbyte >> PAGE_SHIFT); + } + } +out_unlock: + inode_unlock(inode); + if (ret > 0) + ret = generic_write_sync(iocb, ret); + return ret; +} + static ssize_t ext2_file_read_iter(struct kiocb *iocb, struct iov_iter *to) { #ifdef CONFIG_FS_DAX if (IS_DAX(iocb->ki_filp->f_mapping->host)) return ext2_dax_read_iter(iocb, to); #endif + if (iocb->ki_flags & IOCB_DIRECT) + return ext2_dio_read_iter(iocb, to); + return generic_file_read_iter(iocb, to); } @@ -176,6 +287,9 @@ static ssize_t ext2_file_write_iter(struct kiocb *iocb, struct iov_iter *from) if (IS_DAX(iocb->ki_filp->f_mapping->host)) return ext2_dax_write_iter(iocb, from); #endif + if (iocb->ki_flags & IOCB_DIRECT) + return ext2_dio_write_iter(iocb, from); + return generic_file_write_iter(iocb, from); } diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index 26f135e7ffce..7ff669d0b6d2 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c @@ -56,7 +56,7 @@ static inline int ext2_inode_is_fast_symlink(struct inode *inode) static void ext2_truncate_blocks(struct inode *inode, loff_t offset); -static void ext2_write_failed(struct address_space *mapping, loff_t to) +void ext2_write_failed(struct address_space *mapping, loff_t to) { struct inode *inode = mapping->host; @@ -908,22 +908,6 @@ static sector_t ext2_bmap(struct address_space *mapping, sector_t block) return generic_block_bmap(mapping,block,ext2_get_block); } -static ssize_t -ext2_direct_IO(struct kiocb *iocb, struct iov_iter *iter) -{ - struct file *file = iocb->ki_filp; - struct address_space *mapping = file->f_mapping; - struct inode *inode = mapping->host; - size_t count = iov_iter_count(iter); - loff_t offset = iocb->ki_pos; - ssize_t ret; - - ret = blockdev_direct_IO(iocb, inode, iter, ext2_get_block); - if (ret < 0 && iov_iter_rw(iter) == WRITE) - ext2_write_failed(mapping, offset + count); - return ret; -} - static int ext2_writepages(struct address_space *mapping, struct writeback_control *wbc) { @@ -946,7 +930,7 @@ const struct address_space_operations ext2_aops = { .write_begin = ext2_write_begin, .write_end = ext2_write_end, .bmap = ext2_bmap, - .direct_IO = ext2_direct_IO, + .direct_IO = noop_direct_IO, .writepages = ext2_writepages, .migrate_folio = buffer_migrate_folio, .is_partially_uptodate = block_is_partially_uptodate,