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 B73C9C4321E for ; Mon, 18 Oct 2021 11:47:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4173861355 for ; Mon, 18 Oct 2021 11:47:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4173861355 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 963486B006C; Mon, 18 Oct 2021 07:47:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8EAD36B0071; Mon, 18 Oct 2021 07:47:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73D936B0072; Mon, 18 Oct 2021 07:47:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0121.hostedemail.com [216.40.44.121]) by kanga.kvack.org (Postfix) with ESMTP id 5D25A6B006C for ; Mon, 18 Oct 2021 07:47:29 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 156D018026105 for ; Mon, 18 Oct 2021 11:47:29 +0000 (UTC) X-FDA: 78709383018.27.8FC36EC Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by imf02.hostedemail.com (Postfix) with ESMTP id D8D567001A0A for ; Mon, 18 Oct 2021 11:47:26 +0000 (UTC) Received: by mail-ed1-f46.google.com with SMTP id 5so39398266edw.7 for ; Mon, 18 Oct 2021 04:47:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u0T7gxYUX1IZe+6zZc2VL/ygWEQ9BUReTwyQ18vECfw=; b=XZUmbzUWHXP86VAneWrYm11uKnUig82WvVWobJy5U4AYapPbKCoea1NKjGWsyO0ZvS kN/X3nyRSsdCUSPmPt96/Jep7Noy7mo8C9ECmaRrhYlNSU3jF6Hms+2grigUlPG5QRlW HM8tibG1nyPeh/iJmxlCVy7QyjExd0KYP5BQM+/aQH3n4zLTPdegprvcZBLgZOv1Du8c sVuUlnYcb2j/kET+8RhwjBYxuMUUW/rF2JXviRcFk22eP37a+gH0BiZhLvirSz9WFOWp 6d6FW7OYXmIABLKddaSzfYQqv2WedMt9QHRT0HB76kT2Nqbfdh4plwDqT+g42efBlVa3 fL5A== X-Gm-Message-State: AOAM533HyeMaoXWeKEwJP0eLYHGxLV8SIXewlVrg34CObp91AVDlCdIz Mk/N1/wTDOso40aVcaUVgLpuLgr5PvQ= X-Google-Smtp-Source: ABdhPJzA3Yw8UY1rj4xrYibdkMXEXhftxv4Gy8AnglURF2yg0TH0pLfxdQCB3cT2eLr75LPxwjK2Xg== X-Received: by 2002:a17:906:7017:: with SMTP id n23mr29088204ejj.446.1634557647343; Mon, 18 Oct 2021 04:47:27 -0700 (PDT) Received: from localhost.localdomain (ip-85-160-35-99.eurotel.cz. [85.160.35.99]) by smtp.gmail.com with ESMTPSA id b2sm9587458edv.73.2021.10.18.04.47.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 04:47:26 -0700 (PDT) From: Michal Hocko To: Cc: Dave Chinner , Neil Brown , Andrew Morton , Christoph Hellwig , Uladzislau Rezki , , LKML , Ilya Dryomov , Jeff Layton , Michal Hocko Subject: [RFC 1/3] mm/vmalloc: alloc GFP_NO{FS,IO} for vmalloc Date: Mon, 18 Oct 2021 13:47:10 +0200 Message-Id: <20211018114712.9802-2-mhocko@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211018114712.9802-1-mhocko@kernel.org> References: <20211018114712.9802-1-mhocko@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: D8D567001A0A X-Stat-Signature: hzkx4hiu7kz73rri3wm1y5i8fwhmsyg9 Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none); spf=pass (imf02.hostedemail.com: domain of mstsxfx@gmail.com designates 209.85.208.46 as permitted sender) smtp.mailfrom=mstsxfx@gmail.com X-HE-Tag: 1634557646-951158 Content-Transfer-Encoding: quoted-printable 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: From: Michal Hocko 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. 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. 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. 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. Signed-off-by: Michal Hocko --- mm/vmalloc.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) 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 *= area, 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 = *area, 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))) + 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