Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3405520pxb; Mon, 24 Jan 2022 08:55:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJyEaGCDlAko9Cj+dU5y3mvEjcGnIChgIinsqFQCiw7FQv4CCv/X6HqOVZBVPC81D3EKS4tt X-Received: by 2002:a17:90a:7bcb:: with SMTP id d11mr2760034pjl.40.1643043357125; Mon, 24 Jan 2022 08:55:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643043357; cv=none; d=google.com; s=arc-20160816; b=FVY5XDopH94nxXlBK/8Renn0A4np/JRWGUTzjwVKAxrpsSEWwWVfDTng4pmZ3P+qRG kb2YEw/zjUdvj8McqZJysdvHWdP8xSzPFeYd2czPEcWRguqJzTkicH8H728Ape1PHBi/ gRpmjA3PmRotCFFKKN0lEiYyheCz+jt5EKJ1xoQjBmTY6Idcdo67eJABl7YFUZMUMkKb z3AznY24uq9fnNdJflS3X9LQw8oNz+0+oUcqlEeIoANiyVDqov3wqNvXLw3DYX5AxoFc kHF1ksecVFmhsD4x8u9l2na+O37SpcYEsuU37yp1PQZwxlaWFlQiZRQEszk9pFgvIWPy qasQ== 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=jKekh97n0i6AmpeVDE22svCq5nXmamLchP56LCBUk8Y=; b=KBd+2pAmdXnJvJGxv6YlygFldqSCJNUpByGJ6LYkMYxc/63eAU81Wdg7FYlkPU56rt gHv7I+RUdJ4lJnIGkd4DYmzQhIZD4Zy/RvkZXiXMcOjzYmLf880+F4eR4aHXOzJU+/HN sFSJmgJ36wDPNe0usgcw3hLm6rMe6/yCKsd7HsxstMdxnIUw6n5A2b/qhTyLFQkwBJQI ShoI5s5BbObT3d6qynTXa6ZqTKtFt5dHOOdl2G1t91BcKamWQMUgw+ikSEKbNUl/nNhT hyFQfM2rKIlwZ5hHL5pMwshWlkFcTgQHuDRj8YU1ukcIHGjPN9y1r0ZDiGmGsaynN+4L H6CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=cghIZ+ki; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=pyWYRf1S; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-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 e15si11236000pgn.856.2022.01.24.08.55.43; Mon, 24 Jan 2022 08:55:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-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=cghIZ+ki; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=pyWYRf1S; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-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 S241270AbiAXDzZ (ORCPT + 99 others); Sun, 23 Jan 2022 22:55:25 -0500 Received: from smtp-out2.suse.de ([195.135.220.29]:47144 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235321AbiAXDzZ (ORCPT ); Sun, 23 Jan 2022 22:55:25 -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-out2.suse.de (Postfix) with ESMTPS id 314321F3A0; Mon, 24 Jan 2022 03:55:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1642996524; 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=jKekh97n0i6AmpeVDE22svCq5nXmamLchP56LCBUk8Y=; b=cghIZ+kikeLgdtBbznxHOS+3WEdmBrO58IXPnQI2796gYuTKI0vwTkL6GMNqI2mYUIIeU6 ReNJlFXbDr6Eb54AwmHUbjX4yrIkQyU1S2kMSlYL4L6gRIdVymk3q/9Cqx7AimvDYswQYI nxCqilDbnGhP6QAEsarThDH0Sw84OTo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1642996524; 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=jKekh97n0i6AmpeVDE22svCq5nXmamLchP56LCBUk8Y=; b=pyWYRf1SlHJfVNvJ5zVKWKuw4WN+JbjrZRekAoxXuyjygtU2r+5TTggEeP2gXDcVFJ3xIg XpH/SY4pzZRfnFAQ== 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 2E76D13305; Mon, 24 Jan 2022 03:55:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id g+iONygj7mFHRgAAMHmgww (envelope-from ); Mon, 24 Jan 2022 03:55:20 +0000 Subject: [PATCH 22/23] NFS: swap-out must always use STABLE writes. 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: <164299611287.26253.13462969110743208198.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-nfs@vger.kernel.org The commit handling code is not safe against memory-pressure deadlocks when writing to swap. In particular, nfs_commitdata_alloc() blocks indefinitely waiting for memory, and this can consume all available workqueue threads. swap-out most likely uses STABLE writes anyway as COND_STABLE indicates that a stable write should be used if the write fits in a single request, and it normally does. However if we ever swap with a small wsize, or gather unusually large numbers of pages for a single write, this might change. For safety, make it explicit in the code that direct writes used for swap must always use FLUSH_COND_STABLE. Signed-off-by: NeilBrown --- fs/nfs/direct.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c index 43a956d7fd62..29c007b2a17a 100644 --- a/fs/nfs/direct.c +++ b/fs/nfs/direct.c @@ -791,7 +791,7 @@ static const struct nfs_pgio_completion_ops nfs_direct_write_completion_ops = { */ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, struct iov_iter *iter, - loff_t pos) + loff_t pos, int ioflags) { struct nfs_pageio_descriptor desc; struct inode *inode = dreq->inode; @@ -799,7 +799,7 @@ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, size_t requested_bytes = 0; size_t wsize = max_t(size_t, NFS_SERVER(inode)->wsize, PAGE_SIZE); - nfs_pageio_init_write(&desc, inode, FLUSH_COND_STABLE, false, + nfs_pageio_init_write(&desc, inode, ioflags, false, &nfs_direct_write_completion_ops); desc.pg_dreq = dreq; get_dreq(dreq); @@ -905,6 +905,7 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter, struct nfs_direct_req *dreq; struct nfs_lock_context *l_ctx; loff_t pos, end; + int ioflags = swap ? FLUSH_COND_STABLE : FLUSH_STABLE; dfprintk(FILE, "NFS: direct write(%pD2, %zd@%Ld)\n", file, iov_iter_count(iter), (long long) iocb->ki_pos); @@ -947,7 +948,7 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter, if (!swap) nfs_start_io_direct(inode); - requested = nfs_direct_write_schedule_iovec(dreq, iter, pos); + requested = nfs_direct_write_schedule_iovec(dreq, iter, pos, ioflags); if (mapping->nrpages) { invalidate_inode_pages2_range(mapping,