PATCHSET: Minor performance things
Volker Lendecke
Volker.Lendecke at SerNet.DE
Wed Dec 4 14:13:37 MST 2013
Hi!
Attached find a few patches that live somewhere between
cleanup and minor performance things.
Please review/push!
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 c5befad0d1eb4bc3077f37b7b6818e0e8b1ce05b Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 3 Dec 2013 13:20:38 +0000
Subject: [PATCH 1/3] messaging3: Do not go through messages.tdb for
self-sends
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/messages_local.c | 54 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/source3/lib/messages_local.c b/source3/lib/messages_local.c
index c74c0aa..36a267a 100644
--- a/source3/lib/messages_local.c
+++ b/source3/lib/messages_local.c
@@ -354,6 +354,15 @@ static NTSTATUS message_notify(struct server_id procid)
Send a message to a particular pid.
****************************************************************************/
+struct messaging_tdb_self_state {
+ struct messaging_context *msg;
+ struct messaging_rec rec;
+};
+
+static void messaging_tdb_trigger_self(struct tevent_context *ev,
+ struct tevent_immediate *im,
+ void *private_data);
+
static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx,
struct server_id pid, int msg_type,
const DATA_BLOB *data,
@@ -380,6 +389,41 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx,
SMB_ASSERT(procid_to_pid(&pid) > 0);
+ if (server_id_equal(&msg_ctx->id, &pid)) {
+ struct messaging_tdb_self_state *state;
+ struct tevent_immediate *im;
+
+ TALLOC_FREE(frame);
+
+ im = tevent_create_immediate(msg_ctx);
+ if (im == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ state = talloc(im, struct messaging_tdb_self_state);
+ if (state == NULL) {
+ TALLOC_FREE(im);
+ return NT_STATUS_NO_MEMORY;
+ }
+ state->msg = msg_ctx;
+ state->rec.msg_version = MESSAGE_VERSION;
+ state->rec.msg_type = msg_type & MSG_TYPE_MASK;
+ state->rec.dest = pid;
+ state->rec.src = msg_ctx->id;
+
+ state->rec.buf = data_blob_talloc(
+ state, data->data, data->length);
+ if ((state->rec.buf.length != 0) &&
+ (state->rec.buf.data == NULL)) {
+ TALLOC_FREE(im);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ tevent_schedule_immediate(im, msg_ctx->event_ctx,
+ messaging_tdb_trigger_self, state);
+ return NT_STATUS_OK;
+ }
+
key = message_key_pid(frame, pid);
if (tdb_chainlock(tdb->tdb, key) != 0) {
@@ -437,6 +481,16 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx,
return status;
}
+static void messaging_tdb_trigger_self(struct tevent_context *ev,
+ struct tevent_immediate *im,
+ void *private_data)
+{
+ struct messaging_tdb_self_state *state = talloc_get_type_abort(
+ private_data, struct messaging_tdb_self_state);
+ messaging_dispatch_rec(state->msg, &state->rec);
+}
+
+
/****************************************************************************
Retrieve all messages for a process.
****************************************************************************/
--
1.7.9.5
From ea97d7f6aead0392ae1b88e58b59a83516d9a177 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 4 Dec 2013 15:14:03 +0000
Subject: [PATCH 2/3] idmap_cache: Use an fstring instead of talloc_asprintf
In a test doing one million uid2sid calls this brings down user CPU from
1.3 seconds to 0.9 seconds. And it saves a few code lines.
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/idmap_cache.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/source3/lib/idmap_cache.c b/source3/lib/idmap_cache.c
index ffd3c19..4564beb 100644
--- a/source3/lib/idmap_cache.c
+++ b/source3/lib/idmap_cache.c
@@ -200,17 +200,14 @@ bool idmap_cache_find_sid2gid(const struct dom_sid *sid, gid_t *pgid,
bool idmap_cache_find_uid2sid(uid_t uid, struct dom_sid *sid, bool *expired)
{
- char *key;
+ fstring key;
char *value;
time_t timeout;
bool ret = true;
- key = talloc_asprintf(talloc_tos(), "IDMAP/UID2SID/%d", (int)uid);
- if (key == NULL) {
- return false;
- }
+ fstr_sprintf(key, "IDMAP/UID2SID/%d", (int)uid);
+
ret = gencache_get(key, talloc_tos(), &value, &timeout);
- TALLOC_FREE(key);
if (!ret) {
return false;
}
@@ -237,17 +234,14 @@ bool idmap_cache_find_uid2sid(uid_t uid, struct dom_sid *sid, bool *expired)
bool idmap_cache_find_gid2sid(gid_t gid, struct dom_sid *sid, bool *expired)
{
- char *key;
+ fstring key;
char *value;
time_t timeout;
bool ret = true;
- key = talloc_asprintf(talloc_tos(), "IDMAP/GID2SID/%d", (int)gid);
- if (key == NULL) {
- return false;
- }
+ fstr_sprintf(key, "IDMAP/GID2SID/%d", (int)gid);
+
ret = gencache_get(key, talloc_tos(), &value, &timeout);
- TALLOC_FREE(key);
if (!ret) {
return false;
}
--
1.7.9.5
From ad4eaf3095c96083baa1dce3efb0203e37fa99d3 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 4 Dec 2013 15:37:21 +0000
Subject: [PATCH 3/3] idmap_cache: Use gencache_parse
This avoids a few tallocs and brings down user CPU a bit more
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/idmap_cache.c | 79 +++++++++++++++++++++++++++------------------
1 file changed, 47 insertions(+), 32 deletions(-)
diff --git a/source3/lib/idmap_cache.c b/source3/lib/idmap_cache.c
index 4564beb..8844171 100644
--- a/source3/lib/idmap_cache.c
+++ b/source3/lib/idmap_cache.c
@@ -188,6 +188,39 @@ bool idmap_cache_find_sid2gid(const struct dom_sid *sid, gid_t *pgid,
return true;
}
+struct idmap_cache_xid2sid_state {
+ struct dom_sid *sid;
+ bool *expired;
+ bool ret;
+};
+
+static void idmap_cache_xid2sid_parser(time_t timeout, DATA_BLOB blob,
+ void *private_data)
+{
+ struct idmap_cache_xid2sid_state *state =
+ (struct idmap_cache_xid2sid_state *)private_data;
+ char *value;
+
+ ZERO_STRUCTP(state->sid);
+ state->ret = false;
+
+ if ((blob.length == 0) || (blob.data[blob.length-1] != 0)) {
+ /*
+ * Not a string, can't be a valid mapping
+ */
+ return;
+ }
+
+ value = (char *)blob.data;
+
+ if (value[0] != '-') {
+ state->ret = string_to_sid(state->sid, value);
+ }
+ if (state->ret) {
+ *state->expired = (timeout <= time(NULL));
+ }
+}
+
/**
* Find a uid2sid mapping
* @param[in] uid the uid to map
@@ -201,25 +234,16 @@ bool idmap_cache_find_sid2gid(const struct dom_sid *sid, gid_t *pgid,
bool idmap_cache_find_uid2sid(uid_t uid, struct dom_sid *sid, bool *expired)
{
fstring key;
- char *value;
- time_t timeout;
- bool ret = true;
+ struct idmap_cache_xid2sid_state state;
fstr_sprintf(key, "IDMAP/UID2SID/%d", (int)uid);
- ret = gencache_get(key, talloc_tos(), &value, &timeout);
- if (!ret) {
- return false;
- }
- ZERO_STRUCTP(sid);
- if (value[0] != '-') {
- ret = string_to_sid(sid, value);
- }
- TALLOC_FREE(value);
- if (ret) {
- *expired = (timeout <= time(NULL));
- }
- return ret;
+ state.sid = sid;
+ state.expired = expired;
+ state.ret = false;
+
+ gencache_parse(key, idmap_cache_xid2sid_parser, &state);
+ return state.ret;
}
/**
@@ -235,25 +259,16 @@ bool idmap_cache_find_uid2sid(uid_t uid, struct dom_sid *sid, bool *expired)
bool idmap_cache_find_gid2sid(gid_t gid, struct dom_sid *sid, bool *expired)
{
fstring key;
- char *value;
- time_t timeout;
- bool ret = true;
+ struct idmap_cache_xid2sid_state state;
fstr_sprintf(key, "IDMAP/GID2SID/%d", (int)gid);
- ret = gencache_get(key, talloc_tos(), &value, &timeout);
- if (!ret) {
- return false;
- }
- ZERO_STRUCTP(sid);
- if (value[0] != '-') {
- ret = string_to_sid(sid, value);
- }
- TALLOC_FREE(value);
- if (ret) {
- *expired = (timeout <= time(NULL));
- }
- return ret;
+ state.sid = sid;
+ state.expired = expired;
+ state.ret = false;
+
+ gencache_parse(key, idmap_cache_xid2sid_parser, &state);
+ return state.ret;
}
/**
--
1.7.9.5
More information about the samba-technical
mailing list