From nobody Sat Feb 7 19:08:31 2026 Received: from mail-dl1-f41.google.com (mail-dl1-f41.google.com [74.125.82.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E19513806CA for ; Thu, 29 Jan 2026 10:12:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769681546; cv=none; b=brwtVuQm9L8WRj7ODsYrZCdXgsWWMH7Lr3NCGluZGflQFZfCMWF4hwGVxrhXxjxu6hUOhVRRUwrU39A8wxh2raWkffsTdRgTPbivsRcUqG55mjYd43sjDKjOU/ablYay7CpFeME5EMzw+qGuEsavlGU+f4jAAfLVaG5Lw2TQ+nw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769681546; c=relaxed/simple; bh=V4kEo+SZojVCtWgR2qpo3SKCTe5B0pPOMa6sCL8N57o=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=nzlCudfviPfCySAdq5XfpLrrd6yeBUlnNukJtJo3rkuI/wkKPMyWExNYcFhfiqTxEmDhDmMEwzvfnOSkfY4VbcPFxoHxFEzdQdnUiG37QEX09IzpKc9z7Goy0wMnpIrPXxhX23y0hstm5Bs/klDwJaiyd4i2zjATKVfqLxODOT8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UufYWTe9; arc=none smtp.client-ip=74.125.82.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UufYWTe9" Received: by mail-dl1-f41.google.com with SMTP id a92af1059eb24-124a95e592fso218481c88.0 for ; Thu, 29 Jan 2026 02:12:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769681544; x=1770286344; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AJa7eQGWZbzucfOY/PWCQHeENsvDVajhwi4B2jpBWQE=; b=UufYWTe9Z0lCWYsDAoxLx3wof5M0PhfmZve1QGXCGpPQ+uzAnpers4m478HMPzkQYD qYSRVUl3w05ik2EF5YM1zZtxJKZHxMx1SLCXc4Np7MvBlOkD+ksFf2HPngekXdTyQ+C7 AO8kmw0MWfHJvqIgO6cUR/0QG7HO5wLqbIKIfyqbhLc0sqTnGFfRJboSd7wo/+qlvEIH uIiYfXJ0huF3Fsy4VtQlZt4F5rCLIsIPwHn4rPynHU4mhqHh2V9J4w3ZjyTlGECFZN2R eTJl46g9WqzKMubMpCfh5m2M1H2+GaQeS9IenLQ318WsiYYpF8L9sCqjp78qMi+Xizt0 WxtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769681544; x=1770286344; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=AJa7eQGWZbzucfOY/PWCQHeENsvDVajhwi4B2jpBWQE=; b=gqEX7yAyUu2mko+NUoTl+LmgNh0zp07m/vOMKSPh56aP89xVTxE0x6FhlW3oR1FSHv SkDPH7lXQLxXrcEV1hdx1SsxwX6xFPz+MTFkWtMEEIgRaf1IsldGI8LvrE/TJo+cn52s cBZ/du18JbRdWTBQrMBFOEqmFHEpWAZMzfCR2RVLhakgWw8xtpPXEzHQKmQqF4TsYUlt yWgri7SNg7rlx/DDGEIV4V5o0TU1iBa3if9frPoW3qBDmvp0VPNMisSj4svOK/F/XXMR YR2xOHRvVXptcgCIENsdVVHzlh1jS+ZcYmPQf/9z7vvIhy7eVdy2LDypVKWso6xoOSvq 5xDg== X-Forwarded-Encrypted: i=1; AJvYcCXm58c2cjt+QxLAbLR1jisUpncx+wvE0nFXbstxHfVjZHXaxNq3zE4+3mLMZuaXqYYD/khPlV1PPwNavb0=@vger.kernel.org X-Gm-Message-State: AOJu0Yxkh0UFQntUE7DhPIs9XGptvgj3LanPAhsLXeXoP7EDPkGjbmY6 OKWeydyafcNhMNqahiRaKOBuTVc8Bfol+7IVt4iQrRfXKx6VEN0IBXg7 X-Gm-Gg: AZuq6aKfGnBeHQwD8l3pEQzQyM7GcaoqOyRl6U7qcnBHCLDKej9vx+16Xp8Opqn+QPs IjaCcW7dYXBx60Pi3ZwbsAxVRGSoSya6Xh3yEL2bOlHggOx+X/uyr/dWhmjLtQs0VDPUvwvlJer w7Bwi2uCk/9Ub/vr5r4qj1iaJrJ3fUgmbfByMRNvsKynzdJwbXYnN1OqsQIQJzOfTuGA3hTo4I3 VShWJqVDx0TK1WJ5dDnHDskP9n37eBV1AjMGbRS/mPkhTo3UMhaLNYpU/6GD25zcLLKP5ZcePza wBtboQkisSa+YaVVwxxrriaHvJQMn6g7Jhr4ILYfiGDk15HdEtUu1Tq/1/KJH2f9RahPqwzpM/T APulo3FvOSNsUB+LfrD0kt120KUS1s90dfPCOmFyQQ9W/Klkg8MM8cc+dc5UePWolSko8OsIa5L o= X-Received: by 2002:a05:7022:6889:b0:11e:3e9:3e8b with SMTP id a92af1059eb24-124a00e8a82mr4376360c88.50.1769681543633; Thu, 29 Jan 2026 02:12:23 -0800 (PST) Received: from gmail.com ([2a09:bac5:4e24:c8::14:2b2]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-124a9debe5dsm6246054c88.11.2026.01.29.02.12.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jan 2026 02:12:23 -0800 (PST) From: Qingfang Deng To: Pablo Neira Ayuso , Florian Westphal , Phil Sutter , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Lorenzo Bianconi Subject: [PATCH nf-next] netfilter: flowtable: dedicated slab for flow entry Date: Thu, 29 Jan 2026 18:12:12 +0800 Message-ID: <20260129101213.74557-1-dqfext@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The size of `struct flow_offload` has grown beyond 256 bytes on 64-bit kernels (currently 280 bytes) because of the `flow_offload_tunnel` member added recently. So kmalloc() allocates from the kmalloc-512 slab, causing significant memory waste per entry. Introduce a dedicated slab cache for flow entries to reduce memory footprint. Results in a reduction from 512 bytes to 320 bytes per entry on x86_64 kernels. Signed-off-by: Qingfang Deng --- net/netfilter/nf_flow_table_core.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_tab= le_core.c index 06e8251a6644..e075dbf5b0ce 100644 --- a/net/netfilter/nf_flow_table_core.c +++ b/net/netfilter/nf_flow_table_core.c @@ -16,6 +16,7 @@ =20 static DEFINE_MUTEX(flowtable_lock); static LIST_HEAD(flowtables); +static __read_mostly struct kmem_cache *flow_offload_cachep; =20 static void flow_offload_fill_dir(struct flow_offload *flow, @@ -56,7 +57,7 @@ struct flow_offload *flow_offload_alloc(struct nf_conn *c= t) if (unlikely(nf_ct_is_dying(ct))) return NULL; =20 - flow =3D kzalloc(sizeof(*flow), GFP_ATOMIC); + flow =3D kmem_cache_zalloc(flow_offload_cachep, GFP_ATOMIC); if (!flow) return NULL; =20 @@ -812,9 +813,15 @@ static int __init nf_flow_table_module_init(void) { int ret; =20 + flow_offload_cachep =3D kmem_cache_create("nf_flow_offload", + sizeof(struct flow_offload), + NULL, SLAB_HWCACHE_ALIGN); + if (!flow_offload_cachep) + return -ENOMEM; + ret =3D register_pernet_subsys(&nf_flow_table_net_ops); if (ret < 0) - return ret; + goto out_pernet; =20 ret =3D nf_flow_table_offload_init(); if (ret) @@ -830,6 +837,8 @@ static int __init nf_flow_table_module_init(void) nf_flow_table_offload_exit(); out_offload: unregister_pernet_subsys(&nf_flow_table_net_ops); +out_pernet: + kmem_cache_destroy(flow_offload_cachep); return ret; } =20 @@ -837,6 +846,7 @@ static void __exit nf_flow_table_module_exit(void) { nf_flow_table_offload_exit(); unregister_pernet_subsys(&nf_flow_table_net_ops); + kmem_cache_destroy(flow_offload_cachep); } =20 module_init(nf_flow_table_module_init); --=20 2.43.0