dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0033-NSS-make-memcache-size-configurable-in-megabytes.patch

1bb595
From b7f31936e21b109b5446c48513619cd87974be54 Mon Sep 17 00:00:00 2001
1bb595
From: Alexey Tikhonov <atikhono@redhat.com>
1bb595
Date: Tue, 31 Mar 2020 22:57:25 +0200
1bb595
Subject: [PATCH 33/35] NSS: make memcache size configurable in megabytes
1bb595
1bb595
Memcache size was made configurable in megabytes and not in slots
1bb595
to hide internal implementation from users.
1bb595
1bb595
Relates: https://github.com/SSSD/sssd/issues/5115
1bb595
1bb595
Reviewed-by: Sumit Bose <sbose@redhat.com>
1bb595
---
1bb595
 src/config/SSSDConfig/sssdoptions.py |  6 ++---
1bb595
 src/man/sssd.conf.5.xml              | 33 +++++++++++++---------------
1bb595
 src/responder/nss/nsssrv.c           | 20 +++++++++--------
1bb595
 3 files changed, 29 insertions(+), 30 deletions(-)
1bb595
1bb595
diff --git a/src/config/SSSDConfig/sssdoptions.py b/src/config/SSSDConfig/sssdoptions.py
1bb595
index 16d85cfa3..f57ad4b41 100644
1bb595
--- a/src/config/SSSDConfig/sssdoptions.py
1bb595
+++ b/src/config/SSSDConfig/sssdoptions.py
1bb595
@@ -72,9 +72,9 @@ class SSSDOptions(object):
1bb595
         'shell_fallback': _('If a shell stored in central directory is allowed but not available, use this fallback'),
1bb595
         'default_shell': _('Shell to use if the provider does not list one'),
1bb595
         'memcache_timeout': _('How long will be in-memory cache records valid'),
1bb595
-        'memcache_size_passwd': _('Number of slots in fast in-memory cache for passwd requests'),
1bb595
-        'memcache_size_group': _('Number of slots in fast in-memory cache for group requests'),
1bb595
-        'memcache_size_initgroups': _('Number of slots in fast in-memory cache for initgroups requests'),
1bb595
+        'memcache_size_passwd': _('Size (in megabytes) of the data table allocated inside fast in-memory cache for passwd requests'),
1bb595
+        'memcache_size_group': _('Size (in megabytes) of the data table allocated inside fast in-memory cache for group requests'),
1bb595
+        'memcache_size_initgroups': _('Size (in megabytes) of the data table allocated inside fast in-memory cache for initgroups requests'),
1bb595
         'homedir_substring': _('The value of this option will be used in the expansion of the override_homedir option '
1bb595
                                'if the template contains the format string %H.'),
1bb595
         'get_domains_timeout': _('Specifies time in seconds for which the list of subdomains will be considered '
1bb595
diff --git a/src/man/sssd.conf.5.xml b/src/man/sssd.conf.5.xml
1bb595
index 9bc2e26e5..874a09c49 100644
1bb595
--- a/src/man/sssd.conf.5.xml
1bb595
+++ b/src/man/sssd.conf.5.xml
1bb595
@@ -1076,7 +1076,7 @@ fallback_homedir = /home/%u
1bb595
                     </listitem>
1bb595
                 </varlistentry>
1bb595
                 <varlistentry>
1bb595
-                    <term>memcache_timeout (int)</term>
1bb595
+                    <term>memcache_timeout (integer)</term>
1bb595
                     <listitem>
1bb595
                         <para>
1bb595
                             Specifies time in seconds for which records
1bb595
@@ -1104,14 +1104,13 @@ fallback_homedir = /home/%u
1bb595
                     <term>memcache_size_passwd (integer)</term>
1bb595
                     <listitem>
1bb595
                         <para>
1bb595
-                            Number of slots allocated inside fast in-memory
1bb595
-                            cache for passwd requests. Note that one entry
1bb595
-                            in fast in-memory cache can occupy more than one slot.
1bb595
-                            Setting the size to 0 will disable the passwd in-memory
1bb595
-                            cache.
1bb595
+                            Size (in megabytes) of the data table allocated inside
1bb595
+                            fast in-memory cache for passwd requests.
1bb595
+                            Setting the size to 0 will disable the passwd
1bb595
+                            in-memory cache.
1bb595
                         </para>
1bb595
                         <para>
1bb595
-                            Default: 200000
1bb595
+                            Default: 8
1bb595
                         </para>
1bb595
                         <para>
1bb595
                             WARNING: Disabled or too small in-memory cache can
1bb595
@@ -1130,14 +1129,13 @@ fallback_homedir = /home/%u
1bb595
                     <term>memcache_size_group (integer)</term>
1bb595
                     <listitem>
1bb595
                         <para>
1bb595
-                            Number of slots allocated inside fast in-memory
1bb595
-                            cache for group requests. Note that one entry
1bb595
-                            in fast in-memory cache can occupy more than one
1bb595
-                            slot. Setting the size to 0 will disable the group
1bb595
+                            Size (in megabytes) of the data table allocated inside
1bb595
+                            fast in-memory cache for group requests.
1bb595
+                            Setting the size to 0 will disable the group
1bb595
                             in-memory cache.
1bb595
                         </para>
1bb595
                         <para>
1bb595
-                            Default: 150000
1bb595
+                            Default: 6
1bb595
                         </para>
1bb595
                         <para>
1bb595
                             WARNING: Disabled or too small in-memory cache can
1bb595
@@ -1156,14 +1154,13 @@ fallback_homedir = /home/%u
1bb595
                     <term>memcache_size_initgroups (integer)</term>
1bb595
                     <listitem>
1bb595
                         <para>
1bb595
-                            Number of slots allocated inside fast in-memory
1bb595
-                            cache for initgroups requests. Note that one entry
1bb595
-                            in fast in-memory cache can occupy more than one
1bb595
-                            slot. Setting the size to 0 will disable the
1bb595
-                            initgroups in-memory cache.
1bb595
+                            Size (in megabytes) of the data table allocated inside
1bb595
+                            fast in-memory cache for initgroups requests.
1bb595
+                            Setting the size to 0 will disable the initgroups
1bb595
+                            in-memory cache.
1bb595
                         </para>
1bb595
                         <para>
1bb595
-                            Default: 250000
1bb595
+                            Default: 10
1bb595
                         </para>
1bb595
                         <para>
1bb595
                             WARNING: Disabled or too small in-memory cache can
1bb595
diff --git a/src/responder/nss/nsssrv.c b/src/responder/nss/nsssrv.c
1bb595
index 42a63d9bb..741e94aaa 100644
1bb595
--- a/src/responder/nss/nsssrv.c
1bb595
+++ b/src/responder/nss/nsssrv.c
1bb595
@@ -34,6 +34,7 @@
1bb595
 
1bb595
 #include "util/util.h"
1bb595
 #include "util/sss_ptr_hash.h"
1bb595
+#include "util/mmap_cache.h"
1bb595
 #include "responder/nss/nss_private.h"
1bb595
 #include "responder/nss/nss_iface.h"
1bb595
 #include "responder/nss/nsssrv_mmap_cache.h"
1bb595
@@ -210,9 +211,10 @@ done:
1bb595
 static int setup_memcaches(struct nss_ctx *nctx)
1bb595
 {
1bb595
     /* Default memcache sizes */
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
+    static const size_t SSS_MC_CACHE_SLOTS_PER_MB   = 1024*1024/MC_SLOT_SIZE;
1bb595
+    static const size_t SSS_MC_CACHE_PASSWD_SIZE    =  8;
1bb595
+    static const size_t SSS_MC_CACHE_GROUP_SIZE     =  6;
1bb595
+    static const size_t SSS_MC_CACHE_INITGROUP_SIZE = 10;
1bb595
 
1bb595
     int ret;
1bb595
     int memcache_timeout;
1bb595
@@ -251,7 +253,7 @@ static int setup_memcaches(struct nss_ctx *nctx)
1bb595
     ret = confdb_get_int(nctx->rctx->cdb,
1bb595
                          CONFDB_NSS_CONF_ENTRY,
1bb595
                          CONFDB_NSS_MEMCACHE_SIZE_PASSWD,
1bb595
-                         SSS_MC_CACHE_PASSWD_SLOTS,
1bb595
+                         SSS_MC_CACHE_PASSWD_SIZE,
1bb595
                          &mc_size_passwd);
1bb595
     if (ret != EOK) {
1bb595
         DEBUG(SSSDBG_FATAL_FAILURE,
1bb595
@@ -263,7 +265,7 @@ static int setup_memcaches(struct nss_ctx *nctx)
1bb595
     ret = confdb_get_int(nctx->rctx->cdb,
1bb595
                          CONFDB_NSS_CONF_ENTRY,
1bb595
                          CONFDB_NSS_MEMCACHE_SIZE_GROUP,
1bb595
-                         SSS_MC_CACHE_GROUP_SLOTS,
1bb595
+                         SSS_MC_CACHE_GROUP_SIZE,
1bb595
                          &mc_size_group);
1bb595
     if (ret != EOK) {
1bb595
         DEBUG(SSSDBG_FATAL_FAILURE,
1bb595
@@ -275,7 +277,7 @@ static int setup_memcaches(struct nss_ctx *nctx)
1bb595
     ret = confdb_get_int(nctx->rctx->cdb,
1bb595
                          CONFDB_NSS_CONF_ENTRY,
1bb595
                          CONFDB_NSS_MEMCACHE_SIZE_INITGROUPS,
1bb595
-                         SSS_MC_CACHE_INITGROUP_SLOTS,
1bb595
+                         SSS_MC_CACHE_INITGROUP_SIZE,
1bb595
                          &mc_size_initgroups);
1bb595
     if (ret != EOK) {
1bb595
         DEBUG(SSSDBG_FATAL_FAILURE,
1bb595
@@ -290,7 +292,7 @@ static int setup_memcaches(struct nss_ctx *nctx)
1bb595
         ret = sss_mmap_cache_init(nctx, "passwd",
1bb595
                                   nctx->mc_uid, nctx->mc_gid,
1bb595
                                   SSS_MC_PASSWD,
1bb595
-                                  mc_size_passwd,
1bb595
+                                  mc_size_passwd * SSS_MC_CACHE_SLOTS_PER_MB,
1bb595
                                   (time_t)memcache_timeout,
1bb595
                                   &nctx->pwd_mc_ctx);
1bb595
         if (ret) {
1bb595
@@ -310,7 +312,7 @@ 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
-                                  mc_size_group,
1bb595
+                                  mc_size_group * SSS_MC_CACHE_SLOTS_PER_MB,
1bb595
                                   (time_t)memcache_timeout,
1bb595
                                   &nctx->grp_mc_ctx);
1bb595
         if (ret) {
1bb595
@@ -330,7 +332,7 @@ 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
-                                  mc_size_initgroups,
1bb595
+                                  mc_size_initgroups * SSS_MC_CACHE_SLOTS_PER_MB,
1bb595
                                   (time_t)memcache_timeout,
1bb595
                                   &nctx->initgr_mc_ctx);
1bb595
         if (ret) {
1bb595
-- 
1bb595
2.21.3
1bb595