Skip to contentSkip to conversation

udp: add drop count for packets in udp_prod_queue

PATCH In review Mahdi Faramarzpour 3 participants 9 messages Jan 5 – Jan 7

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 udp: add drop count for packets in udp_prod_queue

This commit adds SNMP drop count increment for the packets in per NUMA queues which were introduced in commit b650bf0977d3 ("udp: remove busylock and add per NUMA queues").

---
 net/ipv4/udp.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
net/ipv4/udp.c +18 -1
index ffe074cb5..19ab44e46 100644
@@ -1709,6 +1709,11 @@ int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb)
 	int dropcount;
 	int nb = 0;
 
+	struct {
+		int mem4;
+		int mem6;
+	} err_count = { 0, 0 };
+
 	rmem = atomic_read(&sk->sk_rmem_alloc);
 	rcvbuf = READ_ONCE(sk->sk_rcvbuf);
 	size = skb->truesize;
@@ -1760,6 +1765,10 @@ int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb)
 		total_size += size;
 		err = udp_rmem_schedule(sk, size);
 		if (unlikely(err)) {
+			if (skb->protocol == htons(ETH_P_IP))
+				err_count.mem4++;
+			else
+				err_count.mem6++;
 			/*  Free the skbs outside of locked section. */
 			skb->next = to_drop;
 			to_drop = skb;
@@ -1797,10 +1806,18 @@ int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb)
 			skb = to_drop;
 			to_drop = skb->next;
 			skb_mark_not_on_list(skb);
-			/* TODO: update SNMP values. */
 			sk_skb_reason_drop(sk, skb, SKB_DROP_REASON_PROTO_MEM);
 		}
 		numa_drop_add(&udp_sk(sk)->drop_counters, nb);
+
+		SNMP_ADD_STATS(__UDPX_MIB(sk, true), UDP_MIB_MEMERRORS,
+			       err_count.mem4);
+		SNMP_ADD_STATS(__UDPX_MIB(sk, true), UDP_MIB_INERRORS,
+			       err_count.mem4);
+		SNMP_ADD_STATS(__UDPX_MIB(sk, false), UDP_MIB_MEMERRORS,
+			       err_count.mem6);
+		SNMP_ADD_STATS(__UDPX_MIB(sk, false), UDP_MIB_INERRORS,
+			       err_count.mem6);
 	}
 
 	atomic_sub(total_size, &udp_prod_queue->rmem_alloc);
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 3 lines · On Mon, 5 Jan 2026 15:17:32 +0330 Mahdi Faramarzpour wrote:

This commit adds SNMP drop count increment for the packets in per NUMA queues which were introduced in commit b650bf0977d3 ("udp: remove busylock and add per NUMA queues").

You must not submit more than one version of a patch within a 24h period.

#2 lore raw
Quoted 8 lines · Jakub Kicinski
Quoted 3 lines · On Mon, 5 Jan 2026 15:17:32 +0330 Mahdi Faramarzpour wrote:

This commit adds SNMP drop count increment for the packets in per NUMA queues which were introduced in commit b650bf0977d3 ("udp: remove busylock and add per NUMA queues").

You must not submit more than one version of a patch within a 24h period.

Hi Jakub and sorry for the noise, didn't know that. Is there any way to check my patch against all patchwork checks ,specially the AI-reviewer before submitting it?

maintainer
#3 lore raw
Quoted 6 lines · Mahdi Faramarzpour
Quoted 5 lines · Jakub Kicinski
Quoted 3 lines · On Mon, 5 Jan 2026 15:17:32 +0330 Mahdi Faramarzpour wrote:

This commit adds SNMP drop count increment for the packets in per NUMA queues which were introduced in commit b650bf0977d3 ("udp: remove busylock and add per NUMA queues").

Can you give some rationale why the existing counters are insufficient and why you chose to change then number of counters you suggest between revisions of your patch?

This code adds some cost to the hot path. The blamed commit added drop counters, most likely weighing the value of counters against their cost. I don't immediately see reason to revisit that.

Quoted 6 lines
Quoted 3 lines

You must not submit more than one version of a patch within a 24h period.

Hi Jakub and sorry for the noise, didn't know that. Is there any way to check my patch against all patchwork checks ,specially the AI-reviewer before submitting it?

See https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

#4 lore raw
Quoted 4 lines · Willem de Bruijn
Quoted 2 lines · Mahdi Faramarzpour
Quoted 1 line · Jakub Kicinski
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines · On Mon, 5 Jan 2026 15:17:32 +0330 Mahdi Faramarzpour wrote:
Quoted 3 lines

This commit adds SNMP drop count increment for the packets in per NUMA queues which were introduced in commit b650bf0977d3 ("udp: remove busylock and add per NUMA queues").

Can you give some rationale why the existing counters are insufficient and why you chose to change then number of counters you suggest between revisions of your patch?

The difference between revisions is due to me realizing that the only error the udp_rmem_schedule returns is ENOBUFS, which is mapped to UDP_MIB_MEMERRORS (refer to function __udp_queue_rcv_skb), and thus UDP_MIB_RCVBUFERRORS need not increase.

Quoted 4 lines

This code adds some cost to the hot path. The blamed commit added drop counters, most likely weighing the value of counters against their cost. I don't immediately see reason to revisit that.

AFAIU the drop_counter is per socket, while the counters added in this patch correspond
to /proc/net/{snmp,snmp6} pseudofiles. This patch implements the todo comment added in
the blamed commit.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

You must not submit more than one version of a patch within a 24h period.

Hi Jakub and sorry for the noise, didn't know that. Is there any way to check my patch against all patchwork checks ,specially the AI-reviewer before submitting it?

See https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

thanks.

maintainer
#5 lore raw
Quoted 11 lines · Mahdi Faramarzpour
Quoted 9 lines · Willem de Bruijn
Quoted 6 lines · Mahdi Faramarzpour
Quoted 5 lines · Jakub Kicinski
Quoted 3 lines · On Mon, 5 Jan 2026 15:17:32 +0330 Mahdi Faramarzpour wrote:

This commit adds SNMP drop count increment for the packets in per NUMA queues which were introduced in commit b650bf0977d3 ("udp: remove busylock and add per NUMA queues").

Quoted 8 lines
Quoted 4 lines

Can you give some rationale why the existing counters are insufficient and why you chose to change then number of counters you suggest between revisions of your patch?

The difference between revisions is due to me realizing that the only error the udp_rmem_schedule returns is ENOBUFS, which is mapped to UDP_MIB_MEMERRORS (refer to function __udp_queue_rcv_skb), and thus UDP_MIB_RCVBUFERRORS need not increase.

I see. Please make such a note in the revision changelog. See also

https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html#changes-requested

Quoted 9 lines
Quoted 4 lines

This code adds some cost to the hot path. The blamed commit added drop counters, most likely weighing the value of counters against their cost. I don't immediately see reason to revisit that.

AFAIU the drop_counter is per socket, while the counters added in this patch correspond
to /proc/net/{snmp,snmp6} pseudofiles. This patch implements the todo comment added in
the blamed commit.

Ah indeed.

The entire logic can be inside the unlikely(to_drop) branch right? No need to initialize the counters in the hot path, or do the skb->protocol earlier?

The previous busylock approach could also drop packets at this stage (goto uncharge_drop), and the skb is also dropped if exceeding rcvbuf. Neither of those conditions update SNMP stats. I'd like to understand what makes this case different.

Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

You must not submit more than one version of a patch within a 24h period.

Hi Jakub and sorry for the noise, didn't know that. Is there any way to check my patch against all patchwork checks ,specially the AI-reviewer before submitting it?

See https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

thanks.

#6 lore raw
Quoted 17 lines · Willem de Bruijn
Quoted 15 lines · Mahdi Faramarzpour
Quoted 13 lines · Willem de Bruijn
Quoted 6 lines · Mahdi Faramarzpour
Quoted 5 lines · Jakub Kicinski
Quoted 3 lines · On Mon, 5 Jan 2026 15:17:32 +0330 Mahdi Faramarzpour wrote:

This commit adds SNMP drop count increment for the packets in per NUMA queues which were introduced in commit b650bf0977d3 ("udp: remove busylock and add per NUMA queues").

Can you give some rationale why the existing counters are insufficient and why you chose to change then number of counters you suggest between revisions of your patch?

Quoted 9 lines
Quoted 4 lines

The difference between revisions is due to me realizing that the only error the udp_rmem_schedule returns is ENOBUFS, which is mapped to UDP_MIB_MEMERRORS (refer to function __udp_queue_rcv_skb), and thus UDP_MIB_RCVBUFERRORS need not increase.

I see. Please make such a note in the revision changelog. See also

https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html#changes-requested

Ok.

Quoted 10 lines
Quoted 9 lines
Quoted 4 lines

This code adds some cost to the hot path. The blamed commit added drop counters, most likely weighing the value of counters against their cost. I don't immediately see reason to revisit that.

AFAIU the drop_counter is per socket, while the counters added in this patch correspond
to /proc/net/{snmp,snmp6} pseudofiles. This patch implements the todo comment added in
the blamed commit.

Quoted 6 lines

Ah indeed.

The entire logic can be inside the unlikely(to_drop) branch right? No need to initialize the counters in the hot path, or do the skb->protocol earlier?

Right.

Quoted 5 lines

The previous busylock approach could also drop packets at this stage (goto uncharge_drop), and the skb is also dropped if exceeding rcvbuf. Neither of those conditions update SNMP stats. I'd like to understand what makes this case different.

The difference comes from the intermediate udp_prod_queue which contains packets from calls to __udp_enqueue_schedule_skb that reached this branch:

    if (!llist_add(&skb->ll_node, &udp_prod_queue->ll_root))
        return 0;

these packets might be dropped in batch later by the call that reaches the unlikely(to_drop) branch, and thus SNMP stats must increase. Note that such packets are only dropped due to the ENOBUFS returned from udp_rmem_schedule.

Quoted 12 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

You must not submit more than one version of a patch within a 24h period.

Hi Jakub and sorry for the noise, didn't know that. Is there any way to check my patch against all patchwork checks ,specially the AI-reviewer before submitting it?

See https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

thanks.

maintainer
#7 lore raw
Quoted 56 lines · Mahdi Faramarzpour
Quoted 17 lines · Willem de Bruijn
Quoted 15 lines · Mahdi Faramarzpour
Quoted 13 lines · Willem de Bruijn
Quoted 6 lines · Mahdi Faramarzpour
Quoted 5 lines · Jakub Kicinski
Quoted 3 lines · On Mon, 5 Jan 2026 15:17:32 +0330 Mahdi Faramarzpour wrote:

This commit adds SNMP drop count increment for the packets in per NUMA queues which were introduced in commit b650bf0977d3 ("udp: remove busylock and add per NUMA queues").

Can you give some rationale why the existing counters are insufficient and why you chose to change then number of counters you suggest between revisions of your patch?

Quoted 9 lines
Quoted 4 lines

The difference between revisions is due to me realizing that the only error the udp_rmem_schedule returns is ENOBUFS, which is mapped to UDP_MIB_MEMERRORS (refer to function __udp_queue_rcv_skb), and thus UDP_MIB_RCVBUFERRORS need not increase.

I see. Please make such a note in the revision changelog. See also

https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html#changes-requested

Ok.

Quoted 10 lines
Quoted 9 lines
Quoted 4 lines

This code adds some cost to the hot path. The blamed commit added drop counters, most likely weighing the value of counters against their cost. I don't immediately see reason to revisit that.

AFAIU the drop_counter is per socket, while the counters added in this patch correspond
to /proc/net/{snmp,snmp6} pseudofiles. This patch implements the todo comment added in
the blamed commit.

Quoted 6 lines

Ah indeed.

The entire logic can be inside the unlikely(to_drop) branch right? No need to initialize the counters in the hot path, or do the skb->protocol earlier?

Right.

Quoted 5 lines

The previous busylock approach could also drop packets at this stage (goto uncharge_drop), and the skb is also dropped if exceeding rcvbuf. Neither of those conditions update SNMP stats. I'd like to understand what makes this case different.

The difference comes from the intermediate udp_prod_queue which contains packets from calls to __udp_enqueue_schedule_skb that reached this branch:

Quoted 6 lines
    if (!llist_add(&skb->ll_node, &udp_prod_queue->ll_root))
        return 0;

these packets might be dropped in batch later by the call that reaches the unlikely(to_drop) branch, and thus SNMP stats must increase. Note that such packets are only dropped due to the ENOBUFS returned from udp_rmem_schedule.

Understood.

The difference with the other drops is that those are on the skb that is being passed to __udp_enqueue_schedule_skb, and are accounted to the SNMP stats in the caller when __udp_enqueue_schedule_skb returns with an error.

The skbs queued here cannot be accounted that way, so require additional separate SNMP adds.

Quoted 12 lines
Quoted 12 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

You must not submit more than one version of a patch within a 24h period.

Hi Jakub and sorry for the noise, didn't know that. Is there any way to check my patch against all patchwork checks ,specially the AI-reviewer before submitting it?

See https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

thanks.

maintainer
#8 lore raw
In reply to Mahdi Faramarzpour
Quoted 5 lines · On Tue, 6 Jan 2026 09:41:04 +0330 Mahdi Faramarzpour wrote:
Quoted 2 lines

You must not submit more than one version of a patch within a 24h period.

Hi Jakub and sorry for the noise, didn't know that. Is there any way to check my patch against all patchwork checks ,specially the AI-reviewer before submitting it?

Unfortunately we don't have sufficient funds to open up the access to AI reviews. But we are just using the public review prompts from Chris Mason https://lwn.net/Articles/1041694/ so if you have Gemini / Claude etc. access you can run them "locally".