Browse Source

Ticket 507 - use mutex for FrontendConfig lock instead of rwlock

Bug Description:  There was a lot of contention over the read/write lock
                  for the frontend config

Fix Description:  Updated the macros to use a simple lock.

https://fedorahosted.org/389/ticket/507

Reviewed by: noriko(Thanks!)
Mark Reynolds 13 năm trước cách đây
mục cha
commit
e53973451d
3 tập tin đã thay đổi với 28 bổ sung10 xóa
  1. 4 4
      ldap/servers/slapd/daemon.c
  2. 10 4
      ldap/servers/slapd/libglobs.c
  3. 14 2
      ldap/servers/slapd/slap.h

+ 4 - 4
ldap/servers/slapd/daemon.c

@@ -602,11 +602,11 @@ disk_mon_get_dirs(char ***list, int logs_critical){
     char *dir = NULL;
 
     if(logs_critical){
-        slapi_rwlock_rdlock(config->cfg_rwlock);
+        CFG_LOCK_READ(config);
         disk_mon_add_dir(list, config->accesslog);
         disk_mon_add_dir(list, config->errorlog);
         disk_mon_add_dir(list, config->auditlog);
-        slapi_rwlock_unlock(config->cfg_rwlock);
+        CFG_UNLOCK_READ(config);
     }
 
     /* Add /var just to be safe */
@@ -617,9 +617,9 @@ disk_mon_get_dirs(char ***list, int logs_critical){
 #endif
 
     /* config and backend directories */
-    slapi_rwlock_rdlock(config->cfg_rwlock);
+    CFG_LOCK_READ(config);
     disk_mon_add_dir(list, config->configdir);
-    slapi_rwlock_unlock(config->cfg_rwlock);
+    CFG_UNLOCK_READ(config);
 
     be = slapi_get_first_backend (&cookie);
     while (be) {

+ 10 - 4
ldap/servers/slapd/libglobs.c

@@ -1238,14 +1238,20 @@ void
 FrontendConfig_init () {
   slapdFrontendConfig_t *cfg = getFrontendConfig();
 
+#if SLAPI_CFG_USE_RWLOCK == 1
   /* initialize the read/write configuration lock */
   if ( (cfg->cfg_rwlock = slapi_new_rwlock()) == NULL ) {
-	LDAPDebug ( LDAP_DEBUG_ANY, 
-				"FrontendConfig_init: failed to initialize cfg_rwlock. Exiting now.",
-				0,0,0 );
+	LDAPDebug ( LDAP_DEBUG_ANY, "FrontendConfig_init: "
+	  "failed to initialize cfg_rwlock. Exiting now.",0,0,0);
 	exit(-1);
   }
-				
+#else
+  if ((cfg->cfg_lock = PR_NewLock()) == NULL){
+	LDAPDebug(LDAP_DEBUG_ANY, "FrontendConfig_init: "
+	  "failed to initialize cfg_lock. Exiting now.",0,0,0);
+	exit(-1);
+  }
+#endif
   cfg->port = LDAP_PORT;
   cfg->secureport = LDAPS_PORT;
   cfg->ldapi_filename = slapi_ch_strdup(SLAPD_LDAPI_DEFAULT_FILENAME);

+ 14 - 2
ldap/servers/slapd/slap.h

@@ -2056,10 +2056,18 @@ typedef struct _slapdEntryPoints {
 /* flag used to indicate that the change to the config parameter should be saved */
 #define CONFIG_APPLY 1
 
-#define CFG_LOCK_READ(cfg)   slapi_rwlock_rdlock(cfg->cfg_rwlock)
-#define CFG_UNLOCK_READ(cfg) slapi_rwlock_unlock(cfg->cfg_rwlock)
+#define SLAPI_CFG_USE_RWLOCK 0
+#if SLAPI_CFG_USE_RWLOCK == 0
+#define CFG_LOCK_READ(cfg)    PR_Lock(cfg->cfg_lock)
+#define CFG_UNLOCK_READ(cfg)  PR_Unlock(cfg->cfg_lock)
+#define CFG_LOCK_WRITE(cfg)   PR_Lock(cfg->cfg_lock)
+#define CFG_UNLOCK_WRITE(cfg) PR_Unlock(cfg->cfg_lock)
+#else
+#define CFG_LOCK_READ(cfg)    slapi_rwlock_rdlock(cfg->cfg_rwlock)
+#define CFG_UNLOCK_READ(cfg)  slapi_rwlock_unlock(cfg->cfg_rwlock)
 #define CFG_LOCK_WRITE(cfg)   slapi_rwlock_wrlock(cfg->cfg_rwlock)
 #define CFG_UNLOCK_WRITE(cfg) slapi_rwlock_unlock(cfg->cfg_rwlock)
+#endif
 
 #define REFER_MODE_OFF 0 
 #define REFER_MODE_ON 1
@@ -2067,7 +2075,11 @@ typedef struct _slapdEntryPoints {
 #define MAX_ALLOWED_TIME_IN_SECS	2147483647
 
 typedef struct _slapdFrontendConfig {
+#if SLAPI_CFG_USE_RWLOCK == 1
   Slapi_RWLock     *cfg_rwlock;       /* read/write lock to serialize access */
+#else
+  PRLock           *cfg_lock;
+#endif
   struct pw_scheme *rootpwstoragescheme;
   int accesscontrol;
   int groupevalnestlevel;