Re: [PATCH v3] configurable maximum number of clients

2015-07-07 Thread Olivier Fourdan

Adding the dependency on xproto 7.0.28 that has been released last Wednesday 
which includes the patch to increase the number of file descriptors.

This is required for the second (dependent) patch which has already been 
reviewed by Adam, thus adding the R-b: Adam Jackson a...@redhat.com to that 
second patch.

Cheers,
Olivier
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Re: [PATCH v3] configurable maximum number of clients

2015-07-01 Thread Adam Jackson
On Wed, 2015-06-03 at 16:46 +0200, Olivier Fourdan wrote:
 Make the maximum number of clients user configurable, either from the command
 line or from xorg.conf

Reviewed-by: Adam Jackson a...@redhat.com

- ajax
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Re: [PATCH v3] configurable maximum number of clients

2015-06-15 Thread Olivier Fourdan
Hi all,

Could someone be so kind and take some time to do a review of this patch?

I know it's quite intrusive but tbh such a feature requires to touch the core 
of the X server.

It seems to work fine here (see my other email [1] with the test programs used 
to verify).

Thanks in advance,
Olivier

[1] http://lists.x.org/archives/xorg-devel/2015-June/046584.html

- Original Message -
 Make the maximum number of clients user configurable, either from the command
 line or from xorg.conf
 
 This patch works by using the MAXCLIENTS (raised to 512) as the maximum
 allowed number of clients, but allowing the actual limit to be set by the
 user to a lower value (keeping the default of 256).
 
 There is a limit size of 29 bits to be used to store both the client ID and
 the X resources ID, so by reducing the number of clients allowed to connect
 to
 the X server, the user can increase the number of X resources per client or
 vice-versa.
 
 Parts of this patch are based on a similar patch from Adam Jackson
 a...@redhat.com
 
 Signed-off-by: Adam Jackson a...@redhat.com
 Signed-off-by: Olivier Fourdan ofour...@redhat.com
 ---
  v2: Use the user set client limit in multiple places instead of MAXCLIENTS,
  Bump value for MAXCLIENTS, MAXSELECT, MAXSOCKS and OPEN_MAX to 512,
  Requires an updated Xproto.
  v3: Fix 256 limit still remaining in InitConnectionLimits()
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

[PATCH v3] configurable maximum number of clients

2015-06-03 Thread Olivier Fourdan
Make the maximum number of clients user configurable, either from the command
line or from xorg.conf

This patch works by using the MAXCLIENTS (raised to 512) as the maximum
allowed number of clients, but allowing the actual limit to be set by the
user to a lower value (keeping the default of 256).

There is a limit size of 29 bits to be used to store both the client ID and
the X resources ID, so by reducing the number of clients allowed to connect to
the X server, the user can increase the number of X resources per client or
vice-versa.

Parts of this patch are based on a similar patch from Adam Jackson
a...@redhat.com

Signed-off-by: Adam Jackson a...@redhat.com
Signed-off-by: Olivier Fourdan ofour...@redhat.com
---
 v2: Use the user set client limit in multiple places instead of MAXCLIENTS,
 Bump value for MAXCLIENTS, MAXSELECT, MAXSOCKS and OPEN_MAX to 512,
 Requires an updated Xproto.
 v3: Fix 256 limit still remaining in InitConnectionLimits()

 configure.ac   |  2 +-
 dix/colormap.c | 28 ++--
 dix/dispatch.c |  4 ++--
 dix/main.c |  2 +-
 dix/resource.c | 33 -
 hw/dmx/glxProxy/glxext.c   |  2 +-
 hw/xfree86/common/xf86Config.c | 16 
 hw/xfree86/man/xorg.conf.man   |  4 
 include/misc.h |  3 ++-
 include/opaque.h   |  1 +
 include/resource.h | 15 ++-
 man/Xserver.man|  5 +
 os/connection.c|  6 +++---
 os/osdep.h |  8 
 os/osinit.c|  3 +++
 os/utils.c | 14 ++
 16 files changed, 101 insertions(+), 45 deletions(-)

diff --git a/configure.ac b/configure.ac
index f760730..1473713 100644
--- a/configure.ac
+++ b/configure.ac
@@ -400,7 +400,7 @@ case $host_os in
AC_DEFINE(CSRG_BASED, 1, [System is BSD-like])
;;
   cygwin*|mingw*)
-   CFLAGS=$CFLAGS -DFD_SETSIZE=256
+   CFLAGS=$CFLAGS -DFD_SETSIZE=512
;;
 esac
 
diff --git a/dix/colormap.c b/dix/colormap.c
index a3e5a2c..80928b4 100644
--- a/dix/colormap.c
+++ b/dix/colormap.c
@@ -249,7 +249,7 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr 
pVisual,
 
 size = pVisual-ColormapEntries;
 sizebytes = (size * sizeof(Entry)) +
-(MAXCLIENTS * sizeof(Pixel *)) + (MAXCLIENTS * sizeof(int));
+(LimitClients * sizeof(Pixel *)) + (LimitClients * sizeof(int));
 if ((class | DynamicClass) == DirectColor)
 sizebytes *= 3;
 sizebytes += sizeof(ColormapRec);
@@ -274,7 +274,7 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr 
pVisual,
 sizebytes = size * sizeof(Entry);
 pmap-clientPixelsRed = (Pixel **) ((char *) pmap-red + sizebytes);
 pmap-numPixelsRed = (int *) ((char *) pmap-clientPixelsRed +
-  (MAXCLIENTS * sizeof(Pixel *)));
+  (LimitClients * sizeof(Pixel *)));
 pmap-mid = mid;
 pmap-flags = 0;/* start out with all flags clear */
 if (mid == pScreen-defColormap)
@@ -286,8 +286,8 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr 
pVisual,
 size = NUMRED(pVisual);
 pmap-freeRed = size;
 memset((char *) pmap-red, 0, (int) sizebytes);
-memset((char *) pmap-numPixelsRed, 0, MAXCLIENTS * sizeof(int));
-for (pptr = pmap-clientPixelsRed[MAXCLIENTS];
+memset((char *) pmap-numPixelsRed, 0, LimitClients * sizeof(int));
+for (pptr = pmap-clientPixelsRed[LimitClients];
  --pptr = pmap-clientPixelsRed;)
 *pptr = (Pixel *) NULL;
 if (alloc == AllocAll) {
@@ -310,26 +310,26 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr 
pVisual,
 if ((class | DynamicClass) == DirectColor) {
 pmap-freeGreen = NUMGREEN(pVisual);
 pmap-green = (EntryPtr) ((char *) pmap-numPixelsRed +
-  (MAXCLIENTS * sizeof(int)));
+  (LimitClients * sizeof(int)));
 pmap-clientPixelsGreen = (Pixel **) ((char *) pmap-green + 
sizebytes);
 pmap-numPixelsGreen = (int *) ((char *) pmap-clientPixelsGreen +
-(MAXCLIENTS * sizeof(Pixel *)));
+(LimitClients * sizeof(Pixel *)));
 pmap-freeBlue = NUMBLUE(pVisual);
 pmap-blue = (EntryPtr) ((char *) pmap-numPixelsGreen +
- (MAXCLIENTS * sizeof(int)));
+ (LimitClients * sizeof(int)));
 pmap-clientPixelsBlue = (Pixel **) ((char *) pmap-blue + sizebytes);
 pmap-numPixelsBlue = (int *) ((char *) pmap-clientPixelsBlue +
-   (MAXCLIENTS * sizeof(Pixel *)));
+   (LimitClients * sizeof(Pixel *)));
 
 memset((char *) pmap-green, 0, (int) 

Re: [PATCH v3] configurable maximum number of clients

2015-06-03 Thread Olivier Fourdan
Hi

This needs http://patchwork.freedesktop.org/patch/50714/ to be applied on X 
proto first.

Attaching the small programs I use to test this patch, of course the idea is 
tio choose between the number of clients or the number of resources per client 
(as both end up being in the same 29bit value), so both need to be tested.

With these patches I get pretty good results:

First run with 512 clients:

$ ./hw/kdrive/ephyr/Xephyr -maxclients 512 :10
$ DISPLAY=:10 ./countclients 
Maximum number of clients reached = 508 connections created

$ DISPLAY=:10 ./countres 
Resource mask: 0x000f
1048575 (0x000f) resources created!

Second run with 256 clients:

$ ./hw/kdrive/ephyr/Xephyr -maxclients 256 :10
$ DISPLAY=:10 ./countclients 
Maximum number of clients reached = 255 connections created

$ DISPLAY=:10 ./countres 
Resource mask: 0x001f
2097151 (0x001f) resources created!

Third run with 128 clients:

$ ./hw/kdrive/ephyr/Xephyr -maxclients 128 :10
$ DISPLAY=:10 ./countclients 
Maximum number of clients reached = 127 connections created

$ DISPLAY=:10 ./countres 
Resource mask: 0x003f
4194303 (0x003f) resources created!

Forth run with only 64 clients:

$ ./hw/kdrive/ephyr/Xephyr -maxclients 64 :10
$ DISPLAY=:10 ./countclients 
Maximum number of clients reached = 63 connections created

$ DISPLAY=:10 ./countres 
Resource mask: 0x007f
8388607 (0x007f) resources created!

Cheers,
Olivier/*
 * Compile with:
 * gcc -g -o countclients countclients.c -lX11
 */


#include stdio.h
#include stdlib.h
#include unistd.h
#include sys/types.h
#include sys/signal.h
#include sys/prctl.h
#include X11/Xlib.h
#include X11/Xlibint.h

int
main (int argc, char *argv[])
{
int count = 0;
char status;

do
{
pid_t pid;
int fd[2];
int nbytes;

pipe (fd);
if ((pid = fork ()) == -1)
{
perror (fork);
exit (1);
}

if (!pid)
{
/* Child */
Display *dpy;
Window win;
XEvent event;
int first = 1;

close (fd[0]);
prctl (PR_SET_PDEATHSIG, SIGTERM);
dpy = XOpenDisplay (NULL);
if (!dpy)
{
status = 0; /* Fail */
write (fd[1], status, sizeof (char));
exit (0);
}

win = XCreateSimpleWindow (dpy, 
   RootWindow (dpy, DefaultScreen (dpy)),
   count, count, 50, 50, 10,
   WhitePixel (dpy, DefaultScreen (dpy)),
   BlackPixel (dpy, DefaultScreen (dpy)));
XSelectInput (dpy, win, ExposureMask);
XMapRaised (dpy, win);
XFlush (dpy);

for (;;)
{
XNextEvent (dpy, event);
if (event.type == Expose  first)
{
status = 1; /* Success */
write (fd[1], status, sizeof (char));
first = 0;  /* Do it only once to avoid duplicates, you never know */
}
/* Loop forvever, we want to keep the connection alive */
}
exit (0);
}
else
{
/* Parent */
close (fd[1]);
do
nbytes = read (fd[0], status, sizeof (char));
while (nbytes  sizeof (char));

if (status)
count++;
}
}
while (status);

fprintf (stdout,  = %i connections created\n, count);

return 0;
}
/*
 * Compile with:
 * gcc -o countres countres.c -lX11
 */

#include stdio.h
#include stdlib.h
#include X11/Xlib.h
#include X11/Xlibint.h

static int status = 1;

static int
handleXError (Display * dpy, XErrorEvent * err)
{
status = 0; /* Fail */
return 0;
}

int
main (int argc, char *argv[])
{
Display *display;
int count = 0;
int mask;
XGCValues gcv;
GC gc;

display = XOpenDisplay (NULL);
if (!display)
{
fprintf (stderr, Cannot open display\n);
return -1;
}

XSetErrorHandler (handleXError);

mask = ((struct _XDisplay *) display)-resource_mask;
fprintf (stdout, Resource mask: 0x%0.8lx\n, mask);

do
{
gc = XCreateGC (display, DefaultRootWindow (display), 0L, gcv);
XSync (display, 0);
if (status)
count++;
while (status);

fprintf (stdout, %i (0x%0.8lx) resources created!\n, count, count);

return 0;
}
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel