From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4445CC433FE for ; Tue, 19 Oct 2021 00:44:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D07956103B for ; Tue, 19 Oct 2021 00:44:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D07956103B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 166366B0078; Mon, 18 Oct 2021 20:44:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 113A36B007B; Mon, 18 Oct 2021 20:44:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 001D5900002; Mon, 18 Oct 2021 20:44:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0249.hostedemail.com [216.40.44.249]) by kanga.kvack.org (Postfix) with ESMTP id E35DE6B0078 for ; Mon, 18 Oct 2021 20:44:12 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A56493CC68 for ; Tue, 19 Oct 2021 00:44:12 +0000 (UTC) X-FDA: 78711340344.21.1CBE7D7 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf01.hostedemail.com (Postfix) with ESMTP id 8C49F50819E1 for ; Tue, 19 Oct 2021 00:44:08 +0000 (UTC) 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> X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8C49F50819E1 X-Stat-Signature: asn65grreucopgnkeazzejij955ij587 Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=nsmdlgjt; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=wPDgyK6v; spf=pass (imf01.hostedemail.com: domain of neilb@suse.de designates 195.135.220.29 as permitted sender) smtp.mailfrom=neilb@suse.de; dmarc=pass (policy=none) header.from=suse.de X-HE-Tag: 1634604248-600019 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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