Hi Florian, Thanks for the review, and sorry for the slow reply.
> I think u32 is fine for those.
I used u64 because the byte allowance is derived from queue_maxlen, and the multiplication can exceed 4 GiB. I don't have a use case for more than that in one queue. I'd keep the packet limit as configured, compute the byte allowance in u64, and cap it at U32_MAX before storing it. Would that match what you had in mind?
> I'd suggest DEBUG_NET_WARN_ONCE() here, unless you have a strong > preference/reason for a full splat here.
Agreed. I'll use DEBUG_NET_WARN_ON_ONCE(inst->mem_used) for the teardown check. Thanks, Alireza From: Florian Westphal <f…@strlen.de> To: <alir…@asgari.net> 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>, "Phil Sutter"<ph…@nwl.cc>, "Shuah Khan"<shu…@kernel.org>, "Tejun Heo"<t…@kernel.org>, "Vladimir Davydov"<vdav…@gmail.com>, "Chris Down"<chr…@chrisdown.name>, "Zhang Jiao"<zhan…@cmss.chinamobile.com>, "Song Hu"<huso…@kylinos.cn>, <cgro…@vger.kernel.org>, <netd…@vger.kernel.org>, <linu…@vger.kernel.org> Date: Mon, 16 Nov 2026 23:46:29 +0100 Subject: Re: [PATCH RFC nf-next 6/9] netfilter: nfqueue: account saved skb bytes per queue > Alireza Asgari via B4 Relay <devn…@kernel.org> wrote: > > --- a/net/netfilter/nfnetlink_queue.c > > +++ b/net/netfilter/nfnetlink_queue.c > > @@ -92,6 +92,8 @@ struct nfqnl_instance { > > unsigned int queue_total; > > unsigned int id_sequence; /* 'sequence' of pkt ids */ > > struct list_head queue_list; /* packets in queue */ > > + u64 mem_limit; > > + u64 mem_used; > > I think u32 is fine for those. Or do you see a use case for 2**32 mbyte > worth of queued packets? > > > +/* All release paths use the saved admission cost, including notification undo. */ > > +static void nfqnl_mem_uncharge(struct nfqnl_instance *queue, > > + struct nf_queue_entry *entry) > > +{ > > + lockdep_assert_held(&queue->lock); > > + queue->mem_used -= entry->truesize; > > + entry->truesize = 0; > > +} > > + > > static struct nfqnl_instance * > > instance_create(struct nfnl_queue_net *q, u_int16_t queue_num, u32 portid) > > { > > @@ -152,6 +176,7 @@ instance_create(struct nfnl_queue_net *q, u_int16_t queue_num, u32 portid) > > inst->queue_num = queue_num; > > inst->peer_portid = portid; > > inst->queue_maxlen = NFQNL_QMAX_DEFAULT; > > + inst->mem_limit = nfqnl_mem_limit(NFQNL_QMAX_DEFAULT); > > inst->copy_range = NFQNL_MAX_COPY_RANGE; > > inst->copy_mode = NFQNL_COPY_NONE; > > spin_lock_init(&inst->lock); > > @@ -199,6 +224,7 @@ static void instance_destroy_work(struct work_struct *work) > > rcu_read_lock(); > > nfqnl_flush(inst, NULL, 0); > > rcu_read_unlock(); > > + WARN_ON_ONCE(inst->mem_used); > > I'd suggest DEBUG_NET_WARN_ONCE() here, unless you have a strong > preference/reason for a full splat here. >