mirror of
https://github.com/systemd/systemd.git
synced 2025-02-24 17:57:34 +03:00
Turn mempool_enabled() into a weak symbol
Before we had the following scheme: mempool_enabled() would check mempool_use_allowed, and libsystemd-shared would be linked with a .c file that provides mempool_use_allowed=true, while other things would linked with a different .c file with mempool_use_allowed=false. In the new scheme, mempool_enabled() itself is a weak symbol. If it's not found, we assume false. So it only needs to be provided for libsystemd-shared, where it can return false or true. test-set-disable-mempool is libshared, so it gets the symbol. But then we actually disable the mempool via envvar. mempool_enable() is called to check its return value directly.
This commit is contained in:
parent
f63d1b0efa
commit
b01f31954f
@ -1928,7 +1928,6 @@ alias_target('devel', libsystemd_pc, libudev_pc)
|
||||
|
||||
libsystemd = shared_library(
|
||||
'systemd',
|
||||
disable_mempool_c,
|
||||
version : libsystemd_version,
|
||||
include_directories : libsystemd_includes,
|
||||
link_args : ['-shared',
|
||||
@ -1953,7 +1952,6 @@ install_libsystemd_static = static_library(
|
||||
basic_gcrypt_sources,
|
||||
basic_compress_sources,
|
||||
fundamental_sources,
|
||||
disable_mempool_c,
|
||||
include_directories : libsystemd_includes,
|
||||
build_by_default : static_libsystemd != 'false',
|
||||
install : static_libsystemd != 'false',
|
||||
@ -1975,7 +1973,6 @@ install_libsystemd_static = static_library(
|
||||
|
||||
libudev = shared_library(
|
||||
'udev',
|
||||
disable_mempool_c,
|
||||
version : libudev_version,
|
||||
include_directories : includes,
|
||||
link_args : ['-shared',
|
||||
@ -1997,7 +1994,6 @@ install_libudev_static = static_library(
|
||||
shared_sources,
|
||||
libsystemd_sources,
|
||||
libudev_sources,
|
||||
disable_mempool_c,
|
||||
include_directories : includes,
|
||||
build_by_default : static_libudev != 'false',
|
||||
install : static_libudev != 'false',
|
||||
@ -2118,7 +2114,6 @@ subdir('test')
|
||||
test_dlopen = executable(
|
||||
'test-dlopen',
|
||||
test_dlopen_c,
|
||||
disable_mempool_c,
|
||||
include_directories : includes,
|
||||
link_with : [libbasic],
|
||||
dependencies : [libdl],
|
||||
@ -2148,7 +2143,6 @@ foreach tuple : [['myhostname', 'ENABLE_NSS_MYHOSTNAME'],
|
||||
nss = shared_library(
|
||||
'nss_' + module,
|
||||
sources,
|
||||
disable_mempool_c,
|
||||
version : '2',
|
||||
include_directories : incs,
|
||||
# Note that we link NSS modules with '-z nodelete' so that mempools never get orphaned
|
||||
|
@ -771,16 +771,15 @@ static void shared_hash_key_initialize(void) {
|
||||
static struct HashmapBase* hashmap_base_new(const struct hash_ops *hash_ops, enum HashmapType type HASHMAP_DEBUG_PARAMS) {
|
||||
HashmapBase *h;
|
||||
const struct hashmap_type_info *hi = &hashmap_type_info[type];
|
||||
bool up;
|
||||
|
||||
up = mempool_enabled();
|
||||
bool use_pool = mempool_enabled && mempool_enabled();
|
||||
|
||||
h = up ? mempool_alloc0_tile(hi->mempool) : malloc0(hi->head_size);
|
||||
h = use_pool ? mempool_alloc0_tile(hi->mempool) : malloc0(hi->head_size);
|
||||
if (!h)
|
||||
return NULL;
|
||||
|
||||
h->type = type;
|
||||
h->from_pool = up;
|
||||
h->from_pool = use_pool;
|
||||
h->hash_ops = hash_ops ?: &trivial_hash_ops;
|
||||
|
||||
if (type == HASHMAP_TYPE_ORDERED) {
|
||||
|
@ -3,12 +3,9 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "env-util.h"
|
||||
#include "macro.h"
|
||||
#include "memory-util.h"
|
||||
#include "mempool.h"
|
||||
#include "process-util.h"
|
||||
#include "util.h"
|
||||
|
||||
struct pool {
|
||||
struct pool *next;
|
||||
@ -73,20 +70,6 @@ void mempool_free_tile(struct mempool *mp, void *p) {
|
||||
mp->freelist = p;
|
||||
}
|
||||
|
||||
bool mempool_enabled(void) {
|
||||
static int b = -1;
|
||||
|
||||
if (!is_main_thread())
|
||||
return false;
|
||||
|
||||
if (!mempool_use_allowed)
|
||||
b = false;
|
||||
if (b < 0)
|
||||
b = getenv_bool("SYSTEMD_MEMPOOL") != 0;
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
#if VALGRIND
|
||||
void mempool_drop(struct mempool *mp) {
|
||||
struct pool *p = mp->first_pool;
|
||||
|
@ -23,8 +23,7 @@ static struct mempool pool_name = { \
|
||||
.at_least = alloc_at_least, \
|
||||
}
|
||||
|
||||
extern const bool mempool_use_allowed;
|
||||
bool mempool_enabled(void);
|
||||
__attribute__((weak)) bool mempool_enabled(void);
|
||||
|
||||
#if VALGRIND
|
||||
void mempool_drop(struct mempool *mp);
|
||||
|
@ -1,5 +0,0 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "mempool.h"
|
||||
|
||||
const bool mempool_use_allowed = false;
|
@ -158,7 +158,6 @@ libsystemd_sources = files(
|
||||
'sd-utf8/sd-utf8.c',
|
||||
) + sd_journal_sources + id128_sources + sd_daemon_sources + sd_event_sources + sd_login_sources
|
||||
|
||||
disable_mempool_c = files('disable-mempool.c')
|
||||
|
||||
libsystemd_c_args = ['-fvisibility=default']
|
||||
|
||||
|
@ -1,5 +1,19 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "mempool.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
const bool mempool_use_allowed = true;
|
||||
#include "env-util.h"
|
||||
#include "mempool.h"
|
||||
#include "process-util.h"
|
||||
|
||||
bool mempool_enabled(void) {
|
||||
static int cache = -1;
|
||||
|
||||
if (!is_main_thread())
|
||||
return false;
|
||||
|
||||
if (cache < 0)
|
||||
cache = getenv_bool("SYSTEMD_MEMPOOL") != 0;
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "mempool.h"
|
||||
#include "process-util.h"
|
||||
#include "set.h"
|
||||
#include "tests.h"
|
||||
@ -15,6 +16,9 @@ static void* thread(void *p) {
|
||||
assert_se(*s);
|
||||
|
||||
assert_se(!is_main_thread());
|
||||
assert_se(mempool_enabled);
|
||||
assert_se(!mempool_enabled());
|
||||
|
||||
assert_se(set_size(*s) == NUM);
|
||||
*s = set_free(*s);
|
||||
|
||||
@ -29,7 +33,10 @@ static void test_one(const char *val) {
|
||||
|
||||
log_info("Testing with SYSTEMD_MEMPOOL=%s", val);
|
||||
assert_se(setenv("SYSTEMD_MEMPOOL", val, true) == 0);
|
||||
|
||||
assert_se(is_main_thread());
|
||||
assert_se(mempool_enabled); /* It is a weak symbol, but we expect it to be available */
|
||||
assert_se(!mempool_enabled());
|
||||
|
||||
assert_se(s = set_new(NULL));
|
||||
for (i = 0; i < NUM; i++)
|
||||
|
Loading…
x
Reference in New Issue
Block a user