mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-01-04 03:02:07 +00:00
MINOR: cpuset: dynamically allocate cpu_map
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.
This commit is contained in:
parent
b0f20ed79b
commit
5119109e3f
@ -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>.
|
||||
*/
|
||||
|
23
src/cpuset.c
23
src/cpuset.c
@ -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);
|
||||
|
@ -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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user