🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25345

Re: [PATCH] mm/mm_init: don't shrink large system hash tables below low_limit

#25345
From: Mike Rapoport
Date: Tue, 01 Dec 2026 14:55
62 lines
10207 bytes
On Sun, Nov 29, 2026 at 11:13:12PM +0000, Amir Hosseini wrote:
> On Thu, Nov 26, 2026 at 03:02:02PM +0200, Mike Rapoport wrote:
> > This is hard to read :/
> 
> Sorry about that, I will rewrite it in v2.
> 
> > So, AFAIU the gist is here is that page allocator fails, let's fallback to
> > vmalloc_huge().
> 
> The main problem is what happens after the failure. The loop keeps
> halving the table below low_limit, but table_perturb passes no shift or
> mask, so TCP still uses all 65536 entries. The first connect() then
> writes random data past the end of the table. In my test it hit the TCP
> established hash and the kernel crashed.

I looked more closely at the table_perturb case, and it seems it is really
set on using 65536 entries.

Since that table is allocated in an initcall why not simply replace it with
kvmalloc_array()?

If there is enough free contiguous memory, the kmalloc() branch will
allocate it. If not, vmalloc_huge() for 265k buffer anyway falls back to
small pages.

> > The large hashes are normally allocated at boot time when memory is not yet
> > fragmented, so it's very unlikely that page allocator would fail.
> 
> It is rare, but it does happen. hugetlb_init() takes the boot time 2M
> pages from the buddy allocator before inet_init() runs, so with a large
> hugepages= there may be no order-6 block left. Muchun hit this failure
> on a real server, which is why e67b72b90b7e moved table_perturb to
> alloc_large_system_hash(). That works on NUMA because hashdist uses
> vmalloc, but on a single node system the table is halved instead. On
> mainline I could only trigger it with fail_page_alloc. I first saw it
> with the out-of-tree ASI patches, where it happened in 3 of 4 boots
> with 2 vCPUs.
> 
> > AFAIU, we can just drop the alloc_pages_exact() case and keep memblock for
> > HASH_EARLY and vmalloc_huge() for the rest.
> 
> That would fix this case too, and 64-bit NUMA machines already work this
> way. My only concerns are that on x86 tables smaller than 2M would be
> mapped with 4K pages instead of the direct map's large pages, and that
> 32-bit has little vmalloc space, as the comment above HASHDIST_DEFAULT
> says.
> 
> Either way, I think the loop should not go below low_limit, so that a
> failure panics instead of corrupting memory. I can send v2 with that and
> whichever vmalloc_huge() change you and Eric prefer.

You are right that the loop should respect the low_limit, but the entire
alloc_large_system_hash() is quite convoluted and I believe it requires
more drastic refactoring.
 
> Thanks,
> Amir

-- 
Sincerely yours,
Mike.
Technical Details
Message-ID: <aw7fxwCeHX5jFYW1@kernel.org>
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375179-linux-kernel-netdev=dewy.ru
References: <awgtymEawotNXV8f@kernel.org> <20261129231312.1442788-1-me@amir.fyi>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375179-linux-kernel-netdev=dewy.ru
From: rppt@kernel.org (Mike Rapoport)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH] mm/mm_init: don't shrink large system hash tables below
 low_limit
Date: Tue, 1 Dec 2026 16:55:03 +0200
Organization: Usenet Network
Message-ID: <aw7fxwCeHX5jFYW1@kernel.org>
References: <awgtymEawotNXV8f@kernel.org>
 <20261129231312.1442788-1-me@amir.fyi>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
	logging-data="1740963"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:0HjA1+ASzlstEPspbuHmUK7+Ejo= sha256:4KUS8lhTRy2zlvjqaA+gvDJDqvzoS5kKsKxEQnk3x08=
	sha1:rZp8kH7KcuyDR/0ZeQW31zBL8GI= sha256:r55eEqCfw1eOBDZ3GTJSdgfa18RV8tK4R0nBfb6a4QY=
Content-Disposition: inline
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 45F901173F5; Tue,  1 Dec 2026 17:55:25 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.501
X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id HJhJudZ9fvnS;
	Tue,  1 Dec 2026 17:55:22 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-375179-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 677BD117363; Tue,  1 Dec 2026 17:55:14 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 8E36F6024AB; Tue,  1 Dec 2026 14:55:13 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796136910;
	b=gMdZAkbsa7hqucHChQmzI1CsP3pXmYL8buwCvwCGmt7gR8Po5YhnezQofNE/O5tk2j9+
	 hvVFhmiUvz1Q4M5YB3sLGLYfKNEzht3bTqDNxm489CMsCz17L6cgMZzjV71rd7y0cQUNm
	 1SUkDHIbLCUx2ORyiCzMqqc+G5EmxKZMQW7SJ5VwQi4kJd0Tg7WSi/96rw8GCOpUf1Wkm
	 CCONFzgv0SrBbJH4bwt6XNbEP06i7IPpaWCOCXKz6MbZc/AMI2r3cJgZMx9ZNqagSUszX
	 nqTbJZ8fecyrn4ahgDrpW7wD8agPOgGLOgtjszocIJRYEVdxr4UZ1P85UyEXpGGwCag==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796136910;
	h=X-Original-To:Received:Received:DKIM-Signature:Date:From:To:Cc:
	 Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=bVNhIadRKRpJhrXUTcB1VFVxifaQXygKbLrlzd3X/B0=;
	b=u4Kz8xQu3jZEAeE+mwRU0FuNlYNq4hZ3uKkOnkNcJcXdxWWNW67tOG5xUAaQAKAphRL2
	 AFlbBE1ExukxzeGTqK13ukhsaNBjpQfWXb9Nzq6aKUXQkjXcr0epBSUwMXW9mKq2Hzikj
	 RzsjRzGrpgKwwKHijgwt2/u0f2YPGt8YdCBOAu31Fj6B248LYEeTEtZ5xhvrkHCs1voEr
	 7gOptUPqyE8JmTddsJP1tu+mNcBQUNVL1mNfkMpnT//8O/0G4vkHN3jt9eFkqjjyBu3nx
	 Llr5lRJ/cB53W5aTWlVcUm3n4T1CrPiBWm4D7aWWK9fvMahdJMh9XyN5mNpQEgB+fXQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hOKBA4Os;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id D775A606A32C;
	Tue,  1 Dec 2026 14:55:10 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hOKBA4Os
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796136910;
	b=p3cs2hWN0PKSYqMw5v8hITM5ttGXBezAkmsVZlkZHGi8Fu8sFSUr6UbvORX+ZOWRW57X
	 kbuA6sOczGToNm1hvmtJN9rS8NJHQ4baEokjadR4ne95hP2k3/2WNoEY4bQZJWZRJmILe
	 6KZNtNM3uvzfLTGXEARLGHJuzRIhIXAQJp7/E1+oNrl1M5EdA1SADqEDXm5KLryCvZCK3
	 gAMJxiuqhnRYYxjYdGnQfJVv/yth/j1UkBdIaYm+CstH/yttZZg8d1hKIllZUnw9djjvm
	 wsVF8BR+stNQbLxumZzXDj6/FsHv79p8+bhvRzb0NHmpmI8JCvK5Un13Is1AvWZ6CWA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796136910;
	h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID:
	 References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=bVNhIadRKRpJhrXUTcB1VFVxifaQXygKbLrlzd3X/B0=;
	b=oq5zbVID5esjKXvLBoRWw+b91KAOWoyDihA0sWbTbxcD+rP2Ymjwf3XjszLqkxxbQFi3
	 INXCg0MdqxdMFHFeMcngswUArt20jPPmhcGcJV2hXT1FCeEkhY/cgbgtXGlDz1sJKyila
	 NA/KOWFkw1clFHiHicvkhH8dS+I4840/tTat/n7c9ZIPl6i7cTakBQhthrl3+LRj9MTk+
	 zdhoLjH6c+gcrAp8A52xxFW4R+NM9uiDPu957tXwBd+6Y86Lhsxk9nzZkLlxC98RwBgKF
	 cupImvgJcokVoiVwwroLj2P/VmdG3Xboz2czomKGfjGxnRRFcH1w/x3+OMzVbe9agyg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hOKBA4Os;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00036606A31A
	for <netdev@vger.kernel.org>; Tue,  1 Dec 2026 14:55:09 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 230641F000C1;
	Tue,  1 Dec 2026 14:55:06 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796136909;
	bh=bVNhIadRKRpJhrXUTcB1VFVxifaQXygKbLrlzd3X/B0=;
	h=Date:From:To:Cc:Subject:References:In-Reply-To;
	b=hOKBA4Osc+dAksGEvP7tgpfT1qcGvncpptFbPVjMCMXqI30Xppf3Uw0C2A/FLyMvb
	 O05+U3htylPZpqn/lx/PF0oMv9P81f+Lk6M1qAH3Q46v2LxFzOQgDXJJNmR6n6E4Tl
	 TU9Wt2+K1DSIiInjmzQ1LVIu+vKHutIgE61WfprhTEmhHDvb20glozD3RvNJqnIs1I
	 QWlEmDvlribwPj/0sSBbBco5nIwn6k+zEz/ntqHGbGsU+7qGqgH0Y4Y/nNMHHHlYsB
	 2WyRV6TX87rrNLjaobLxgBbKW91tmbs/q54MIA2Crr+QcGit11n8xTGZjAHSYqP4pI
	 cXBGGtcleTDlg==
X-Cc: akpm@linux-foundation.org, edumazet@kernel.org, davem@davemloft.net,
	brauner@kernel.org, muchun.song@linux.dev, linux-mm@kvack.org,
	netdev@vger.kernel.org
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <20261129231312.1442788-1-me@amir.fyi>