Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2405229pxp; Mon, 21 Mar 2022 19:21:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhRbX82djjun3g0esuDHyfa4AlGvnO/0tNVIhgyB5HJqWuIurgYLcuPdPo3gxVGqh7Ego9 X-Received: by 2002:a17:90a:4749:b0:1be:ea64:4348 with SMTP id y9-20020a17090a474900b001beea644348mr2259558pjg.231.1647915702285; Mon, 21 Mar 2022 19:21:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647915702; cv=none; d=google.com; s=arc-20160816; b=Jdcts7Uld0u3AKq5LBMx+WoMf+nor8SrwIBAPcjOmkSHddzpxjWkSuIUdDQBBwoEaQ OsLwdykmbj7MxfC+CA+Mgrhvc7EDGWT9xoZutcLb2tXY8hAaS67IePY9OBzDBOEvzrYf w7jzCrCG4AOQXLCBWhbdQisRNEc/3aIlgwMy2GeceNSv6PXemZfMB/yQWIdNGhsosCSG SaqZOyyFHK6o1xWVboH7wbMaJKyp8DRiGeduNf+28qi1I0WTBxYsi2BYOmL1NoTkcB2u LVRzzroXVxLOb+pvkJPR+cbyK0gQ2Ki+HqqtHLtTrT0kqIyfJz1LAGc6sWRpE2fDUBnA IW3A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BTKYx9pOdvAwFiQJBOoUmfw0KEMOaQm+YrpWTUGGzRw=; b=fj+X6rVCRbFfkKVm12l9NGRrUPQSdOw4E6/xGLqQGANoRDzbeUnOPD2dxtVteP9SuP XvCTlsK7ZGMB9WMeiiM9FCLfieVJJ2SsahWIwEOlIVqk27G/6TezQK+HvG4yadoGOifK 1fmwFE4yKe3nKdWCyFIBGXV9S36LBxxSErhPhVmI2FYbTtLFxVDjZkF4WgbV3jzftxeb cldiAjMr1SQjG/7HbcORMWintf4Vtwv+X0WVCYSF+1/kG/JxtxZlTujCEyDs/qshCV0h FhBUUdp+2uW2P3InaEKqlUdlmxbAnbRQqeFfMm2H2OEt3HuRmdxfRcW3igI599slUhzn 6y2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KPjDhmxV; spf=softfail (google.com: domain of transitioning linux-nfs-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id g6-20020a17090a714600b001c6953a47c9si878162pjs.151.2022.03.21.19.21.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 19:21:42 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-nfs-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KPjDhmxV; spf=softfail (google.com: domain of transitioning linux-nfs-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B98BD13E26; Mon, 21 Mar 2022 18:54:39 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235195AbiCVB4C (ORCPT + 99 others); Mon, 21 Mar 2022 21:56:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235139AbiCVB4A (ORCPT ); Mon, 21 Mar 2022 21:56:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96D3843EC2 for ; Mon, 21 Mar 2022 18:54:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1F9AF60AE1 for ; Tue, 22 Mar 2022 01:54:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2FB94C340EE; Tue, 22 Mar 2022 01:54:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647914073; bh=TpFozSPyg7PH9QSv7+9Ca1GGRZqck54LuncQ6km/yVM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KPjDhmxVgFg76pCE4V6GXV92+dm5JSf3uQHe1MG1aYfvkKKk91FTh7RcM2Gy4jHcg IhZBFNiZDKLq9eGvWpXBWHiPe2Tohs42Is7zTUa2NT6B1kNXzQf4/AuyTVtb6kguYu pbrUrbxXO+nJ9AsrySop0/YpaK0IvqEdZw5DOOW48LjXxaxCGISvhaY6/glvv13n8T WPhx/gwQwRSQFFmxbpH++vsHeXJju52SHhVddWoim9RQSuri4jHQHzyc481dlLYlzf lZW/JZqVfUDvlNMjRvA7uQ4z+mMAc5WPiejTGN39CAnwynwP56D1xXYMjeY/JOPxe6 vYSUBF0gqcbNw== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Cc: Chuck Lever , Enrico Scholz Subject: [PATCH v2 1/9] NFS: Fix memory allocation in rpc_malloc() Date: Mon, 21 Mar 2022 21:47:38 -0400 Message-Id: <20220322014746.1052984-2-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220322014746.1052984-1-trondmy@kernel.org> References: <20220322014746.1052984-1-trondmy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust When in a low memory situation, we do want rpciod to kick off direct reclaim in the case where that helps, however we don't want it looping forever in mempool_alloc(). So first try allocating from the slab using GFP_KERNEL | __GFP_NORETRY, and then fall back to a GFP_NOWAIT allocation from the mempool. Ditto for rpc_alloc_task() Signed-off-by: Trond Myklebust --- include/linux/sunrpc/sched.h | 1 + net/sunrpc/sched.c | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h index 56710f8056d3..1d7a3e51b795 100644 --- a/include/linux/sunrpc/sched.h +++ b/include/linux/sunrpc/sched.h @@ -262,6 +262,7 @@ void rpc_destroy_mempool(void); extern struct workqueue_struct *rpciod_workqueue; extern struct workqueue_struct *xprtiod_workqueue; void rpc_prepare_task(struct rpc_task *task); +gfp_t rpc_task_gfp_mask(void); static inline int rpc_wait_for_completion_task(struct rpc_task *task) { diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c index 7c8f87ebdbc0..d59a033820be 100644 --- a/net/sunrpc/sched.c +++ b/net/sunrpc/sched.c @@ -57,6 +57,13 @@ struct workqueue_struct *rpciod_workqueue __read_mostly; struct workqueue_struct *xprtiod_workqueue __read_mostly; EXPORT_SYMBOL_GPL(xprtiod_workqueue); +gfp_t rpc_task_gfp_mask(void) +{ + if (current->flags & PF_WQ_WORKER) + return GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN; + return GFP_KERNEL; +} + unsigned long rpc_task_timeout(const struct rpc_task *task) { @@ -1030,15 +1037,15 @@ int rpc_malloc(struct rpc_task *task) struct rpc_rqst *rqst = task->tk_rqstp; size_t size = rqst->rq_callsize + rqst->rq_rcvsize; struct rpc_buffer *buf; - gfp_t gfp = GFP_KERNEL; - - if (RPC_IS_ASYNC(task)) - gfp = GFP_NOWAIT | __GFP_NOWARN; + gfp_t gfp = rpc_task_gfp_mask(); size += sizeof(struct rpc_buffer); - if (size <= RPC_BUFFER_MAXSIZE) - buf = mempool_alloc(rpc_buffer_mempool, gfp); - else + if (size <= RPC_BUFFER_MAXSIZE) { + buf = kmem_cache_alloc(rpc_buffer_slabp, gfp); + /* Reach for the mempool if dynamic allocation fails */ + if (!buf && RPC_IS_ASYNC(task)) + buf = mempool_alloc(rpc_buffer_mempool, GFP_NOWAIT); + } else buf = kmalloc(size, gfp); if (!buf) -- 2.35.1