From patchwork Fri Aug 11 06:27:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13350166 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 E76E1C41513 for ; Fri, 11 Aug 2023 06:27:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CC206B0071; Fri, 11 Aug 2023 02:27:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 67C386B0072; Fri, 11 Aug 2023 02:27:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56AAC6B0074; Fri, 11 Aug 2023 02:27:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 485956B0071 for ; Fri, 11 Aug 2023 02:27:13 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1B76B1CA106 for ; Fri, 11 Aug 2023 06:27:13 +0000 (UTC) X-FDA: 81110841546.04.C065E5C Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) by imf24.hostedemail.com (Postfix) with ESMTP id 5BF7F18001A for ; Fri, 11 Aug 2023 06:27:11 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="Ne5/1/Yu"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of hughd@google.com designates 209.85.128.174 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691735231; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LjSC6ORUGqX5v9IH/a5QjzTjJ0xPrBuZ4pptH8o9IgM=; b=07P+Imij9SnucrKSF80z9nL4B/fZL2VFm689sOf2+583IsP8VTm7hJhNrOUi3wF3US/Hnz 3Ui39rJr/wHtK3E0Hzi+MknVciTYkRYrvVydEjJeKD+lD6skmH+kwElfKqt/3W0PayU2BB cMrIntWmednYkDoimTTGhxgNO8Kblos= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="Ne5/1/Yu"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of hughd@google.com designates 209.85.128.174 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691735231; a=rsa-sha256; cv=none; b=MYf0oSSmnxwGvYIyYO7z8i8jr4Gu/wO9nZcpoWImPMVTa+USMXIENd2z36hlVD/0g7yntQ MsE57ZxMrUUqS+x47prpE48yWxOGkaAEaTH226soNEG+KFGTjH0H5FKDfXwy6LtQCtxuHv 8haUHHWSoxYR2LZ41L6g3fN1LY9x8Y0= Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-583b0637c04so24029987b3.1 for ; Thu, 10 Aug 2023 23:27:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691735230; x=1692340030; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=LjSC6ORUGqX5v9IH/a5QjzTjJ0xPrBuZ4pptH8o9IgM=; b=Ne5/1/YuoznmAWP9saoti+yPi0jnWl9VKghSRaCnRpWZ7kNaigo131ld1R4sZCWXqM xtptL/obzPWlxsXVucEc3oZ4xmUq5seUpUn98/zCzzLrVv3rEWkugM13AkU/qG6VX1dm y/JYsycPB7FgCJHOFC9703Kyw3lew4kxX3gDdpeTK6ormuMaU8wtH2CfpSRrsHn2f570 D0BkT8Y5oGI3Ie+WE6RJXuJ/xOAbo9z6es7jdLyxTRRXwUKS7Rz85MukUwZaLlw/rwDi BkR60JRKmE0fy31UnWWmQcytaMlzBzyIoXN2ooIB4VemfkZPzGKD64GxN2uoWeL+Lmae TKXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691735230; x=1692340030; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LjSC6ORUGqX5v9IH/a5QjzTjJ0xPrBuZ4pptH8o9IgM=; b=QQgyLEdf7DeWKhvaZLzNjGPI73CxO+bG5rxQhrR8q302TAywXiyVaU5/U/BXYbL7Dt 1IUXAIzFFwe+xYO8vS61xu8Z6dKLQkfN1chqEoUYz9AXWadfLgtkyNk86/vAD9a/UpPD 2AX5p0CVfOioMVsoIJ6z0jHUWOFgT6mL4k8iN7Zx3AlZR7Qki7S9p08CV/ajLZOVjfb3 iuW7uJVBx4DZwSZZRkZOusDisBTk2r+zVkieze4bCmDOeZMHxAb9USvr0+geRyvqwIjm ogr/e1bwsIFmHZd6OKiXaM2hkfuCRJMZBrQk/bubTovtcoj8EgwoBUbPRLXXGDhMjjhX iPFA== X-Gm-Message-State: AOJu0Yx28J/JentdYWoYuqTZJPJG3dCEO/8QP6gDOzD4EvYCbfUpXsEu rzTduE9X/shLNRBBQoav4Mksmg== X-Google-Smtp-Source: AGHT+IEmm8MWAaG7syMMW88reDhcEhTyiYTMB0u94NqgqZhkO7TO6fu1NBNpSAC8ZfvcJtoyRS37fA== X-Received: by 2002:a0d:d4c9:0:b0:579:e6e4:a165 with SMTP id w192-20020a0dd4c9000000b00579e6e4a165mr5056049ywd.10.1691735230373; Thu, 10 Aug 2023 23:27:10 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id h123-20020a0df781000000b0055a373a7e5asm817227ywf.131.2023.08.10.23.27.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 23:27:09 -0700 (PDT) Date: Thu, 10 Aug 2023 23:27:07 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Christian Brauner cc: Andrew Morton , Oleksandr Tymoshenko , Carlos Maiolino , Jeff Layton , Chuck Lever , Jan Kara , Miklos Szeredi , Daniel Xu , Chris Down , Tejun Heo , Greg Kroah-Hartman , Matthew Wilcox , Christoph Hellwig , Pete Zaitcev , Helge Deller , Topi Miettinen , Yu Kuai , "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH vfs.tmpfs v2 4/5] tmpfs: trivial support for direct IO In-Reply-To: <7c12819-9b94-d56-ff88-35623aa34180@google.com> Message-ID: <6f2742-6f1f-cae9-7c5b-ed20fc53215@google.com> References: <7c12819-9b94-d56-ff88-35623aa34180@google.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 5BF7F18001A X-Stat-Signature: hdowxu74jiem4k6j37zy3nh3zukti6ou X-Rspam-User: X-HE-Tag: 1691735231-873615 X-HE-Meta: U2FsdGVkX1+tyV3evgEsYWxz3B4Jq7xluqNwGH0uv0cGpeINPK36bsH6tEWgIrkT1uSBGpQrNLB1VZy7x6F3li5D/whSKsX7QnxixwrAqcK60xkY5LIcaW1O1m/cZVUjO8LA6r7ccfNlB/e3in8cfvrT4yXw/2V1qnYEwGVqIBgpHQILg9XiQcIR0QIpa1LOCyEXk2ZpJqVGPLfFrGucyIC3XtHGfR0yUPv897nlqIqc7O6dli6LRGgyjcIjO+bkknZ/u+8tITkJQae+4mChis53W791ZHIg2N7vIyjCHg1DuBl3x4NhwK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/g1L/D6QuURUWV 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: Depending upon your philosophical viewpoint, either tmpfs always does direct IO, or it cannot ever do direct IO; but whichever, if tmpfs is to stand in for a more sophisticated filesystem, it can be helpful for tmpfs to support O_DIRECT. So, give tmpfs a shmem_file_open() method, to set the FMODE_CAN_ODIRECT flag: then unchanged shmem_file_read_iter() and new shmem_file_write_iter() do the work (without any shmem_direct_IO() stub). Perhaps later, once the direct_IO method has been eliminated from all filesystems, generic_file_write_iter() will be such that tmpfs can again use it, even for O_DIRECT. xfstests auto generic which were not run on tmpfs before but now pass: 036 091 113 125 130 133 135 198 207 208 209 210 211 212 214 226 239 263 323 355 391 406 412 422 427 446 451 465 551 586 591 609 615 647 708 729 with no new failures. LTP dio tests which were not run on tmpfs before but now pass: dio01 through dio30, except for dio04 and dio10, which fail because tmpfs dio read and write allow odd count: tmpfs could be made stricter, but would that be an improvement? Signed-off-by: Hugh Dickins Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- Thanks for your earlier review, Jan: I've certainly not copied that into this entirely different version. I prefer the v1, but fine if people prefer this v2. mm/shmem.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index ca43fb256b8e..b782edeb69aa 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2388,6 +2388,12 @@ static int shmem_mmap(struct file *file, struct vm_area_struct *vma) return 0; } +static int shmem_file_open(struct inode *inode, struct file *file) +{ + file->f_mode |= FMODE_CAN_ODIRECT; + return generic_file_open(inode, file); +} + #ifdef CONFIG_TMPFS_XATTR static int shmem_initxattrs(struct inode *, const struct xattr *, void *); @@ -2839,6 +2845,28 @@ static ssize_t shmem_file_read_iter(struct kiocb *iocb, struct iov_iter *to) return retval ? retval : error; } +static ssize_t shmem_file_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; + + inode_lock(inode); + ret = generic_write_checks(iocb, from); + if (ret <= 0) + goto unlock; + ret = file_remove_privs(file); + if (ret) + goto unlock; + ret = file_update_time(file); + if (ret) + goto unlock; + ret = generic_perform_write(iocb, from); +unlock: + inode_unlock(inode); + return ret; +} + static bool zero_pipe_buf_get(struct pipe_inode_info *pipe, struct pipe_buffer *buf) { @@ -4434,12 +4462,12 @@ EXPORT_SYMBOL(shmem_aops); static const struct file_operations shmem_file_operations = { .mmap = shmem_mmap, - .open = generic_file_open, + .open = shmem_file_open, .get_unmapped_area = shmem_get_unmapped_area, #ifdef CONFIG_TMPFS .llseek = shmem_file_llseek, .read_iter = shmem_file_read_iter, - .write_iter = generic_file_write_iter, + .write_iter = shmem_file_write_iter, .fsync = noop_fsync, .splice_read = shmem_file_splice_read, .splice_write = iter_file_splice_write,