Hi Chris, Thanks for looking at this, and sorry for the slow reply.
> They would just need exporting.
I'll try obj_cgroup_charge() and obj_cgroup_uncharge() on the objcg captured at BIND. On my base, the helpers take a size_t but use unsigned int for byte counts in the per-CPU stock. I'll check the largest charge and refund, and what happens if the owner cgroup is removed while the queue still holds a charge.
> most of that memory could be reclaimed.
Agreed. I'll try allowing reclaim during queue configuration and check that a failed resize leaves the previous configuration usable.
> the excess doesn't have to come back as the queue drains.
Yes. On shrink I'll keep enough charged for the larger of the new limit and the bytes still held. If those packets drain, the surplus can stay charged until the next configuration change or queue destruction. That lets me drop the refund worker. Thanks, Alireza From: Chris Down <chr…@chrisdown.name> To: "Alireza Asgari via B4 Relay"<devn…@kernel.org> Cc: <netf…@vger.kernel.org>, <linu…@kvack.org>, "Johannes Weiner"<hann…@cmpxchg.org>, "Michal Hocko"<mhoc…@kernel.org>, "Roman Gushchin"<roma…@linux.dev>, "Shakeel Butt"<shak…@linux.dev>, "Muchun Song"<much…@linux.dev>, "Andrew Morton"<ak…@linux-foundation.org>, "David Hildenbrand"<dav…@kernel.org>, "Pablo Neira Ayuso"<pab…@netfilter.org>, "Florian Westphal"<f…@strlen.de>, "Phil Sutter"<ph…@nwl.cc>, "Shuah Khan"<shu…@kernel.org>, "Tejun Heo"<t…@kernel.org>, "Vladimir Davydov"<vdav…@gmail.com>, "Zhang Jiao"<zhan…@cmss.chinamobile.com>, "Song Hu"<huso…@kylinos.cn>, <cgro…@vger.kernel.org>, <netd…@vger.kernel.org>, <linu…@vger.kernel.org>, "Alireza Asgari"<alir…@asgari.net> Date: Wed, 18 Nov 2026 04:38:43 +0100 Subject: Re: [PATCH RFC nf-next 0/9] netfilter: nfqueue: account queued memory and reserve capacity > Hi Alireza, > > Alireza Asgari via B4 Relay writes: > >3. Whether the proposed bulk reservation interface is an appropriate MM > > interface for this use, including the explicit restriction of charged > > growth to 64-bit kernels. Is this compatibility tradeoff acceptable for > > the initial interface? > > Hmm, I don't think this needs a new interface. obj_cgroup_charge() and > obj_cgroup_uncharge() on the objcg you take at BIND already deal with root > ownership, reparenting and the kmem statistics, which is most of what patch > 4 reimplements. They would just need exporting. > > >4. Whether non-reclaiming reservation growth is the desired failure policy. > > I don't think so. A long-running cgroup usually sits at memory.max, mostly > with page cache, so resizing the queue would fail with ENOMEM even though > most of that memory could be reclaimed. > > >Increasing capacity obtains the additional reservation before publishing > >the new limit. Failure leaves the existing configuration intact. Shrinking > >preserves queued packets and retains page-rounded backing for the greater > >of the configured allowance and outstanding saved charges. Excess capacity > >is refunded as entries drain, with refund work serialized against resizing > >and coordinated with queue destruction. Refunds settle the actual memory > > Keeping the charge at the larger of the limit and the bytes still queued > makes sense. Otherwise one could shrink a full queue, charge the refund to > another queue, and leave the old packets uncharged. But, unless I'm > mistaken, the excess doesn't have to come back as the queue drains. > Configuration already runs under the nfnl subsystem mutex, so if the excess > is released at the next configuration change or when the queue is > destroyed, it looks like mem_work, mem_mutex and mem_stopping can all go. > > Thanks! > > Chris >