🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #17505

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

#17505
From: Florian Westphal
Date: Mon, 16 Nov 2026 23:17
46 lines
9221 bytes
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: <avuO9UUriolRoRg8@strlen.de>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364815-linux-kernel-netdev=dewy.ru
References: <20261115-b4-nfqueue-memory-accounting-v1-0-b9cc30819997@asgari.net> <20261115-b4-nfqueue-memory-accounting-v1-7-b9cc30819997@asgari.net>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364815-linux-kernel-netdev=dewy.ru
From: fw@strlen.de (Florian Westphal)
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <avuO9UUriolRoRg8@strlen.de>
References: <20261115-b4-nfqueue-memory-accounting-v1-0-b9cc30819997@asgari.net>
 <20261115-b4-nfqueue-memory-accounting-v1-7-b9cc30819997@asgari.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
	logging-data="2191238"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:uKXbaVLPbRKNSuIbdEaaBfXOFt8= sha256:6nh2H1TJWJ7x/0z/y0CZGkGFdLOroN5ikgte3kq4niY=
	sha1:FRK/jpH/gduC+g7UKW8WKm6EjBs= sha256:kwyyoUEx+DJ5wrDIw+ShAvKBvlAXcHP2rM2pqwHsDrY=
Content-Disposition: inline
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 47591114DB2; Tue, 17 Nov 2026 02:17:32 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.951
X-Spam-Status: No, score=-2.951 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=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-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 uaWV61MLGgDo;
	Tue, 17 Nov 2026 02:17:29 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-364815-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=strlen.de
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id D299D114DAD; Tue, 17 Nov 2026 02:17:23 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id 325BD27D8E; Mon, 16 Nov 2026 23:17:20 +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=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794871037;
	b=cvms+y06S2p5B3ON6ht7qPY5uMGHLxSwmP6eMS2/JIE/3l6Vbad7lQUAIz4Q21uBlNEf
	 nrRQKrgTHfRd52oPElgbCYpq/SUH54wAm94HfgsSVum+KVJsxSysLH4C93rWHhUP5Jjbx
	 tOCyNdHljaWIFtoEnh1xNcYqQuRWSOJpTN4qL5HNchFgmtHsi+6TQGfh47MBr527C7a30
	 oMpNe1STclLYS0JhIrj6r+SshCIQYbuP3Fk+etBDrQfd2idhiRTpHqNSM6ZkrN26mZ6ZY
	 HB8xUwSUeVwzANjiBUJPPxO3SNtxO3qIedC4BTDHWc06q4WhvKOIcFAE9XNjrhjPQog==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794871037;
	h=X-Original-To:Received:DMARC-Filter:Received:Date:From:To:Cc:Subject:
	 Message-ID:References:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Type:Content-Disposition:In-Reply-To;
	bh=lBMZHfw7i4eJx0zD4VQ6/+RNNcDSsfzhNT1NDQ8/k0U=;
	b=bS1BMs8LkycgpXzfiNnjkxUwcQrkKG9PvQ1d89kbo/5jBjrbLN2ff3bdoWXGdg3jepdu
	 GHabo+t9sHjyEXti08fTwXLAwu2EhQ+LfOhkaLfnjZkntUQeHIOThwhzCoMz3WwHf7ze2
	 obwvTt2Rp7IwWkJ8FOpk5tBMMExesOkZzl/yRuBtRa3EJQUgqNYyfLqqipfLQskjJWg3O
	 W89zTpFJ1SoY9v0rgv59vxdGfjhnoX/UGmFpPxQHZhnlmCPd54YQyRNFs7qlZly+Y4pRg
	 0pn8Hy09mCtF2hhRZFj17ZlH6Ygo4Z6zros0fqz68lHMe4kvidpYDlvispbFCAOZnyw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dmarc=none header.from=strlen.de;
	spf=pass smtp.mailfrom=strlen.de;
	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 281DD606A881;
	Mon, 16 Nov 2026 23:17:17 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.216.245.30
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794871036;
	b=q8tLCo5Y+hDK9P11urBy0IWUcs4wOO8dVYERj3nLOUeZt0RAqsxH5LRH2CHkZ5P8b/Br
	 uA0W+iAud/Gz0h3Ot0iaIJnt0p9KaoArGrJj/GYtuImfIRlNzsX0kg4VvGGksZdKT7PZ5
	 DQTc2Z5oXR16+DZT/Exg+tY6Ec4IGd3BGtBIRTOhD6yBS5FCTj5ZsvOQa+I0+J1k8BCQC
	 /RC89nKaGFX7yTkr+ttNmTBv8J8MDf2StSQry/shtMhHteHow9679mepPKTFZ6d27o05b
	 kPI6B44PPYmaFvsDYsTOFI/Ttw0TZF/GcQliyskFyb3+AnkoeOWTyHCzryL6SvKWxGA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794871036;
	h=DMARC-Filter:Received:Date:From:To:Cc:Subject:Message-ID:References:
	 MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=lBMZHfw7i4eJx0zD4VQ6/+RNNcDSsfzhNT1NDQ8/k0U=;
	b=XfAlAmJkpbGMqNThMMsUE3r3OWTjhQzdzdkOEV5afSvwoWSi7bqJGmpX6U7OZfKnd8K9
	 Vowr4c9jtgGoxf+I/6dT6SAN1KuuFeScg0+W0tNUSbGNP7QFO1XE7AzLxCh/CxDRmUL24
	 t0FeI/0vUmt/FhIx5jNuDaFtHB5TPdhyGS0uRr8NTtSjRBkN00//6kluw2Vw23YBNLx7E
	 890FbrOxKyxjDk0wcq1A09GfEIXHpg1SKTJUxRiovUHeJRlDDUILn2C1ZC/iF5TwGwwpd
	 +/Q9/M3e/qtBw7W7HtGdo+KYdDyxDYc9WSso3H+TEXWNLZZ8JilVH6PwTP9JtnSW17A==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=none header.from=strlen.de;
	spf=pass smtp.mailfrom=strlen.de;
	arc=none smtp.remote-ip=91.216.245.30
X-Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [91.216.245.30])
	(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 B7B09606A31C;
	Mon, 16 Nov 2026 23:17:15 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B7B09606A31C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=strlen.de
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=strlen.de
X-Received: by Chamillionaire.breakpoint.cc (Postfix, from userid 1003)
	id 1421760342; Tue, 17 Nov 2026 00:17:13 +0100 (CET)
X-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
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-In-Reply-To: <20261115-b4-nfqueue-memory-accounting-v1-7-b9cc30819997@asgari.net>