首页 > 其他分享 >free batches of packets in tcp_prune_ofo_queue()

free batches of packets in tcp_prune_ofo_queue()

时间:2024-06-01 23:00:14浏览次数:16  
标签:node sk batches prune packets tcp queue skb

  之前在做waf并发压力测试的时候,遇到一个问题,仪器测试正常,但是真实环境测试超时丢包的验证的时候,并发cps都很低。

查看cat /proc/net/netstat发现OfoPruned 对应值很大,看内核代码才发现,内存不够或rmem超过sk_rcvbuf,就会私房ofo队列,还是全部释放。当时将全部释放改为释放最高的50%,效果明显。

今天查看新的内核发现依旧修改了。

  在TCP套接口接收数据过程中,如果套接口接收缓存已经大于限定的套接口缓存限值,或者TCP系统占用的缓存已超过限定的总阈值,内核将使用tcp_prune_queue函数尝试回收接收队列占用的缓存。首先使用tcp_collapse_ofo_queue函数尝试合并out_of_order_queue队列中的重复数据,之后使用tcp_collapse函数尝试将sk_receive_queue队列中的数据折叠到少量的skb结构中;最后如果接收缓存还是占用过高,调用函数tcp_prune_ofo_queue删除out_of_order_queue队列中的数据包。

目前看最新的改动原则有:

/*
 * Clean the out-of-order queue to make room.
 * We drop high sequences packets to :
 * 1) Let a chance for holes to be filled.
 *    This means we do not drop packets from ooo queue if their sequence
 *    is before incoming packet sequence.
 * 2) not add too big latencies if thousands of packets sit there.
 *    (But if application shrinks SO_RCVBUF, we could still end up
 *     freeing whole queue here)
 * 3) Drop at least 12.5 % of sk_rcvbuf to avoid malicious attacks.
 *
 * Return true if queue has shrunk.
 */

1、让漏洞有机会被填补。这意味着如果数据包的序列位于传入数据包序列之前。

2、如果有数千个数据包停留在那里,则不会增加太大的延迟。(但如果应用程序缩小 SO_RCVBUF,我们仍然可能会此处释放整个队列)

针对这一块最新的内核改动如下:

/*
 * Clean the out-of-order queue to make room.
 * We drop high sequences packets to :
 * 1) Let a chance for holes to be filled.
 *    This means we do not drop packets from ooo queue if their sequence
 *    is before incoming packet sequence.
 * 2) not add too big latencies if thousands of packets sit there.
 *    (But if application shrinks SO_RCVBUF, we could still end up
 *     freeing whole queue here)
 * 3) Drop at least 12.5 % of sk_rcvbuf to avoid malicious attacks.
 *
 * Return true if queue has shrunk.
 */
static bool tcp_prune_ofo_queue(struct sock *sk, const struct sk_buff *in_skb)
{
	struct tcp_sock *tp = tcp_sk(sk);
	struct rb_node *node, *prev;
	bool pruned = false;
	int goal;

	if (RB_EMPTY_ROOT(&tp->out_of_order_queue))
		return false;

	goal = sk->sk_rcvbuf >> 3;
	node = &tp->ooo_last_skb->rbnode;

	do {
		struct sk_buff *skb = rb_to_skb(node);

		/* If incoming skb would land last in ofo queue, stop pruning. */
		if (after(TCP_SKB_CB(in_skb)->seq, TCP_SKB_CB(skb)->seq))
			break;
		pruned = true;
		prev = rb_prev(node);
		rb_erase(node, &tp->out_of_order_queue);
		goal -= skb->truesize;
		tcp_drop_reason(sk, skb, SKB_DROP_REASON_TCP_OFO_QUEUE_PRUNE);
		tp->ooo_last_skb = rb_to_skb(prev);
		if (!prev || goal <= 0) {
			if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf &&
			    !tcp_under_memory_pressure(sk))
				break;
			goal = sk->sk_rcvbuf >> 3;
		}
		node = prev;
	} while (node);

	if (pruned) {
		NET_INC_STATS(sock_net(sk), LINUX_MIB_OFOPRUNED);
		/* Reset SACK state.  A conforming SACK implementation will
		 * do the same at a timeout based retransmit.  When a connection
		 * is in a sad state like this, we care only about integrity
		 * of the connection not performance.
		 */
		if (tp->rx_opt.sack_ok)
			tcp_sack_reset(&tp->rx_opt);
	}
	return pruned;
}

需要注意的是:

1、/* If incoming skb would land last in ofo queue, stop pruning. */---

2、只有发生了重传队列修剪才会重置sack选项信息

 

当时修改内核的时候,默认删除50%的量直接就干了

 

标签:node,sk,batches,prune,packets,tcp,queue,skb
From: https://www.cnblogs.com/codestack/p/18226533

相关文章

  • air interface packets --- 蓝牙广播包
    LE物理层类型一共有三种,分别是LEUncodedPHYs(LE1Mand LE2M)、LECodedPHY,本文主要讲解LE1M报文格式前导码所有链路层数据包都有一组前导码,前导码被接收机用于执行频率同步、符号时序预估和自动增益控制(AGC)训练。前导码为固定的0和1交替二进制序列。对于在LE1M......
  • DrawCall、Batches、SetPassCalls
    详细看:https://blog.csdn.net/csuyuanxing/article/details/123005558https://blog.csdn.net/chqj_163/article/details/107675176一个batch是一个批次(cpu将一次渲染所需信息打包好准备发给gpu)一个drawcall是一次渲染指令的调用,基本等于batch,但可能受带宽的限制,一个大的batch......
  • Qualcomm LTE Packets log 分析
    QualcommLTEPacketslog分析来源 https://blog.csdn.net/qq_35427437/article/details/118078115来源 https://blog.51cto.com/u_13355654/6246809 1.涉及的PacketsPSS主同步信号数据捕获(InitialAcquisition)信令说明[0xB113][LL1] LTELL1PSSResults主......
  • docker system prune -a
    dockersystemprune-a  docker system prune -a 是一个Docker命令,用于清理Docker系统中未使用的镜像、容器、网络和数据卷等资源。这个命令会删除所有未被使用的资源,包括未被使用的...TRANSLATEwithxEnglishArabicHebrewPolishBulgarianHindi......
  • Linux中find命令的prune参数探究
     记得很久之前找过prune的参数使用,应急用了之后没有记录,但过了一段时间就会忘记,这次趁机找了一圈,包括Google-aosp里面的用法也对比参照了一下。 参考https://www.jianshu.com/p/e0a9fb35601a 发现描述基本没问题,使用上还有些差异,特此记录一下:<以下主要是 -prune-o-p......
  • 记录一下Linux下远程访问Mysql连接不上,报错The driver has not received any packets
    问题所在远程服务器已经提前安装好了MySQL,版本也是对应的。在ssh上可以正常进入MySQL数据库。但是其他地方无法连接上,例如navicat和IDE内部都发生报错。排查1.首先排查了一下远程服务器上mysql服务状态是否处于正常运行状态sudoservicemysqldstatus没有发生问题。2.检......
  • 重新定义:全新应用XPackets
    X·PacketsX·Packets是著名的文件搜索工具Everything的迭代品X·Packets相比Eveything,多了针对Windows文件资源管理器的一些GUI适配,若您安装了虚拟机VMware,也同时搜索虚拟机中的文件及应用同时,也装载宏编译,以达到更好的效果现在,X·Packet处于开发中,由TheMuggle开发......
  • Docker CLI docker container prune 常用命令
    Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的Linux或Windows操作系统的机器上,也可以实现虚拟化。Docker是内核虚拟化,不使用Hypervisor是不完全虚拟化,依赖内核的特性实现资源隔离。本文主要介绍DockerCLI中......
  • 如何解决系统报错:nf_conntrack: table full, dropping packets
    问题在系统日志中(/var/log/messages),有时会看到大面积的下面的报错:nf_conntrack:tablefull,droppingpacket这说明系统接到了大量的连接请求,但是系统的连接跟踪表已经满了,无法再记录新的连接了。这时候,系统会丢弃新的连接请求。在CentOS下,默认的连接跟踪表大小是65536,可......
  • 【THM】Packets & Frames(了解数据包和帧)-学习
    本文相关的TryHackMe实验房间链接:https://tryhackme.com/room/packetsframes本文相关内容:了解数据如何被分成更小的部分并通过网络传输到另一台设备。什么是数据包和帧?......