Navigation Menu

Skip to content

Commit

Permalink
Clamp the iomatrix size to IOV_MAX to fix Solaris
Browse files Browse the repository at this point in the history
  • Loading branch information
stash committed Apr 11, 2011
1 parent cf77690 commit f74c685
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
32 changes: 24 additions & 8 deletions Feersum.xs
Expand Up @@ -7,13 +7,10 @@
#include <ctype.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <sys/uio.h>

#include "ppport.h"

#include "picohttpparser-git/picohttpparser.c"

#include "rinq.c"

#ifdef __GNUC__
# define likely(x) __builtin_expect(!!(x), 1)
# define unlikely(x) __builtin_expect(!!(x), 0)
Expand Down Expand Up @@ -101,13 +98,21 @@
#define trace3(...)
#endif

#include <sys/uio.h>
#define IOMATRIX_SIZE 64
#include "picohttpparser-git/picohttpparser.c"
#include "rinq.c"

// Check FEERSUM_IOMATRIX_SIZE against what's actually usable on this
// platform. See $iomatrix_size in Makefile.PL for the default.
#if FEERSUM_IOMATRIX_SIZE > IOV_MAX
# undef FEERSUM_IOMATRIX_SIZE
# define FEERSUM_IOMATRIX_SIZE IOV_MAX
#endif

struct iomatrix {
unsigned offset;
unsigned count;
struct iovec iov[IOMATRIX_SIZE];
SV *sv[IOMATRIX_SIZE];
struct iovec iov[FEERSUM_IOMATRIX_SIZE];
SV *sv[FEERSUM_IOMATRIX_SIZE];
};

struct feer_req {
Expand Down Expand Up @@ -2613,4 +2618,15 @@ BOOT:

Zero(&psgix_io_vtbl, 1, MGVTBL);
psgix_io_vtbl.svt_get = psgix_io_svt_get;

trace3("Feersum booted, iomatrix %lu "
"(IOV_MAX=%u, FEERSUM_IOMATRIX_SIZE=%u), "
"feer_req %lu, "
"feer_conn %lu\n",
(long unsigned int)sizeof(struct iomatrix),
(unsigned int)IOV_MAX,
(unsigned int)FEERSUM_IOMATRIX_SIZE,
(long unsigned int)sizeof(struct feer_req),
(long unsigned int)sizeof(struct feer_conn)
);
}
14 changes: 13 additions & 1 deletion Makefile.PL
Expand Up @@ -58,6 +58,17 @@ if ($convert_deps) {
use Config;
my $steal = ($] >= 5.012 && !defined($Config{useithreads}));

# Control the size of the main write-buffer structure in feersum. Making this
# value lower will use slightly less memory per connection at the cost of
# speed and vice-versa. It's most noticeable when you're app is buffering a
# lot of sparce writes. The default of 64 generally keeps usage under 4k per
# connection on full 64-bit when you take into account the other connection
# and request structures.
# NOTE: If your OS defines IOV_MAX or UIO_MAXIOV then this value will be
# forced to be at most that size with a #define. Solaris defines IOV_MAX to
# be 16. Linux and OSX generally have IOV_MAX as 1024.
my $iomatrix_size = 64;

WriteMakefile(ev_args(
NAME => 'Feersum',
VERSION_FROM => 'lib/Feersum.pm',
Expand Down Expand Up @@ -92,7 +103,8 @@ WriteMakefile(ev_args(
},
LIBS => [''],
EXE_FILES => ['bin/feersum'],
DEFINE => ($steal ? '-DFEERSUM_STEAL' : ''),
DEFINE => "-DFEERSUM_IOMATRIX_SIZE=$iomatrix_size ".
($steal ? '-DFEERSUM_STEAL' : ''),
INC => '-I.',
dynamic_lib => {OTHERLDFLAGS => $otherldflags},
));

0 comments on commit f74c685

Please sign in to comment.