Zero-copy kernel sniffer

本文介绍了一种零拷贝内核嗅探器的设计思路,通过重映射物理页面到用户进程空间,显著提升了数据处理速度。实测显示,与复制相同数量的数据相比,重映射操作快5至20倍。为了实现这一目标,采用了内核中提供的unmap_mapping_range()和__flush_tlb()等函数,并将主要重映射代码放入工作队列中执行。

Zero-copy kernel sniffer.


Basic idea behind zero-copy is remapping of the physical pages where skb->data lives to the userspace process.

According to my tests, which can be found commented in the code, remapping of one page gets from 5 upto 20 times faster than copying the same amount of data (i.e. PAGE_SIZE).

Since current VM code requires PTE to be unmapped, when remapping, but only exports unmap_mapping_range() and __flush_tlb(), I used them, although they are quite heavy monsters.
It also required mm->mmap_sem to be held, so I placed main remapping code into workqueue.
Current schema is following - according to mmap size I have some budget of packets, i.e. PAGE_SIZE per packet, so if 5 pages were requested to be mapped, so budget is 4, one page is reserved for control block.

New skbs are linked into per-socket queue where they are remapped into provided pointers, after remapping skb is queued into list of to be freed skbs. When remapping code will be called next time(i.e. new skb is being received) it checks if some timeout expires after the last freeing, if so, code frees all skbs from the free list except the last budget number of skbs. With high budget userspace will be able to read several times the same skb before budget is exhausted and skbs will be freed.
Duplicate reading can be eliminated by checking control block for the same skb cookie of even just offset of skb->data in the page - it is very unlikely in my tests that budget number of skbs will have the same offset of skb->data in the page.

Benchmarks can be found here. The latest version is always available in archive.

http://tservice.net.ru/~s0mbre/old/?section=projects&item=af_tlb

http://marc.info/?l=linux-netdev&m=112262743505711&w=2

http://tservice.net.ru/~s0mbre/archive/af_tlb/

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值