From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E49E72264B0 for ; Wed, 29 Jul 2026 00:17:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785284233; cv=none; b=Hvg6R3x93qC5ejuzceCyAzmDAs4NSkiOLVlfuuq5+RaR7fMMjiwYfO2p4IKEsC+2EfjEJY08ydgjfR3M7f3xGY2YAwzoP3aY+K3BEd5cCpA8NWlJW6sjQDX6oKX+I3u+z0syxENHqCVD06bAgt9gCms839zTr1Fl6mw7Vzy4zIE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785284233; c=relaxed/simple; bh=d88+AtxwN3HFHcz5jZfBHtcdNdFj+2J8kUKbkr/60yM=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=WxOhxYJoH7+8eY2oi40bdN5dl9BRAcxKP7BNdQK89yjlXW5D/tv3Ffc5b6oYk76ZjKIpLDTJTS7fwAmexDdPKEgS4pUSIoKOsK+yc1vkGsN1JCckKTz8LJbLLLT1dGqHnsP5auCGlGVxg/yGM9k6aG228aFg1zkx63bNZL4B02A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=NorZHzN9; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="NorZHzN9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 000081F000E9; Wed, 29 Jul 2026 00:17:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1785284231; bh=WrRa98Mp/atYIONxnPxZqx0DdLUbpJpuwe1g02aeyAQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=NorZHzN9psCu1CZnNbJfKVXqkf1EQWsigxlnlqTi0HMHs8B5E1hg7Pq9f+7+kxGhP hJpry06tkKI9ByiZs9Y6UkpaurRy+q3UxpG8D6eqADcZXWBYrMtftUDsJAe2vHC4dy 4UX6Tfi/l7dalCJh3jwae8Ii21MLI1xCj59nSjTo= Date: Tue, 28 Jul 2026 17:17:10 -0700 From: Andrew Morton To: Nimrod Oren Cc: David Hildenbrand , Lorenzo Stoakes , Zi Yan , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , , , Vlastimil Babka Subject: Re: [PATCH] mm/khugepaged: cap min_free_kbytes recommendation at 1 GiB Message-Id: <20260728171710.a968591ceea5782270dffcee@linux-foundation.org> In-Reply-To: <20260728202014.2517142-1-noren@nvidia.com> References: <20260728202014.2517142-1-noren@nvidia.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 28 Jul 2026 23:20:14 +0300 Nimrod Oren wrote: > When THP is enabled, set_recommended_min_free_kbytes() may raise > min_free_kbytes using a heuristic that scales with pageblock_nr_pages. > With MIGRATE_PCPTYPES equal to 3, the formula accounts for 11 > pageblocks for every eligible populated zone before capping the result > at 5% of low memory. > > This is reasonable when a pageblock is 2 MiB, as on common 4 KiB page > configurations, but scales poorly with larger base page sizes. With > the default arm64 pageblock sizes, the contribution per eligible zone > before the 5% cap is: > > 4 KiB pages: 2 MiB pageblock, 22 MiB per zone > 16 KiB pages: 32 MiB pageblock, 352 MiB per zone > 64 KiB pages: 512 MiB pageblock, 5.5 GiB per zone > > Consequently, min_free_kbytes can reach excessive and unwanted levels. > > Add an absolute 1 GiB cap to the recommendation, in addition to the > existing percentage cap. This bounds the automatic recommendation to a > sane value on systems with large pageblocks while preserving existing > behavior for typical systems with 2 MiB pageblocks. Another hard-coded number isn't pretty :( > mm/khugepaged.c | 7 ++++++- Now, why is a page-allocator function sitting in khugepaged.c? Perhaps to avoid a #ifdef CONFIG_TRANSPARENT_HUGEPAGE. Or perhaps so that page-allocator maintainers don't get cc'ed on page-allocator patches ;) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 27e8f3077e80..d9caf10e05b5 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -23,6 +23,7 @@ > #include > #include > #include > +#include Why this? > #include > #include "internal.h" > @@ -3096,9 +3097,13 @@ void set_recommended_min_free_kbytes(void) > recommended_min += pageblock_nr_pages * nr_zones * > MIGRATE_PCPTYPES * MIGRATE_PCPTYPES; > > - /* don't ever allow to reserve more than 5% of the lowmem */ > + /* > + * Don't ever allow to reserve more than 5% of lowmem or 1 GiB, > + * whichever is smaller. > + */ > recommended_min = min(recommended_min, > (unsigned long) nr_free_buffer_pages() / 20); > + recommended_min = min(recommended_min, SZ_1G / PAGE_SIZE); > recommended_min <<= (PAGE_SHIFT-10); > > if (recommended_min > min_free_kbytes) { Is a min_free_kbytes documentation update needed? Documentation/admin-guide/sysctl/vm.rst.