Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3392934pxb; Mon, 24 Jan 2022 08:40:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJyvE+S3Ny0h6tuYL7SUWwelJGrcmrxMozwyOBAEglzutepmeWmTzEs8x5ZzmPCp2admJE0O X-Received: by 2002:a63:844a:: with SMTP id k71mr4752072pgd.495.1643042452418; Mon, 24 Jan 2022 08:40:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643042452; cv=none; d=google.com; s=arc-20160816; b=z2ExE6nXiFnhaJzFlQoWB5r9al1DMeUCtKwA11IHcLGlZzgiIjrpgIfmJ3xPYnLCxb NDdjbCNWwHT0mwFJtm27p+bx1HIShCEFhKjKGOwWqZZMKWbSdqBVYkNdX4HksVXGGkbo FBEHo2e/mM9yIxIqpD+1RTiyDBXS/Xe3oByzEVKityYmkDnmQwly30IFVF3f6YW4Nyve M2wdPW5+XA6FtCd+2VQNYXW27CCWelWGig2CCYzVCgiJXPEhNCc/J/OOfG3A57qOV2tU JJgEzBo31pm1BQuGsvSE++gHu6BN2Hp5P22hrFGTexmhv0BHsf1gEB4Msmmyx7LQC96s G5Cw== 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:dkim-signature:dkim-signature; bh=n/cgZ4EscdnFAYZEj1bTLNqQrrTGr07Xq40A143hCZg=; b=wzasfPmPZujj8Mi6xtp2wCD3B8qBYTvqWwzqX7WArpbisKQ5fjA7MjGCse1bzxJ63W sS0R7FTUIvpXld8+XGiWWdwHKmOfxloXjj+n/FRsQ5BYteBjUf6ZRYsOvbrmWLGXwINp Kv8/YukT9HKMm3IDU8GNFuX1eXDgweDeQu2FqcbjGn/PyCcrF6zb2M1r+CVQl8A7ysDb 4hoGRJ8mZOpNkRa6x4WUyJDk95t6gZTM+vAiabNvJ2fQpTBmv75Q5Tn5YpSShHIk9gUR 8rbaULARWWeobB84wBCe3PVvKjAhXmyMWFdHrxh9dhR3d7jrFMuv29/Vq52kt1yvpK2p yqKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="ILMY/8fq"; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o6si7583326pjt.142.2022.01.24.08.40.39; Mon, 24 Jan 2022 08:40:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@suse.de header.s=susede2_rsa header.b="ILMY/8fq"; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231579AbiAXDvh (ORCPT + 99 others); Sun, 23 Jan 2022 22:51:37 -0500 Received: from smtp-out1.suse.de ([195.135.220.28]:56810 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236070AbiAXDvf (ORCPT ); Sun, 23 Jan 2022 22:51:35 -0500 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8F8C721997; Mon, 24 Jan 2022 03:51:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1642996294; h=from:from:reply-to: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=n/cgZ4EscdnFAYZEj1bTLNqQrrTGr07Xq40A143hCZg=; b=ILMY/8fqzrFhuGhnzWH1cISUXoOxajFChXV5nL0F6ougH4v9ZA49wxyAPika9w+KNSkjIG Ldlv1Kbfge/z8iesN89TjyDMtwHIx0eat7CA18+AsvUv9mzrqaQPrnmY4LCbEJLUWGCpi8 JbZI8wzk/DT2TJbFezEh8jd2DsrvUNM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1642996294; h=from:from:reply-to: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=n/cgZ4EscdnFAYZEj1bTLNqQrrTGr07Xq40A143hCZg=; b=3XRlusLMmRngEeDcRJoZzsb1O+QmpENg6F1W4CG9Ja5wmBVrcmYAwywsYrnnbT7xSuDx99 E3g39JDAS350EEAw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 95CE613305; Mon, 24 Jan 2022 03:51:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GTGYFEMi7mEaRQAAMHmgww (envelope-from ); Mon, 24 Jan 2022 03:51:31 +0000 Subject: [PATCH 07/23] MM: perform async writes to SWP_FS_OPS swap-space using ->swap_rw From: NeilBrown To: Trond Myklebust , Anna Schumaker , Chuck Lever , Andrew Morton , Mel Gorman , Christoph Hellwig , David Howells Cc: linux-nfs@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Mon, 24 Jan 2022 14:48:32 +1100 Message-ID: <164299611277.26253.18349860115008677213.stgit@noble.brown> In-Reply-To: <164299573337.26253.7538614611220034049.stgit@noble.brown> References: <164299573337.26253.7538614611220034049.stgit@noble.brown> User-Agent: StGit/0.23 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch switches swap-out to SWP_FS_OPS swap-spaces to use ->swap_rw and makes the writes asynchronous, like they are for other swap spaces. To make it async we need to allocate the kiocb struct from a mempool. This may block, but won't block as long as waiting for the write to complete. At most it will wait for some previous swap IO to complete. Signed-off-by: NeilBrown --- mm/page_io.c | 93 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 40 deletions(-) diff --git a/mm/page_io.c b/mm/page_io.c index e90a3231f225..6e32ca35d9b6 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -303,6 +303,57 @@ int sio_pool_init(void) return 0; } +static void sio_write_complete(struct kiocb *iocb, long ret) +{ + struct swap_iocb *sio = container_of(iocb, struct swap_iocb, iocb); + struct page *page = sio->bvec.bv_page; + + if (ret != 0 && ret != PAGE_SIZE) { + /* + * In the case of swap-over-nfs, this can be a + * temporary failure if the system has limited + * memory for allocating transmit buffers. + * Mark the page dirty and avoid + * folio_rotate_reclaimable but rate-limit the + * messages but do not flag PageError like + * the normal direct-to-bio case as it could + * be temporary. + */ + set_page_dirty(page); + ClearPageReclaim(page); + pr_err_ratelimited("Write error %ld on dio swapfile (%llu)\n", + ret, page_file_offset(page)); + } else + count_vm_event(PSWPOUT); + end_page_writeback(page); + mempool_free(sio, sio_pool); +} + +static int swap_writepage_fs(struct page *page, struct writeback_control *wbc) +{ + struct swap_iocb *sio; + struct swap_info_struct *sis = page_swap_info(page); + struct file *swap_file = sis->swap_file; + struct address_space *mapping = swap_file->f_mapping; + struct iov_iter from; + int ret; + + set_page_writeback(page); + unlock_page(page); + sio = mempool_alloc(sio_pool, GFP_NOIO); + init_sync_kiocb(&sio->iocb, swap_file); + sio->iocb.ki_complete = sio_write_complete; + sio->iocb.ki_pos = page_file_offset(page); + sio->bvec.bv_page = page; + sio->bvec.bv_len = PAGE_SIZE; + sio->bvec.bv_offset = 0; + iov_iter_bvec(&from, WRITE, &sio->bvec, 1, PAGE_SIZE); + ret = mapping->a_ops->swap_rw(&sio->iocb, &from); + if (ret != -EIOCBQUEUED) + sio_write_complete(&sio->iocb, ret); + return ret; +} + int __swap_writepage(struct page *page, struct writeback_control *wbc, bio_end_io_t end_write_func) { @@ -311,46 +362,8 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc, struct swap_info_struct *sis = page_swap_info(page); VM_BUG_ON_PAGE(!PageSwapCache(page), page); - if (data_race(sis->flags & SWP_FS_OPS)) { - struct kiocb kiocb; - struct file *swap_file = sis->swap_file; - struct address_space *mapping = swap_file->f_mapping; - struct bio_vec bv = { - .bv_page = page, - .bv_len = PAGE_SIZE, - .bv_offset = 0 - }; - struct iov_iter from; - - iov_iter_bvec(&from, WRITE, &bv, 1, PAGE_SIZE); - init_sync_kiocb(&kiocb, swap_file); - kiocb.ki_pos = page_file_offset(page); - - set_page_writeback(page); - unlock_page(page); - ret = mapping->a_ops->direct_IO(&kiocb, &from); - if (ret == PAGE_SIZE) { - count_vm_event(PSWPOUT); - ret = 0; - } else { - /* - * In the case of swap-over-nfs, this can be a - * temporary failure if the system has limited - * memory for allocating transmit buffers. - * Mark the page dirty and avoid - * folio_rotate_reclaimable but rate-limit the - * messages but do not flag PageError like - * the normal direct-to-bio case as it could - * be temporary. - */ - set_page_dirty(page); - ClearPageReclaim(page); - pr_err_ratelimited("Write error on dio swapfile (%llu)\n", - page_file_offset(page)); - } - end_page_writeback(page); - return ret; - } + if (data_race(sis->flags & SWP_FS_OPS)) + return swap_writepage_fs(page, wbc); ret = bdev_write_page(sis->bdev, swap_page_sector(page), page, wbc); if (!ret) {