dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0028-mem-cache-sizes-of-free-and-data-tables-were-made-co.patch

1bb595
From 2d90e642078c15f001b34a0a50a67fa6eac9a3b9 Mon Sep 17 00:00:00 2001
1bb595
From: Alexey Tikhonov <atikhono@redhat.com>
1bb595
Date: Tue, 3 Mar 2020 18:44:11 +0100
1bb595
Subject: [PATCH 28/35] mem-cache: sizes of free and data tables were made
1bb595
 consistent
1bb595
1bb595
Since size of "free table" didn't account for SSS_AVG_*_PAYLOAD factor
1bb595
only small fraction of "data table" was actually used.
1bb595
SSS_AVG_*_PAYLOAD differentiation for different payload types only
1bb595
affected size of hash table and was removed as unjustified.
1bb595
1bb595
Resolves:
1bb595
https://github.com/SSSD/sssd/issues/5115
1bb595
1bb595
Reviewed-by: Sumit Bose <sbose@redhat.com>
1bb595
---
1bb595
 src/responder/nss/nsssrv.c            | 22 +++++++++++-------
1bb595
 src/responder/nss/nsssrv_mmap_cache.c | 33 +++++++--------------------
1bb595
 src/responder/nss/nsssrv_mmap_cache.h |  2 --
1bb595
 src/util/mmap_cache.h                 |  3 ---
1bb595
 4 files changed, 22 insertions(+), 38 deletions(-)
1bb595
1bb595
diff --git a/src/responder/nss/nsssrv.c b/src/responder/nss/nsssrv.c
1bb595
index 87300058f..21d93ae77 100644
1bb595
--- a/src/responder/nss/nsssrv.c
1bb595
+++ b/src/responder/nss/nsssrv.c
1bb595
@@ -83,10 +83,9 @@ nss_clear_memcache(TALLOC_CTX *mem_ctx,
1bb595
         return ret;
1bb595
     }
1bb595
 
1bb595
-    /* TODO: read cache sizes from configuration */
1bb595
     DEBUG(SSSDBG_TRACE_FUNC, "Clearing memory caches.\n");
1bb595
     ret = sss_mmap_cache_reinit(nctx, nctx->mc_uid, nctx->mc_gid,
1bb595
-                                SSS_MC_CACHE_ELEMENTS,
1bb595
+                                -1, /* keep current size */
1bb595
                                 (time_t) memcache_timeout,
1bb595
                                 &nctx->pwd_mc_ctx);
1bb595
     if (ret != EOK) {
1bb595
@@ -96,7 +95,7 @@ nss_clear_memcache(TALLOC_CTX *mem_ctx,
1bb595
     }
1bb595
 
1bb595
     ret = sss_mmap_cache_reinit(nctx, nctx->mc_uid, nctx->mc_gid,
1bb595
-                                SSS_MC_CACHE_ELEMENTS,
1bb595
+                                -1, /* keep current size */
1bb595
                                 (time_t) memcache_timeout,
1bb595
                                 &nctx->grp_mc_ctx);
1bb595
     if (ret != EOK) {
1bb595
@@ -106,7 +105,7 @@ nss_clear_memcache(TALLOC_CTX *mem_ctx,
1bb595
     }
1bb595
 
1bb595
     ret = sss_mmap_cache_reinit(nctx, nctx->mc_uid, nctx->mc_gid,
1bb595
-                                SSS_MC_CACHE_ELEMENTS,
1bb595
+                                -1, /* keep current size */
1bb595
                                 (time_t)memcache_timeout,
1bb595
                                 &nctx->initgr_mc_ctx);
1bb595
     if (ret != EOK) {
1bb595
@@ -210,6 +209,11 @@ done:
1bb595
 
1bb595
 static int setup_memcaches(struct nss_ctx *nctx)
1bb595
 {
1bb595
+    /* TODO: read cache sizes from configuration */
1bb595
+    static const size_t SSS_MC_CACHE_PASSWD_SLOTS    = 200000;  /*  8mb */
1bb595
+    static const size_t SSS_MC_CACHE_GROUP_SLOTS     = 150000;  /*  6mb */
1bb595
+    static const size_t SSS_MC_CACHE_INITGROUP_SLOTS = 250000;  /* 10mb */
1bb595
+
1bb595
     int ret;
1bb595
     int memcache_timeout;
1bb595
 
1bb595
@@ -239,11 +243,11 @@ static int setup_memcaches(struct nss_ctx *nctx)
1bb595
         return EOK;
1bb595
     }
1bb595
 
1bb595
-    /* TODO: read cache sizes from configuration */
1bb595
     ret = sss_mmap_cache_init(nctx, "passwd",
1bb595
                               nctx->mc_uid, nctx->mc_gid,
1bb595
                               SSS_MC_PASSWD,
1bb595
-                              SSS_MC_CACHE_ELEMENTS, (time_t)memcache_timeout,
1bb595
+                              SSS_MC_CACHE_PASSWD_SLOTS,
1bb595
+                              (time_t)memcache_timeout,
1bb595
                               &nctx->pwd_mc_ctx);
1bb595
     if (ret) {
1bb595
         DEBUG(SSSDBG_CRIT_FAILURE, "passwd mmap cache is DISABLED\n");
1bb595
@@ -252,7 +256,8 @@ static int setup_memcaches(struct nss_ctx *nctx)
1bb595
     ret = sss_mmap_cache_init(nctx, "group",
1bb595
                               nctx->mc_uid, nctx->mc_gid,
1bb595
                               SSS_MC_GROUP,
1bb595
-                              SSS_MC_CACHE_ELEMENTS, (time_t)memcache_timeout,
1bb595
+                              SSS_MC_CACHE_GROUP_SLOTS,
1bb595
+                              (time_t)memcache_timeout,
1bb595
                               &nctx->grp_mc_ctx);
1bb595
     if (ret) {
1bb595
         DEBUG(SSSDBG_CRIT_FAILURE, "group mmap cache is DISABLED\n");
1bb595
@@ -261,7 +266,8 @@ static int setup_memcaches(struct nss_ctx *nctx)
1bb595
     ret = sss_mmap_cache_init(nctx, "initgroups",
1bb595
                               nctx->mc_uid, nctx->mc_gid,
1bb595
                               SSS_MC_INITGROUPS,
1bb595
-                              SSS_MC_CACHE_ELEMENTS, (time_t)memcache_timeout,
1bb595
+                              SSS_MC_CACHE_INITGROUP_SLOTS,
1bb595
+                              (time_t)memcache_timeout,
1bb595
                               &nctx->initgr_mc_ctx);
1bb595
     if (ret) {
1bb595
         DEBUG(SSSDBG_CRIT_FAILURE, "initgroups mmap cache is DISABLED\n");
1bb595
diff --git a/src/responder/nss/nsssrv_mmap_cache.c b/src/responder/nss/nsssrv_mmap_cache.c
1bb595
index 69e767690..5e23bbe6f 100644
1bb595
--- a/src/responder/nss/nsssrv_mmap_cache.c
1bb595
+++ b/src/responder/nss/nsssrv_mmap_cache.c
1bb595
@@ -28,13 +28,6 @@
1bb595
 #include "responder/nss/nss_private.h"
1bb595
 #include "responder/nss/nsssrv_mmap_cache.h"
1bb595
 
1bb595
-/* arbitrary (avg of my /etc/passwd) */
1bb595
-#define SSS_AVG_PASSWD_PAYLOAD (MC_SLOT_SIZE * 4)
1bb595
-/* short group name and no gids (private user group */
1bb595
-#define SSS_AVG_GROUP_PAYLOAD (MC_SLOT_SIZE * 3)
1bb595
-/* average place for 40 supplementary groups + 2 names */
1bb595
-#define SSS_AVG_INITGROUP_PAYLOAD (MC_SLOT_SIZE * 5)
1bb595
-
1bb595
 #define MC_NEXT_BARRIER(val) ((((val) + 1) & 0x00ffffff) | 0xf0000000)
1bb595
 
1bb595
 #define MC_RAISE_BARRIER(m) do { \
1bb595
@@ -1251,24 +1244,14 @@ errno_t sss_mmap_cache_init(TALLOC_CTX *mem_ctx, const char *name,
1bb595
                             enum sss_mc_type type, size_t n_elem,
1bb595
                             time_t timeout, struct sss_mc_ctx **mcc)
1bb595
 {
1bb595
+    /* sss_mc_header alone occupies whole slot,
1bb595
+     * so each entry takes 2 slots at the very least
1bb595
+     */
1bb595
+    static const int PAYLOAD_FACTOR = 2;
1bb595
+
1bb595
     struct sss_mc_ctx *mc_ctx = NULL;
1bb595
-    int payload;
1bb595
     int ret, dret;
1bb595
 
1bb595
-    switch (type) {
1bb595
-    case SSS_MC_PASSWD:
1bb595
-        payload = SSS_AVG_PASSWD_PAYLOAD;
1bb595
-        break;
1bb595
-    case SSS_MC_GROUP:
1bb595
-        payload = SSS_AVG_GROUP_PAYLOAD;
1bb595
-        break;
1bb595
-    case SSS_MC_INITGROUPS:
1bb595
-        payload = SSS_AVG_INITGROUP_PAYLOAD;
1bb595
-        break;
1bb595
-    default:
1bb595
-        return EINVAL;
1bb595
-    }
1bb595
-
1bb595
     mc_ctx = talloc_zero(mem_ctx, struct sss_mc_ctx);
1bb595
     if (!mc_ctx) {
1bb595
         return ENOMEM;
1bb595
@@ -1303,9 +1286,9 @@ errno_t sss_mmap_cache_init(TALLOC_CTX *mem_ctx, const char *name,
1bb595
 
1bb595
     /* hash table is double the size because it will store both forward and
1bb595
      * reverse keys (name/uid, name/gid, ..) */
1bb595
-    mc_ctx->ht_size = MC_HT_SIZE(n_elem * 2);
1bb595
-    mc_ctx->dt_size = MC_DT_SIZE(n_elem, payload);
1bb595
-    mc_ctx->ft_size = MC_FT_SIZE(n_elem);
1bb595
+    mc_ctx->ht_size = MC_HT_SIZE(2 * n_elem / PAYLOAD_FACTOR);
1bb595
+    mc_ctx->dt_size = n_elem * MC_SLOT_SIZE;
1bb595
+    mc_ctx->ft_size = n_elem / 8; /* 1 bit per slot */
1bb595
     mc_ctx->mmap_size = MC_HEADER_SIZE +
1bb595
                         MC_ALIGN64(mc_ctx->dt_size) +
1bb595
                         MC_ALIGN64(mc_ctx->ft_size) +
1bb595
diff --git a/src/responder/nss/nsssrv_mmap_cache.h b/src/responder/nss/nsssrv_mmap_cache.h
1bb595
index e06257949..c40af2fb4 100644
1bb595
--- a/src/responder/nss/nsssrv_mmap_cache.h
1bb595
+++ b/src/responder/nss/nsssrv_mmap_cache.h
1bb595
@@ -22,8 +22,6 @@
1bb595
 #ifndef _NSSSRV_MMAP_CACHE_H_
1bb595
 #define _NSSSRV_MMAP_CACHE_H_
1bb595
 
1bb595
-#define SSS_MC_CACHE_ELEMENTS 50000
1bb595
-
1bb595
 struct sss_mc_ctx;
1bb595
 
1bb595
 enum sss_mc_type {
1bb595
diff --git a/src/util/mmap_cache.h b/src/util/mmap_cache.h
1bb595
index 63e096027..d3d92bc98 100644
1bb595
--- a/src/util/mmap_cache.h
1bb595
+++ b/src/util/mmap_cache.h
1bb595
@@ -40,9 +40,6 @@ typedef uint32_t rel_ptr_t;
1bb595
 
1bb595
 #define MC_HT_SIZE(elems) ( (elems) * MC_32 )
1bb595
 #define MC_HT_ELEMS(size) ( (size) / MC_32 )
1bb595
-#define MC_DT_SIZE(elems, payload) ( (elems) * (payload) )
1bb595
-#define MC_FT_SIZE(elems) ( (elems) / 8 )
1bb595
-/* ^^ 8 bits per byte so we need just elems/8 bytes to represent all blocks */
1bb595
 
1bb595
 #define MC_PTR_ADD(ptr, bytes) (void *)((uint8_t *)(ptr) + (bytes))
1bb595
 #define MC_PTR_DIFF(ptr, base) ((uint8_t *)(ptr) - (uint8_t *)(base))
1bb595
-- 
1bb595
2.21.3
1bb595