From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DEE1E4E2348; Tue, 8 Sep 2026 09:59:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788861573; cv=none; b=uBz3tkfGpkYrcr6KLLu4quDEbkAX5997yCFBmtB3RFAFIVdoKbZEgCB/FM6km2rd4gjI5XdtRVKD38tpbRrkRRrXAQDvb3BQuILCIZGosgmwh3C06fFnVCWQKQPky7aa8I9wUrWOfi4PeLHxK9uGXecOiF8ss5BgAp8fHLrcD48= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788861573; c=relaxed/simple; bh=a/a9VuH1Pbu7fuqb4EF439JhWu4OMvquSWkjlVGi4tM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=d9NrlQfbUwzi9bC6eRkx0309zqD7HriuT4VuNK7/JkCQeLaoMbTVYEULukp88lTfWTwU/hpMmOIyZ27bZ4lk7zb5cNf6fkDHiH0xqYy6yN4G7jU/OKqrg098K8xzOkBNCyLys1qvDhq3rVzhsXzNwyJ09loh9ZLcNaIpbpyPsJ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=YR0UOmZK; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="YR0UOmZK" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7E6391476; Tue, 8 Sep 2026 02:59:25 -0700 (PDT) Received: from [10.164.19.55] (unknown [10.164.19.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8CBC43F7B4; Tue, 8 Sep 2026 02:59:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1788861569; bh=a/a9VuH1Pbu7fuqb4EF439JhWu4OMvquSWkjlVGi4tM=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=YR0UOmZKFbfAJ3SQSDswiFS+rXAWEo6USejgl07yJMtcUVzwUvoX92dfUQwwVpdX5 EaS2HlcY5AR9bV7tQg2bFaeizuNwDp69wiztfvHe7QfBZ8M2HAbZx4+U2VfjisKvus ye1W5JquN+zfg/oiJuWT9J+cxec8MSXZ7ZVkbbDw= Message-ID: <88b48587-1f3e-479b-ae9b-67aa643e2acb@arm.com> Date: Tue, 8 Sep 2026 15:29:16 +0530 Precedence: bulk X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 4/6] mm/vmalloc: make set_area_direct_map HUGE_VMAP friendly To: "Mike Rapoport (Microsoft)" , Andrew Morton 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 , x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-pm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, loongarch@lists.linux.dev References: <20260903-execmem-set-vm-perms-v0-2-v3-0-949b64a9f755@kernel.org> <20260903-execmem-set-vm-perms-v0-2-v3-4-949b64a9f755@kernel.org> Content-Language: en-US From: Dev Jain In-Reply-To: <20260903-execmem-set-vm-perms-v0-2-v3-4-949b64a9f755@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 03/09/26 2:58 pm, 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. Correct, this would also help us on arm64 once we have ROX caches. > > 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) > --- LGTM: Reviewed-by: Dev Jain > mm/vmalloc.c | 13 ++++++++----- > 1 file changed, 8 insertions(+), 5 deletions(-) > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index 5506b180f5c27..6ed6c160abed7 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -3367,12 +3367,15 @@ static inline void set_area_direct_map(const struct vm_struct *area, > int (*set_direct_map)(struct page *page, > unsigned int nr)) > { > - unsigned long i; > + unsigned int nr = (1U << vm_area_page_order(area)); > + > + for (unsigned long i = 0; i < area->nr_pages; i += nr) { > + if (page_address(area->pages[i])) { > + int err = set_direct_map(area->pages[i], nr); > > - /* HUGE_VMALLOC passes small pages to set_direct_map */ > - for (i = 0; i < area->nr_pages; i++) > - if (page_address(area->pages[i])) > - set_direct_map(area->pages[i], 1); > + WARN_ON_ONCE(err); > + } > + } > } > > /* >