Live data from Hacker News

An eBPF loophole: Using XDP for egress traffic

loopholelabs.io

21–30 of 81 posts

Re: An eBPF loophole: Using XDP for egress traffic

#21

Hi HN, Shivansh (founder) here, happy to answer any questions folks might have about the implementation and the benchmarks!

I come from a very different world (optimizing the FreeBSD kernel for the Netflix CDN, running on bare metal) but performance leaps like this are fascinating to me. One of the things that struck me when reading this with only general knowledge of the linux kernel is: What makes things so terrible? Is iptables really that bad? Is something serialized to a single core somewhere in the other 3 scenarios? Is the CPU at 1…

As far as we can tell, it’s a mixture of a lot of things. One of the questions I got asked was how useful this is if you have a smaller performance requirement than 200Gbps (or, maybe a better way to put it, what if your host is small and can only do 10Gbps anyways).

You’ll have to wait for the follow up post with the CNI plugin for the full self-reproducible benchmark, but on a 16 core EC2 instance with a 10Gbps connection IPtables couldn’t do more than 5Gbps of throughput (TCP!), whereas again XDP was able to do 9.84Gbps on average.

Furthermore, running bidirectional iPerf3 tests in the larger hosts shows us that both ingress and egress throughput increase when we swap out iptables on just the egresss path.

This is all to say, our current assumption is when the CPU is thrashed by iPerf3, the RSS queues, the Linux kernel’s ksoftirqd threads, etc. all at once it destroys performance. XDP is moving some of the work outside the kernel, while at the same time the packet is only processed through the kernel stack half as much as without XDP (only on the path before or after the veth).

It really is all CPU usage in the end as far as I can tell. It’s not like our checksumming approach is any better than what the kernel already does.

Re: An eBPF loophole: Using XDP for egress traffic

#22
post #15

Earlier quoted context omitted.

I come from a very different world (optimizing the FreeBSD kernel for the Netflix CDN, running on bare metal) but performance leaps like this are fascinating to me. One of the things that struck me when reading this with only general knowledge of the linux kernel is: What makes things so terrible? Is iptables really that bad? Is something serialized to a single core somewhere in the other 3 scenarios? Is the CPU at 1…

It's also a bit depressing that everyone is still using the slower iptables, when nftables has been in the kernel for over a decade.

Actually the latest benchmarks were ran on a Fedora 43 host, which as far as I can tell uses the nftables backend for iptables!

Re: An eBPF loophole: Using XDP for egress traffic

#23

Really good, and glad that you're taking this technique further into a docker network plugin. I wouldn't be surprised to see a Kubernetes CNI appear using this approach, seems entirely viable unless I am missing something. I'll definitely be coming to check you all out at Kubecon.

Awesome we’ll be looking forward to it!

Re: An eBPF loophole: Using XDP for egress traffic

#25

Hi HN, Shivansh (founder) here, happy to answer any questions folks might have about the implementation and the benchmarks!

I come from a very different world (optimizing the FreeBSD kernel for the Netflix CDN, running on bare metal) but performance leaps like this are fascinating to me. One of the things that struck me when reading this with only general knowledge of the linux kernel is: What makes things so terrible? Is iptables really that bad? Is something serialized to a single core somewhere in the other 3 scenarios? Is the CPU at 1…

In the case of XDP, the reason it's so much faster is that it requires 0 allocations in the most common case. The DMA buffers are recycled in a page pool that's already allocated and mapped at least queue depth buffers for each hardware queue. XDP is simply running on the raw buffer data, then telling the driver what the user wants to do with the buffer. If all you are doing is rewriting an IP address, this is incredibly fast.

In the non XDP case (ebpf on TC) you have to allocate a sk buff and initialize it. This is very expensive, there's tons of accounting in the struct itself, and components that track every sk buff. Then there are the various CPU bound routing layers.

Overall the network core of Linux is very efficient. The actual page pool buffer isn't copied until the user reads data. But there's a million features the stack needs to support, and all of these cost efficiency.

Re: An eBPF loophole: Using XDP for egress traffic

#27
post #17
post #8

I understand they are attached to the phrase "loophole" but it feels fairly like they are using it as designed to me?

XDP is intended only for inbound traffic. They are exploiting veth pairs to make outbound traffic "look like" inbound traffic. That's the "loophole".

It's really not a loophole. I think this might literally be in the xdp-tutorials repo.

Re: An eBPF loophole: Using XDP for egress traffic

#29
post #15

Earlier quoted context omitted.

I come from a very different world (optimizing the FreeBSD kernel for the Netflix CDN, running on bare metal) but performance leaps like this are fascinating to me. One of the things that struck me when reading this with only general knowledge of the linux kernel is: What makes things so terrible? Is iptables really that bad? Is something serialized to a single core somewhere in the other 3 scenarios? Is the CPU at 1…

It's also a bit depressing that everyone is still using the slower iptables, when nftables has been in the kernel for over a decade.

Iptables uses nftables under the hood.

Re: An eBPF loophole: Using XDP for egress traffic

#30

For NAT (Network Address Translation) or any other packet header modifications, you need to recalculate checksums manually Why doesn’t checksum offload in the NIC take care of that?

And I'm confused how they have to correct the TCP checksum but not the IPv4 header checksum...
Post reply on HN