|
|
836b22 |
From 38d4eabf1a8e61b4facdd3f2cb385498471d1ea9 Mon Sep 17 00:00:00 2001
|
|
|
836b22 |
From: Alexey Tikhonov <atikhono@redhat.com>
|
|
|
836b22 |
Date: Tue, 3 Mar 2020 18:44:11 +0100
|
|
|
836b22 |
Subject: [PATCH] mem-cache: sizes of free and data tables were made consistent
|
|
|
836b22 |
|
|
|
836b22 |
Since size of "free table" didn't account for SSS_AVG_*_PAYLOAD factor
|
|
|
836b22 |
only small fraction of "data table" was actually used.
|
|
|
836b22 |
SSS_AVG_*_PAYLOAD differentiation for different payload types only
|
|
|
836b22 |
affected size of hash table and was removed as unjustified.
|
|
|
836b22 |
|
|
|
836b22 |
Resolves: https://pagure.io/SSSD/sssd/issue/4160
|
|
|
836b22 |
(cherry picked from PR999)
|
|
|
836b22 |
|
|
|
836b22 |
Reviewed-by: Sumit Bose <sbose@redhat.com>
|
|
|
836b22 |
|
|
|
836b22 |
Reviewed-by: Sumit Bose <sbose@redhat.com>
|
|
|
836b22 |
---
|
|
|
836b22 |
src/responder/nss/nsssrv.c | 22 +++++++++++-------
|
|
|
836b22 |
src/responder/nss/nsssrv_mmap_cache.c | 33 +++++++--------------------
|
|
|
836b22 |
src/responder/nss/nsssrv_mmap_cache.h | 2 --
|
|
|
836b22 |
src/util/mmap_cache.h | 3 ---
|
|
|
836b22 |
4 files changed, 22 insertions(+), 38 deletions(-)
|
|
|
836b22 |
|
|
|
836b22 |
diff --git a/src/responder/nss/nsssrv.c b/src/responder/nss/nsssrv.c
|
|
|
836b22 |
index 87a3f1d50..d9fe28708 100644
|
|
|
836b22 |
--- a/src/responder/nss/nsssrv.c
|
|
|
836b22 |
+++ b/src/responder/nss/nsssrv.c
|
|
|
836b22 |
@@ -99,10 +99,9 @@ static int nss_clear_memcache(struct sbus_request *dbus_req, void *data)
|
|
|
836b22 |
return ret;
|
|
|
836b22 |
}
|
|
|
836b22 |
|
|
|
836b22 |
- /* TODO: read cache sizes from configuration */
|
|
|
836b22 |
DEBUG(SSSDBG_TRACE_FUNC, "Clearing memory caches.\n");
|
|
|
836b22 |
ret = sss_mmap_cache_reinit(nctx, nctx->mc_uid, nctx->mc_gid,
|
|
|
836b22 |
- SSS_MC_CACHE_ELEMENTS,
|
|
|
836b22 |
+ -1, /* keep current size */
|
|
|
836b22 |
(time_t) memcache_timeout,
|
|
|
836b22 |
&nctx->pwd_mc_ctx);
|
|
|
836b22 |
if (ret != EOK) {
|
|
|
836b22 |
@@ -112,7 +111,7 @@ static int nss_clear_memcache(struct sbus_request *dbus_req, void *data)
|
|
|
836b22 |
}
|
|
|
836b22 |
|
|
|
836b22 |
ret = sss_mmap_cache_reinit(nctx, nctx->mc_uid, nctx->mc_gid,
|
|
|
836b22 |
- SSS_MC_CACHE_ELEMENTS,
|
|
|
836b22 |
+ -1, /* keep current size */
|
|
|
836b22 |
(time_t) memcache_timeout,
|
|
|
836b22 |
&nctx->grp_mc_ctx);
|
|
|
836b22 |
if (ret != EOK) {
|
|
|
836b22 |
@@ -122,7 +121,7 @@ static int nss_clear_memcache(struct sbus_request *dbus_req, void *data)
|
|
|
836b22 |
}
|
|
|
836b22 |
|
|
|
836b22 |
ret = sss_mmap_cache_reinit(nctx, nctx->mc_uid, nctx->mc_gid,
|
|
|
836b22 |
- SSS_MC_CACHE_ELEMENTS,
|
|
|
836b22 |
+ -1, /* keep current size */
|
|
|
836b22 |
(time_t)memcache_timeout,
|
|
|
836b22 |
&nctx->initgr_mc_ctx);
|
|
|
836b22 |
if (ret != EOK) {
|
|
|
836b22 |
@@ -257,6 +256,11 @@ static void nss_dp_reconnect_init(struct sbus_connection *conn,
|
|
|
836b22 |
|
|
|
836b22 |
static int setup_memcaches(struct nss_ctx *nctx)
|
|
|
836b22 |
{
|
|
|
836b22 |
+ /* TODO: read cache sizes from configuration */
|
|
|
836b22 |
+ static const size_t SSS_MC_CACHE_PASSWD_SLOTS = 200000; /* 8mb */
|
|
|
836b22 |
+ static const size_t SSS_MC_CACHE_GROUP_SLOTS = 150000; /* 6mb */
|
|
|
836b22 |
+ static const size_t SSS_MC_CACHE_INITGROUP_SLOTS = 250000; /* 10mb */
|
|
|
836b22 |
+
|
|
|
836b22 |
int ret;
|
|
|
836b22 |
int memcache_timeout;
|
|
|
836b22 |
|
|
|
836b22 |
@@ -286,11 +290,11 @@ static int setup_memcaches(struct nss_ctx *nctx)
|
|
|
836b22 |
return EOK;
|
|
|
836b22 |
}
|
|
|
836b22 |
|
|
|
836b22 |
- /* TODO: read cache sizes from configuration */
|
|
|
836b22 |
ret = sss_mmap_cache_init(nctx, "passwd",
|
|
|
836b22 |
nctx->mc_uid, nctx->mc_gid,
|
|
|
836b22 |
SSS_MC_PASSWD,
|
|
|
836b22 |
- SSS_MC_CACHE_ELEMENTS, (time_t)memcache_timeout,
|
|
|
836b22 |
+ SSS_MC_CACHE_PASSWD_SLOTS,
|
|
|
836b22 |
+ (time_t)memcache_timeout,
|
|
|
836b22 |
&nctx->pwd_mc_ctx);
|
|
|
836b22 |
if (ret) {
|
|
|
836b22 |
DEBUG(SSSDBG_CRIT_FAILURE, "passwd mmap cache is DISABLED\n");
|
|
|
836b22 |
@@ -299,7 +303,8 @@ static int setup_memcaches(struct nss_ctx *nctx)
|
|
|
836b22 |
ret = sss_mmap_cache_init(nctx, "group",
|
|
|
836b22 |
nctx->mc_uid, nctx->mc_gid,
|
|
|
836b22 |
SSS_MC_GROUP,
|
|
|
836b22 |
- SSS_MC_CACHE_ELEMENTS, (time_t)memcache_timeout,
|
|
|
836b22 |
+ SSS_MC_CACHE_GROUP_SLOTS,
|
|
|
836b22 |
+ (time_t)memcache_timeout,
|
|
|
836b22 |
&nctx->grp_mc_ctx);
|
|
|
836b22 |
if (ret) {
|
|
|
836b22 |
DEBUG(SSSDBG_CRIT_FAILURE, "group mmap cache is DISABLED\n");
|
|
|
836b22 |
@@ -308,7 +313,8 @@ static int setup_memcaches(struct nss_ctx *nctx)
|
|
|
836b22 |
ret = sss_mmap_cache_init(nctx, "initgroups",
|
|
|
836b22 |
nctx->mc_uid, nctx->mc_gid,
|
|
|
836b22 |
SSS_MC_INITGROUPS,
|
|
|
836b22 |
- SSS_MC_CACHE_ELEMENTS, (time_t)memcache_timeout,
|
|
|
836b22 |
+ SSS_MC_CACHE_INITGROUP_SLOTS,
|
|
|
836b22 |
+ (time_t)memcache_timeout,
|
|
|
836b22 |
&nctx->initgr_mc_ctx);
|
|
|
836b22 |
if (ret) {
|
|
|
836b22 |
DEBUG(SSSDBG_CRIT_FAILURE, "initgroups mmap cache is DISABLED\n");
|
|
|
836b22 |
diff --git a/src/responder/nss/nsssrv_mmap_cache.c b/src/responder/nss/nsssrv_mmap_cache.c
|
|
|
836b22 |
index d5181d771..5296952a5 100644
|
|
|
836b22 |
--- a/src/responder/nss/nsssrv_mmap_cache.c
|
|
|
836b22 |
+++ b/src/responder/nss/nsssrv_mmap_cache.c
|
|
|
836b22 |
@@ -27,13 +27,6 @@
|
|
|
836b22 |
#include "responder/nss/nss_private.h"
|
|
|
836b22 |
#include "responder/nss/nsssrv_mmap_cache.h"
|
|
|
836b22 |
|
|
|
836b22 |
-/* arbitrary (avg of my /etc/passwd) */
|
|
|
836b22 |
-#define SSS_AVG_PASSWD_PAYLOAD (MC_SLOT_SIZE * 4)
|
|
|
836b22 |
-/* short group name and no gids (private user group */
|
|
|
836b22 |
-#define SSS_AVG_GROUP_PAYLOAD (MC_SLOT_SIZE * 3)
|
|
|
836b22 |
-/* average place for 40 supplementary groups + 2 names */
|
|
|
836b22 |
-#define SSS_AVG_INITGROUP_PAYLOAD (MC_SLOT_SIZE * 5)
|
|
|
836b22 |
-
|
|
|
836b22 |
#define MC_NEXT_BARRIER(val) ((((val) + 1) & 0x00ffffff) | 0xf0000000)
|
|
|
836b22 |
|
|
|
836b22 |
#define MC_RAISE_BARRIER(m) do { \
|
|
|
836b22 |
@@ -1253,25 +1246,15 @@ errno_t sss_mmap_cache_init(TALLOC_CTX *mem_ctx, const char *name,
|
|
|
836b22 |
enum sss_mc_type type, size_t n_elem,
|
|
|
836b22 |
time_t timeout, struct sss_mc_ctx **mcc)
|
|
|
836b22 |
{
|
|
|
836b22 |
+ /* sss_mc_header alone occupies whole slot,
|
|
|
836b22 |
+ * so each entry takes 2 slots at the very least
|
|
|
836b22 |
+ */
|
|
|
836b22 |
+ static const int PAYLOAD_FACTOR = 2;
|
|
|
836b22 |
+
|
|
|
836b22 |
struct sss_mc_ctx *mc_ctx = NULL;
|
|
|
836b22 |
unsigned int rseed;
|
|
|
836b22 |
- int payload;
|
|
|
836b22 |
int ret, dret;
|
|
|
836b22 |
|
|
|
836b22 |
- switch (type) {
|
|
|
836b22 |
- case SSS_MC_PASSWD:
|
|
|
836b22 |
- payload = SSS_AVG_PASSWD_PAYLOAD;
|
|
|
836b22 |
- break;
|
|
|
836b22 |
- case SSS_MC_GROUP:
|
|
|
836b22 |
- payload = SSS_AVG_GROUP_PAYLOAD;
|
|
|
836b22 |
- break;
|
|
|
836b22 |
- case SSS_MC_INITGROUPS:
|
|
|
836b22 |
- payload = SSS_AVG_INITGROUP_PAYLOAD;
|
|
|
836b22 |
- break;
|
|
|
836b22 |
- default:
|
|
|
836b22 |
- return EINVAL;
|
|
|
836b22 |
- }
|
|
|
836b22 |
-
|
|
|
836b22 |
mc_ctx = talloc_zero(mem_ctx, struct sss_mc_ctx);
|
|
|
836b22 |
if (!mc_ctx) {
|
|
|
836b22 |
return ENOMEM;
|
|
|
836b22 |
@@ -1306,9 +1289,9 @@ errno_t sss_mmap_cache_init(TALLOC_CTX *mem_ctx, const char *name,
|
|
|
836b22 |
|
|
|
836b22 |
/* hash table is double the size because it will store both forward and
|
|
|
836b22 |
* reverse keys (name/uid, name/gid, ..) */
|
|
|
836b22 |
- mc_ctx->ht_size = MC_HT_SIZE(n_elem * 2);
|
|
|
836b22 |
- mc_ctx->dt_size = MC_DT_SIZE(n_elem, payload);
|
|
|
836b22 |
- mc_ctx->ft_size = MC_FT_SIZE(n_elem);
|
|
|
836b22 |
+ mc_ctx->ht_size = MC_HT_SIZE(2 * n_elem / PAYLOAD_FACTOR);
|
|
|
836b22 |
+ mc_ctx->dt_size = n_elem * MC_SLOT_SIZE;
|
|
|
836b22 |
+ mc_ctx->ft_size = n_elem / 8; /* 1 bit per slot */
|
|
|
836b22 |
mc_ctx->mmap_size = MC_HEADER_SIZE +
|
|
|
836b22 |
MC_ALIGN64(mc_ctx->dt_size) +
|
|
|
836b22 |
MC_ALIGN64(mc_ctx->ft_size) +
|
|
|
836b22 |
diff --git a/src/responder/nss/nsssrv_mmap_cache.h b/src/responder/nss/nsssrv_mmap_cache.h
|
|
|
836b22 |
index e06257949..c40af2fb4 100644
|
|
|
836b22 |
--- a/src/responder/nss/nsssrv_mmap_cache.h
|
|
|
836b22 |
+++ b/src/responder/nss/nsssrv_mmap_cache.h
|
|
|
836b22 |
@@ -22,8 +22,6 @@
|
|
|
836b22 |
#ifndef _NSSSRV_MMAP_CACHE_H_
|
|
|
836b22 |
#define _NSSSRV_MMAP_CACHE_H_
|
|
|
836b22 |
|
|
|
836b22 |
-#define SSS_MC_CACHE_ELEMENTS 50000
|
|
|
836b22 |
-
|
|
|
836b22 |
struct sss_mc_ctx;
|
|
|
836b22 |
|
|
|
836b22 |
enum sss_mc_type {
|
|
|
836b22 |
diff --git a/src/util/mmap_cache.h b/src/util/mmap_cache.h
|
|
|
836b22 |
index 63e096027..d3d92bc98 100644
|
|
|
836b22 |
--- a/src/util/mmap_cache.h
|
|
|
836b22 |
+++ b/src/util/mmap_cache.h
|
|
|
836b22 |
@@ -40,9 +40,6 @@ typedef uint32_t rel_ptr_t;
|
|
|
836b22 |
|
|
|
836b22 |
#define MC_HT_SIZE(elems) ( (elems) * MC_32 )
|
|
|
836b22 |
#define MC_HT_ELEMS(size) ( (size) / MC_32 )
|
|
|
836b22 |
-#define MC_DT_SIZE(elems, payload) ( (elems) * (payload) )
|
|
|
836b22 |
-#define MC_FT_SIZE(elems) ( (elems) / 8 )
|
|
|
836b22 |
-/* ^^ 8 bits per byte so we need just elems/8 bytes to represent all blocks */
|
|
|
836b22 |
|
|
|
836b22 |
#define MC_PTR_ADD(ptr, bytes) (void *)((uint8_t *)(ptr) + (bytes))
|
|
|
836b22 |
#define MC_PTR_DIFF(ptr, base) ((uint8_t *)(ptr) - (uint8_t *)(base))
|
|
|
836b22 |
--
|
|
|
836b22 |
2.21.1
|
|
|
836b22 |
|