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