lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <AANLkTimodVFC8969md-f7iebS_9WvVahV9fPFFLtup73@mail.gmail.com>
Date:	Fri, 25 Feb 2011 18:45:00 +0200
From:	Daniel Baluta <dbaluta@...acom.com>
To:	Eric Dumazet <eric.dumazet@...il.com>
Cc:	netdev@...r.kernel.org, davem@...emloft.net,
	Rohan Chitradurga <rohan@...acom.com>
Subject: Re: [PATCH] udp: avoid searching when no ports are available

On Fri, Feb 25, 2011 at 2:06 PM, Eric Dumazet <eric.dumazet@...il.com> wrote:
> Le vendredi 25 février 2011 à 13:35 +0200, Daniel Baluta a écrit :
>> udp_lib_get_port uses a bitmap to mark used ports.
>>
>> When no ports are available we spend a lot of time, searching
>> for a port while holding hslot lock. Avoid this by checking if
>> bitmap is full.
>>
>>
>> Signed-off-by: Rohan Chitradurga <rohan@...acom.com>
>> Signed-off-by: Daniel Baluta <dbaluta@...acom.com>
>> ---
>>  net/ipv4/udp.c |    6 ++++++
>>  1 files changed, 6 insertions(+), 0 deletions(-)
>>
>> diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
>> index d37baaa..3e3592d 100644
>> --- a/net/ipv4/udp.c
>> +++ b/net/ipv4/udp.c
>> @@ -225,6 +225,12 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
>>                       udp_lib_lport_inuse(net, snum, hslot, bitmap, sk,
>>                                           saddr_comp, udptable->log);
>>
>> +                     /* avoid searching when no ports are available */
>> +                     if (bitmap_full(bitmap, PORTS_PER_CHAIN)) {
>> +                             spin_unlock_bh(&hslot->lock);
>> +                             break;
>> +                     }
>> +
>>                       snum = first;
>>                       /*
>>                        * Iterate on all possible values of snum for this hash.
>
> Really ? I wonder how you got your performance numbers then.
>
> First, PORTS_PER_CHAIN is wrong here, since its value is the max
> possible value (256 bits)

You are right. I have been working/testing on 2.6.32 where:

#define PORTS_PER_CHAIN (65536 / UDP_HTABLE_SIZE)

and I thought that the latest kernel has the same meaning
for PORTS_PER_CHAIN.

>
> #define UDP_HTABLE_SIZE_MIN              (CONFIG_BASE_SMALL ? 128 : 256)
> #define MAX_UDP_PORTS 65536
> #define PORTS_PER_CHAIN (MAX_UDP_PORTS / UDP_HTABLE_SIZE_MIN)   -> 256
>
> As soon as your machine (and most current machines have) has enough
> memory, UDP hash table size is not 256, but 1024 or 2048
>
> dmesg | grep "UDP hash"
> [    1.735203] UDP hash table entries: 2048 (order: 6, 327680 bytes)
>
> So real bitmap size is 64 or 32 bits.
>
> Your call to bitmap_full() always return false.

I guess now, the correct bitmap size is MAX_UDP_PORTS / (udptable->mask + 1)
or  MAX_UDP_PORTS >> udptable->log,  right?

> I dont like this patch. If you have special UDP needs on a small
> machine, just add to kernel boot param "uhash_entries=8192", so that the
> bitmap has 8 bits only.

We don't have special needs on a small machine. We just want that when
when all UDP ports are exhausted, bind calls to fail faster.

I will be back with tests on latest kernel.

thanks,
Daniel.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ