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=1796205110; b=5OuWGuXtDxqIsuCizyGMINNgzopcNbx3Y1G+qIYIQZH7yTP9DZgF62uo6CPjoKQ74NVR jFPQCCb5TOwdm0cnwARcSLe+D1bSDraP6qVbume8gP5BUuLZG7a1GMCTtyMWHubCqglfV 0ltYdmPDKVb3NcuqhVGeg4Udf0rxVFESh+OCn6AUdz988BGI3azSGX2QcbMZ62CXpQ8y5 NLr+OgeW9rHbHMKNAGktiHa04U1qmWsdSQUddsnAP1AsJBjSGJIF8EVib8+39RglPz0RE 6Seu9RkBeFCbVafooUrzzplTQ2+QyToZhM6sXxcVdPa6YpK7jpFCLYwGX8Z1ODhXRYw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796205110; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=b2WXVW9kyVSQ7mCJNqfR3+X3W2khE/Qicg+A7KdCWgc=; b=lFLTjltCyHsQ86WjMvZFz6ph+4wSLq7CmpjZ5gZLYQDDdcN8sxh9hlQlQUuHsT9Sqe03 jSQl5doAqkg9e8qofClyCGyIeXlEhJXfAW5cqMDuYikTJVb26RxXRz5tQtYv+bnKOj5iv 9a/19oX/JaHs23sXg53qfLSUefh0IWJSgSmTKIpTCRVoqE9k8D3PgZoKJ34dK46YAbpN7 tEI5+gN8doBSLDZAlGw1KwPWyqIOxsE/FuhP/VdhTdqMPb0qKHoFSp+tnW8sAxNEnHZEG T/MPTioe+Jdx6mBNUrM9Z7GutqSX0K64kiDw7NcX4fivK6ZRF+g3FHQLH8jtunoHhTQ== 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=HiveoKxg; 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 25EF5606A33B for ; Wed, 2 Dec 2026 09:51:49 +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=HiveoKxg Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38DD61F00931; Wed, 2 Dec 2026 09:51:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796205109; bh=b2WXVW9kyVSQ7mCJNqfR3+X3W2khE/Qicg+A7KdCWgc=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=HiveoKxgz4woC5gumjwR0uPNYWoK+caPJYQOdxPfLCVYH0zQ/Lp4YVHwYRc4AECeu aVo1gLBf5MqFBLZfSQ3BhHc25h/2/IcCbPiy3E3BBi710n51Xm1iJ5jsHK0s+H5fkU kpcNQcPx5MuOyMoxdkuzRisPbyMNdfabfB9yLbx8HFjRhthjioO0pMuY2zqVwFWT0K 0Rda50CWJcVgH5bZdxvH9HxaM3SZOd8oRv5QN++daMEcCl6HJ9DuJV0OELrVLVfh6K T3kQAoGmhYivAvnHsW1PQw0bT0U8/NBDtaMK613z2RfT5xAGXbxxHHo/5EUsSTeHoE bpcfpF4n1aveg== Date: Wed, 2 Dec 2026 11:51:33 +0200 From: Mike Rapoport To: me@amir.fyi Cc: Eric Dumazet , Neal Cardwell , Kuniyuki Iwashima , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Muchun Song , netdev@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH net] tcp: avoid table_perturb overflow on single node hosts Message-ID: References: <20261201-tcp-perturb-kvmalloc-v1-1-deee7c745fa3@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: <20261201-tcp-perturb-kvmalloc-v1-1-deee7c745fa3@amir.fyi> Hi Amir, On Tue, Dec 01, 2026 at 07:31:32PM +0000, Amir Hosseini wrote: > > From: Amir Hosseini > > Since commit e67b72b90b7e ("tcp: use alloc_large_system_hash() to > allocate table_perturb"), table_perturb is allocated with > alloc_large_system_hash(). On NUMA hosts it uses vmalloc(), but on > single node hosts it needs one contiguous 256KB block. It's vmalloc_huge() and it's used when hashdist is set, i.e. on 64-bit with more than one node with memory. > When there is no such block, for example after many HugeTLB pages were > reserved at boot, the table is made smaller without telling the caller. It's worth mentioning that alloc_large_system_hash() ignores low_limit when it retries with smaller sizes. ... > - table_perturb = alloc_large_system_hash("Table-perturb", > - sizeof(*table_perturb), > - INET_TABLE_PERTURB_SIZE, > - 0, 0, NULL, NULL, > - INET_TABLE_PERTURB_SIZE, > - INET_TABLE_PERTURB_SIZE); > + if (num_online_nodes() > 1) { > + /* Use vmalloc() to allow NUMA policy to spread pages > + * on all available nodes if desired. > + */ > + table_perturb = vmalloc_array(INET_TABLE_PERTURB_SIZE, > + sizeof(*table_perturb)); > + } I don't think the special case for NUMA makes sense. Since commit a061578043993 ("mm/vmalloc: request large order pages from buddy allocator") vmalloc takes large order blocks from the buddy allocator, so vmalloc_array() gets the whole table as one block from one node when it's available. With the existing code, if there's a free order-6 block, it comes from alloc_pages() with hashdist=0 and with hashdist=1 it's a single block from vmalloc mapped with 4k pages. If there's no such block, with hashdist=0 alloc_large_system_hash() continues the loop and returns the largest block alloc_pages() can get, and with hashdist=1 vmalloc is likely to succeed with several blocks spread across the nodes and mapped with 4k pages. With kvmalloc_array() a free order-6 block comes from kmalloc() -> alloc_pages() and if there is no such block, several smaller blocks come from vmalloc(), spread across the nodes and mapped with 4k pages. So kvmalloc_array() never shrinks the table, prefers the linear map when there's a contiguous block and spreads the table across the nodes exactly in the case where hashdist=1 actually spreads it now. Please drop the NUMA branch and just use kvmalloc_array(). > + if (!table_perturb) > + table_perturb = kvmalloc_array(INET_TABLE_PERTURB_SIZE, > + sizeof(*table_perturb), > + GFP_KERNEL); > + if (!table_perturb) > + panic("TCP: failed to alloc table_perturb"); > } -- Sincerely yours, Mike.