From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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 ; Tue, 1 Dec 2026 14:55:09 +0000 (UTC) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 230641F000C1; Tue, 1 Dec 2026 14:55:06 +0000 (UTC) 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== Date: Tue, 1 Dec 2026 16:55:03 +0200 From: Mike Rapoport To: Amir Hosseini 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 Subject: Re: [PATCH] mm/mm_init: don't shrink large system hash tables below low_limit Message-ID: References: <20261129231312.1442788-1-me@amir.fyi> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261129231312.1442788-1-me@amir.fyi> 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.