Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3399487pxb; Mon, 24 Jan 2022 08:49:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJws22cyLWGEjL87/wY1WuzWs3t7hZhmONoOebE/EMZPRodfhIWdP5t4+IoUUUDm8jukuY+7 X-Received: by 2002:a17:90b:390f:: with SMTP id ob15mr2034408pjb.160.1643042970617; Mon, 24 Jan 2022 08:49:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643042970; cv=none; d=google.com; s=arc-20160816; b=rbbGEFmOn8/GFHW/rxPUJtTVgqZ1Xxmg3J/i8d5VLOQaa3XqVH6kb3yxlXE1ifjvKM dJfOEgjLQLIVgS29Q/ZewwfVRjyFnOkBIiiJ0Twyht/j7skWdDEP7FoVIBnijCgsOQTg paLfqMABAJgP+6B+vI7lFWQc6taQJQ/jiML+4TcKXqZ1E04/oKbJquExzTAQWEm4pu5/ jd6GIgAPOH/RYB5MkhkWsSoD+yfOwS0TAZd+TDvttI51zklGffuSQKrdb357BTfYtKBW 9u83l7IN9Z3/CyM6QidAEVjeIsafpLk/BEU0cbGjnMlB5/0L/teo5fncDWZhq2fQlvrL 8Zwg== 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=uJLgBSr+4ac2HtnFPf6KLC0wSgPyRK3wpQcub+LxsjE=; b=uO3L/zsKNNRxgfN6R03HV2kbpfRyIMbjjDK6Uha6F/9r1sOMv+XS468J2Gmge4bfTb DXnod03KkModQt/a911LIN6Ld6lGMWLf9P9ugn85VQI6d5Kxnro+9R0Lhj0rtb1LnOZ7 w5YvoyTlIA5j+to3mXvr9VhpbUCNcoBDNOjKME6D9vjR7piZg5u4qIHOiBhuO+HkPsuy oqHDaTnLaxGRgpCb2Yw0g63aC6/iH3hiGHVDYJvWgpF8myyv8lwe2omyaeMYrPz7lm8a brtJ+woZ90RnTNDGhCmu9VoSjxYyAU87GXphXiswiKFyKdYZT1HrIJmrLd2EiFVZW/Hu az1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=L+FUcoLP; 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 t12si13435489pgm.258.2022.01.24.08.49.17; Mon, 24 Jan 2022 08:49:30 -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=L+FUcoLP; 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 S241232AbiAXDx4 (ORCPT + 99 others); Sun, 23 Jan 2022 22:53:56 -0500 Received: from smtp-out2.suse.de ([195.135.220.29]:47044 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241222AbiAXDxv (ORCPT ); Sun, 23 Jan 2022 22:53:51 -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 6876A1F3B1; Mon, 24 Jan 2022 03:53:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1642996430; 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=uJLgBSr+4ac2HtnFPf6KLC0wSgPyRK3wpQcub+LxsjE=; b=L+FUcoLPZYljCcLvX9K/q773EowcGOY8gOh2JXFdbx114stJhLzsplomQo6lS03JO1xwlC OavO7aodABOj7DM1zEtaS/Ps5dJk9Ssg9PCkZwiOH5l/8hLzNgEAcW9R8+SJWWbmvSdRn8 k3eQL2WEaG21D23do3D5THtg8zaCB24= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1642996430; 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=uJLgBSr+4ac2HtnFPf6KLC0wSgPyRK3wpQcub+LxsjE=; b=GFxtFEBVjqgFB2/OrAAU487VJVhuxNXgm3YLtOlyWOoqsbllVn80PezNyfHwKM+Br1Tv3T F0v5MecEjjKEBUDg== 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 07CFF13305; Mon, 24 Jan 2022 03:53:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id m2I4Lcoi7mHGRQAAMHmgww (envelope-from ); Mon, 24 Jan 2022 03:53:46 +0000 Subject: [PATCH 15/23] SUNRPC/call_alloc: async tasks mustn't block waiting for memory 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: <164299611282.26253.11804975093411638223.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 When memory is short, new worker threads cannot be created and we depend on the minimum one rpciod thread to be able to handle everything. So it must not block waiting for memory. mempools are particularly a problem as memory can only be released back to the mempool by an async rpc task running. If all available workqueue threads are waiting on the mempool, no thread is available to return anything. rpc_malloc() can block, and this might cause deadlocks. So check RPC_IS_ASYNC(), rather than RPC_IS_SWAPPER() to determine if blocking is acceptable. Signed-off-by: NeilBrown --- net/sunrpc/sched.c | 4 +++- net/sunrpc/xprtrdma/transport.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c index e2c835482791..d5b6e897f5a5 100644 --- a/net/sunrpc/sched.c +++ b/net/sunrpc/sched.c @@ -1023,8 +1023,10 @@ int rpc_malloc(struct rpc_task *task) struct rpc_buffer *buf; gfp_t gfp = GFP_NOFS; + if (RPC_IS_ASYNC(task)) + gfp = GFP_NOWAIT | __GFP_NOWARN; if (RPC_IS_SWAPPER(task)) - gfp = __GFP_MEMALLOC | GFP_NOWAIT | __GFP_NOWARN; + gfp |= __GFP_MEMALLOC; size += sizeof(struct rpc_buffer); if (size <= RPC_BUFFER_MAXSIZE) diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c index 16e5696314a4..a52277115500 100644 --- a/net/sunrpc/xprtrdma/transport.c +++ b/net/sunrpc/xprtrdma/transport.c @@ -574,8 +574,10 @@ xprt_rdma_allocate(struct rpc_task *task) gfp_t flags; flags = RPCRDMA_DEF_GFP; + if (RPC_IS_ASYNC(task)) + flags = GFP_NOWAIT | __GFP_NOWARN; if (RPC_IS_SWAPPER(task)) - flags = __GFP_MEMALLOC | GFP_NOWAIT | __GFP_NOWARN; + flags |= __GFP_MEMALLOC; if (!rpcrdma_check_regbuf(r_xprt, req->rl_sendbuf, rqst->rq_callsize, flags))