[PATCH] gencache: Add gencache values to memcache
Volker Lendecke
Volker.Lendecke at SerNet.DE
Mon Mar 10 13:43:36 MDT 2014
Hi!
Attached find a patch that caches gencache values in the
memcache. The gencache tdb access shows in profiles when
doing a lot of ACL checks (for example during open) with
large, similar ACLs. If I do 1.000.000 gencache_parse for an
existing value on my laptop, timing it shows
real 0m1.787s
user 0m0.672s
sys 0m1.056s
without this patch and
real 0m0.199s
user 0m0.152s
sys 0m0.008s
with this patch.
Review would be appreciated!
Thanks,
Volker
--
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From 6a6d9e556642d3ea0d80bdcf524805e3da9dab02 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 10 Mar 2014 15:41:32 +0100
Subject: [PATCH] gencache: Add gencache values to memcache
gencache_parse calling tdb shows up in profiles when we do a lot of open/close
traffic with large ACLs. For every file we convert unix ids to sids, and in the
domain member case this goes through gencache.
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/include/memcache.h | 1 +
source3/lib/gencache.c | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/source3/include/memcache.h b/source3/include/memcache.h
index 9362483..d5a0376 100644
--- a/source3/include/memcache.h
+++ b/source3/include/memcache.h
@@ -35,6 +35,7 @@ struct memcache;
enum memcache_number {
STAT_CACHE,
+ GENCACHE_RAM,
GETWD_CACHE,
GETPWNAM_CACHE, /* talloc */
MANGLE_HASH2_CACHE,
diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c
index 168b511..0fb1fd8 100644
--- a/source3/lib/gencache.c
+++ b/source3/lib/gencache.c
@@ -25,6 +25,7 @@
#include "system/filesys.h"
#include "system/glob.h"
#include "util_tdb.h"
+#include "memcache.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_TDB
@@ -37,6 +38,7 @@
static struct tdb_context *cache;
static struct tdb_context *cache_notrans;
+static int cache_notrans_seqnum;
/**
* @file gencache.c
@@ -112,6 +114,7 @@ static bool gencache_init(void)
cache_notrans = tdb_open_log(cache_fname, 0,
TDB_CLEAR_IF_FIRST|
TDB_INCOMPATIBLE_HASH|
+ TDB_SEQNUM|
TDB_NOSYNC,
open_flags, 0644);
if (cache_notrans == NULL) {
@@ -413,6 +416,7 @@ static bool gencache_pull_timeout(char *val, time_t *pres, char **pendptr)
struct gencache_parse_state {
void (*parser)(time_t timeout, DATA_BLOB blob, void *private_data);
void *private_data;
+ bool is_memcache;
};
static int gencache_parse_fn(TDB_DATA key, TDB_DATA data, void *private_data)
@@ -434,6 +438,13 @@ static int gencache_parse_fn(TDB_DATA key, TDB_DATA data, void *private_data)
blob = data_blob_const(
endptr+1, data.dsize - PTR_DIFF(endptr+1, data.dptr));
state->parser(t, blob, state->private_data);
+
+ if (!state->is_memcache) {
+ memcache_add(NULL, GENCACHE_RAM,
+ data_blob_const(key.dptr, key.dsize),
+ data_blob_const(data.dptr, data.dsize));
+ }
+
return 0;
}
@@ -444,6 +455,7 @@ bool gencache_parse(const char *keystr,
{
struct gencache_parse_state state;
TDB_DATA key = string_term_tdb_data(keystr);
+ DATA_BLOB memcache_val;
int ret;
if (keystr == NULL) {
@@ -459,6 +471,31 @@ bool gencache_parse(const char *keystr,
state.parser = parser;
state.private_data = private_data;
+ if (memcache_lookup(NULL, GENCACHE_RAM,
+ data_blob_const(key.dptr, key.dsize),
+ &memcache_val)) {
+ /*
+ * Make sure that nobody has changed the gencache behind our
+ * back.
+ */
+ int current_seqnum = tdb_get_seqnum(cache_notrans);
+ if (current_seqnum == cache_notrans_seqnum) {
+ /*
+ * Ok, our memcache is still current, use it without
+ * going to the tdb files.
+ */
+ state.is_memcache = true;
+ gencache_parse_fn(key, make_tdb_data(memcache_val.data,
+ memcache_val.length),
+ &state);
+ return true;
+ }
+ memcache_flush(NULL, GENCACHE_RAM);
+ cache_notrans_seqnum = current_seqnum;
+ }
+
+ state.is_memcache = false;
+
ret = tdb_parse_record(cache_notrans, key, gencache_parse_fn, &state);
if (ret == 0) {
return true;
--
1.7.9.5
More information about the samba-technical
mailing list