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
Subject: Re: [PATCH RFC nf-next 7/9] netfilter: nfqueue: reserve capacity against the bound owner
Date: Tue, 17 Nov 2026 00:17:09 +0100 [thread overview]
Message-ID: <avuO9UUriolRoRg8@strlen.de> (raw)
In-Reply-To: <20261115-b4-nfqueue-memory-accounting-v1-7-b9cc30819997@asgari.net>
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).
next prev parent reply other threads:[~2026-11-16 23:17 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 22:34 [PATCH RFC nf-next 0/9] netfilter: nfqueue: account queued memory and reserve capacity Alireza Asgari via B4 Relay
2026-11-15 22:34 ` [PATCH RFC nf-next 1/9] memcg: saturate deferred memory.high page debt Alireza Asgari via B4 Relay
2026-11-15 22:34 ` [PATCH RFC nf-next 2/9] memcg: bound memory.high delay arithmetic Alireza Asgari via B4 Relay
2026-11-15 22:34 ` [PATCH RFC nf-next 3/9] memcg: add KUnit coverage for memory.high accounting Alireza Asgari via B4 Relay
2026-11-15 22:34 ` [PATCH RFC nf-next 4/9] memcg: add an owner-bound capacity reservation interface Alireza Asgari via B4 Relay
2026-11-15 22:34 ` [PATCH RFC nf-next 5/9] memcg: test capacity reservation rollback and refunds Alireza Asgari via B4 Relay
2026-11-15 22:34 ` [PATCH RFC nf-next 6/9] netfilter: nfqueue: account saved skb bytes per queue Alireza Asgari via B4 Relay
2026-11-16 22:46 ` Florian Westphal
2026-11-15 22:34 ` [PATCH RFC nf-next 7/9] netfilter: nfqueue: reserve capacity against the bound owner Alireza Asgari via B4 Relay
2026-11-16 23:17 ` Florian Westphal [this message]
2026-11-15 22:34 ` [PATCH RFC nf-next 8/9] netfilter: nfqueue: add KUnit memory accounting coverage Alireza Asgari via B4 Relay
2026-11-15 22:34 ` [PATCH RFC nf-next 9/9] selftests: netfilter: exercise nfqueue memory accounting Alireza Asgari via B4 Relay
2026-11-16 22:34 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=avuO9UUriolRoRg8@strlen.de \
--to=fw@strlen.de \
--cc=akpm@linux-foundation.org \
--cc=alireza@asgari.net \
--cc=cgroups@vger.kernel.org \
--cc=chris@chrisdown.name \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=husong@kylinos.cn \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=phil@nwl.cc \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=shuah@kernel.org \
--cc=tj@kernel.org \
--cc=vdavydov.dev@gmail.com \
--cc=zhangjiao2@cmss.chinamobile.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox