Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1900706pxb; Fri, 24 Sep 2021 14:49:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLoBXZrcN/rVBIkdiXIZ/E4jx1jb50U3a3j4y8o86ELcAmgO3BntY9oV4tJNSjguF5+rGW X-Received: by 2002:a92:d3c1:: with SMTP id c1mr10478063ilh.223.1632520196252; Fri, 24 Sep 2021 14:49:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632520196; cv=none; d=google.com; s=arc-20160816; b=Xue0Xo7LnhH8oN9OhC+fUS70UFJ6n35UrhNnjzDPuSbM11jdWY7cL2C8lBypQ5FAHN WhDoe+IXp/lNhbJN3gbNEyvWAgXP9eqeM8eOAqAx5aBSQLDclYbNRaE3guQQFsvIWuFl sUp7jtJ5INbcJsnwJNPkorT29fwj2zNkGivWHKasNkt1r+L+hP+MSvDTdpzsFgTSvZv6 mHD6I8/2yLr1RdgEL2QSA9ybcMVooelcYh/kBgnFoCI+v+/5I88+4hKE6ltfuZSpSEco fBTMGVzEdTehSWPqX7LNLSePrxiA0R7b+5oAkMAkMimDHe6/hTb3lR6edh39X7H2ruHz FPtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization:dkim-signature; bh=x7BpkThd4W7Otj77d326ZQ439zIBR66OsnpLRS8EUC4=; b=INTl6MizTIxJuVzKX040CY8l8BTy1Nqj7472ZyplTGVKHfb8OHDlHeIzjFHj2wpyYL DiBSVJAzUBs6PyUQjnMyKaDZeHD2k12T0BOMCkm+hrV71qdQJGoI3yQnLb3kixlD4t2O /jYXCwfPN8vaotIPB31/3awZvBw4Q7R73MoyaAW6JcYtNNXp9Gx6LujyN30MveJekTsF XRwyfMBuzHhqvKWo3YH10vC2mAHK0qSbgD5aYcrjIbh9oZJ/mqtSuPM9Siz02wCevPnV pgSycLCA0FhLlGtoum00NtguZBzp/4e3l43IzR+ctjZkojRSd7BgCydt7UqdCZACqSsm P+IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EnuirPLM; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b7si13300401ilv.56.2021.09.24.14.49.44; Fri, 24 Sep 2021 14:49:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EnuirPLM; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347778AbhIXRVx (ORCPT + 99 others); Fri, 24 Sep 2021 13:21:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:28040 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347774AbhIXRUz (ORCPT ); Fri, 24 Sep 2021 13:20:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632503962; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x7BpkThd4W7Otj77d326ZQ439zIBR66OsnpLRS8EUC4=; b=EnuirPLModdDX58xXF8rMtKag2tVQLfPVY5pY7QCZBXWth90DhAClt9aRZaJo+le1WtDfO mI3548RUesLmS5gIvm/mWVEPKgFdW8iA9eR7VovqB/87sW3kKzIBhHb0ovhU/iNDVJ0Ce1 nEGxpejQSTuERWCpK0O72rW8ouuFnk8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-384-FXe5ABoKNvWZ-0xXSP1U8g-1; Fri, 24 Sep 2021 13:19:21 -0400 X-MC-Unique: FXe5ABoKNvWZ-0xXSP1U8g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4F5DC802B9F; Fri, 24 Sep 2021 17:19:18 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7B3D5F707; Fri, 24 Sep 2021 17:19:12 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH v3 8/9] block, btrfs, ext4, xfs: Implement swap_rw From: David Howells To: willy@infradead.org, hch@lst.de, trond.myklebust@primarydata.com Cc: Jens Axboe , Chris Mason , Josef Bacik , David Sterba , Theodore Ts'o , Andreas Dilger , "Darrick J. Wong" , linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, dhowells@redhat.com, dhowells@redhat.com, darrick.wong@oracle.com, viro@zeniv.linux.org.uk, jlayton@kernel.org, torvalds@linux-foundation.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 24 Sep 2021 18:19:11 +0100 Message-ID: <163250395192.2330363.9101664122191208351.stgit@warthog.procyon.org.uk> In-Reply-To: <163250387273.2330363.13240781819520072222.stgit@warthog.procyon.org.uk> References: <163250387273.2330363.13240781819520072222.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.23 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Implement swap_rw for block devices, btrfs, ext4 and xfs. This allows the the page swapping code to use direct-IO rather than direct bio submission, whilst skipping the checks going via read/write_iter would entail. Signed-off-by: David Howells cc: Matthew Wilcox cc: Christoph Hellwig cc: Jens Axboe cc: Chris Mason cc: Josef Bacik cc: David Sterba cc: "Theodore Ts'o" cc: Andreas Dilger cc: Darrick J. Wong cc: linux-block@vger.kernel.org cc: linux-btrfs@vger.kernel.org cc: linux-ext4@vger.kernel.org cc: linux-xfs@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- block/fops.c | 1 + fs/btrfs/inode.c | 12 +++++------- fs/ext4/inode.c | 9 +++++++++ fs/xfs/xfs_aops.c | 9 +++++++++ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/block/fops.c b/block/fops.c index 84c64d814d0d..7ba37dfafae2 100644 --- a/block/fops.c +++ b/block/fops.c @@ -382,6 +382,7 @@ const struct address_space_operations def_blk_aops = { .write_end = blkdev_write_end, .writepages = blkdev_writepages, .direct_IO = blkdev_direct_IO, + .swap_rw = blkdev_direct_IO, .migratepage = buffer_migrate_page_norefs, .is_dirty_writeback = buffer_check_dirty_writeback, .supports = AS_SUPPORTS_DIRECT_IO, diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index b479c97e42fc..9ffcefecb3bb 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -10852,15 +10852,10 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file, sis->highest_bit = bsi.nr_pages - 1; return bsi.nr_extents; } -#else -static void btrfs_swap_deactivate(struct file *file) -{ -} -static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file, - sector_t *span) +static ssize_t btrfs_swap_rw(struct kiocb *iocb, struct iov_iter *iter) { - return -EOPNOTSUPP; + return iomap_dio_rw(iocb, iter, &btrfs_dio_iomap_ops, NULL, 0); } #endif @@ -10944,8 +10939,11 @@ static const struct address_space_operations btrfs_aops = { #endif .set_page_dirty = btrfs_set_page_dirty, .error_remove_page = generic_error_remove_page, +#ifdef CONFIG_SWAP .swap_activate = btrfs_swap_activate, .swap_deactivate = btrfs_swap_deactivate, + .swap_rw = btrfs_swap_rw, +#endif .supports = AS_SUPPORTS_DIRECT_IO, }; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 08d3541d8daa..3c14724d58a8 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3651,6 +3651,11 @@ static int ext4_iomap_swap_activate(struct swap_info_struct *sis, &ext4_iomap_report_ops); } +static ssize_t ext4_swap_rw(struct kiocb *iocb, struct iov_iter *iter) +{ + return iomap_dio_rw(iocb, iter, &ext4_iomap_ops, NULL, 0); +} + static const struct address_space_operations ext4_aops = { .readpage = ext4_readpage, .readahead = ext4_readahead, @@ -3666,6 +3671,7 @@ static const struct address_space_operations ext4_aops = { .is_partially_uptodate = block_is_partially_uptodate, .error_remove_page = generic_error_remove_page, .swap_activate = ext4_iomap_swap_activate, + .swap_rw = ext4_swap_rw, .supports = AS_SUPPORTS_DIRECT_IO, }; @@ -3683,6 +3689,7 @@ static const struct address_space_operations ext4_journalled_aops = { .is_partially_uptodate = block_is_partially_uptodate, .error_remove_page = generic_error_remove_page, .swap_activate = ext4_iomap_swap_activate, + .swap_rw = ext4_swap_rw, .supports = AS_SUPPORTS_DIRECT_IO, }; @@ -3701,6 +3708,7 @@ static const struct address_space_operations ext4_da_aops = { .is_partially_uptodate = block_is_partially_uptodate, .error_remove_page = generic_error_remove_page, .swap_activate = ext4_iomap_swap_activate, + .swap_rw = ext4_swap_rw, .supports = AS_SUPPORTS_DIRECT_IO, }; @@ -3710,6 +3718,7 @@ static const struct address_space_operations ext4_dax_aops = { .bmap = ext4_bmap, .invalidatepage = noop_invalidatepage, .swap_activate = ext4_iomap_swap_activate, + .swap_rw = ext4_swap_rw, .supports = AS_SUPPORTS_DIRECT_IO, }; diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 2a4570516591..23ade2cc8241 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -540,6 +540,13 @@ xfs_iomap_swapfile_activate( &xfs_read_iomap_ops); } +static ssize_t xfs_swap_rw(struct kiocb *iocb, struct iov_iter *iter) +{ + if (iocb->ki_flags & IOCB_WRITE) + return iomap_dio_rw(iocb, iter, &xfs_direct_write_iomap_ops, NULL, 0); + return iomap_dio_rw(iocb, iter, &xfs_read_iomap_ops, NULL, 0); +} + const struct address_space_operations xfs_address_space_operations = { .readpage = xfs_vm_readpage, .readahead = xfs_vm_readahead, @@ -552,6 +559,7 @@ const struct address_space_operations xfs_address_space_operations = { .is_partially_uptodate = iomap_is_partially_uptodate, .error_remove_page = generic_error_remove_page, .swap_activate = xfs_iomap_swapfile_activate, + .swap_rw = xfs_swap_rw, .supports = AS_SUPPORTS_DIRECT_IO, }; @@ -560,5 +568,6 @@ const struct address_space_operations xfs_dax_aops = { .set_page_dirty = __set_page_dirty_no_writeback, .invalidatepage = noop_invalidatepage, .swap_activate = xfs_iomap_swapfile_activate, + .swap_rw = xfs_swap_rw, .supports = AS_SUPPORTS_DIRECT_IO, };