You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Dean Gaudet <dg...@arctic.org> on 1997/06/23 08:44:21 UTC

[PATCH] create fd slack (take 2)

Here it is with Marc's suggested improvements.  -DNO_SLACK will disable
all slack.  This is the version that I'm proposing for 1.2.1.  For 1.3
there's some api changes we can make down the road to give modules more
control over their own influence on slack.

Dean

Index: alloc.c
===================================================================
RCS file: /export/home/cvs/apache/src/alloc.c,v
retrieving revision 1.32
diff -c -3 -r1.32 alloc.c
*** alloc.c	1997/06/16 18:42:47	1.32
--- alloc.c	1997/06/23 06:42:01
***************
*** 58,65 ****
   * rst --- 4/95 --- 6/95
   */
  
! #include "conf.h"
! #include "alloc.h"
  #include "multithread.h"
  
  #include <stdarg.h>
--- 58,64 ----
   * rst --- 4/95 --- 6/95
   */
  
! #include "httpd.h"
  #include "multithread.h"
  
  #include <stdarg.h>
***************
*** 832,838 ****
    block_alarms();
    fd = open(name, flg, mode);
    save_errno = errno;
!   if (fd >= 0) note_cleanups_for_fd (a, fd);
    unblock_alarms();
    errno = save_errno;
    return fd;
--- 831,840 ----
    block_alarms();
    fd = open(name, flg, mode);
    save_errno = errno;
!   if (fd >= 0) {
!     fd = ap_slack (fd, AP_SLACK_HIGH);
!     note_cleanups_for_fd (a, fd);
!   }
    unblock_alarms();
    errno = save_errno;
    return fd;
***************
*** 884,889 ****
--- 886,892 ----
      desc = open(name, baseFlag | O_APPEND | O_CREAT,
  		modeFlags);
      if (desc >= 0) {
+       desc = ap_slack(desc, AP_SLACK_LOW);
        fd = fdopen(desc, mode);
      }
    } else {
Index: http_main.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_main.c,v
retrieving revision 1.157
diff -c -3 -r1.157 http_main.c
*** http_main.c	1997/06/21 22:27:11	1.157
--- http_main.c	1997/06/23 06:42:09
***************
*** 1819,1824 ****
--- 1819,1826 ----
          exit(1);
      }
  
+     s = ap_slack(s, AP_SLACK_HIGH);
+ 
      note_cleanups_for_socket(pconf, s); /* arrange to close on exec or restart */
      
  #ifndef MPE
Index: httpd.h
===================================================================
RCS file: /export/home/cvs/apache/src/httpd.h,v
retrieving revision 1.113
diff -c -3 -r1.113 httpd.h
*** httpd.h	1997/06/15 19:22:28	1.113
--- httpd.h	1997/06/23 06:42:10
***************
*** 271,276 ****
--- 271,277 ----
  #define DECLINED -1		/* Module declines to handle */
  #define OK 0			/* Module has handled this stage. */
  
+ 
  /* ----------------------- HTTP Status Codes  ------------------------- */
  
  #define RESPONSE_CODES 38
***************
*** 714,716 ****
--- 715,745 ----
  unsigned long get_virthost_addr (const char *hostname, unsigned short *port);
  
  extern time_t restart_time;
+ 
+ /*
+  * Apache tries to keep all of its long term filehandles (such as log files,
+  * and sockets) above this number.  This is to workaround problems in many
+  * third party libraries that are compiled with a small FD_SETSIZE.  There
+  * should be no reason to lower this, because it's only advisory.  If a file
+  * can't be allocated above this number then it will remain in the "slack"
+  * area.
+  *
+  * Only the low slack line is used by default.  If HIGH_SLACK_LINE is defined
+  * then an attempt is also made to keep all non-FILE * files above the high
+  * slack line.  This is to work around a Solaris C library limitation, where it
+  * uses an unsigned char to store the file descriptor.
+  */
+ #ifndef LOW_SLACK_LINE
+ #define LOW_SLACK_LINE	15
+ #endif
+ /* #define HIGH_SLACK_LINE	255 */
+ 
+ /*
+  * The ap_slack() function takes a fd, and tries to move it above the indicated
+  * line.  It returns an fd which may or may not have moved above the line, and
+  * never fails.  If the high line was requested and it fails it will also try
+  * the low line.
+  */
+ int ap_slack (int fd, int line);
+ #define AP_SLACK_LOW	1
+ #define AP_SLACK_HIGH	2
Index: util.c
===================================================================
RCS file: /export/home/cvs/apache/src/util.c,v
retrieving revision 1.54
diff -c -3 -r1.54 util.c
*** util.c	1997/06/22 20:35:26	1.54
--- util.c	1997/06/23 06:42:13
***************
*** 1334,1336 ****
--- 1334,1363 ----
      return (p);
  }
  #endif
+ 
+ 
+ int ap_slack (int fd, int line)
+ {
+ #if !defined(F_DUPFD) || defined(NO_SLACK)
+     return fd;
+ #else
+     int new_fd;
+ 
+ #ifdef HIGH_SLACK_LINE
+     if (line == AP_SLACK_HIGH) {
+ 	new_fd = fcntl (fd, F_DUPFD, HIGH_SLACK_LINE);
+ 	if (new_fd != -1) {
+ 	    close (fd);
+ 	    return new_fd;
+ 	}
+     }
+ #endif
+     /* otherwise just assume line == AP_SLACK_LOW */
+     new_fd = fcntl (fd, F_DUPFD, LOW_SLACK_LINE);
+     if (new_fd == -1) {
+       return fd;
+     }
+     close (fd);
+     return new_fd;
+ #endif
+ }


Re: [PATCH] create fd slack (take 2)

Posted by Marc Slemko <ma...@worldgate.com>.
On Sun, 22 Jun 1997, Dean Gaudet wrote:

> Here it is with Marc's suggested improvements.  -DNO_SLACK will disable
> all slack.  This is the version that I'm proposing for 1.2.1.  For 1.3
> there's some api changes we can make down the road to give modules more
> control over their own influence on slack.

You are proposing it for 1.2 with a patch against 1.3 source?  <g>

+1.  Isn't there a file or two where the define(s) should be documented?

> 
> Dean
> 
> Index: alloc.c
> ===================================================================
> RCS file: /export/home/cvs/apache/src/alloc.c,v
> retrieving revision 1.32
> diff -c -3 -r1.32 alloc.c
> *** alloc.c	1997/06/16 18:42:47	1.32
> --- alloc.c	1997/06/23 06:42:01
> ***************
> *** 58,65 ****
>    * rst --- 4/95 --- 6/95
>    */
>   
> ! #include "conf.h"
> ! #include "alloc.h"
>   #include "multithread.h"
>   
>   #include <stdarg.h>
> --- 58,64 ----
>    * rst --- 4/95 --- 6/95
>    */
>   
> ! #include "httpd.h"
>   #include "multithread.h"
>   
>   #include <stdarg.h>
> ***************
> *** 832,838 ****
>     block_alarms();
>     fd = open(name, flg, mode);
>     save_errno = errno;
> !   if (fd >= 0) note_cleanups_for_fd (a, fd);
>     unblock_alarms();
>     errno = save_errno;
>     return fd;
> --- 831,840 ----
>     block_alarms();
>     fd = open(name, flg, mode);
>     save_errno = errno;
> !   if (fd >= 0) {
> !     fd = ap_slack (fd, AP_SLACK_HIGH);
> !     note_cleanups_for_fd (a, fd);
> !   }
>     unblock_alarms();
>     errno = save_errno;
>     return fd;
> ***************
> *** 884,889 ****
> --- 886,892 ----
>       desc = open(name, baseFlag | O_APPEND | O_CREAT,
>   		modeFlags);
>       if (desc >= 0) {
> +       desc = ap_slack(desc, AP_SLACK_LOW);
>         fd = fdopen(desc, mode);
>       }
>     } else {
> Index: http_main.c
> ===================================================================
> RCS file: /export/home/cvs/apache/src/http_main.c,v
> retrieving revision 1.157
> diff -c -3 -r1.157 http_main.c
> *** http_main.c	1997/06/21 22:27:11	1.157
> --- http_main.c	1997/06/23 06:42:09
> ***************
> *** 1819,1824 ****
> --- 1819,1826 ----
>           exit(1);
>       }
>   
> +     s = ap_slack(s, AP_SLACK_HIGH);
> + 
>       note_cleanups_for_socket(pconf, s); /* arrange to close on exec or restart */
>       
>   #ifndef MPE
> Index: httpd.h
> ===================================================================
> RCS file: /export/home/cvs/apache/src/httpd.h,v
> retrieving revision 1.113
> diff -c -3 -r1.113 httpd.h
> *** httpd.h	1997/06/15 19:22:28	1.113
> --- httpd.h	1997/06/23 06:42:10
> ***************
> *** 271,276 ****
> --- 271,277 ----
>   #define DECLINED -1		/* Module declines to handle */
>   #define OK 0			/* Module has handled this stage. */
>   
> + 
>   /* ----------------------- HTTP Status Codes  ------------------------- */
>   
>   #define RESPONSE_CODES 38
> ***************
> *** 714,716 ****
> --- 715,745 ----
>   unsigned long get_virthost_addr (const char *hostname, unsigned short *port);
>   
>   extern time_t restart_time;
> + 
> + /*
> +  * Apache tries to keep all of its long term filehandles (such as log files,
> +  * and sockets) above this number.  This is to workaround problems in many
> +  * third party libraries that are compiled with a small FD_SETSIZE.  There
> +  * should be no reason to lower this, because it's only advisory.  If a file
> +  * can't be allocated above this number then it will remain in the "slack"
> +  * area.
> +  *
> +  * Only the low slack line is used by default.  If HIGH_SLACK_LINE is defined
> +  * then an attempt is also made to keep all non-FILE * files above the high
> +  * slack line.  This is to work around a Solaris C library limitation, where it
> +  * uses an unsigned char to store the file descriptor.
> +  */
> + #ifndef LOW_SLACK_LINE
> + #define LOW_SLACK_LINE	15
> + #endif
> + /* #define HIGH_SLACK_LINE	255 */
> + 
> + /*
> +  * The ap_slack() function takes a fd, and tries to move it above the indicated
> +  * line.  It returns an fd which may or may not have moved above the line, and
> +  * never fails.  If the high line was requested and it fails it will also try
> +  * the low line.
> +  */
> + int ap_slack (int fd, int line);
> + #define AP_SLACK_LOW	1
> + #define AP_SLACK_HIGH	2
> Index: util.c
> ===================================================================
> RCS file: /export/home/cvs/apache/src/util.c,v
> retrieving revision 1.54
> diff -c -3 -r1.54 util.c
> *** util.c	1997/06/22 20:35:26	1.54
> --- util.c	1997/06/23 06:42:13
> ***************
> *** 1334,1336 ****
> --- 1334,1363 ----
>       return (p);
>   }
>   #endif
> + 
> + 
> + int ap_slack (int fd, int line)
> + {
> + #if !defined(F_DUPFD) || defined(NO_SLACK)
> +     return fd;
> + #else
> +     int new_fd;
> + 
> + #ifdef HIGH_SLACK_LINE
> +     if (line == AP_SLACK_HIGH) {
> + 	new_fd = fcntl (fd, F_DUPFD, HIGH_SLACK_LINE);
> + 	if (new_fd != -1) {
> + 	    close (fd);
> + 	    return new_fd;
> + 	}
> +     }
> + #endif
> +     /* otherwise just assume line == AP_SLACK_LOW */
> +     new_fd = fcntl (fd, F_DUPFD, LOW_SLACK_LINE);
> +     if (new_fd == -1) {
> +       return fd;
> +     }
> +     close (fd);
> +     return new_fd;
> + #endif
> + }
>