]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cpuset: dynamically allocate cpu_map
authorWilly Tarreau <w@1wt.eu>
Wed, 12 Jul 2023 09:35:32 +0000 (11:35 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 8 Sep 2023 14:25:19 +0000 (16:25 +0200)
cpu_map is 8.2kB/entry and there's one such entry per group, that's
~520kB total. In addition, the init code is still in haproxy.c enclosed
in ifdefs. Let's make this a dynamically allocated array in the cpuset
code and remove that init code.

Later we may even consider reallocating it once the number of threads
and groups is known, in order to shrink it a little bit, as the typical
setup with a single group will only need 8.2kB, thus saving half a MB
of RAM. This would require that the upper bound is placed in a variable
though.

include/haproxy/cpuset.h
src/cpuset.c
src/haproxy.c

index 78c4df270723e2f4bdf43a723cc078cb0812f580..e4811bcd6c18d00fe56b840cc0a0294fdfd9e8b6 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <haproxy/cpuset-t.h>
 
-extern struct cpu_map cpu_map[MAX_TGROUPS];
+extern struct cpu_map *cpu_map;
 
 /* Unset all indexes in <set>.
  */
index 73b97b975940c0036ef6db6cf8fbc8d0d9caa60e..3ce6cf22310f57532d2f398667202befa7fbef82 100644 (file)
@@ -5,7 +5,7 @@
 #include <haproxy/cpuset.h>
 #include <haproxy/intops.h>
 
-struct cpu_map cpu_map[MAX_TGROUPS];
+struct cpu_map *cpu_map;
 
 void ha_cpuset_zero(struct hap_cpuset *set)
 {
@@ -185,3 +185,24 @@ int cpu_map_configured(void)
        }
        return 0;
 }
+
+/* Allocates everything needed to store CPU information at boot.
+ * Returns non-zero on success, zero on failure.
+ */
+static int cpuset_alloc(void)
+{
+       /* allocate the structures used to store CPU topology info */
+       cpu_map = (struct cpu_map*)calloc(MAX_TGROUPS, sizeof(*cpu_map));
+       if (!cpu_map)
+               return 0;
+
+       return 1;
+}
+
+static void cpuset_deinit(void)
+{
+       ha_free(&cpu_map);
+}
+
+INITCALL0(STG_ALLOC, cpuset_alloc);
+REGISTER_POST_DEINIT(cpuset_deinit);
index 18308bc59ad217432b0bd2d7b8d436fbdf5bde8f..383d1e47dcd80b49c6c63cefe2e2ad12bb639596 100644 (file)
@@ -1530,19 +1530,6 @@ static void init_early(int argc, char **argv)
                exit(EXIT_FAILURE);
        }
 
-       /* Some CPU affinity stuff may have to be initialized */
-#ifdef USE_CPU_AFFINITY
-       {
-               int g, i;
-
-               for (g = 0; g < MAX_TGROUPS; g++) {
-                       for (i = 0; i < MAX_THREADS_PER_GROUP; ++i) {
-                               ha_cpuset_zero(&cpu_map[g].thread[i]);
-                       }
-               }
-       }
-#endif
-
        /* extract the program name from argv[0], it will be used for the logs
         * and error messages.
         */