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 5A3C7606A323 for ; Wed, 2 Dec 2026 09:40:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=rqvVjKeR Received: by kanga.kvack.org (Postfix) id 7C99E6B062E; Wed, 2 Dec 2026 04:40:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A14A6B0631; Wed, 2 Dec 2026 04:40:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B6AF6B064E; Wed, 2 Dec 2026 04:40:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E947B6B062E for ; Wed, 2 Dec 2026 04:40:04 -0500 (EST) Received: from smtpin09.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay02.hostedemail.com (Postfix) with ESMTP id DCB9512023A for ; Wed, 2 Dec 2026 09:40:02 +0000 (UTC) X-FDA: 85498546644.09.5FBDFB3 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) by imf06.hostedemail.com (Postfix) with ESMTP id 01BD6180005 for ; Wed, 2 Dec 2026 09:40:00 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20260707 header.b=rqvVjKeR; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of david.laight.linux@gmail.com designates 209.85.221.49 as permitted sender) smtp.mailfrom=david.laight.linux@gmail.com ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796204401; b=D8B/E2YPPxKxsKMgmULNvL1DPr2xugJunttqlGnQ+Nsa5SD7Vm/n6VxkvAummPrPP/VSjb 5aynXEmQmrc5DAc7o+7zk5FkCIdKvHNFLa4L70jHC5jUjh5lOgLSCB2S282L62CXfpSvYI p3f0Igk+VbMmCyax5UDTgE8xvDsvgbE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796204401; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PEiSFyO8II3MtezXTx/ZRqALvumCid4JrIzemk2+dEU=; b=BikomFQnvHiPmRpDORprW/JsRU1bT0fO17FHu72aGZYk0gqpoOZxsiSuRDNeMaRYHNYZSK kJ6fEPYNJbiTWDMmaUmaesM9kQhC88BYgOs19vqIGCILTZ2cwz6qlldMv1LK4C1jVFnoef 3zXmCtk2/7dcpodb3jVXeyjG99FoFnA= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20260707 header.b=rqvVjKeR; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of david.laight.linux@gmail.com designates 209.85.221.49 as permitted sender) smtp.mailfrom=david.laight.linux@gmail.com Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-4c4b8e58cfeso2455441f8f.3 for ; Wed, 02 Dec 2026 01:40:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796204399; x=1796809199; darn=kvack.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=PEiSFyO8II3MtezXTx/ZRqALvumCid4JrIzemk2+dEU=; b=rqvVjKeRj5OnjXiyjUDTx+9ijP0fByPsNzU3QDpnTU8Pka8eNN0lOgXMUKC0qUWzV2 9ILKYRoFCCTYVZ+hnnDiqp1sqyxCEsdipaao4SWVuaSyL2kCw/MegECaWQRgFPdkQEPQ ddBY7eaFaQ8YAyyPwodewvvhWtwt6uUBbIXqRxHMCzHJkHDGzpxbMLckLqs8LbF7H+dT gSwm7NypAHAZhnIzaYLFSAvz4ORup4BkLZ2lqWNX8alewoih4dqoOXDzTE2eunvvvqU7 lMIerSF7tKk6y8pPsyM6TQHfb5663utakMxOkq1PASW/IuRmbTEtKIIao8awwVIdYp7/ gp+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796204399; x=1796809199; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=PEiSFyO8II3MtezXTx/ZRqALvumCid4JrIzemk2+dEU=; b=CWtoZNA3YJ8moWmGmBZxnncjl1F0k9f6uQ2/HbS6Grg+r7wjK4OGk2y2Y0EnZei7SI oxxhqCE86/jumKhXQwLuu5rFLZPohQMtkGOb60BbRIa+Y0feBe3LxpYFXpp3eLO2MAiq yfwQUDQNCxyby67fq8Qced4cBmrcRN2qvDgL5rowCe8w+r/jvMotDer2Pgz6K4apKYwh r/TW4Qfr0RpA2Z/Kp43o2smcjTAcNBNg66/qiFgZ3mQEFW+zGneh8hLrcciPpfb6BsYY erLCsSXP+4+bydqYipnVp8/N8NgR6a5dkeAR0Wdw00v3rROTNr0clwEDZzo6l5nRWL/8 Wvqw== X-Forwarded-Encrypted: i=1; AL+hErGY52456k9O9XrVkiz4ypH25G46xG7ncKae+WguuZiPSMiZnqhB55hb3AqT818KnTn+pbud2d5TXQ==@kvack.org X-Gm-Message-State: APuU4Z+zDmPaLMbEUtab0Z/+5/0z1ukfSZYJpjcAr/lcB2R+GR6tZy10 aOEia7lVxh5nwOqwdeoTLp3h8VC5G0og9DV9VfwF6vH5ndrKRL9mxClF X-Gm-Gg: AZFdTZfcQ1naI++Le4ln0sOeWMwqyBFlfz9CU/I+acl4lkZHlH8GAkaDAZScTu9Tenf gK+0lKr/xsIgmiohdt+9kL1Fs3Rv94vJVzgdkQA2syycpfHI/pO1UIr7DS6OYHno6UXuxbePdgZ z5q2UIn55DVKnI8lVSiJcBt4H7FXk7ctxST+uFq40R5SGQXaTxZdMEcXHGbh5Z3iaJ2L+g5hkO8 tn+OW53gARDuMwN/GfOD0pWQr88rgkP5b5/2Mwd+MrqQoZSjjtKe/EzAuRdrXjgvY+tyvbXg/mF YRa1mOVFchXNF/zm5/WHUo/dHXKRyVU1r9w2NV8PNnS8epYmRGFPp0HOwImX+uX+Ekj9rVCBNXh WCFZCpa1B6IF43wKVpSBsEHS1VXFKNn1EoT7HTwz9+pGddkG0/xHnPQsQGCjqJXKl9WvXoQGb2h 83upHYvjn2yRpRPqiSSCBELU8YZe/gj4XJ3/kIwrHXx+HYQVi9SFrf1OLjV5BPnw8AhXKLegtuD hSiWlq+qbXk7jnXCuKBIQVhP1mWeFsNWZSn/V/2OWfYDPUjaGa6nXE4Dxz2xE+2lm2cxN4QP/Fn bfJrzGluhk9v3wUOw/ZW59rv+a7kfMAywRDd09o3EhuGK7XRrhmetCwu/JLAVH/y X-Received: by 2002:a05:600c:6290:b0:4bb:741d:eba with SMTP id 5b1f17b1804b1-4bb88824a5bmr761783165e9.13.1796204399077; Wed, 02 Dec 2026 01:39:59 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6bb989e3sm78190502f8f.52.2026.12.02.01.39.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 01:39:58 -0800 (PST) Date: Wed, 2 Dec 2026 09:39:57 +0000 From: David Laight To: Mike Rapoport Cc: me@amir.fyi, Andrew Morton , Eric Dumazet , "David S. Miller" , linux-mm@kvack.org, Muchun Song , netdev@vger.kernel.org, Christian Brauner Subject: Re: [PATCH] mm/mm_init: don't shrink large system hash tables below low_limit Message-ID: <20261202093957.01c5ae1a@pumpkin> In-Reply-To: References: <20261123-mm-hash-low-limit-v1-1-8a803aa8ac70@amir.fyi> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Stat-Signature: bashis1p3ormiuwt1s5gfjdwuewf9zh4 X-Rspamd-Server: rspam03 X-Rspam-User: X-Spam-Status: No, score=-14.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS,USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=4.0.1 X-Rspamd-Queue-Id: 01BD6180005 X-HE-Tag: 1796204400-814802 X-HE-Meta: U2FsdGVkX18gnFuLmyd+F04uWd9sOY3bMLD3uP89TDRjJaHTNJY92sTevkPnRrn63LkVJSl/GlJIOINP7ycX/DK/05ImCyBMFKqJ8i2UFdIl8GVi64F1SnO9cpZQYVuxvR6UMRUNt2UAO5nUyQS3OZK3AL7duPdW5FMcUasSRgsschxKYUT8z18C5718QPJBxZDxvU0X+E7RBMDyxe7dsfv7I5QqnbQqKEX0abTfZsQcN2KfZ0WeDnvHrmC3bBJRMK8N4S5lW1EsSiqBqh/k+IwRUAmkXW4CqVNUP/YXLA8+BuqirXJ+pb54YaiZ5FkLqEgup2mTV2HWjrhCKfnt2vrj5KQkTtryS+9g+d8ZFlEqkILiwW1LXdP349ruIi0VaoOee/ag1L26qJ1mXyo0Ie0HogDKvCySKLRLnn9Qen9qJG6qMZYBAFkSnPgbzLcLVmhEoAKYgu2sTpweYWK9Ov6Wj1kL1xLuURgcMXjHPkuuZgDjqsDiaMNWljVG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TDxJ6wwzfs8pwTL1Ufmo8xrRyr3CQ1r0Lcct7OQgncC5IuakcuQ7MxyOVje1xtPDoVH3J+rxa4J61hsi03u+r5KP+OmpL0YHuGhSZA7g/Yr34uOManOSPoRx2eeej66TZzaDf1VgA5e72Ml9/roSBus4T1g9xww+y/rmJyAN1zFFrNan+VP2rYhytCJwFea5mo 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 Thu, 26 Nov 2026 15:02:02 +0200 Mike Rapoport wrote: > (added Christian) > > On Mon, Nov 23, 2026 at 08:15:49PM +0000, Amir Hosseini via B4 Relay wrote: > > From: Amir Hosseini > > > > When an allocation fails, alloc_large_system_hash() halves the table and > > retries until it is down to a single page. It does not stop at > > low_limit, although commit 31fe62b95866 ("mm: add a low limit to > > alloc_large_system_hash") added low_limit precisely so that callers need > > not check the size they get back. > > > > The TCP source port perturbation table depends on that. It passes > > low_limit == high_limit == INET_TABLE_PERTURB_SIZE and neither > > _hash_shift nor _hash_mask, so it cannot learn the real size, and > > __inet_hash_connect() fills and indexes INET_TABLE_PERTURB_SIZE entries. > > On a single node system hashdist is off and the table needs one order-6 > > GFP_ATOMIC allocation. If that fails, e.g. because most memory was > > reserved for HugeTLB at boot, the situation commit e67b72b90b7e ("tcp: > > use alloc_large_system_hash() to allocate table_perturb") was meant to > > handle, the table is silently halved and the first connect() writes up > > to 240 KiB of random bytes past its end, typically into the TCP > > established hash table: > > This is hard to read :/ > > > Table-perturb hash table entries: 32768 (order: 5, 131072 bytes, linear) > > ... > > Oops: general protection fault, probably for non-canonical address 0xe480dbf6b420b3d9: 0000 [#1] SMP KASAN > > RIP: 0010:__inet_lookup_established+0x168/0x5d0 > > Call Trace: > > > > tcp_v4_rcv > > ip_protocol_deliver_rcu > > ip_local_deliver > > > > Stop halving at low_limit. If the linear allocation still fails, retry > > the same size with vmalloc_huge(), which this function already uses for > > tables that are too large for the page allocator or when hashdist is > > set, and which does not need physically contiguous memory. If that > > fails too, panic as before. > > So, AFAIU the gist is here is that page allocator fails, let's fallback to > vmalloc_huge(). > > 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. > > But there is another question: do we really need physically contiguous > memory for the hashes we get from alloc_large_system_hash()? Or even, does it make sense to me allocating such large hash tables. Many systems won't allocate enough items to make them sensible. I'm sure there is a big one in SCTP - even systems that use SCTP might only have 4 active connections. David > > AFAIU, we can just drop the alloc_pages_exact() case and keep memblock for > HASH_EARLY and vmalloc_huge() for the rest. > > Eric, Christian, what do you think? > > > Reproduced on v7.4-rc4 in an x86_64 QEMU guest (virtme-ng, 1 node, > > KASAN) by failing just that allocation with CONFIG_FAIL_PAGE_ALLOC and > > fail_page_alloc=1,100,,1, where was measured with the > > kmem:mm_page_alloc tracepoint so that the one injected failure hits the > > Table-perturb allocation. Without this patch the table is halved and > > the kernel crashes as above on the first connect(); with it the table > > keeps 65536 entries (vmalloc) and the system works normally. > > > > The reproducer and fix were developed with the help of Claude Code. > > > > Fixes: 31fe62b95866 ("mm: add a low limit to alloc_large_system_hash") > > Cc: stable@vger.kernel.org > > Signed-off-by: Amir Hosseini > > --- > > mm/mm_init.c | 18 ++++++++++++++++-- > > 1 file changed, 16 insertions(+), 2 deletions(-) > > > > diff --git a/mm/mm_init.c b/mm/mm_init.c > > index d99af80ec752..418068bad006 100644 > > --- a/mm/mm_init.c > > +++ b/mm/mm_init.c > > @@ -2359,6 +2359,7 @@ void __init page_alloc_init_late(void) > > * - it is assumed that the hash table must contain an exact power-of-2 > > * quantity of entries > > * - limit is the number of hash buckets, not the total allocation size > > + * - the table has at least low_limit entries, callers may rely on that > > */ > > void *__init alloc_large_system_hash(const char *tablename, > > unsigned long bucketsize, > > @@ -2371,7 +2372,7 @@ void *__init alloc_large_system_hash(const char *tablename, > > unsigned long high_limit) > > { > > unsigned long long max = high_limit; > > - unsigned long log2qty, size; > > + unsigned long log2qty, min_log2qty, size; > > void *table; > > gfp_t gfp_flags; > > bool virt; > > @@ -2420,6 +2421,7 @@ void *__init alloc_large_system_hash(const char *tablename, > > numentries = max; > > > > log2qty = ilog2(numentries); > > + min_log2qty = max(order_base_2(low_limit), 1); > > > > gfp_flags = (flags & HASH_ZERO) ? GFP_ATOMIC | __GFP_ZERO : GFP_ATOMIC; > > do { > > @@ -2445,7 +2447,19 @@ void *__init alloc_large_system_hash(const char *tablename, > > table = alloc_pages_exact(size, gfp_flags); > > kmemleak_alloc(table, size, 1, gfp_flags); > > } > > - } while (!table && size > PAGE_SIZE && --log2qty); > > + } while (!table && size > PAGE_SIZE && log2qty > min_log2qty && > > + --log2qty); > > + > > + /* > > + * Shrinking below low_limit would break callers that size other data > > + * from it, so fall back to vmalloc, which needs no contiguous memory. > > + */ > > + if (!table && !virt && !(flags & HASH_EARLY)) { > > + table = vmalloc_huge(size, gfp_flags); > > + virt = true; > > + if (table) > > + huge = is_vm_area_hugepages(table); > > + } > > > > if (!table) > > panic("Failed to allocate %s hash table\n", tablename); > > > > --- > > base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f > > change-id: 20261123-mm-hash-low-limit-37a3a47c7cd1 > > > > Best regards, > > -- > > Amir Hosseini > > > > >