Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2387640pxp; Mon, 21 Mar 2022 18:48:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFpp5+6mHWtYe4gjIAqgHXM8xUmhCgAe4JanJZmPXOQB88+7ARMWmEQ0AwA+PFepM9cbST X-Received: by 2002:a17:90b:1d84:b0:1bf:674d:2db5 with SMTP id pf4-20020a17090b1d8400b001bf674d2db5mr2211978pjb.8.1647913717942; Mon, 21 Mar 2022 18:48:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647913717; cv=none; d=google.com; s=arc-20160816; b=cOUfCcRTGdOuRcUuyHphlcNvGOqJh2WFV/hsPkCpaYbukSozXEJ3RFH07DHq0AGYmb 63IMsYhGU5Cm/yIFibyfApXNBZnhUt1cR9kCZ+czCYDCLJJdywSGWcqb9yUzk39McdE2 XsL9OjsmmEzY/t7KrvRJr3q3Vt8qJOp5vYOKOyaJabOOQyue/WpcfnejENYtcZkCeIUs WzYNG/fw5G54OhXR1y52Ehmuc0HqWWdT8ksDxNvHb6Jg92hdtJfuVRo5AwMS+C4yM5W7 /wptMInolPNFv0rLBy9I509RYzjfuM1zQOv1Bu+QgcY4g/53p9DWhpDrsa0d0iMF8Rfw h8kw== 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=KW/LE97xdvoF9jbcrws3ny8GUGs6FaO/f1GmIEcmFtI=; b=QsmfIqNj2FUoAmedb+ekpT2WZEU+mE1qe50+yKNgFGza3fgClXXY2Cot8j3gOWEcbq GQgBu1sWbWqVcBrqyKMdDKVq+SEciBss0aSZBF3haHuF2KjFJeFPdRa5n2bJHbbGNVLY H2D41lK2FiUGIpR1gFK3+Jhldix811AjKtPoe1kH/t2eHnRBv+4Zl8GKgEQNmufRwcO6 e41p2vAhCpLnqR1kRBnV5MBmfMzoU5sg1WsDgJgB+BAW6P9jAnW6xr/lL0z8wXxlp79X qJAX8+0KzT+/kwBzIaN6c1+RnAuV3Y+Dv8VTYTpKKliVpcNd7y3am84QC4UV6VKpHcmR BpOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ECvS0kw3; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q5-20020a170902b10500b00153b2d1665asi12014205plr.610.2022.03.21.18.48.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 18:48:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ECvS0kw3; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:18 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 AA86028E23; Mon, 21 Mar 2022 18:22:34 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234640AbiCVBX5 (ORCPT + 99 others); Mon, 21 Mar 2022 21:23:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234641AbiCVBXz (ORCPT ); Mon, 21 Mar 2022 21:23:55 -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 616AD1DA77 for ; Mon, 21 Mar 2022 18:22:29 -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 EB639615C7 for ; Tue, 22 Mar 2022 01:22:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87A0DC340EE; Tue, 22 Mar 2022 01:22:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647912147; bh=hQqYU8IsqDxmW6S3nbP0jML+3PV2udg3I0lI/1Lhslo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ECvS0kw3goZUwUn+E2P8B93ZE3JFhkzKOwaEVXyST/8CmSHEQuiHufz+ADJdvsP8U t30WTPlRe10KblU0JNz6b1g+VyxMP7BXsqE4YI57NXx7kx91JxG4DuKz7euVWbYnbK T70TXLkSgVtgoIcGzfNOgF96NiMw6HdCEjXqLuh886uKiK2DeQtSBJMERxc08MGurs 6b9CoI52Li4UbGX5Aiftnk32RxML7R4/3/OuD5lUZxGdJrdKEAFJiJariME4meHOzt aRpBz5jdk4PCywfvHsMYNPun2KEZrnVEHnSioC/X58bP7IuxJ+1f1683nxJ44feTWl /fXMLkoYlXPCQ== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Cc: Neil Brown Subject: [PATCH v2 5/9] NFS: nfsiod should not block forever in mempool_alloc() Date: Mon, 21 Mar 2022 21:16:14 -0400 Message-Id: <20220322011618.1052288-6-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220322011618.1052288-5-trondmy@kernel.org> References: <20220322011618.1052288-1-trondmy@kernel.org> <20220322011618.1052288-2-trondmy@kernel.org> <20220322011618.1052288-3-trondmy@kernel.org> <20220322011618.1052288-4-trondmy@kernel.org> <20220322011618.1052288-5-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 The concern is that since nfsiod is sometimes required to kick off a commit, it can get locked up waiting forever in mempool_alloc() instead of failing gracefully and leaving the commit until later. Try to allocate from the slab first, with GFP_KERNEL | __GFP_NORETRY, then fall back to a non-blocking attempt to allocate from the memory pool. Signed-off-by: Trond Myklebust --- fs/nfs/internal.h | 7 +++++++ fs/nfs/pnfs_nfs.c | 8 ++++++-- fs/nfs/write.c | 24 +++++++++--------------- include/linux/nfs_fs.h | 2 +- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index 194840a97e3a..57b0497105c8 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h @@ -587,6 +587,13 @@ nfs_write_match_verf(const struct nfs_writeverf *verf, !nfs_write_verifier_cmp(&req->wb_verf, &verf->verifier); } +static inline gfp_t nfs_io_gfp_mask(void) +{ + if (current->flags & PF_WQ_WORKER) + return GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN; + return GFP_KERNEL; +} + /* unlink.c */ extern struct rpc_task * nfs_async_rename(struct inode *old_dir, struct inode *new_dir, diff --git a/fs/nfs/pnfs_nfs.c b/fs/nfs/pnfs_nfs.c index 316f68f96e57..657c242a18ff 100644 --- a/fs/nfs/pnfs_nfs.c +++ b/fs/nfs/pnfs_nfs.c @@ -419,7 +419,7 @@ static struct nfs_commit_data * pnfs_bucket_fetch_commitdata(struct pnfs_commit_bucket *bucket, struct nfs_commit_info *cinfo) { - struct nfs_commit_data *data = nfs_commitdata_alloc(false); + struct nfs_commit_data *data = nfs_commitdata_alloc(); if (!data) return NULL; @@ -515,7 +515,11 @@ pnfs_generic_commit_pagelist(struct inode *inode, struct list_head *mds_pages, unsigned int nreq = 0; if (!list_empty(mds_pages)) { - data = nfs_commitdata_alloc(true); + data = nfs_commitdata_alloc(); + if (!data) { + nfs_retry_commit(mds_pages, NULL, cinfo, -1); + return -ENOMEM; + } data->ds_commit_index = -1; list_splice_init(mds_pages, &data->pages); list_add_tail(&data->list, &list); diff --git a/fs/nfs/write.c b/fs/nfs/write.c index 599a82406d38..ef47e3700e4b 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c @@ -70,27 +70,17 @@ static mempool_t *nfs_wdata_mempool; static struct kmem_cache *nfs_cdata_cachep; static mempool_t *nfs_commit_mempool; -struct nfs_commit_data *nfs_commitdata_alloc(bool never_fail) +struct nfs_commit_data *nfs_commitdata_alloc(void) { struct nfs_commit_data *p; - if (never_fail) - p = mempool_alloc(nfs_commit_mempool, GFP_NOIO); - else { - /* It is OK to do some reclaim, not no safe to wait - * for anything to be returned to the pool. - * mempool_alloc() cannot handle that particular combination, - * so we need two separate attempts. - */ + p = kmem_cache_zalloc(nfs_cdata_cachep, nfs_io_gfp_mask()); + if (!p) { p = mempool_alloc(nfs_commit_mempool, GFP_NOWAIT); - if (!p) - p = kmem_cache_alloc(nfs_cdata_cachep, GFP_NOIO | - __GFP_NOWARN | __GFP_NORETRY); if (!p) return NULL; + memset(p, 0, sizeof(*p)); } - - memset(p, 0, sizeof(*p)); INIT_LIST_HEAD(&p->pages); return p; } @@ -1826,7 +1816,11 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how, if (list_empty(head)) return 0; - data = nfs_commitdata_alloc(true); + data = nfs_commitdata_alloc(); + if (!data) { + nfs_retry_commit(head, NULL, cinfo, -1); + return -ENOMEM; + } /* Set up the argument struct */ nfs_init_commit(data, head, NULL, cinfo); diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h index c47c448befc8..db305abafc9e 100644 --- a/include/linux/nfs_fs.h +++ b/include/linux/nfs_fs.h @@ -580,7 +580,7 @@ extern int nfs_wb_all(struct inode *inode); extern int nfs_wb_page(struct inode *inode, struct page *page); extern int nfs_wb_page_cancel(struct inode *inode, struct page* page); extern int nfs_commit_inode(struct inode *, int); -extern struct nfs_commit_data *nfs_commitdata_alloc(bool never_fail); +extern struct nfs_commit_data *nfs_commitdata_alloc(void); extern void nfs_commit_free(struct nfs_commit_data *data); bool nfs_commit_end(struct nfs_mds_commit_info *cinfo); -- 2.35.1