Re: [PATCH RFC nf-next 7/9] netfilter: nfqueue: reserve capacity against the bound owner

From
Florian Westphal <fw@strlen.de>
Date
2026-11-16 23:17:15
Also in
cgroups, linux-kselftest, linux-mm, netfilter-devel
Reply to
Alireza Asgari, 2026-11-15
Alireza Asgari via B4 Relay [off-list ref] wrote:
quoted hunk ↗ jump to hunk
+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).
Thread (12 messages) 12 messages, 2 authors, last reply 1h ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help