Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3536033pxb; Mon, 18 Oct 2021 17:50:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqh7n+yCKnb0yI9bsHA0dAvHar9Sg7K+hzbQTapvXCmWSslRzfgFUMfTDRTP6Yv71jAPvA X-Received: by 2002:a17:902:d483:b0:13f:342d:ec92 with SMTP id c3-20020a170902d48300b0013f342dec92mr30199980plg.67.1634604620078; Mon, 18 Oct 2021 17:50:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634604620; cv=none; d=google.com; s=arc-20160816; b=GfTvckFnZeaBg9IIkrbgwEcYgdXqs7Lu8CAbRgNz0Wb0Jjg/PS7UJqI847lXxxS12l TdRM5chnXpTbzsWWKnbu/Yk3TAX36vmkx9Yp81/vjvmavS4htsLY0TQxHTKE0iV2lOLi BnUX7W8ET9YB8V6CjnSOwiVGyJrNKJgO8ZUduNn5NuZAW0l++50znjUoOjpFlNwpijio A38bjSOWEPoPXnatbtBJzZQH0TSSConXp5aj7JVeVYrMldjl1jXlLr8lzXpLMj5a32pa yXv8ypupRWk1bI8/InUP/hjG1SPN6jk+jxx0B5bNLXo4pt2gRmATYj6uVuYwIAU20v6x KWrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:references:in-reply-to:subject :cc:to:from:mime-version:content-transfer-encoding:dkim-signature :dkim-signature; bh=+7MDIVddTTR3Nn2OmbQgxanaSoSzcymYHoV7ZFfbLL0=; b=ee5ekK4EAlmHX8ud+tFuYEdBWsIjV842rTYK9bFwTM/W1SwQIXmwhiXnDrCR2Gl2vm fj12cvmBRVdLwv6L3+NmPDzgOiJl89sGgq+rwPzxKYFnW5JJszTwO0NxcZj9CTaNBtir CLDd24w3pK9qwqCDUQ3jndPhOgaAoJdXl7XDLtigJQmc2aCeLVGxOuHZQ0cjTLpUlcQu bg0kOZBQ1hJ6DMOtkwexg17KFv7nXj5GNhkE/GpWz46TrcoTJS36fj4lJpzR7LlMwnaQ 2ZLW8Kga+f/0aeQkPLluojuRQaQSTTvTQyJ3BzhapPzkpmBa+XYFA/eA0nW0jOUXpfa6 oq7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=nsmdlgjt; dkim=neutral (no key) header.i=@suse.de header.b=wPDgyK6v; 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 w2si6519495pgs.469.2021.10.18.17.49.52; Mon, 18 Oct 2021 17:50:20 -0700 (PDT) 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=nsmdlgjt; dkim=neutral (no key) header.i=@suse.de header.b=wPDgyK6v; 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 S233225AbhJSAqX (ORCPT + 99 others); Mon, 18 Oct 2021 20:46:23 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:50482 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230269AbhJSAqX (ORCPT ); Mon, 18 Oct 2021 20:46:23 -0400 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 2DC8F1FD80; Tue, 19 Oct 2021 00:44:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1634604250; 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=+7MDIVddTTR3Nn2OmbQgxanaSoSzcymYHoV7ZFfbLL0=; b=nsmdlgjtsikqzwRYRpA93ruXN5FVrH9vm4r0YkTS49qakVY+NA5qUC5BYQCCr4qaw2iFy3 GF2EoGxULtbssiz6Vkb9gmPX5dkerB/ZjJt08i1uoE3w1lpdu8DpDICfRRgsctD/7W0E2j IMH3ydPdO2ZF6GCoE1eeUrAmrQRGBYo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1634604250; 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=+7MDIVddTTR3Nn2OmbQgxanaSoSzcymYHoV7ZFfbLL0=; b=wPDgyK6vgSH0rWVje3Iv8x1uFmwkDPrXxSkl+b+PvZzB2BL7+BVCGTZ27jgAcRWVmv8CaJ QIAYwO+6p7yZUsBA== 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 3679213F09; Tue, 19 Oct 2021 00:44:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id TU7wNNUUbmG3awAAMHmgww (envelope-from ); Tue, 19 Oct 2021 00:44:05 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 From: "NeilBrown" To: "Michal Hocko" Cc: linux-mm@kvack.org, "Dave Chinner" , "Andrew Morton" , "Christoph Hellwig" , "Uladzislau Rezki" , linux-fsdevel@vger.kernel.org, "LKML" , "Ilya Dryomov" , "Jeff Layton" , "Michal Hocko" Subject: Re: [RFC 1/3] mm/vmalloc: alloc GFP_NO{FS,IO} for vmalloc In-reply-to: <20211018114712.9802-2-mhocko@kernel.org> References: <20211018114712.9802-1-mhocko@kernel.org>, <20211018114712.9802-2-mhocko@kernel.org> Date: Tue, 19 Oct 2021 11:44:01 +1100 Message-id: <163460424165.17149.585825289709126969@noble.neil.brown.name> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 18 Oct 2021, Michal Hocko wrote: > From: Michal Hocko >=20 > vmalloc historically hasn't supported GFP_NO{FS,IO} requests because > page table allocations do not support externally provided gfp mask > and performed GFP_KERNEL like allocations. >=20 > Since few years we have scope (memalloc_no{fs,io}_{save,restore}) APIs > to enforce NOFS and NOIO constrains implicitly to all allocators within > the scope. There was a hope that those scopes would be defined on a > higher level when the reclaim recursion boundary starts/stops (e.g. when > a lock required during the memory reclaim is required etc.). It seems > that not all NOFS/NOIO users have adopted this approach and instead > they have taken a workaround approach to wrap a single [k]vmalloc > allocation by a scope API. >=20 > These workarounds do not serve the purpose of a better reclaim recursion > documentation and reduction of explicit GFP_NO{FS,IO} usege so let's > just provide them with the semantic they are asking for without a need > for workarounds. >=20 > Add support for GFP_NOFS and GFP_NOIO to vmalloc directly. All internal > allocations already comply with the given gfp_mask. The only current > exception is vmap_pages_range which maps kernel page tables. Infer the > proper scope API based on the given gfp mask. >=20 > Signed-off-by: Michal Hocko > --- > mm/vmalloc.c | 22 ++++++++++++++++++++-- > 1 file changed, 20 insertions(+), 2 deletions(-) >=20 > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index d77830ff604c..7455c89598d3 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -2889,6 +2889,8 @@ static void *__vmalloc_area_node(struct vm_struct *ar= ea, gfp_t gfp_mask, > unsigned long array_size; > unsigned int nr_small_pages =3D size >> PAGE_SHIFT; > unsigned int page_order; > + unsigned int flags; > + int ret; > =20 > array_size =3D (unsigned long)nr_small_pages * sizeof(struct page *); > gfp_mask |=3D __GFP_NOWARN; > @@ -2930,8 +2932,24 @@ static void *__vmalloc_area_node(struct vm_struct *a= rea, gfp_t gfp_mask, > goto fail; > } > =20 > - if (vmap_pages_range(addr, addr + size, prot, area->pages, > - page_shift) < 0) { > + /* > + * page tables allocations ignore external gfp mask, enforce it > + * by the scope API > + */ > + if ((gfp_mask & (__GFP_FS | __GFP_IO)) =3D=3D __GFP_IO) > + flags =3D memalloc_nofs_save(); > + else if (!(gfp_mask & (__GFP_FS | __GFP_IO))) I would *much* rather this were written else if ((gfp_mask & (__GFP_FS | __GFP_IO)) =3D=3D 0) so that the comparison with the previous test is more obvious. Ditto for similar code below. It could even be switch (gfp_mask & (__GFP_FS | __GFP_IO)) { case __GFP__IO: flags =3D memalloc_nofs_save(); break; case 0: flags =3D memalloc_noio_save(); break; } But I'm not completely convinced that is an improvement. In terms of functionality this looks good. Thanks, NeilBrown > + flags =3D memalloc_noio_save(); > + > + ret =3D vmap_pages_range(addr, addr + size, prot, area->pages, > + page_shift); > + > + if ((gfp_mask & (__GFP_FS | __GFP_IO)) =3D=3D __GFP_IO) > + memalloc_nofs_restore(flags); > + else if (!(gfp_mask & (__GFP_FS | __GFP_IO))) > + memalloc_noio_restore(flags); > + > + if (ret < 0) { > warn_alloc(gfp_mask, NULL, > "vmalloc error: size %lu, failed to map pages", > area->nr_pages * PAGE_SIZE); > --=20 > 2.30.2 >=20 >=20