Skip to contentSkip to conversation

Enhance AF_PACKET implementation to not require high order contiguous memory allocation

PATCH Eric Dumazet 4 participants 6 messages Oct 25, 2010 – Oct 26, 2010 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 9 lines · Le lundi 25 octobre 2010 à 18:14 -0400, [email protected] a écrit :

I think I remember those changes and IIrc yes, tcpdump will make several attempts to get buffers of an appropriate size. But while it tries to do that it bogs the system trying to write out pagecahe, swap, etc. And that activity doesn't guarantee success. His does either, but getting 5 order 0 pages is far easier and less intrusive to a loaded system than trying to get 1 order 4 chunk. That's all I'm trying to accomplish here. Just making it easier to use af_packet sockets without interfering with system performance

Actually, using vmalloc() would probably hurt performance, because of extra TLB pressure.

Of course, on recent x86 hardware you dont notice that much...

If not, why af_packet would use such convoluted double array of 'compound pages' ?

Also, on x86_32, vmalloc()/vmap() space is small (128 MB) so you might exhaust it pretty fast with several sniffers running.

I would try a two level thing : Try to get high order pages, and fallback on low order pages, but normally libpcap does this for us ?

#2 lore raw
Quoted 11 lines · Eric Dumazet
Quoted 9 lines · Le lundi 25 octobre 2010 à 18:14 -0400, [email protected] a écrit :

I think I remember those changes and IIrc yes, tcpdump will make several attempts to get buffers of an appropriate size. But while it tries to do that it bogs the system trying to write out pagecahe, swap, etc. And that activity doesn't guarantee success. His does either, but getting 5 order 0 pages is far easier and less intrusive to a loaded system than trying to get 1 order 4 chunk. That's all I'm trying to accomplish here. Just making it easier to use af_packet sockets without interfering with system performance

Quoted 5 lines

Actually, using vmalloc() would probably hurt performance, because of extra TLB pressure.

Of course, on recent x86 hardware you dont notice that much...

Exactly, you notice it a good deal less then you do the swapping that occurs if you try to allocate a contiguous order 4 chunk of RAM. That will bog down the system, even if the allocation ultimately fails.

Quoted 3 lines

If not, why af_packet would use such convoluted double array of 'compound pages' ?

Gah! Because I have blinders on, apparently. The origional implementation used a ring of pointer, and apparently I was so focused on keeping with that implementation, it never occured to me to just use vmalloc. That was stupid of me, I'll respin this and get rid of my idiocy.

Quoted 3 lines

Also, on x86_32, vmalloc()/vmap() space is small (128 MB) so you might exhaust it pretty fast with several sniffers running.

You might, although (assuming no other significant users), 64K * 32 ~= 1.5Mb. You could run 10 sniffers and only consume about 10-15% of the vmalloc space.

Quoted 4 lines

I would try a two level thing : Try to get high order pages, and fallback on low order pages, but normally libpcap does this for us ?

It does, but it tries them in that order, which causes the problem I'm describing, which is to say that attempting to get a large high order allocation causes the system to dig into swap and become unresponsive while it tries to assemble those allocations. I would suggest a vmalloc, with a backoff to high order allocation if that fails.

I'll post a new patch shortly.
Neil

Quoted 2 lines
maintainer
#3 lore raw

From: Neil Horman <[email protected]>
Date: Mon, 25 Oct 2010 19:35:58 -0400

Quoted 10 lines · Eric Dumazet
Quoted 4 lines

I would try a two level thing : Try to get high order pages, and fallback on low order pages, but normally libpcap does this for us ?

It does, but it tries them in that order, which causes the problem I'm describing, which is to say that attempting to get a large high order allocation causes the system to dig into swap and become unresponsive while it tries to assemble those allocations. I would suggest a vmalloc, with a backoff to high order allocation if that fails.

I think that logic should be maintained, except that one of the GFP_* flags should be specified so that it doesn't go all swap crazy on us, and instead fails a high order allocation earlier.

#5 lore raw
Quoted 5 lines · Maciej Żenczykowski

This is http://bugzilla.redhat.com/637619

I'm the original reporter and I haven't yet fully vetted / tested the patch (not directly related to my job and all that).

I validated it. You reported that tcpdump startup caused your system to 'freeze'. I managed to recreate that situation, as observed by my system becomming unresponsive on the console, and validated that that situation did not occur when this patch was applied.

Neil

#6 lore raw
In reply to David Miller
Quoted 14 lines · David Miller

From: Neil Horman <[email protected]>
Date: Mon, 25 Oct 2010 19:35:58 -0400

Quoted 10 lines · Eric Dumazet
Quoted 4 lines

I would try a two level thing : Try to get high order pages, and fallback on low order pages, but normally libpcap does this for us ?

It does, but it tries them in that order, which causes the problem I'm describing, which is to say that attempting to get a large high order allocation causes the system to dig into swap and become unresponsive while it tries to assemble those allocations. I would suggest a vmalloc, with a backoff to high order allocation if that fails.

Quoted 4 lines

I think that logic should be maintained, except that one of the GFP_* flags should be specified so that it doesn't go all swap crazy on us, and instead fails a high order allocation earlier.

I suppose we can do that. Specifically we can add __GFP_NORETRY so that we don't continually drive I/O or swap to get pages freed, but I think that all that will result in is earlier failures. No matter how you look at it, order 4 allocations are hard to come by, and we can make it work with non-contigous pages (the vmalloc case). Given that each of the cases can fail, I can see this being a workable fallback set:

1) get_free_pages (GFP_KERNEL|...+|__GFP_NORETRY)
2) vmalloc
3) get_free_pages (GFP_KERNEL|...)

Theres no reason to fail af_packet socket options just because the system is under presure. My only concern is that, since af_packet is typically used for debugging/tracing, I'd rather not have its memory allocation adversely affect system behavio.