On Tue, May 02, 2000 at 10:24:13AM -0400, Marian Stagarescu wrote:
> Hi ,
> 
> I need you help with some networking related Linux/kernel issues.
> 
> 1) I do have a question related to setsockopt() too:
> 
> I am using the following settings:
> 
> /proc/sys/net/core/wmem_default 65535
> /proc/sys/net/core/rmem_default 65535 
> /proc/sys/net/core/wmem_max     65535
> /proc/sys/net/core/rmem_max     65535
> 
> and I am running an application where I use setsockopt()
> to set socket buffer to 80K for example.
> I check the setting by using getsockopt and I
> am getting 128K instead of 80K.
> 
> I looked into the implementation and here is the code:

[ code showing the kernel multiplying the buffer by 2 ]

Here's a post I made to this list a few days ago.  I have no issue
with the need for the doubling of the size (BSD compatibility), but I
think that getsockopt should return the correct number from the
perspective of the program (value/2).

David

-- 
  David Shaw  |  Chief Architect, Streaming Systems  |  Akamai Technologies
+---------------------------------------------------------------------------+
    [EMAIL PROTECTED]   |   617-250-3028   |   http://www.jabberwocky.com/


On Wed, Apr 26, 2000 at 11:18:33PM +0200, Andi Kleen wrote:
> On Wed, Apr 26, 2000 at 04:55:38PM -0400, David Shaw wrote:
> > On Wed, Apr 26, 2000 at 10:38:41PM +0200, Andi Kleen wrote:
> > > On Wed, Apr 26, 2000 at 04:19:55PM -0400, David Shaw wrote:
> > > > Hi,
> > > > 
> > > > Run the attached program under 2.0.36 and you get:
> > > >   Setting socket receive buffer size to 1024
> > > >   The socket receive buffer size was set to 1024
> > > > 
> > > > Run it under 2.2.14 and you get:
> > > >   Setting socket receive buffer size to 1024
> > > >   The socket receive buffer size was set to 2048
> > > > 
> > > > The code in question (/usr/src/linux/net/core/sock.c) seems to be very
> > > > clear - it doubles the value.
> > > > 
> > > > What do you think - bug?  Intentional?  Other?
> > > 
> > > Intentional.
> > 
> > Ah.  So if I want a buffer size of X should I ask for X/2, or should I
> > continue to ask for X?
> > 
> > What was the intention behind the change?
> 
> BSD compatibility. BSD does not account internal metadata, Linux assumes
> half of the buffer will be taken up for it. If the real value was used
> BSD applications would only get half the buffer they need.

Sounds reasonable.  The only thing is, why doesn't getsockopt return
the "right" (i.e. internal value divided by 2) answer.  After all,
from the program's perspective that IS what the value is.  Principle
of least surprise, and all that.

This exposes internal kernel stuff to the user and may make them do
the wrong thing.  For example, if a program tried to base internal
functionality on the buffer size it would do the wrong thing under
linux 2.2.

David

-- 
  David Shaw  |  Chief Architect, Streaming Systems  |  Akamai Technologies
+---------------------------------------------------------------------------+
    [EMAIL PROTECTED]   |   617-250-3028   |   http://www.jabberwocky.com/


Reply via email to