Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2387631pxp; Mon, 21 Mar 2022 18:48:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydEchbMzV/1UUcfhIs2LpcI1urr8kbseubNNLOV8Sxap2g3mtxx8N1IJcs0rTOs7P2pLJH X-Received: by 2002:a17:90b:1e04:b0:1c6:fbac:b0e2 with SMTP id pg4-20020a17090b1e0400b001c6fbacb0e2mr2140206pjb.207.1647913716865; Mon, 21 Mar 2022 18:48:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647913716; cv=none; d=google.com; s=arc-20160816; b=IfdhsXTIygN6CJKavzbpm4RQ31+WWePmfMwZ+tpqkKABiNF9v6JYHL/7xBd6ZeG5+8 m8t3BdK2VjxKMYJu3YyQKhNYG6gR0GtL3DkzyQpeZ1DYkyfo2k+dCwIPTEDybb5poRSQ hs17HORdn6294qKOkUjZhGVV4pgIMBzogbMPoeuwNyOvKETMLUibiisL9X5HvLkrJ28/ GN1ifFMuAYm1IRUkPlIHoaKB/rPa31pRuOfz9mlHB96GQkqX/VXJ9kTZmd0K7OiPpFJr 0GlmJSPsg/fYtlS9H3vYnUvOeb+xGk8A0KiP07aIoM+f/lm7umpyKu0Pj3RBydDRzBkN ZRzQ== 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=nVHIb4RfPVwu9EgrXy+lT75AKVoVOuxyCs2YGayCJgk1X4i7DkaZsdKXWryMNdn8hP n3lvWYVZHrKZJWvL1toT7e9sJ27un3N41JeWAEfJzEhoR9qekWY6guUZSYDvVj4g6DS0 BQ3qtO2X9MZPJYkpNp8oyQRFX0XzGFIUxLIn3OddH6sc5GLdxggVUwzcxNsbO/zu7Thj Dalw2MozxY6tWVw+rOg9bnf7Vwk466FB1XFweanOIw0O56F+xAyBPvlgISZFjvfCmMVQ Id2po3nVqKztu44jq31YdB+Z7k2+lgbUb8AMo35POLTL1plmFAGhhuZt6sgkpZm4NR9g 9VCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="AjoGLz/Q"; 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 h1-20020a635741000000b003816043ee8esi14710980pgm.131.2022.03.21.18.48.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 18:48:36 -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="AjoGLz/Q"; 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 B0C2E2AC70; Mon, 21 Mar 2022 18:22:33 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234638AbiCVBX5 (ORCPT + 99 others); Mon, 21 Mar 2022 21:23:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234640AbiCVBXz (ORCPT ); Mon, 21 Mar 2022 21:23:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14A151D304 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 80380615D2 for ; Tue, 22 Mar 2022 01:22:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0989AC340F3; 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=1647912148; bh=cMhxDfxaL3CMXtievitinje637wKuEu08nEHHZec6MA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AjoGLz/QfGuh5LXnhLuIHAWNvAU+MS/JFZv30KzihXAecrWVtmQFtv85Yxac147o+ 2Bd4V3rooOLdmOWegHX3MIATyuwJ1iB14Dw+MmdUy8Z8qD96mCDe6cMOpA7YoRgcVU FKijj/WM6ZE2dpouB0nUKYj+R3lJq3IRVpA6cjyCTyiA+xWuT4P7Ab1WtGLAzNSqdC 4gSuP87ddqoDltDqZPrURuDC1AXkUUKrcAtV+Db443geMgYnRbwLqc66PQdrCeCyXS E6ufPoIndJIQOpgtKjyjvjq5lVNrXjvTihMzKYFAozaISwYax/sg7nuUH1lwazXpEo S/OCFF0pzqNxg== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Cc: Neil Brown Subject: [PATCH v2 6/9] NFS: Avoid writeback threads getting stuck in mempool_alloc() Date: Mon, 21 Mar 2022 21:16:15 -0400 Message-Id: <20220322011618.1052288-7-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220322011618.1052288-6-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> <20220322011618.1052288-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