]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Windows: restrict service to 2 cpus by default
authorJeffrey Altman <jaltman@your-file-system.com>
Sat, 14 Jan 2012 15:31:01 +0000 (10:31 -0500)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Wed, 18 Jan 2012 15:35:35 +0000 (07:35 -0800)
Performance drops off considerably when the number of processors
increases due to lock contention and the cm_SyncOp wait processing.
If the MaxCPUs registry value is not set, limit ourselves to two.
Setting MaxCPUs to zero permits use of all CPUs.

Change-Id: I4bae328ed589811b0ea2a514501a0c1aa74e8015
Reviewed-on: http://gerrit.openafs.org/6555
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@secure-endpoints.com>
Tested-by: Jeffrey Altman <jaltman@secure-endpoints.com>
src/WINNT/afsd/afsd_init.c

index eff213c806245aedba7bdc8ff86377a61363599c..d4dc292bf69f67f179036011a877290737a92ba5 100644 (file)
@@ -610,7 +610,11 @@ afsd_InitCM(char **reasonP)
     dummyLen = sizeof(maxcpus);
     code = RegQueryValueEx(parmKey, "MaxCPUs", NULL, NULL,
                             (BYTE *) &maxcpus, &dummyLen);
-    if (code == ERROR_SUCCESS) {
+    if (code != ERROR_SUCCESS) {
+        maxcpus = 2;
+    }
+
+    {
         HANDLE hProcess;
         DWORD_PTR processAffinityMask, systemAffinityMask;
 
@@ -619,7 +623,7 @@ afsd_InitCM(char **reasonP)
         if ( hProcess != NULL &&
              GetProcessAffinityMask(hProcess, &processAffinityMask, &systemAffinityMask) )
         {
-            int i, n, bits;
+            int i, n, bits, cpu_count = 0;
             DWORD_PTR mask, newAffinityMask;
 
 #if defined(_WIN64)
@@ -627,19 +631,26 @@ afsd_InitCM(char **reasonP)
 #else
             bits = 32;
 #endif
-            for ( i=0, n=0, mask=1, newAffinityMask=0; i<bits && n<maxcpus; i++ ) {
+            for ( i=0, n=0, mask=1, newAffinityMask=0; i<bits; i++ ) {
                 if ( processAffinityMask & mask ) {
-                    newAffinityMask |= mask;
-                    n++;
+                    cpu_count++;
+                    if (n<maxcpus) {
+                        newAffinityMask |= mask;
+                        n++;
+                    }
                 }
                 mask *= 2;
             }
 
-            SetProcessAffinityMask(hProcess, newAffinityMask);
+            if (maxcpus == 0) {
+                afsi_log("No CPU Restrictions; %d cpu(s) available", cpu_count);
+            } else {
+                SetProcessAffinityMask(hProcess, newAffinityMask);
+            }
             CloseHandle(hProcess);
-            afsi_log("CPU Restrictions set to %d cpu(s); %d cpu(s) available", maxcpus, n);
+            afsi_log("CPU Restrictions set to %d cpu(s); %d cpu(s) available", maxcpus, cpu_count);
         } else {
-            afsi_log("CPU Restrictions set to %d cpu(s); unable to access process information", maxcpus);
+            afsi_log("CPU Restrictions requested %d cpu(s); unable to access process information", maxcpus);
         }
     }