Article View: linux.kernel.netdev
Article #26082Re: [PATCH RFC nf-next 7/9] netfilter: nfqueue: reserve capacity against the bound owner
From: Alireza Asgari
Date: Thu, 03 Dec 2026 01:17
Date: Thu, 03 Dec 2026 01:17
74 lines
13714 bytes
13714 bytes
Hi Florian,
> This is rather complex, do we really need all of this extra machinery?
I added the worker so a queue that was shrunk while full could return
the excess charge as its packets drained. I agree with Chris that the
refund can wait until the next configuration change or queue teardown.
That would let me drop the refund worker and its mutex. Verdicts would
just update the queue's byte count.
I'd keep v1's choice to capture the owner at BIND and take the first
charge when the queue is enabled. That lets userspace bind a queue
and set a smaller limit before it has to pay for the default size.
Does that fit the lifecycle you had in mind?
Thanks,
Alireza
From: Florian Westphal <fw@strlen.de>
To: <alireza@asgari.net>
Cc: <netfilter-devel@vger.kernel.org>, <linux-mm@kvack.org>, "Johannes Weiner"<hannes@cmpxchg.org>, "Michal Hocko"<mhocko@kernel.org>, "Roman Gushchin"<roman.gushchin@linux.dev>, "Shakeel Butt"<shakeel.butt@linux.dev>, "Muchun Song"<muchun.song@linux.dev>, "Andrew Morton"<akpm@linux-foundation.org>, "David Hildenbrand"<david@kernel.org>, "Pablo Neira Ayuso"<pablo@netfilter.org>, "Phil Sutter"<phil@nwl.cc>, "Shuah Khan"<shuah@kernel.org>, "Tejun Heo"<tj@kernel.org>, "Vladimir Davydov"<vdavydov.dev@gmail.com>, "Chris Down"<chris@chrisdown.name>, "Zhang Jiao"<zhangjiao2@cmss.chinamobile.com>, "Song Hu"<husong@kylinos.cn>, <cgroups@vger.kernel.org>, <netdev@vger.kernel.org>, <linux-kselftest@vger.kernel.org>
Date: Tue, 17 Nov 2026 00:17:09 +0100
Subject: Re: [PATCH RFC nf-next 7/9] netfilter: nfqueue: reserve capacity against the bound owner
> Alireza Asgari via B4 Relay <devnull+alireza.asgari.net@kernel.org> wrote:
> > +static void nfqnl_mem_refund(struct nfqnl_instance *queue)
> > +{
> > + u64 pages;
> > +
> > + lockdep_assert_held(&queue->mem_mutex);
> > + spin_lock_bh(&queue->lock);
> > + pages = nfqnl_mem_pages(max(queue->mem_limit, queue->mem_used));
> > + spin_unlock_bh(&queue->lock);
> > +
> > + if (pages >= queue->memcg.pages)
> > + return;
> > +
> > + /* Shrinking cannot fail. Keep the packet-path copy conservative meanwhile. */
> > + mem_cgroup_reservation_resize(&queue->memcg, pages);
> > + spin_lock_bh(&queue->lock);
> > + queue->mem_reserved = pages;
> > + /* A final drain may have happened while the refund was in progress. */
> > + if (!queue->mem_stopping &&
> > + pages > nfqnl_mem_pages(max(queue->mem_limit, queue->mem_used)))
> > + queue_work(nfq_cleanup_wq, &queue->mem_work);
> > + spin_unlock_bh(&queue->lock);
> > +}
> > +
> > +static void nfqnl_mem_work(struct work_struct *work)
> > +{
> > + struct nfqnl_instance *queue =
> > + container_of(work, struct nfqnl_instance, mem_work);
> > +
> > + mutex_lock(&queue->mem_mutex);
> > + nfqnl_mem_refund(queue);
> > + mutex_unlock(&queue->mem_mutex);
> > +}
>
> This is rather complex, do we really need all of this extra machinery?
>
> I had hoped we could do the memcg equivalent of
>
> vmalloc(4 * 1024 * 1024, GFP_KERNEL_ACCOUNT);
> on queue creation / instantiation, and vfree() on instance destruction.
>
> The only minor inconvenience is queue limit reconfiguration. But that
> also happens from process context, so it should be enough to just
> do the equivalent of vrealloc; or, if memcg precharge cannot easily
> support that, just vmalloc, then vfree(old).
>
Technical Details
Message-ID:
<1a2397a2879.65ff3e1a693887.7059125950252366825@asgari.net>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376191-linux-kernel-netdev=dewy.ruReferences:
<20261115-b4-nfqueue-memory-accounting-v1-0-b9cc30819997@asgari.net> <20261115-b4-nfqueue-memory-accounting-v1-7-b9cc30819997@asgari.net> <avuO9UUriolRoRg8@strlen.de>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376191-linux-kernel-netdev=dewy.ru From: alireza@asgari.net (Alireza Asgari) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH RFC nf-next 7/9] netfilter: nfqueue: reserve capacity against the bound owner Date: Thu, 03 Dec 2026 02:17:16 +0100 Organization: Usenet Network Message-ID: <1a2397a2879.65ff3e1a693887.7059125950252366825@asgari.net> References: <20261115-b4-nfqueue-memory-accounting-v1-0-b9cc30819997@asgari.net> <20261115-b4-nfqueue-memory-accounting-v1-7-b9cc30819997@asgari.net> <avuO9UUriolRoRg8@strlen.de> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="2104801"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:eCd639PCsColShN4wN12PPUMGPk= sha256:FInA9/eyJpRytCQ86ePE9N9BTG/nR0qrMZVktrPBfZY= sha1:+AXwLabaS3NYgAU+SQJo7jedhsw= sha256:CyzqoVwESLEHQbbYDA+vlDmc+T0mbFzYBiFj6fz7Uqc= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 0AFC311750E; Thu, 3 Dec 2026 04:18:14 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.851 X-Spam-Status: No, score=-2.851 tagged_above=-9999 required=6.31 tests=[DKIM_INVALID=0.1, DKIM_SIGNED=0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=fail (1024-bit key) reason="fail (message has been altered)" header.d=asgari.net X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id afXAfU-1WlrY; Thu, 3 Dec 2026 04:18:09 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-376191-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=asgari.net X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id C64D1116175; Thu, 3 Dec 2026 04:17:59 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 9AB3E2666D; Thu, 3 Dec 2026 01:17:57 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796260677; b=cYofz8FDlPyO3zpr21I2/fvdU8FYu//Iw081HH1xIvXrtKKZdxe7qT25ZXkZlgTpI13L VJMKaK0cJUP8Fw/Kf1dbl1LtZF70KXmu0SuFu20LSzmsxGZoXBby2qWgj2H4IEbGA87Tf xMqOFy4ifKuW1r+siWeqpHY/+uEbR1XKJZkCDeE24PTXQGFcU27rSKTXAVB6g01qGPgpC P71pmJx2DiqdVO0v+NXLDBLB6PmP75zDwFIb6t2JrzX4ZE9XfIahiwWSOq69dY39RJ4ti LZwPmGKL02N+OUI5jATuLl/cIx+KBU9QeYbJQ6DGwbr1/W5oMJPkZkpIX4CwHeNTbNg== X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796260677; h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:Date: From:To:Cc:Message-ID:In-Reply-To:References:Subject:X-Mailing-List: List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe: List-Owner:Precedence:MIME-Version:Content-Type: Content-Transfer-Encoding:Importance:User-Agent:X-Mailer; bh=uX/7lejOsHs1DK8otvS27iPzCLb9j0eamWEngzyiyz4=; b=IwXb0dMPiEfADFNT4r50rmYE6i/Y9CjtJEnYJLMbQ04Uxc9WC1AUAc+8PsC0urGVRl87 G1C/SXb+QYj5CPdY0LQVV17DKsEHa87WlQrnvMPU9kj0w7+Z6Dgj9b4tsmK1LGr4AW1Gl mOyFF8wn+ZA3Ea6YIHNZJ9WgE0aK5V0gK0++75pPR1vtyjLZ+a4kwTXOt5v+jCR75Dhb5 c38ZaR7SBiwcvFbVjcQeogvioghaaVkmt6+7NB3gKOOY63NSAAzqncv17dxB/kPaVnTAD dxhbEeqx6k8exl/sFvdgrp46AnLqqvF+QzTS9U5yuTeCQHAULILKCBGtaiNLLpNoywA== X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" header.d=asgari.net header.i=@asgari.net header.a=rsa-sha256 header.s=zmail header.b=biGXOHBj; dmarc=none header.from=asgari.net; spf=pass smtp.mailfrom=asgari.net; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E8384606A339; Thu, 3 Dec 2026 01:17:56 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=asgari.net header.i=@asgari.net header.a=rsa-sha256 header.s=zmail header.b=biGXOHBj X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=136.143.169.50 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796260676; b=tkUrv+YxMVD2b5n/2sgO1Je/t2QB1n5We5RrJ76sowXvqjp8x+bgktft3GYTjHTdQuNm dzBqFQCFb9uVu6sQW2NJTk2g0XFbzZgqtX4qlhC5iPp49ISk7NOcN2j83cv2ifWFhCUxh 0fZprwd0GDfe+0JBUJ5BSAo7iVp59lMuIBOvu95aae+JwFW18XPX8AiQ+IfaAVoaMG+Ii IWOFz5bUWcLiWnWdJ3jHLHN24tMIAiZOL9KinkLcc6pWFUb+ds5tNHA4CWE28exDOEjLp HIr2Rsjl55Ktnli1P3dcVLrs17nH9O5j+KO5V9GpfD/GWFCk719nCLIuE+oIqQ7KuCQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796260676; h=DMARC-Filter:DKIM-Signature:Received:Date:From:To:Cc:Message-ID: In-Reply-To:References:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Importance:User-Agent:X-Mailer; bh=uX/7lejOsHs1DK8otvS27iPzCLb9j0eamWEngzyiyz4=; b=Kx31rw2Heiptta8kvqg37/zXQWIjlq0CeP9+VxQtd6N/szNoBZmlGBRQWoJi0uEnaW7S PyqW4gPLeY8Bk/1U42dbeSzXrp42TZ8mdG9wnsQU8Zm0qY1sWIZJO5eIBIOPbjE4jMZhc kNXF4re4cySebsbSfrK+rsSjmK1gtkzIs0xqfJ2z/ZQn7bMZKgAeiOHORNRfKFrMp7rlH RhdNa2U4dauGdeTtr7azSF1PzNn80f/1yvEpR6ILXdCBffoavxbQsRBn3DNj+HWZXFPpo 9UAafw4Ess0B2pU/ygmPut0GwxpMIQFwjTrKYWZRYF4NWtry+rLfljHa85TP03jwF8A== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none header.from=asgari.net; spf=pass smtp.mailfrom=asgari.net; dkim=pass header.d=asgari.net header.i=@asgari.net header.a=rsa-sha256 header.s=zmail header.b=biGXOHBj; arc=pass header.oldest-pass=0 smtp.remote-ip=136.143.169.50 X-Received: from sender-of-o50.zoho.eu (sender-of-o50.zoho.eu [136.143.169.50]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCFB4606A322; Thu, 3 Dec 2026 01:17:54 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CCFB4606A322 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=asgari.net X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=asgari.net X-ARC-Seal: i=1; a=rsa-sha256; t=1796260639; cv=none; d=zohomail.eu; s=zohoarc; b=A4gaFi/7rU6uRSIb+jO5FXVschEcs1wzkQZNI9JaoafPllTOTYUvBHv5+3jH1c3+c1m9lqCJ1xR/XOMt/DuDlHxTk0yEzxG5xhYS+nkkqPzwENP0C2HguTb1/8MS507NH9FqrXxlJeUSj3awnkHY2xDQA+RkRuldnrCH4JKGJLM= X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1796260639; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=uX/7lejOsHs1DK8otvS27iPzCLb9j0eamWEngzyiyz4=; b=NlmVKbDM+BguvHdXzbkTw3k5TAcYEsheY4wQ3o/CSy5M7pn4QIqS0PoH9PSeHCZyWp7J1v6EF+A1HPNLArf6vQHmdL/mOqWC8oNYuFyIKho6wlOKpDxceyr0GbGv5YxPXZjvCnE+sns8/j2XqZrkGTb8CxwBSfhxAMH/de/vZRU= X-ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=asgari.net; spf=pass smtp.mailfrom=alireza@asgari.net; dmarc=pass header.from=<alireza@asgari.net> X-DKIM-Signature: a=rsa-sha256; b=biGXOHBjPvaFv8ao9OvbQKuwBD8wemHNsxsG92Bw5mgKw1kQziuAdXGv/NBAwLO/w+wkIEjhc37eZeAwFHNmM8DzovTfE9fadh9BWFwN7zWSEBMlbLucgWtUj1XkZKENSSWSki1IAgg9A1krWL3/gFRlu5wmPbZ7WdJyZTnUPWs=; c=relaxed/relaxed; s=zmail; d=asgari.net; v=1; bh=uX/7lejOsHs1DK8otvS27iPzCLb9j0eamWEngzyiyz4=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; X-Received: from mail.zoho.eu by mx.zoho.eu with SMTP id 1796260636804531.3011633421801; Thu, 3 Dec 2026 02:17:16 +0100 (CET) X-Cc: "netfilter-devel" <netfilter-devel@vger.kernel.org>, "linux-mm" <linux-mm@kvack.org>, "Johannes Weiner" <hannes@cmpxchg.org>, "Michal Hocko" <mhocko@kernel.org>, "Roman Gushchin" <roman.gushchin@linux.dev>, "Shakeel Butt" <shakeel.butt@linux.dev>, "Muchun Song" <muchun.song@linux.dev>, "Andrew Morton" <akpm@linux-foundation.org>, "David Hildenbrand" <david@kernel.org>, "Pablo Neira Ayuso" <pablo@netfilter.org>, "Phil Sutter" <phil@nwl.cc>, "Shuah Khan" <shuah@kernel.org>, "Tejun Heo" <tj@kernel.org>, "Vladimir Davydov" <vdavydov.dev@gmail.com>, "Chris Down" <chris@chrisdown.name>, "Zhang Jiao" <zhangjiao2@cmss.chinamobile.com>, "Song Hu" <husong@kylinos.cn>, "cgroups" <cgroups@vger.kernel.org>, "netdev" <netdev@vger.kernel.org>, "linux-kselftest" <linux-kselftest@vger.kernel.org> X-In-Reply-To: <avuO9UUriolRoRg8@strlen.de> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-Importance: Medium X-User-Agent: Zoho Mail X-Mailer: Zoho Mail