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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BB42FC5DF7D for ; Mon, 17 Aug 2026 12:22:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:References:To: From:Subject:Cc:Message-Id:Date:Content-Type:Content-Transfer-Encoding: Mime-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Ksysbh4dcTuDtSNajt7R605hngUF6zYW8EyMCk1D+1g=; b=iB07dXCvUpqwtm0xV3PVU83sbv m5q9+l+OOQPmFkg4Khd47Wyj3KlHig3zNOQxtGbWup5x2VA83bq9H5H2hy3xz2K64gy8e1fUavhdE dEqjmAx4HD//YGD4bFsClLK+klvOyjUne7gouLNL8JuSOVSc6Nbu5O5+0PgONSAAW7qAHyzQytuGL jzcgGD18tLYV1b7zboSyElNiuqB3sWomklczDAA32Jz688ghbhrISNs8ztk5l35nNY2LSiUFuZ4N5 B1y6evOMUV8X5QoJTlDork6w/JP6cPfjHEaGSDKb1uimXXctGLk6VFezSs4j8BMMZNO5jSvyRwCB7 CuTmB1Ng==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wvwLu-000000067Mh-2pZo; Mon, 17 Aug 2026 12:22:06 +0000 Received: from out-252.mta1.migadu.com ([2001:41d0:203:375::fc] helo=mta1.migadu.com) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wvwLs-000000067La-3TOp for linux-arm-kernel@lists.infradead.org; Mon, 17 Aug 2026 12:22:06 +0000 X-Envelope-To: linux-arm-kernel@lists.infradead.org DKIM-Signature: a=rsa-sha256; bh=XUz20HjX88HKc3zhTmA9XIj0WBNTBdnuMyd7s0rygf4=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1786969322; v=1; x=1787574122; b=XkldS3CHg9hCBivEOhkQQzkmUhdPITkRmMuNYQi3cCkftCjtJWWLDRiDP/+pw18b1esq4lNP slbcZxty0whFStgDGAoQnHGUK2wfA2IpllM//lyHcu35MfQ6dkOPY6w42V/iiNp8rSh+jXtT66Q Gkbjx9DvRnQfiagSi2bv5dsQ= X-Envelope-To: linux-arm-kernel@lists.infradead.org Received: from localhost (185.201.63.253) by smtp.migadu.com with ESMTPS id ac101bf52cfc1249; Mon, 17 Aug 2026 12:22:02 +0000 X-Migadu-Flow: FLOW_OUT Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Mon, 17 Aug 2026 14:21:41 +0200 Message-Id: Cc: =?utf-8?q?Adrian_Barna=C5=9B?= , "Albert Ou" , "Alexander Gordeev" , "Alexandre Ghiti" , "Andy Lutomirski" , "Borislav Petkov" , "Brendan Jackman" , "Catalin Marinas" , "Christian Borntraeger" , "Dave Hansen" , "David Hildenbrand" , "Gerald Schaefer" , "Heiko Carstens" , "Huacai Chen" , "Ingo Molnar" , "Len Brown" , "Palmer Dabbelt" , "Paul Walmsley" , "Pavel Machek" , "Peter Zijlstra" , "H. Peter Anvin" , "Rafael J. Wysocki" , "Ryan Roberts" , "Sven Schnelle" , "Thomas Gleixner" , "Uladzislau Rezki" , "Vasily Gorbik" , "WANG Xuerui" , "Will Deacon" , , , , , , , , Subject: Re: [PATCH 4/6] mm/vmalloc: make set_area_direct_map HUGE_VMAP friendly From: "Brendan Jackman" To: "Mike Rapoport (Microsoft)" , "Andrew Morton" X-Mailer: aerc 0.21.0 References: <20260816-execmem-set-vm-perms-v0-2-v1-0-90944a3ad43f@kernel.org> <20260816-execmem-set-vm-perms-v0-2-v1-4-90944a3ad43f@kernel.org> In-Reply-To: <20260816-execmem-set-vm-perms-v0-2-v1-4-90944a3ad43f@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260817_052204_999659_F1FE5F15 X-CRM114-Status: GOOD ( 20.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sun Aug 16, 2026 at 12:59 PM CEST, Mike Rapoport (Microsoft) wrote: > set_area_direct_map() always updates direct map alias permissions in > single page increments. > > For HUGE_VMAP areas it's suboptimal. Not only the loop in > set_area_direct_map() needlessly has more iterations (e.g times 512 on > x86), but it also causes fragmentation of the direct map that could be > avoided for the HUGE_VMAP areas populated with large pages. > > All pages in an area are always of the same order: either same-order > large pages when VM_ALLOW_HUGE_VMAP is set and all huge pages were > successfully allocated, or order-0 page when VM_ALLOW_HUGE_VMAP is > cleared or when huge pages allocation fails and fallback path is taken. > > Instead of updating the direct map permissions for every order-0 page in > an area, use the area's page_order as the loop increment and update the > large pages in one call to set_direct_map_{invalid,default}_noflush(). > > Signed-off-by: Mike Rapoport (Microsoft) > --- > mm/vmalloc.c | 13 ++++++++----- > 1 file changed, 8 insertions(+), 5 deletions(-) > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index fc7993db4152..11170d1ee5be 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -3361,12 +3361,15 @@ static inline void set_area_direct_map(const stru= ct vm_struct *area, > int (*set_direct_map)(struct page *page, > unsigned int nr)) > { > - unsigned long i; > + unsigned int nr =3D (1U << vm_area_page_order(area)); > + > + for (unsigned long i =3D 0; i < area->nr_pages; i +=3D nr) { > + if (page_address(area->pages[i])) { > + int err =3D set_direct_map(area->pages[i], nr); > =20 > - /* HUGE_VMALLOC passes small pages to set_direct_map */ > - for (i =3D 0; i < area->nr_pages; i++) > - if (page_address(area->pages[i])) > - set_direct_map(area->pages[i], 1); > + WARN_ON_ONCE(err); Nit: Maybe worth a comment on why this is expected to always succeed? I.e. I think we are assuming the only failure mode is allocation but=20 because we know vm_area_page_order() there shouldn't be any allocation?