public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: Bug(s) with creating large numbers of sockets
Date: Fri, 03 Nov 2017 20:36:00 -0000	[thread overview]
Message-ID: <20171103203614.GB18070@calimero.vinschen.de> (raw)
In-Reply-To: <CAOTD34buW09SOu8D+fcLZ+O22JsmuDMjyMj4B4tE6Bs_0LFa+g@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3276 bytes --]

Hi Erik,

why didn't you send this to cygwin-patches?  Not much of a problem,
just wondering...

On Nov  3 15:39, Erik Bray wrote:
> [...]
> After some playing around I found that I could make up to exactly 1365
> sockets and use them without error.  At 1366 I get the error.  A very
> strange and arbitrary number.  It turns out this is limited in Cygwin
> by the array in fhandler_socket.cc:
> 
>  496 /* Maximum number of concurrently opened sockets from all Cygwin processes
>  497    per session.  Note that shared sockets (through dup/fork/exec) are
>  498    counted as one socket. */
>  499 #define NUM_SOCKS       (32768 / sizeof (wsa_event))
> ...
>  510 static wsa_event wsa_events[NUM_SOCKS] __attribute__((section
> (".cygwin_dll     _common"), shared));
> 
> This choice for NUM_SOCKS is still seemingly small and pretty
> arbitrary, but at least it's a choice, and probably well-motivated.

This obviously dates back to pre-64 bit times.  The idea at the time was
that the .cygwin_dll_common section fits into a single 64K allocation
chunk.  Every section takes at least this 64K chunk, so we get away with
only one of them for this section.

Turns out, shared sections have a few issues so we even reduced the
usage and only kept stuff in which doesn't pose much of a problem.

Right now .cygwin_dll_common has a size of 0x8220 / 0x8200 of a max.
of 0x10000, so we have still lots of room and nothing really in need
of using a shared section.

> However, I think it's a problem that it's defined in terms of
> sizeof(wsa_event).  On 32-bit Cygwin this is 16, so NUM_SOCKS is 2048
> (a less strange number), whereas on 64-bit Cygwin sizeof(wsa_event) ==
> 24 (due to sizeof(long) == 8, plus alignment), so we are limited
> to...1365 sockets.
> 
> If we have to set a limit I would just hard-code it to 2048 exactly.
> I understand that the overhead associated with sockets in Cygwin
> probably limits us from having 10s of thousands (much less millions)
> and that's OK--I'm not trying to run some kind of C10K challenge on
> Cygwin :)

We only need another 0x220 bytes so we have a theoretical 0xfde0 / 64992
bytes or 2708 sockets for wsa_events on 64 bit.

So, yeah, I think you're right, 2048 is good number.  As I wrote in the
comment preceeding NUM_SOCKS, these are 2048 independent sockets per
user session in parallel.  Sockets created by dup or shared via
fork/exec only take one slot anyway.  2048 independent sockets per user
session should really suffice outside of testcases.

> The other problem, then, seems to be a bug in
> fhandler_socket::init_events().  It doesn't check the return value of
> search_wsa_event_slot(), which returns NULL if the wsa_events array is
> full (and the socket is not a shared socket).  There's not a great
> choice here for error code, but setting ENOBUF seems like the best
> option.

Yep, bug.  Thanks for catching.

> Please see attached patch.

Can you please send it to cygwin-patches with a bit of additional
comment (just a couple of words) why we choose 2048 here?


Thanks,
Corinna


-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2017-11-03 20:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-03 14:39 Erik Bray
2017-11-03 20:36 ` Corinna Vinschen [this message]
     [not found]   ` <CAOTD34ZjH-iwQhCMKgz4B8hRRzXMsbLPT3VEhV9YkjZoTj0oGg@mail.gmail.com>
     [not found]     ` <CAOTD34aGdwfRA2HXKTJGSQDo1sATN8Ji2kdNVR14CzgicFnC-w@mail.gmail.com>
2017-11-03 22:11       ` Erik Bray

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171103203614.GB18070@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).