[prev in list] [next in list] [prev in thread] [next in thread]
List: openjdk-net-dev
Subject: RE: Patch for adding SO_REUSEPORT socket option
From: "Lu, Yingqi" <yingqi.lu () intel ! com>
Date: 2015-11-26 1:11:49
Message-ID: 9ACD5B67AAC5594CB6268234CF29CF9AA3A8A611 () ORSMSX113 ! amr ! corp ! intel ! com
[Download RAW message or body]
[Attachment #2 (text/plain)]
Here is an update.
Changes are already completed locally. All the tests passed on an old Linux kernel \
3.4.110 which does not have SO_REUSEPORT. Same tests are done on Linux 4.2 kernel \
before.
Here are the quick information on the current implementation:
1. For multicast socket, SO_REUSEPORT will be set by default if supported. We \
use Net.reuseportSupported method to check before calling setReusePort(). If not \
supported, will silently continue without setting it.
2. For socket, serversocket and datagramsocket, we check if SO_REUSEPORT is \
supported before calling setOption/getOption and setReusePort/ getReusePort methods. \
If not supported, UOE exception will be thrown.
3. We modified a bug in the OptionsTest.java file.
We will test Windows environment to see if it behaves the expected way. However, we \
need help to test other OSes from the community ☺
Due to the Thanksgiving holiday schedule, we will send updated webrev package on \
Monday.
Thank you all for your help and happy thanksgiving!
Lucy
From: Lu, Yingqi
Sent: Wednesday, November 25, 2015 1:23 PM
To: 'Volker Simonis' <volker.simonis@gmail.com>
Cc: Michael McMahon <michael.x.mcmahon@oracle.com>; Alan Bateman \
<Alan.Bateman@oracle.com>; Kharbas, Kishor <kishor.kharbas@intel.com>; \
net-dev@openjdk.java.net; Kaczmarek, Eric <eric.kaczmarek@intel.com>
Subject: RE: Patch for adding SO_REUSEPORT socket option
Yes, it should work! I already located the issues. Good catch!
I will submit an update as soon as possible.
Thanks,
Lucy
From: Volker Simonis [mailto:volker.simonis@gmail.com]
Sent: Wednesday, November 25, 2015 12:17 PM
To: Lu, Yingqi <yingqi.lu@intel.com<mailto:yingqi.lu@intel.com>>
Cc: Michael McMahon <michael.x.mcmahon@oracle.com<mailto:michael.x.mcmahon@oracle.com>>; \
Alan Bateman <Alan.Bateman@oracle.com<mailto:Alan.Bateman@oracle.com>>; Kharbas, \
Kishor <kishor.kharbas@intel.com<mailto:kishor.kharbas@intel.com>>; \
net-dev@openjdk.java.net<mailto:net-dev@openjdk.java.net>; Kaczmarek, Eric \
<eric.kaczmarek@intel.com<mailto:eric.kaczmarek@intel.com>>
Subject: Re: Patch for adding SO_REUSEPORT socket option
Yes, I indeed tested on an old kernel - but that should still work after your change!
On Wednesday, November 25, 2015, Lu, Yingqi \
<yingqi.lu@intel.com<mailto:yingqi.lu@intel.com>> wrote: Hi Volker,
Thanks very much for letting me know. I actually took the related regression tests \
and they all passed. I think you tested on an old kernel which does not have \
SO_REUSEPORT enabled. In this case, it should not set the flag.
Let me double check. I will get back to you as soon as I can.
Thanks,
Lucy
-----Original Message-----
From: Volker Simonis [mailto:volker.simonis@gmail.com<javascript:;>]
Sent: Wednesday, November 25, 2015 10:46 AM
To: Lu, Yingqi <yingqi.lu@intel.com<javascript:;>>
Cc: Michael McMahon <michael.x.mcmahon@oracle.com<javascript:;>>; Alan Bateman \
<Alan.Bateman@oracle.com<javascript:;>>; Kharbas, Kishor \
<kishor.kharbas@intel.com<javascript:;>>; net-dev@openjdk.java.net<javascript:;>; \
Kaczmarek, Eric <eric.kaczmarek@intel.com<javascript:;>>
Subject: Re: Patch for adding SO_REUSEPORT socket option
Hi Lucy,
I took a brief look at your changes but there seems to be something not right. I \
can't understand for example why you unconditionally try to set SO_REUSEPORT on all \
sockets in Java_sun_nio_ch_Net_socket0() ?
Also which your changes applied, simple regression tests like \
test/java/net/SocketOption/OptionsTest.java start to fail even on Linux/x86_64:
java.net.SocketException: Protocol not available
at java.net.PlainDatagramSocketImpl.socketSetOption0(Native Method)
at java.net.PlainDatagramSocketImpl.socketSetOption(PlainDatagramSocketImpl.java:85)
at java.net.AbstractPlainDatagramSocketImpl.setOption(AbstractPlainDatagramSocketImpl.java:314)
at java.net.DatagramSocket.setReusePort(DatagramSocket.java:1145)
at java.net.MulticastSocket.<init>(MulticastSocket.java:180)
at java.net.MulticastSocket.<init>(MulticastSocket.java:142)
at OptionsTest.doMcSocketTests(OptionsTest.java:131)
at OptionsTest.main(OptionsTest.java:247)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:520)
at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:92)
at java.lang.Thread.run(Thread.java:747)
Can you please make sure that your changes at least don't break the regression tests?
Thank you and best regards,
Volker
On Tue, Nov 24, 2015 at 6:04 PM, Lu, Yingqi <yingqi.lu@intel.com<javascript:;>> \
wrote:
> Hi Michael/Alan/Volker,
>
> Following your suggestions, here is the most recent version (Version
> 4) of the patch.
> http://cr.openjdk.java.net/~mcberg/jdk/6432031/webrev.04/
>
> In this version, we have done following changes:
>
> 1. Add reuseportSupported() method in sun.nio.ch.Net<http://sun.nio.ch.Net> and its \
> implementation in Net.c. Only add SO_REUSEPORT to the option set when it is \
> supported. In all the tests, we use supportedOptions method to test if SO_REUSEPORT \
> is supported or not.
> 2. We dropped NetworkChannels from the Javadoc. We removed Linux specific wordings \
> in Javadoc for SO_REUSEPORT.
> 3. We expand the feature to all UNIX based OSes. However, we do not have all the \
> OSes to test. Please test and let us know if there is anything missing in either \
> compilation or run time.
> Please review the patch and let us know your feedback. Thank you very much for your \
> help!
> Thanks,
> Lucy
>
> -----Original Message-----
> From: net-dev [mailto:net-dev-bounces@openjdk.java.net<javascript:;>] On Behalf Of
> Michael McMahon
> Sent: Monday, November 23, 2015 2:54 AM
> To: Volker Simonis <volker.simonis@gmail.com<javascript:;>>; Alan Bateman
> <Alan.Bateman@oracle.com<javascript:;>>
> Cc: Kharbas, Kishor <kishor.kharbas@intel.com<javascript:;>>;
> net-dev@openjdk.java.net<javascript:;>
> Subject: Re: Patch for adding SO_REUSEPORT socket option
>
> I agree we should enable the option on all platforms.
> We can add the code to do that and run the tests.
>
> On the existing use of SO_REUSEPORT on AIX and Mac it appears that is set to \
> emulate expected behavior on other platforms when SO_REUSEADDR is set for datagram \
> sockets. The expectation is that ports can be reused for datagram sockets and the \
> JCK tests this. So, I guess we have to leave this behavior by default, except if \
> SO_REUSEPORT is explicitly disabled maybe. Though this code hasn't been forward \
> ported to JDK 9 yet.
> For reference, SO_REUSEPORT on Linux is documented here
> http://man7.org/linux/man-pages/man7/socket.7.html
>
> - Michael
>
> On 23/11/15 09:13, Volker Simonis wrote:
> > Hi Lucy,
> >
> > in general I support the addition of SO_REUSEPORT to the set of
> > standard socket options. However for me the problem is not that this
> > new option is not supported on all platforms, but instead that it has
> > such different semantics on different platforms. If you look at the
> > code, you'll see that we already implicitly set SO_REUSEPORT on Mac
> > and AIX for datagram sockets for which we set SO_REUSEADDR. So maybe
> > we have to rethink this, once SO_REUSEPORT becomes available as a
> > standard socket option.
> >
> > I like the new wording you've posted for JavaDoc of SO_REUSEPORT, but
> > I think the sentence:
> >
> > * Although SO_REUSEADDR option already enables similar
> > * functionality, SO_REUSEPORT prevents port hijacking and
> > * distributes the involving datagrams evenly across all of the
> > * receiving threads.
> >
> > refers to a Linux-specific implementation detail which shouldn't be
> > mentioned in the general documentation. You already have the sentence
> > "The exact semantics of this socket option are socket type and system
> > dependent" which should let everybody think twice before using this
> > option. I'm also not sure about the link to the Linux article but I
> > again think it is inappropriate in a general API documentation
> > (otherwise we would have to add links for every platform which
> > supports SO_REUSEPORT).
> >
> > As far as I can see (and please correct me if I'm wrong) you actually
> > only add the new option for Linux platforms. But this socket option
> > is also supported on Solaris (>= 11), MacOS X, AIX. So could you
> > please enable it on the other platforms as well.
> >
> > Finally I want to mention the good stackoverflow article at
> > http://stackoverflow.com/questions/14388706/socket-options-so-reusead
> > d r-and-so-reuseport-how-do-they-differ-do-they-mean-t
> > which covers the topic SO_REUSEADDR vs. SO_REUSEPORT quite well. And
> > I've collected the man-page entries for SO_REUSEADDR and SO_REUSEPORT
> > for the systems I have (unfortunately, I couldn't find an updated
> > Linux man-page which mentions SO_REUSEPORT):
> >
> > Linux
> > =====
> >
> > SO_REUSEADDR
> > Indicates that the rules used in validating addresses
> > supplied in a bind(2) call should allow reuse of local
> > addresses. For AF_INET sockets this means that a socket
> > may bind, except when there is an active listening
> > socket bound to the address. When the listening socket
> > is bound to INADDR_ANY with a specific port then it is
> > not possi- ble to bind to this port for any local
> > address. Argument is an integer boolean flag.
> >
> > Linux will only allow port reuse with the SO_REUSEADDR option
> > when this option was set both in the previous program that
> > performed a bind(2) to the port and in the program that wants
> > to reuse the port. This differs from some implementations
> > (e.g., FreeBSD) where only the later program needs to set the
> > SO_REUSEADDR option. Typically this difference is invisi- ble,
> > since, for example, a server program is designed to always set
> > this option.
> >
> > MacOS X
> > =======
> > SO_REUSEADDR enables local address reuse
> > SO_REUSEPORT enables duplicate address and port bindings
> >
> > SO_REUSEADDR indicates that the rules used in validating
> > addresses supplied in a bind(2) call should allow reuse of local
> > addresses.
> >
> > SO_REUSEPORT allows completely duplicate bindings by multiple
> > processes if they all set SO_REUSEPORT before bind- ing the port.
> > This option permits multiple instances of a program to each
> > receive UDP/IP multicast or broadcast datagrams destined for the
> > bound port.
> >
> > Solaris
> > =======
> >
> > SO_REUSEADDR enable/disable local address reuse
> >
> >
> > SO_REUSEPORT enable/disable local port reuse for
> > PF_INET/PF_INET6 socket
> >
> > The SO_REUSEADDR/SO_REUSEPORT options indi- cate that the rules
> > used in validating addresses and ports supplied in a
> > bind(3SOCKET) call should allow reuse of local addresses or
> > ports.
> >
> > AIX
> > ===
> >
> > SO_REUSEADDR
> > Specifies that the rules used in validating
> > addresses supplied by a bind subroutine should
> > allow reuse of a local port. A particular IP
> > address can only be bound once to the same
> > port. This option enables or disables reuse of
> > local ports.
> >
> > SO_REUSEADDR allows an application to explicitly
> > deny subsequent bind subroutine to the port/address
> > of the socket with SO_REUSEADDR set. This allows an
> > application to block other applications from
> > binding with the bind subroutine.
> >
> > SO_REUSEPORT
> > Specifies that the rules used in validating
> > addresses supplied by a bind subroutine should
> > allow reuse of a local port/address
> > combination. Each binding of the port/address
> > combination must specify the SO_REUSEPORT socket
> > option. This option enables or disables the reuse
> > of local port/address combinations.
> >
> > HPUX
> > ====
> >
> > SO_REUSEADDR
> > (int; boolean; AF_INET sockets only) If enabled, allows
> > a local address to be reused in subsequent calls to
> > bind(). Default: disallowed.
> >
> > SO_REUSEPORT
> > (int; boolean; AF_INET sockets only) If enabled, allows
> > a local address and port to be reused in subsequent
> > calls to bind(). Default: disallowed.
> >
> > Setting the SO_REUSEADDR option allows the local socket address
> > to be reused in subsequent calls to bind(). This permits
> > multiple SOCK_STREAM sockets to be bound to the same local
> > address, as long as all existing sockets with the desired local
> > address are in a connected state before bind() is called for a
> > new socket. For SOCK_DGRAM sockets, SO_REUSEADDR allows
> > multiple sockets to receive UDP multicast datagrams addressed to
> > the bound port number. For all SOCK_DGRAM sockets bound to the
> > same local address, SO_REUSEADDR must be set before calling
> > bind().
> >
> > Setting the SO_REUSEPORT option allows multiple SOCK_DGRAM
> > sockets to share the same address and port. Each one of those
> > sockets, including the first one to use that port, must specify
> > this option before calling bind().
> >
> > Regards,
> > Volker
> >
> >
> > On Mon, Nov 23, 2015 at 9:00 AM, Alan Bateman \
> > <Alan.Bateman@oracle.com<javascript:;>> wrote:
> > >
> > > On 23/11/2015 04:12, Lu, Yingqi wrote:
> > >
> > > Hi Alan,
> > >
> > >
> > >
> > > One more question please J I want to make sure I understand
> > > correctly on your following suggestion. In order to use
> > > supportedOptions method to test SO_REUSEPORT, I will need to first
> > > write a native function to check if SO_REUSEPORT is supported. Then,
> > > in the defaultOptions method, I do a conditional add for
> > > StandardSocketOptions.SO_REUSEPORT
> > > if it is supported on the platform? Is this a preferred way to implement? \
> > > Please let me know!
> > >
> > > Yes as supportedOptions() shouldn't return SO_REUSEPORT in the set
> > > when it's not supported. It might be simplest to put that code in
> > > sun.nio.ch.Net<http://sun.nio.ch.Net>, maybe isReusePortSupported or some such \
> > > method. In the implementation
> > > (Net.c) then you can return true or false depending on the platform
> > > and maybe kernel version.
> > >
> > > -Alan
>
[Attachment #3 (text/html)]
<html xmlns:v="urn:schemas-microsoft-com:vml" \
xmlns:o="urn:schemas-microsoft-com:office:office" \
xmlns:w="urn:schemas-microsoft-com:office:word" \
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" \
xmlns="http://www.w3.org/TR/REC-html40"> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:SimSun;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"\@SimSun";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle17
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:#1F497D;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
@list l0
{mso-list-id:1588727522;
mso-list-type:hybrid;
mso-list-template-ids:-2128680830 67698703 67698713 67698715 67698703 67698713 \
67698715 67698703 67698713 67698715;} @list l0:level1
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l0:level2
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l0:level3
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l0:level4
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l0:level5
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l0:level6
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l0:level7
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l0:level8
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l0:level9
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l1
{mso-list-id:2122603040;
mso-list-type:hybrid;
mso-list-template-ids:781776878 67698703 67698713 67698715 67698703 67698713 \
67698715 67698703 67698713 67698715;} @list l1:level1
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l1:level2
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l1:level3
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l1:level4
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l1:level5
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l1:level6
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l1:level7
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l1:level8
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l1:level9
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
ol
{margin-bottom:0in;}
ul
{margin-bottom:0in;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Here \
is an update.<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Changes \
are already completed locally. All the tests passed on an old Linux kernel 3.4.110 \
which does not have SO_REUSEPORT. Same tests are done on Linux 4.2 kernel \
before.<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Here \
are the quick information on the current implementation:<o:p></o:p></span></p> <p \
class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l1 level1 lfo2"><![if \
!supportLists]><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><span \
style="mso-list:Ignore">1.<span style="font:7.0pt "Times New \
Roman""> \
</span></span></span><![endif]><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">For \
multicast socket, SO_REUSEPORT will be set by default if supported. We use \
Net.reuseportSupported method to check before calling setReusePort(). If not \
supported, will silently continue without setting it.<o:p></o:p></span></p> <p \
class="MsoListParagraph" style="text-indent:-.25in;mso-list:l1 level1 lfo2"><![if \
!supportLists]><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><span \
style="mso-list:Ignore">2.<span style="font:7.0pt "Times New \
Roman""> \
</span></span></span><![endif]><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">For \
socket, serversocket and datagramsocket, we check if SO_REUSEPORT is supported before \
calling setOption/getOption and setReusePort/ getReusePort methods. If not \
supported, UOE exception will be thrown. <o:p></o:p></span></p> <p \
class="MsoListParagraph" style="text-indent:-.25in;mso-list:l1 level1 lfo2"><![if \
!supportLists]><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><span \
style="mso-list:Ignore">3.<span style="font:7.0pt "Times New \
Roman""> \
</span></span></span><![endif]><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">We \
modified a bug in the OptionsTest.java file.<o:p></o:p></span></p> <p \
class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">We \
will test Windows environment to see if it behaves the expected way. However, we need \
help to test other OSes from the community </span><span \
style="font-size:11.0pt;font-family:Wingdings;color:#1F497D">J</span><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p></o:p></span></p>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Due \
to the Thanksgiving holiday schedule, we will send updated webrev package on \
Monday.<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Thank \
you all for your help and happy thanksgiving!<o:p></o:p></span></p> <p \
class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Lucy<o:p></o:p></span></p>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Lu, Yingqi <br>
<b>Sent:</b> Wednesday, November 25, 2015 1:23 PM<br>
<b>To:</b> 'Volker Simonis' <volker.simonis@gmail.com><br>
<b>Cc:</b> Michael McMahon <michael.x.mcmahon@oracle.com>; Alan Bateman \
<Alan.Bateman@oracle.com>; Kharbas, Kishor <kishor.kharbas@intel.com>; \
net-dev@openjdk.java.net; Kaczmarek, Eric <eric.kaczmarek@intel.com><br> \
<b>Subject:</b> RE: Patch for adding SO_REUSEPORT socket option<o:p></o:p></span></p> \
</div> </div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Yes, \
it should work! I already located the issues. Good catch! <o:p></o:p></span></p>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">I \
will submit an update as soon as possible.<o:p></o:p></span></p> <p \
class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Lucy<o:p></o:p></span></p>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Volker Simonis \
[<a href="mailto:volker.simonis@gmail.com">mailto:volker.simonis@gmail.com</a>] <br>
<b>Sent:</b> Wednesday, November 25, 2015 12:17 PM<br>
<b>To:</b> Lu, Yingqi <<a \
href="mailto:yingqi.lu@intel.com">yingqi.lu@intel.com</a>><br> <b>Cc:</b> Michael \
McMahon <<a href="mailto:michael.x.mcmahon@oracle.com">michael.x.mcmahon@oracle.com</a>>; \
Alan Bateman <<a href="mailto:Alan.Bateman@oracle.com">Alan.Bateman@oracle.com</a>>; \
Kharbas, Kishor <<a \
href="mailto:kishor.kharbas@intel.com">kishor.kharbas@intel.com</a>>; <a \
href="mailto:net-dev@openjdk.java.net">net-dev@openjdk.java.net</a>; Kaczmarek, Eric \
<<a href="mailto:eric.kaczmarek@intel.com">eric.kaczmarek@intel.com</a>><br> \
<b>Subject:</b> Re: Patch for adding SO_REUSEPORT socket option<o:p></o:p></span></p> \
<p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal">Yes, I indeed tested \
on an old kernel - but that should still work after your change!<br> <br>
On Wednesday, November 25, 2015, Lu, Yingqi <<a \
href="mailto:yingqi.lu@intel.com">yingqi.lu@intel.com</a>> wrote:<o:p></o:p></p> \
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in \
6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt"> <p \
class="MsoNormal">Hi Volker,<br> <br>
Thanks very much for letting me know. I actually took the related regression tests \
and they all passed. I think you tested on an old kernel which does not have \
SO_REUSEPORT enabled. In this case, it should not set the flag.<br> <br>
Let me double check. I will get back to you as soon as I can.<br>
<br>
Thanks,<br>
Lucy<br>
<br>
-----Original Message-----<br>
From: Volker Simonis [mailto:<a href="javascript:;">volker.simonis@gmail.com</a>]<br>
Sent: Wednesday, November 25, 2015 10:46 AM<br>
To: Lu, Yingqi <<a href="javascript:;">yingqi.lu@intel.com</a>><br>
Cc: Michael McMahon <<a href="javascript:;">michael.x.mcmahon@oracle.com</a>>; \
Alan Bateman <<a href="javascript:;">Alan.Bateman@oracle.com</a>>; Kharbas, \
Kishor <<a href="javascript:;">kishor.kharbas@intel.com</a>>; <a \
href="javascript:;">net-dev@openjdk.java.net</a>; Kaczmarek, Eric <<a \
href="javascript:;">eric.kaczmarek@intel.com</a>><br>
Subject: Re: Patch for adding SO_REUSEPORT socket option<br>
<br>
Hi Lucy,<br>
<br>
I took a brief look at your changes but there seems to be something not right. I \
can't understand for example why you unconditionally try to set SO_REUSEPORT on all \
sockets in Java_sun_nio_ch_Net_socket0() ?<br> <br>
Also which your changes applied, simple regression tests like \
test/java/net/SocketOption/OptionsTest.java start to fail even on<br> \
Linux/x86_64:<br> <br>
java.net.SocketException: Protocol not available<br>
at \
java.net.PlainDatagramSocketImpl.socketSetOption0(Native Method)<br> \
at java.net.PlainDatagramSocketImpl.socketSetOption(PlainDatagramSocketImpl.java:85)<br>
at \
java.net.AbstractPlainDatagramSocketImpl.setOption(AbstractPlainDatagramSocketImpl.java:314)<br>
at \
java.net.DatagramSocket.setReusePort(DatagramSocket.java:1145)<br> \
at java.net.MulticastSocket.<init>(MulticastSocket.java:180)<br> \
at \
java.net.MulticastSocket.<init>(MulticastSocket.java:142)<br> \
at OptionsTest.doMcSocketTests(OptionsTest.java:131)<br> \
at OptionsTest.main(OptionsTest.java:247)<br> \
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br> \
at \
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)<br> \
at \
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)<br>
at java.lang.reflect.Method.invoke(Method.java:520)<br>
at \
com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:92)<br> \
at java.lang.Thread.run(Thread.java:747)<br> <br>
<br>
Can you please make sure that your changes at least don't break the regression \
tests?<br> <br>
Thank you and best regards,<br>
Volker<br>
<br>
On Tue, Nov 24, 2015 at 6:04 PM, Lu, Yingqi <<a \
href="javascript:;">yingqi.lu@intel.com</a>> wrote:<br> > Hi \
Michael/Alan/Volker,<br> ><br>
> Following your suggestions, here is the most recent version (Version<br>
> 4) of the patch.<br>
> <a href="http://cr.openjdk.java.net/~mcberg/jdk/6432031/webrev.04/" \
target="_blank"> http://cr.openjdk.java.net/~mcberg/jdk/6432031/webrev.04/</a><br>
><br>
> In this version, we have done following changes:<br>
><br>
> 1. Add reuseportSupported() method in <a href="http://sun.nio.ch.Net" \
target="_blank"> sun.nio.ch.Net</a> and its implementation in Net.c. Only add \
SO_REUSEPORT to the option set when it is supported. In all the tests, we use \
supportedOptions method to test if SO_REUSEPORT is supported or not.<br> ><br>
> 2. We dropped NetworkChannels from the Javadoc. We removed Linux specific \
wordings in Javadoc for SO_REUSEPORT.<br> ><br>
> 3. We expand the feature to all UNIX based OSes. However, we do not have all the \
OSes to test. Please test and let us know if there is anything missing in either \
compilation or run time.<br> ><br>
> Please review the patch and let us know your feedback. Thank you very much for \
your help!<br> ><br>
> Thanks,<br>
> Lucy<br>
><br>
> -----Original Message-----<br>
> From: net-dev [mailto:<a \
href="javascript:;">net-dev-bounces@openjdk.java.net</a>] On Behalf Of<br> > \
Michael McMahon<br> > Sent: Monday, November 23, 2015 2:54 AM<br>
> To: Volker Simonis <<a href="javascript:;">volker.simonis@gmail.com</a>>; \
Alan Bateman<br> > <<a href="javascript:;">Alan.Bateman@oracle.com</a>><br>
> Cc: Kharbas, Kishor <<a \
href="javascript:;">kishor.kharbas@intel.com</a>>;<br> > <a \
href="javascript:;">net-dev@openjdk.java.net</a><br> > Subject: Re: Patch for \
adding SO_REUSEPORT socket option<br> ><br>
> I agree we should enable the option on all platforms.<br>
> We can add the code to do that and run the tests.<br>
><br>
> On the existing use of SO_REUSEPORT on AIX and Mac it appears that is set to \
emulate expected behavior on other platforms when SO_REUSEADDR is set for datagram \
sockets.<br> > The expectation is that ports can be reused for datagram sockets \
and the JCK tests this. So, I guess we have to leave this behavior by default, except \
if SO_REUSEPORT is explicitly disabled maybe. Though this code hasn't been forward \
ported to JDK 9 yet.<br> ><br>
> For reference, SO_REUSEPORT on Linux is documented here<br>
> <a href="http://man7.org/linux/man-pages/man7/socket.7.html" \
target="_blank">http://man7.org/linux/man-pages/man7/socket.7.html</a><br> ><br>
> - Michael<br>
><br>
> On 23/11/15 09:13, Volker Simonis wrote:<br>
>> Hi Lucy,<br>
>><br>
>> in general I support the addition of SO_REUSEPORT to the set of<br>
>> standard socket options. However for me the problem is not that this<br>
>> new option is not supported on all platforms, but instead that it has<br>
>> such different semantics on different platforms. If you look at the<br>
>> code, you'll see that we already implicitly set SO_REUSEPORT on Mac<br>
>> and AIX for datagram sockets for which we set SO_REUSEADDR. So maybe<br>
>> we have to rethink this, once SO_REUSEPORT becomes available as a<br>
>> standard socket option.<br>
>><br>
>> I like the new wording you've posted for JavaDoc of SO_REUSEPORT, but<br>
>> I think the sentence:<br>
>><br>
>> * Although SO_REUSEADDR option already enables similar<br>
>> * functionality, SO_REUSEPORT prevents port hijacking and<br>
>> * distributes the involving datagrams evenly across all of the<br>
>> * receiving threads.<br>
>><br>
>> refers to a Linux-specific implementation detail which shouldn't be<br>
>> mentioned in the general documentation. You already have the sentence<br>
>> "The exact semantics of this socket option are socket type and \
system<br> >> dependent" which should let everybody think twice before \
using this<br> >> option. I'm also not sure about the link to the Linux article \
but I<br> >> again think it is inappropriate in a general API documentation<br>
>> (otherwise we would have to add links for every platform which<br>
>> supports SO_REUSEPORT).<br>
>><br>
>> As far as I can see (and please correct me if I'm wrong) you actually<br>
>> only add the new option for Linux platforms. But this socket option<br>
>> is also supported on Solaris (>= 11), MacOS X, AIX. So could you<br>
>> please enable it on the other platforms as well.<br>
>><br>
>> Finally I want to mention the good stackoverflow article at<br>
>> <a href="http://stackoverflow.com/questions/14388706/socket-options-so-reusead" \
target="_blank"> http://stackoverflow.com/questions/14388706/socket-options-so-reusead</a><br>
>> d r-and-so-reuseport-how-do-they-differ-do-they-mean-t<br>
>> which covers the topic SO_REUSEADDR vs. SO_REUSEPORT quite well. And<br>
>> I've collected the man-page entries for SO_REUSEADDR and SO_REUSEPORT<br>
>> for the systems I have (unfortunately, I couldn't find an updated<br>
>> Linux man-page which mentions SO_REUSEPORT):<br>
>><br>
>> Linux<br>
>> =====<br>
>><br>
>> SO_REUSEADDR<br>
>> Indicates that the \
rules used in validating addresses<br> >> \
supplied in a bind(2) call should allow reuse of local<br> \
>> addresses. For \
AF_INET sockets this means that a socket<br> >> \
may bind, except when there is an active listening<br> \
>> socket bound to the \
address. When the listening socket<br> >> \
is bound to INADDR_ANY with a specific port then it \
is<br> >> not possi- ble \
to bind to this port for any local<br> >> \
address. Argument is an integer boolean flag.<br> \
>><br> >> Linux will only allow port \
reuse with the SO_REUSEADDR option<br> >> when \
this option was set both in the previous program that<br> >> \
performed a bind(2) to the port and in the program that wants<br> \
>> to reuse the port. This differs from \
some implementations<br> >> (e.g., FreeBSD) \
where only the later program needs to set the<br> >> \
SO_REUSEADDR option. Typically this difference is invisi- ble,<br> \
>> since, for example, a server program is \
designed to always set<br> >> this option.<br>
>><br>
>> MacOS X<br>
>> =======<br>
>> SO_REUSEADDR \
enables local address reuse<br> >> \
SO_REUSEPORT enables duplicate address and port bindings<br> \
>><br> >> SO_REUSEADDR indicates that the rules \
used in validating<br> >> addresses supplied in a \
bind(2) call should allow reuse of local<br> >> \
addresses.<br> >><br>
>> SO_REUSEPORT allows completely duplicate bindings \
by multiple<br> >> processes if they all set \
SO_REUSEPORT before bind- ing the port.<br> >> This \
option permits multiple instances of a program to each<br> >> \
receive UDP/IP multicast or broadcast datagrams destined for the<br> \
>> bound port.<br> >><br>
>> Solaris<br>
>> =======<br>
>><br>
>> SO_REUSEADDR \
enable/disable local address reuse<br> >><br>
>><br>
>> SO_REUSEPORT \
enable/disable local port reuse for<br> >> \
\
PF_INET/PF_INET6 socket<br> >><br>
>> The SO_REUSEADDR/SO_REUSEPORT options indi- cate \
that the rules<br> >> used in validating addresses \
and ports supplied in a<br> >> bind(3SOCKET) call \
should allow reuse of local addresses or<br> >> \
ports.<br> >><br>
>> AIX<br>
>> ===<br>
>><br>
>> SO_REUSEADDR<br>
>> \
Specifies that the rules used in validating<br> >> \
addresses supplied by a bind \
subroutine should<br> >> \
allow reuse of a local port. A particular IP<br> >> \
address can only \
be bound once to the same<br> >> \
port. This option enables or disables reuse of<br> \
>> \
local ports.<br> >><br>
>> \
SO_REUSEADDR allows an application to explicitly<br> >> \
deny subsequent bind \
subroutine to the port/address<br> >> \
of the socket with SO_REUSEADDR set. This allows \
an<br> >> \
application to block other applications from<br> >> \
binding with the bind \
subroutine.<br> >><br>
>> SO_REUSEPORT<br>
>> \
Specifies that the rules used in validating<br> >> \
addresses supplied by a bind \
subroutine should<br> >> \
allow reuse of a local port/address<br> >> \
combination. Each \
binding of the port/address<br> >> \
combination must specify the SO_REUSEPORT \
socket<br> >> \
option. This option enables or disables the reuse<br> >> \
of local \
port/address combinations.<br> >><br>
>> HPUX<br>
>> ====<br>
>><br>
>> SO_REUSEADDR<br>
>> (int; boolean; \
AF_INET sockets only) If enabled, allows<br> >> \
a local address to be reused in subsequent calls to<br> \
>> bind(). \
Default: disallowed.<br> >><br>
>> SO_REUSEPORT<br>
>> (int; boolean; \
AF_INET sockets only) If enabled, allows<br> >> \
a local address and port to be reused in subsequent<br> \
>> calls to \
bind(). Default: disallowed.<br> >><br>
>> Setting the SO_REUSEADDR option allows the local \
socket address<br> >> to be reused in subsequent \
calls to bind(). This permits<br> >> multiple \
SOCK_STREAM sockets to be bound to the same local<br> >> \
address, as long as all existing sockets with the desired local<br> \
>> address are in a connected state before bind() is \
called for a<br> >> new socket. For SOCK_DGRAM \
sockets, SO_REUSEADDR allows<br> >> multiple sockets \
to receive UDP multicast datagrams addressed to<br> >> \
the bound port number. For all SOCK_DGRAM sockets bound to the<br> \
>> same local address, SO_REUSEADDR must be set \
before calling<br> >> bind().<br>
>><br>
>> Setting the SO_REUSEPORT option allows multiple \
SOCK_DGRAM<br> >> sockets to share the same address \
and port. Each one of those<br> >> sockets, \
including the first one to use that port, must specify<br> >> \
this option before calling bind().<br> >><br>
>> Regards,<br>
>> Volker<br>
>><br>
>><br>
>> On Mon, Nov 23, 2015 at 9:00 AM, Alan Bateman <<a \
href="javascript:;">Alan.Bateman@oracle.com</a>> wrote:<br> >>><br>
>>> On 23/11/2015 04:12, Lu, Yingqi wrote:<br>
>>><br>
>>> Hi Alan,<br>
>>><br>
>>><br>
>>><br>
>>> One more question please J I want to make sure I understand<br>
>>> correctly on your following suggestion. In order to use<br>
>>> supportedOptions method to test SO_REUSEPORT, I will need to first<br>
>>> write a native function to check if SO_REUSEPORT is supported. Then,<br>
>>> in the defaultOptions method, I do a conditional add for<br>
>>> StandardSocketOptions.SO_REUSEPORT<br>
>>> if it is supported on the platform? Is this a preferred way to \
implement? Please let me know!<br> >>><br>
>>><br>
>>> Yes as supportedOptions() shouldn't return SO_REUSEPORT in the set<br>
>>> when it's not supported. It might be simplest to put that code in<br>
>>> <a href="http://sun.nio.ch.Net" target="_blank">sun.nio.ch.Net</a>, \
maybe isReusePortSupported or some such method. In<br> >>> the \
implementation<br> >>> (Net.c) then you can return true or false depending \
on the platform<br> >>> and maybe kernel version.<br>
>>><br>
>>> -Alan<br>
><o:p></o:p></p>
</blockquote>
</div>
</body>
</html>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic