From: Marko Kreen Date: Fri, 11 Jan 2008 21:52:00 +0000 (+0000) Subject: move db/user/pool alloc also to slabs X-Git-Tag: pgbouncer_1_2_rc2~63 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6d5577eac502e5e4f9b411a45ef4129f38270fd5;p=pgbouncer move db/user/pool alloc also to slabs --- diff --git a/include/objects.h b/include/objects.h index 3e241cb..92f44a7 100644 --- a/include/objects.h +++ b/include/objects.h @@ -23,6 +23,9 @@ extern StatList database_list; extern StatList login_client_list; extern ObjectCache *client_cache; extern ObjectCache *server_cache; +extern ObjectCache *db_cache; +extern ObjectCache *pool_cache; +extern ObjectCache *user_cache; PgDatabase *find_database(const char *name); PgUser *find_user(const char *name); diff --git a/src/janitor.c b/src/janitor.c index a596313..301e090 100644 --- a/src/janitor.c +++ b/src/janitor.c @@ -527,7 +527,7 @@ static void kill_pool(PgPool *pool) list_del(&pool->map_head); statlist_remove(&pool->head, &pool_list); - free(pool); + obj_free(pool_cache, pool); } static void kill_database(PgDatabase *db) @@ -543,9 +543,9 @@ static void kill_database(PgDatabase *db) kill_pool(pool); } if (db->forced_user) - free(db->forced_user); + obj_free(user_cache, db->forced_user); statlist_remove(&db->head, &database_list); - free(db); + obj_free(db_cache, db); } /* as [pgbouncer] section can be loaded after databases, diff --git a/src/objects.c b/src/objects.c index 70c5686..7e15549 100644 --- a/src/objects.c +++ b/src/objects.c @@ -38,6 +38,9 @@ STATLIST(login_client_list); ObjectCache *server_cache; ObjectCache *client_cache; +ObjectCache *db_cache; +ObjectCache *pool_cache; +ObjectCache *user_cache; /* * libevent may still report events when event_del() @@ -114,6 +117,12 @@ static int user_node_cmp(long userptr, Node *node) void init_objects(void) { tree_init(&user_tree, user_node_cmp, NULL); + user_cache = objcache_create("user_cache", sizeof(PgUser), 0, NULL, NULL); + db_cache = objcache_create("db_cache", sizeof(PgDatabase), 0, NULL, NULL); + pool_cache = objcache_create("pool_cache", sizeof(PgPool), 0, NULL, NULL); + + if (!user_cache || !db_cache || !pool_cache) + fatal("cannot create initial caches"); } /* initialization after config loading */ @@ -300,7 +309,7 @@ PgDatabase *add_database(const char *name) /* create new object if needed */ if (db == NULL) { - db = zmalloc(sizeof(*db)); + db = obj_alloc(db_cache); if (!db) return NULL; @@ -318,7 +327,7 @@ PgUser *add_user(const char *name, const char *passwd) PgUser *user = find_user(name); if (user == NULL) { - user = zmalloc(sizeof(*user)); + user = obj_alloc(user_cache); if (!user) return NULL; @@ -338,7 +347,7 @@ PgUser *force_user(PgDatabase *db, const char *name, const char *passwd) { PgUser *user = db->forced_user; if (!user) { - user = zmalloc(sizeof(*user)); + user = obj_alloc(user_cache); if (!user) return NULL; list_init(&user->head); @@ -379,7 +388,7 @@ static PgPool *new_pool(PgDatabase *db, PgUser *user) { PgPool *pool; - pool = zmalloc(sizeof(*pool)); + pool = obj_alloc(pool_cache); if (!pool) return NULL;