Skip to content

Instantly share code, notes, and snippets.

@nigoroll
Created September 8, 2016 11:53
Show Gist options
  • Save nigoroll/1cd3932172ca8ac03c2f3ef909fc1cf6 to your computer and use it in GitHub Desktop.
Save nigoroll/1cd3932172ca8ac03c2f3ef909fc1cf6 to your computer and use it in GitHub Desktop.
old MADV_DONTDUMP patch
commit 77444bb6dca702e075aa44f7b4c7358e87927163
Author: Nils Goroll <nils.goroll@uplex.de>
Date: Mon Apr 25 16:22:50 2016 +0200
MADV_DONTDUMP
diff --git a/bin/varnishd/storage/storage_file.c b/bin/varnishd/storage/storage_file.c
index dc15ddf..0915781 100644
--- a/bin/varnishd/storage/storage_file.c
+++ b/bin/varnishd/storage/storage_file.c
@@ -367,6 +367,10 @@ smf_open_chunk(struct smf_sc *sc, off_t sz, off_t off, off_t *fail, off_t *sum)
MAP_NOCORE | MAP_NOSYNC | MAP_SHARED, sc->fd, off);
if (p != MAP_FAILED) {
(void) madvise(p, sz, MADV_RANDOM);
+#ifdef HAVE_MADV_DONTDUMP
+ if (DO_DEBUG(DBG_STV_DONTDUMP))
+ (void) madvise(p, sz, MADV_DONTDUMP);
+#endif
(*sum) += sz;
new_smf(sc, p, off, sz);
return;
diff --git a/bin/varnishd/storage/storage_malloc.c b/bin/varnishd/storage/storage_malloc.c
index a936b2d..b69920d 100644
--- a/bin/varnishd/storage/storage_malloc.c
+++ b/bin/varnishd/storage/storage_malloc.c
@@ -31,6 +31,10 @@
#include "config.h"
+#ifdef HAVE_MADV_DONTDUMP
+#include <sys/mman.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
@@ -122,6 +126,11 @@ sma_alloc(const struct stevedore *st, size_t size)
sma->s.len = 0;
sma->s.space = size;
sma->s.magic = STORAGE_MAGIC;
+
+#ifdef HAVE_MADV_DONTDUMP
+ if (DO_DEBUG(DBG_STV_DONTDUMP))
+ (void) madvise(sma->s.ptr, sma->sz, MADV_DONTDUMP);
+#endif
return (&sma->s);
}
@@ -143,6 +152,10 @@ sma_free(struct storage *s)
if (sma_sc->sma_max != SIZE_MAX)
sma_sc->stats->g_space += sma->sz;
Lck_Unlock(&sma_sc->sma_mtx);
+#ifdef HAVE_MADV_DONTDUMP
+ if (DO_DEBUG(DBG_STV_DONTDUMP))
+ (void) madvise(sma->s.ptr, sma->sz, MADV_DODUMP);
+#endif
free(sma->s.ptr);
free(sma);
}
diff --git a/configure.ac b/configure.ac
index edba56a..46bb52e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -530,6 +530,11 @@ if test "$ac_cv_have_tcp_keep" = yes; then
fi
LIBS="${save_LIBS}"
+AC_CHECK_DEFINE([sys/mman.h],[MADV_DONTDUMP],
+ AC_DEFINE([HAVE_MADV_DONTDUMP], [1],
+ [Define if madvise knows about MADV_DONTDUMP]))
+
+
# Run-time directory
VARNISH_STATE_DIR='${localstatedir}/varnish'
AC_SUBST(VARNISH_STATE_DIR)
diff --git a/include/tbl/debug_bits.h b/include/tbl/debug_bits.h
index fa0d32f..14a4ad0 100644
--- a/include/tbl/debug_bits.h
+++ b/include/tbl/debug_bits.h
@@ -43,4 +43,5 @@ DEBUG_BIT(FLUSH_HEAD, flush_head, "Flush after http1 head")
DEBUG_BIT(VTC_MODE, vtc_mode, "Varnishtest Mode")
DEBUG_BIT(WITNESS, witness, "Emit WITNESS lock records")
DEBUG_BIT(VSM_KEEP, vsm_keep, "Keep the VSM file on restart")
+DEBUG_BIT(STV_DONTDUMP, stv_dontdump, "Reduce core size by calling madvise(MADV_DONTDUMP) on stevedore allocations")
/*lint -restore */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment