Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2405248pxp; Mon, 21 Mar 2022 19:21:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlUvsAtE7I8Qv5oT31xPBBGFHmPnNqlSD31yHyWZOW/yCRuFA1nY9/H/tEIQIHCY+BhD4a X-Received: by 2002:a17:90a:ba07:b0:1bc:a0fd:faf with SMTP id s7-20020a17090aba0700b001bca0fd0fafmr2326255pjr.194.1647915705145; Mon, 21 Mar 2022 19:21:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647915705; cv=none; d=google.com; s=arc-20160816; b=PahwQn+TVgPjYhvZwvX7M/GAnkRXPnPal8I4VT3Y0edSVQOImOT/XIRjrhP64v7ARa c6ltEOftI+IDzX9RvNQzbg2xyxoMmcbx4LW6zYlOIayQ5KDXsi8fXDEsWW+IHU+L895W ZIXjgXak9fzF4F4JmeliK+d0QeSzIALKp9+yyvB0v+oPH6mb5ZJUY+wp90e22YbdMNsN ixXyvWc4kTWTnnkTtc5iUEgWTxBLDAoIe4MIo6hA1fpbPq4bEroZn+Ym12HZqU+38yrk hd2PeMU1M5geBI+Ry7nzU3INA4w2qrxRAY6rsy2wL34qk6cDzWHp6k/QVZDWvAavvxDj D5kg== 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=dUAWs6kL8yIHdMlS7SZijTc0FZcGeisTNWrg+39+4oQ=; b=d54b7TnVyR+EekPBNOi2zfscwSsl3z1VPdPyyaBkY2jB3t56SFhMyW+yie1Ywsn2Y6 OMMcONEDjF1cPj4oV/CGmi6E01qdNqElYv57dMwIsOSIc9tMR3xW5ZaF/igOmLJQ6inT w6j8SDok3swyQsHdoOsoU1A2fGfpKsvJ1c3bNaC6U5u81UzcOEe7NZ7Cm/SARr0jvnUW zvOKypdByN2kH35fIaRYWjxNv6+31p0pQYGITqxGswT8WvzC9gkwe+B95lrKnpTst8k4 1DJXFl4EprvbT15FhGUo3QSR0WxFxAY+PWnxHufr+CQfXloANlcx3TErBObr1INxhmKA pgXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rjR6MRRZ; 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 bg8-20020a056a02010800b003820b4f8361si14390583pgb.182.2022.03.21.19.21.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 19:21:45 -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=rjR6MRRZ; 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 89F3A43ED6; Mon, 21 Mar 2022 18:54:44 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235197AbiCVB4I (ORCPT + 99 others); Mon, 21 Mar 2022 21:56:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235139AbiCVB4E (ORCPT ); Mon, 21 Mar 2022 21:56:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C5101EC7C for ; Mon, 21 Mar 2022 18:54:37 -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 9816660B0E for ; Tue, 22 Mar 2022 01:54:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18996C340F2; Tue, 22 Mar 2022 01:54:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647914076; bh=cMhxDfxaL3CMXtievitinje637wKuEu08nEHHZec6MA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rjR6MRRZ3PAxs71bbCE7PKTUCkiMaM9ZVgI7guqemUyQR30934jP1JTLh6u9wtxri q7qc9Hh/TDyOXs1EdZfXTM8gAr+Oo2q0ui8lIUdcVVc8oLyLNyRbUuQVbXmg61x49G m+Htc4xZo6mFnkIA+bu5wqB3CulFhQnDVyJaqVdXhkgprfU6tr856DFZyoi9Qimyq4 1WRHbW+hGi0axv6gy5GsJDR7IMtLj08xLLu8Oy9VStPg4EVGDatMyw/RVQf28FOm3P S274u4S9Q5V5PW/t7MPUjDZc3JGPIX1Jny4HhdSR5+GUajBoWfUXOvYfznk3XPN05O tJCHuVZJr9CKw== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Cc: Chuck Lever , Enrico Scholz Subject: [PATCH v2 6/9] NFS: Avoid writeback threads getting stuck in mempool_alloc() Date: Mon, 21 Mar 2022 21:47:43 -0400 Message-Id: <20220322014746.1052984-7-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220322014746.1052984-6-trondmy@kernel.org> References: <20220322014746.1052984-1-trondmy@kernel.org> <20220322014746.1052984-2-trondmy@kernel.org> <20220322014746.1052984-3-trondmy@kernel.org> <20220322014746.1052984-4-trondmy@kernel.org> <20220322014746.1052984-5-trondmy@kernel.org> <20220322014746.1052984-6-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 In a low memory situation, allow the NFS writeback code to fail without getting stuck in infinite loops in mempool_alloc(). Signed-off-by: Trond Myklebust --- fs/nfs/pagelist.c | 10 +++++----- fs/nfs/write.c | 10 ++++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c index ad7f83dc9a2d..3156db526cc4 100644 --- a/fs/nfs/pagelist.c +++ b/fs/nfs/pagelist.c @@ -90,10 +90,10 @@ void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos) } } -static inline struct nfs_page * -nfs_page_alloc(void) +static inline struct nfs_page *nfs_page_alloc(void) { - struct nfs_page *p = kmem_cache_zalloc(nfs_page_cachep, GFP_KERNEL); + struct nfs_page *p = + kmem_cache_zalloc(nfs_page_cachep, nfs_io_gfp_mask()); if (p) INIT_LIST_HEAD(&p->wb_list); return p; @@ -892,7 +892,7 @@ int nfs_generic_pgio(struct nfs_pageio_descriptor *desc, struct nfs_commit_info cinfo; struct nfs_page_array *pg_array = &hdr->page_array; unsigned int pagecount, pageused; - gfp_t gfp_flags = GFP_KERNEL; + gfp_t gfp_flags = nfs_io_gfp_mask(); pagecount = nfs_page_array_len(mirror->pg_base, mirror->pg_count); pg_array->npages = pagecount; @@ -979,7 +979,7 @@ nfs_pageio_alloc_mirrors(struct nfs_pageio_descriptor *desc, desc->pg_mirrors_dynamic = NULL; if (mirror_count == 1) return desc->pg_mirrors_static; - ret = kmalloc_array(mirror_count, sizeof(*ret), GFP_KERNEL); + ret = kmalloc_array(mirror_count, sizeof(*ret), nfs_io_gfp_mask()); if (ret != NULL) { for (i = 0; i < mirror_count; i++) nfs_pageio_mirror_init(&ret[i], desc->pg_bsize); diff --git a/fs/nfs/write.c b/fs/nfs/write.c index ef47e3700e4b..e864ac836237 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c @@ -94,9 +94,15 @@ EXPORT_SYMBOL_GPL(nfs_commit_free); static struct nfs_pgio_header *nfs_writehdr_alloc(void) { - struct nfs_pgio_header *p = mempool_alloc(nfs_wdata_mempool, GFP_KERNEL); + struct nfs_pgio_header *p; - memset(p, 0, sizeof(*p)); + p = kmem_cache_zalloc(nfs_wdata_cachep, nfs_io_gfp_mask()); + if (!p) { + p = mempool_alloc(nfs_wdata_mempool, GFP_NOWAIT); + if (!p) + return NULL; + memset(p, 0, sizeof(*p)); + } p->rw_mode = FMODE_WRITE; return p; } -- 2.35.1