From patchwork Fri May 19 07:40:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247771 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 4DB85C7EE2C for ; Fri, 19 May 2023 07:42:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CBED4900018; Fri, 19 May 2023 03:42:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C4595900003; Fri, 19 May 2023 03:42:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE635900018; Fri, 19 May 2023 03:42:06 -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 9DFB8900003 for ; Fri, 19 May 2023 03:42:06 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 77077140928 for ; Fri, 19 May 2023 07:42:06 +0000 (UTC) X-FDA: 80806211052.18.1BA5704 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf01.hostedemail.com (Postfix) with ESMTP id C326140013 for ; Fri, 19 May 2023 07:42:04 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CkAWxd+t; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482124; a=rsa-sha256; cv=none; b=onMaeZ3z9RDZM+DqJmtnacCwzzy8wcqzftffies+R+hn0bDZue1/wjlCqYsPuo2IZRNix4 fZ227IAbe51a1z/xB5c6zJkJieGPrq7h0Wj5zrNd146cXvdioXl2QlVtn9RyOskH4GpFon qRtnmOVMydO896CYxzGj9S/Bg6XOpMI= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CkAWxd+t; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684482124; 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=r5qDgkT4BMNnpU06yXa6htF6MTIyeI5iJgctjYsdWto=; b=jhHorrHVhaCVSTWpXcfF0YD7qgX9DFcZYnpGnXwUP2hFPVQvR60GYZbXoTVi/Ha0YfBwNo LO2MqpwNnl2d3z/V3ouzxHKB8FfDrko46AKqtvad/nfQ28HJu/4aj9I+T4IEPeSSxCi4t7 rgiEudPborpRimBSJJo5AABTz7YdqSQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482124; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r5qDgkT4BMNnpU06yXa6htF6MTIyeI5iJgctjYsdWto=; b=CkAWxd+tnzBvrvZkNPcdTTWBZO4EbktfAvmMHvMLkwgEmfdT/Dc0a/yOfu080htf1hVzDO qqfMYQCFlsP3MKrd6gIHXBsRas8j3QwNWjHcgcbl0Iv8KzBm3gGCjOv3Wo65aWNp+pdfj3 0rzvmbw5HjUnq7HHg+MilZrIuhdFzf4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-636-UwmqYBTZNaOSEg7543TOgw-1; Fri, 19 May 2023 03:41:56 -0400 X-MC-Unique: UwmqYBTZNaOSEg7543TOgw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ABE8E1C04B50; Fri, 19 May 2023 07:41:55 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 367671121314; Fri, 19 May 2023 07:41:53 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH v20 16/32] f2fs: Provide a splice-read stub Date: Fri, 19 May 2023 08:40:31 +0100 Message-Id: <20230519074047.1739879-17-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C326140013 X-Stat-Signature: 561kek6tbqkiytrziifi1w7xcnqzhgsr X-HE-Tag: 1684482124-783283 X-HE-Meta: U2FsdGVkX19Wa7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Cb34UNFLTaX3G2L+yHJFUMB1+xclgrE6TMGKOsDJYzip66RPAvso+TLEuNeJBgReyDq5KeumsXnySYL57qw0B5T1eSwaZ2VpmSV3PxBfmYAm7sp09L/msv9M54xD6KQl9fhNkTWd/zA7APkld6W78yD9QZiFoQaNjprW6DakRGeHoNY86DvU1VyYtdpoeKdaiNToiAE4nCJFXBYZ8IKvsww/OuqIO7NJtpwRODa9dd17LAVLKNOYLeg== 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: Provide a splice_read stub for f2fs. This does some checks and tracing before proceeding and will switch from direct-I/O to buffered I/O if forced or if misaligned. It also updates the iostats after doing a buffered I/O. [Note: I wonder if I should only do the tracing if I call filemap_splice_read() as direct_splice_read() will call f2fs_file_read_iter().] Signed-off-by: David Howells cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: Jaegeuk Kim cc: Chao Yu cc: linux-f2fs-devel@lists.sourceforge.net cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org --- fs/f2fs/file.c | 68 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 5ac53d2627d2..3723387f4a87 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4367,22 +4367,23 @@ static ssize_t f2fs_dio_read_iter(struct kiocb *iocb, struct iov_iter *to) return ret; } -static void f2fs_trace_rw_file_path(struct kiocb *iocb, size_t count, int rw) +static void f2fs_trace_rw_file_path(struct file *file, loff_t pos, size_t count, + int rw) { - struct inode *inode = file_inode(iocb->ki_filp); + struct inode *inode = file_inode(file); char *buf, *path; buf = f2fs_getname(F2FS_I_SB(inode)); if (!buf) return; - path = dentry_path_raw(file_dentry(iocb->ki_filp), buf, PATH_MAX); + path = dentry_path_raw(file_dentry(file), buf, PATH_MAX); if (IS_ERR(path)) goto free_buf; if (rw == WRITE) - trace_f2fs_datawrite_start(inode, iocb->ki_pos, count, + trace_f2fs_datawrite_start(inode, pos, count, current->pid, path, current->comm); else - trace_f2fs_dataread_start(inode, iocb->ki_pos, count, + trace_f2fs_dataread_start(inode, pos, count, current->pid, path, current->comm); free_buf: f2fs_putname(buf); @@ -4398,7 +4399,8 @@ static ssize_t f2fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) return -EOPNOTSUPP; if (trace_f2fs_dataread_start_enabled()) - f2fs_trace_rw_file_path(iocb, iov_iter_count(to), READ); + f2fs_trace_rw_file_path(iocb->ki_filp, iocb->ki_pos, + iov_iter_count(to), READ); if (f2fs_should_use_dio(inode, iocb, to)) { ret = f2fs_dio_read_iter(iocb, to); @@ -4413,6 +4415,55 @@ static ssize_t f2fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) return ret; } +static ssize_t f2fs_file_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, + size_t len, unsigned int flags) +{ + struct inode *inode = file_inode(in); + const loff_t pos = *ppos; + ssize_t ret; + + if (!f2fs_is_compress_backend_ready(inode)) + return -EOPNOTSUPP; + + if (trace_f2fs_dataread_start_enabled()) + f2fs_trace_rw_file_path(in, pos, len, READ); + + if (in->f_flags & O_DIRECT) { + if (f2fs_force_buffered_io(inode, READ)) + goto buffered; + + /* + * Direct I/O not aligned to the disk's logical_block_size will + * be attempted, but will fail with -EINVAL. + * + * f2fs additionally requires that direct I/O be aligned to the + * filesystem block size, which is often a stricter + * requirement. However, f2fs traditionally falls back to + * buffered I/O on requests that are logical_block_size-aligned + * but not fs-block aligned. + * + * The below logic implements this behavior. + */ + if (!IS_ALIGNED(pos, i_blocksize(inode)) && + IS_ALIGNED(pos, bdev_logical_block_size(inode->i_sb->s_bdev))) + goto buffered; + ret = direct_splice_read(in, ppos, pipe, len, flags); + goto done; + } + +buffered: + ret = filemap_splice_read(in, ppos, pipe, len, flags); + if (ret > 0) + f2fs_update_iostat(F2FS_I_SB(inode), inode, + APP_BUFFERED_READ_IO, ret); + +done: + if (trace_f2fs_dataread_end_enabled()) + trace_f2fs_dataread_end(inode, pos, ret); + return ret; +} + static ssize_t f2fs_write_checks(struct kiocb *iocb, struct iov_iter *from) { struct file *file = iocb->ki_filp; @@ -4714,7 +4765,8 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) ret = preallocated; } else { if (trace_f2fs_datawrite_start_enabled()) - f2fs_trace_rw_file_path(iocb, orig_count, WRITE); + f2fs_trace_rw_file_path(iocb->ki_filp, iocb->ki_pos, + orig_count, WRITE); /* Do the actual write. */ ret = dio ? @@ -4919,7 +4971,7 @@ const struct file_operations f2fs_file_operations = { #ifdef CONFIG_COMPAT .compat_ioctl = f2fs_compat_ioctl, #endif - .splice_read = generic_file_splice_read, + .splice_read = f2fs_file_splice_read, .splice_write = iter_file_splice_write, .fadvise = f2fs_file_fadvise, };