dovecot-2.2: stats: Use the new str-table API to reduce memory u...

dovecot at dovecot.org dovecot at dovecot.org
Thu Nov 13 00:30:07 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/688da3675901
changeset: 18070:688da3675901
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Nov 13 02:28:46 2014 +0200
description:
stats: Use the new str-table API to reduce memory usage for service strings.
There are only a couple of services, while there can be a lot of sessions.

diffstat:

 src/stats/mail-session.c |  10 +++++++---
 src/stats/mail-stats.h   |   2 +-
 2 files changed, 8 insertions(+), 4 deletions(-)

diffs (70 lines):

diff -r 4c956747c36f -r 688da3675901 src/stats/mail-session.c
--- a/src/stats/mail-session.c	Thu Nov 13 02:24:46 2014 +0200
+++ b/src/stats/mail-session.c	Thu Nov 13 02:28:46 2014 +0200
@@ -4,6 +4,7 @@
 #include "ioloop.h"
 #include "hash.h"
 #include "llist.h"
+#include "str-table.h"
 #include "global-memory.h"
 #include "stats-settings.h"
 #include "mail-stats.h"
@@ -28,12 +29,13 @@
 static struct mail_session *mail_sessions_head, *mail_sessions_tail;
 static time_t session_guid_warn_hide_until;
 static bool session_guid_hide_warned = FALSE;
+static struct str_table *services;
 
 struct mail_session *stable_mail_sessions;
 
 static size_t mail_session_memsize(const struct mail_session *session)
 {
-	return sizeof(*session) + strlen(session->service) + 1;
+	return sizeof(*session) + 1;
 }
 
 static void mail_session_disconnect(struct mail_session *session)
@@ -99,7 +101,7 @@
 	}
 	session = i_new(struct mail_session, 1);
 	session->refcount = 1; /* unrefed at disconnect */
-	session->service = i_strdup(args[2]);
+	session->service = str_table_ref(services, args[2]);
 	memcpy(session->guid, session_guid, sizeof(session->guid));
 	session->pid = pid;
 	session->last_update = ioloop_timeval;
@@ -171,7 +173,7 @@
 		mail_ip_unref(&session->ip);
 	}
 
-	i_free(session->service);
+	str_table_unref(services, &session->service);
 	i_free(session);
 }
 
@@ -319,6 +321,7 @@
 		ioloop_time + SESSION_GUID_WARN_HIDE_SECS;
 	hash_table_create(&mail_sessions_hash, default_pool, 0,
 			  guid_128_hash, guid_128_cmp);
+	services = str_table_init();
 }
 
 void mail_sessions_deinit(void)
@@ -331,4 +334,5 @@
 		mail_session_free(mail_sessions_head);
 	}
 	hash_table_destroy(&mail_sessions_hash);
+	str_table_deinit(&services);
 }
diff -r 4c956747c36f -r 688da3675901 src/stats/mail-stats.h
--- a/src/stats/mail-stats.h	Thu Nov 13 02:24:46 2014 +0200
+++ b/src/stats/mail-stats.h	Thu Nov 13 02:28:46 2014 +0200
@@ -42,7 +42,7 @@
 	/* if guid is empty, the session no longer exists */
 	guid_128_t guid;
 	struct mail_user *user;
-	char *service;
+	const char *service;
 	pid_t pid;
 	/* ip address may be NULL if there's none */
 	struct mail_ip *ip;


More information about the dovecot-cvs mailing list