From c6fd845824cf4c661bf2633e2f1b7dc72bed4858 Mon Sep 17 00:00:00 2001 From: phk Date: Sun, 3 Feb 2008 15:59:01 +0000 Subject: [PATCH] Look for the new SF_SYNC facility in FreeBSDs sendfile(2), and if we find it, allow its use, but still default to off via sendfile_threshold paramter. SF_SYNC is only available in FreeBSD-current as of a few seconds ago, and is unlikely to appear in any release before FreeBSD-8.0 for intricate reasons of ABI compliance. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2417 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 4 +-- varnish-cache/bin/varnishd/cache_pool.c | 8 ++--- varnish-cache/bin/varnishd/cache_response.c | 4 +-- varnish-cache/bin/varnishd/heritage.h | 2 +- varnish-cache/bin/varnishd/mgt_param.c | 8 ++--- varnish-cache/configure.ac | 34 ++++++++++++++------- 6 files changed, 36 insertions(+), 24 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index a3a34d69..2f88c25e 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -541,9 +541,9 @@ void WRK_Reset(struct worker *w, int *fd); unsigned WRK_Flush(struct worker *w); unsigned WRK_Write(struct worker *w, const void *ptr, int len); unsigned WRK_WriteH(struct worker *w, const txt *hh, const char *suf); -#ifdef HAVE_SENDFILE +#ifdef SENDFILE_WORKS void WRK_Sendfile(struct worker *w, int fd, off_t off, unsigned len); -#endif /* HAVE_SENDFILE */ +#endif /* SENDFILE_WORKS */ /* cache_session.c [SES] */ void SES_Init(void); diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index a5d961e2..90edfe2e 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -34,7 +34,7 @@ #include #include -#ifdef HAVE_SENDFILE +#ifdef SENDFILE_WORKS #if defined(__FreeBSD__) #include #elif defined(__linux__) @@ -42,7 +42,7 @@ #else #error Unknown sendfile() implementation #endif -#endif /* HAVE_SENDFILE */ +#endif /* SENDFILE_WORKS */ #include #include @@ -142,7 +142,7 @@ WRK_Write(struct worker *w, const void *ptr, int len) return (len); } -#ifdef HAVE_SENDFILE +#ifdef SENDFILE_WORKS void WRK_Sendfile(struct worker *w, int fd, off_t off, unsigned len) { @@ -174,7 +174,7 @@ WRK_Sendfile(struct worker *w, int fd, off_t off, unsigned len) #error Unknown sendfile() implementation #endif } -#endif /* HAVE_SENDFILE */ +#endif /* SENDFILE_WORKS */ /*--------------------------------------------------------------------*/ diff --git a/varnish-cache/bin/varnishd/cache_response.c b/varnish-cache/bin/varnishd/cache_response.c index 5831a135..aa4021f8 100644 --- a/varnish-cache/bin/varnishd/cache_response.c +++ b/varnish-cache/bin/varnishd/cache_response.c @@ -150,7 +150,7 @@ RES_WriteObj(struct sess *sp) CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC); u += st->len; sp->wrk->acct.bodybytes += st->len; -#ifdef HAVE_SENDFILE +#ifdef SENDFILE_WORKS /* * XXX: the overhead of setting up sendfile is not * XXX: epsilon and maybe not even delta, so avoid @@ -164,7 +164,7 @@ RES_WriteObj(struct sess *sp) st->where, st->len); continue; } -#endif /* HAVE_SENDFILE */ +#endif /* SENDFILE_WORKS */ VSL_stats->n_objwrite++; WRK_Write(sp->wrk, st->ptr, st->len); } diff --git a/varnish-cache/bin/varnishd/heritage.h b/varnish-cache/bin/varnishd/heritage.h index 79570101..e0e763c6 100644 --- a/varnish-cache/bin/varnishd/heritage.h +++ b/varnish-cache/bin/varnishd/heritage.h @@ -98,7 +98,7 @@ struct params { /* Fetcher hints */ unsigned fetch_chunksize; -#ifdef HAVE_SENDFILE +#ifdef SENDFILE_WORKS /* Sendfile object minimum size */ unsigned sendfile_threshold; #endif diff --git a/varnish-cache/bin/varnishd/mgt_param.c b/varnish-cache/bin/varnishd/mgt_param.c index c29eb86f..f850f0ff 100644 --- a/varnish-cache/bin/varnishd/mgt_param.c +++ b/varnish-cache/bin/varnishd/mgt_param.c @@ -371,7 +371,7 @@ tweak_fetch_chunksize(struct cli *cli, struct parspec *par, const char *arg) 4, UINT_MAX / 1024); } -#ifdef HAVE_SENDFILE +#ifdef SENDFILE_WORKS /*--------------------------------------------------------------------*/ static void @@ -381,7 +381,7 @@ tweak_sendfile_threshold(struct cli *cli, struct parspec *par, const char *arg) (void)par; tweak_generic_uint(cli, &master.sendfile_threshold, arg, 0, UINT_MAX); } -#endif /* HAVE_SENDFILE */ +#endif /* SENDFILE_WORKS */ /*--------------------------------------------------------------------*/ @@ -699,12 +699,12 @@ static struct parspec parspec[] = { "above 128kb a dubious idea.", EXPERIMENTAL, "128", "kilobytes" }, -#ifdef HAVE_SENDFILE +#ifdef SENDFILE_WORKS { "sendfile_threshold", tweak_sendfile_threshold, "The minimum size of objects transmitted with sendfile.", EXPERIMENTAL, "-1", "bytes" }, -#endif /* HAVE_SENDFILE */ +#endif /* SENDFILE_WORKS */ { "vcl_trace", tweak_vcl_trace, "Trace VCL execution in the shmlog.\n" "Enabling this will allow you to see the path each " diff --git a/varnish-cache/configure.ac b/varnish-cache/configure.ac index 3ea79a27..53263c70 100644 --- a/varnish-cache/configure.ac +++ b/varnish-cache/configure.ac @@ -103,18 +103,30 @@ AC_CHECK_FUNCS([strptime]) AC_CHECK_FUNCS([fmtcheck]) AC_CHECK_FUNCS([getdtablesize]) -# Don't look for sendfile at all, none of them work -# anyway. (don't tell when done with passed mem-range) -# ## This one is tricky, there are multiple versions -#case $host in -#*-*-freebsd*|*-*-linux*) -# AC_CHECK_FUNCS([sendfile]) -# ;; -#*) -# AC_MSG_WARN([won't look for sendfile() on $host]) -# ;; -#esac +case $host in +*-*-freebsd*) + AC_CACHE_CHECK([whether sendfile works], + [ac_cv_so_sendfile_works], + [AC_RUN_IFELSE( + [AC_LANG_PROGRAM([[ + #include + #include + #include + ]],[[ + return (SF_SYNC == 0); + ]])], + [ac_cv_so_sendfile_works=yes], + [ac_cv_so_sendfile_works=no]) + ]) + if test "$ac_cv_so_sendfile_works" = yes; then + AC_DEFINE([SENDFILE_WORKS], [1], [Define if SENDFILE works]) + fi + ;; +*) + AC_MSG_WARN([won't look for sendfile() on $host]) + ;; +esac # These functions are provided by libcompat on platforms where they # are not available -- 2.39.5