From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DABDF606A31A for ; Tue, 1 Dec 2026 14:55:13 +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 kanga.kvack.org (Postfix) id 0CD676B00EF; Tue, 1 Dec 2026 09:55:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 07E796B05B7; Tue, 1 Dec 2026 09:55:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EFE0B6B05BC; Tue, 1 Dec 2026 09:55:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 96FCA6B00EF for ; Tue, 1 Dec 2026 09:55:12 -0500 (EST) Received: from smtpin21.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 30935160ED1 for ; Tue, 1 Dec 2026 14:55:12 +0000 (UTC) X-FDA: 85495712064.21.5997F51 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf01.hostedemail.com (Postfix) with ESMTP id 9211340014 for ; Tue, 1 Dec 2026 14:55:10 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=hOKBA4Os; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf01.hostedemail.com: domain of rppt@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796136910; b=IlQR7SsFv7RN56ZVcGsZVahuY99uJVFDAqmqm4wXjbowvREVf0Lm7+ey3+AcvNPf0q3hvY wlbyKn/ccLB1Bx9fCE3xhcdC/1lq1IRai+ayZCnaKlO6xrL1zOReDhBtzPusdk/lzXo2FP qZ4SndncCDJrLXYuZ87L2e9HG6dabxE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796136910; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=bVNhIadRKRpJhrXUTcB1VFVxifaQXygKbLrlzd3X/B0=; b=4bdvQHv/xLfLTswVGtRgg6hnCSUfuclc9cczYplG6pqNEkY1N0wRdZd6it3JVyXPvua1m7 88jj0y0IOu3fufirp/KqOL4+xVXBLSofCHEGapvKp7V12UtwVtFJxe1KrzoZ0kJ/UxiBzX sbyDAAZUyAzAGqNIUarxKKmPGpQjpv0= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=hOKBA4Os; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf01.hostedemail.com: domain of rppt@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=rppt@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 125AF601C3; Tue, 1 Dec 2026 14:55:10 +0000 (UTC) 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-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261129231312.1442788-1-me@amir.fyi> X-Stat-Signature: jwhj1f51714omi3m8jpfdakm7asd97e8 X-Rspamd-Server: rspam03 X-Rspam-User: X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Rspamd-Queue-Id: 9211340014 X-HE-Tag: 1796136910-863118 X-HE-Meta: U2FsdGVkX1+eodpLRuyhgqmIyh9iD2v5AnibJ9MoeoGBSf2f3fzntx/afwM4eMFa45Qnz956MlvsAOCYsWRoqS5uYDPYKRL+s1lDNuyMmSiGNBvW4tcx6lq9+dzzNM+Wdr3O4anK0UrO/KRN8r9jqwpQ7nwZ5Kpd4fgY0OboMGulyJvMdho6q4fwdmURpsFuna7xDhbTzCW5w4AOdHdlTq6fXOgTng+AsCDimNvfD5COZnMLSAHl4GFQ4oHA3v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+r4ieHTZKSWNzzJxYxpQEb0I8DZXiD6Nw7tNCp/DrCViAIKpUL8r/aB+6tMfLfPPfUmRDr4XtfrmwhEz6ikiSE5v5qjMa1Sfg65jz7fdBDWZq6QZLAuHCV2caLK9QRmrOwT0FlfD3abr4lqJq/wjezcloYg0WDk8Bve66SSExpee/qao/DzqUkweZk19CGOyHWj9EUurqXw== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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.