From 8ac679a98081c50e91758da84466faf9685f369c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 23 Aug 2023 10:05:30 +0200 Subject: [PATCH] Remove ISC_MEM_ALIGN() memory flag The ISC_MEM_ALIGN() was not used anywhere (except mem.c itself), so just remove the unused flag. --- lib/isc/include/isc/mem.h | 16 --------- lib/isc/mem.c | 7 ++-- tests/isc/mem_test.c | 68 --------------------------------------- 3 files changed, 2 insertions(+), 89 deletions(-) diff --git a/lib/isc/include/isc/mem.h b/lib/isc/include/isc/mem.h index 9dde53c6d5f..9532b2ae6d4 100644 --- a/lib/isc/include/isc/mem.h +++ b/lib/isc/include/isc/mem.h @@ -134,25 +134,9 @@ extern unsigned int isc_mem_defaultflags; * The definitions of the macros have been pulled directly from jemalloc.h * and checked for consistency in mem.c. * - *\li ISC_MEM_ALIGN(alignment) - use when you need aligned allocation, - * - * NOTE: Set the matching flag, when freeing aligned memory allocation. - * *\li ISC_MEM_ZERO - fill the memory with zeroes before returning */ -#if defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC) -#if __SIZEOF_POINTER__ == 4 -#define ISC_MEM_ALIGN(a) ((int)(ffs((int)(a)) - 1)) -#else -#define ISC_MEM_ALIGN(a) \ - ((int)(((size_t)(a) < (size_t)INT_MAX) \ - ? ffs((int)(a)) - 1 \ - : ffs((int)(((size_t)(a)) >> 32)) + 31)) -#endif -#else -#define ISC_MEM_ALIGN(a) (a & 0) -#endif #define ISC_MEM_ZERO ((int)0x40) #define isc_mem_get(c, s) isc__mem_get((c), (s), 0 _ISC_MEM_FILELINE) diff --git a/lib/isc/mem.c b/lib/isc/mem.c index 2689965a0df..e3242f92e06 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -384,9 +384,6 @@ mem_initialize(void) { */ #ifdef JEMALLOC_API_SUPPORTED RUNTIME_CHECK(ISC_MEM_ZERO == MALLOCX_ZERO); - RUNTIME_CHECK(ISC_MEM_ALIGN(0) == MALLOCX_ALIGN(0)); - RUNTIME_CHECK(ISC_MEM_ALIGN(sizeof(void *)) == - MALLOCX_ALIGN(sizeof(void *))); #endif /* JEMALLOC_API_SUPPORTED */ isc_mutex_init(&contextslock); @@ -416,7 +413,7 @@ mem_create(isc_mem_t **ctxp, unsigned int debugging, unsigned int flags) { REQUIRE(ctxp != NULL && *ctxp == NULL); - ctx = mallocx(sizeof(*ctx), ISC_MEM_ALIGN(isc_os_cacheline())); + ctx = malloc(sizeof(*ctx)); INSIST(ctx != NULL); *ctx = (isc_mem_t){ @@ -497,7 +494,7 @@ destroy(isc_mem_t *ctx) { if (ctx->checkfree) { INSIST(atomic_load(&ctx->inuse) == 0); } - sdallocx(ctx, sizeof(*ctx), ISC_MEM_ALIGN(isc_os_cacheline())); + free(ctx); } void diff --git a/tests/isc/mem_test.c b/tests/isc/mem_test.c index 4e80db0111a..6d781ddba0a 100644 --- a/tests/isc/mem_test.c +++ b/tests/isc/mem_test.c @@ -126,70 +126,6 @@ ISC_RUN_TEST_IMPL(isc_mem_get) { isc_mempool_destroy(&mp1); } -#if defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC) -/* aligned memory system tests */ -ISC_RUN_TEST_IMPL(isc_mem_get_align) { - isc_mem_t *mctx2 = NULL; - void *ptr; - size_t alignment; - uintptr_t aligned; - - /* Check different alignment sizes up to the page size */ - for (alignment = sizeof(void *); alignment <= 4096; alignment *= 2) { - size_t size = alignment / 2 - 1; - ptr = isc_mem_getx(mctx, size, ISC_MEM_ALIGN(alignment)); - - /* Check if the pointer is properly aligned */ - aligned = (((uintptr_t)ptr / alignment) * alignment); - assert_ptr_equal(aligned, (uintptr_t)ptr); - - /* Check if we can resize to range */ - ptr = isc_mem_regetx(mctx, ptr, size, size * 2 + alignment, - ISC_MEM_ALIGN(alignment)); - - /* Check if the pointer is still properly aligned */ - aligned = (((uintptr_t)ptr / alignment) * alignment); - assert_ptr_equal(aligned, (uintptr_t)ptr); - - isc_mem_putx(mctx, ptr, size * 2 + alignment, - ISC_MEM_ALIGN(alignment)); - - /* Check whether isc_mem_putanddetach_detach() also works */ - isc_mem_create(&mctx2); - ptr = isc_mem_getx(mctx2, size, ISC_MEM_ALIGN(alignment)); - isc_mem_putanddetachx(&mctx2, ptr, size, - ISC_MEM_ALIGN(alignment)); - } -} - -/* aligned memory system tests */ -ISC_RUN_TEST_IMPL(isc_mem_allocate_align) { - void *ptr; - size_t alignment; - uintptr_t aligned; - - /* Check different alignment sizes up to the page size */ - for (alignment = sizeof(void *); alignment <= 4096; alignment *= 2) { - size_t size = alignment / 2 - 1; - ptr = isc_mem_allocatex(mctx, size, ISC_MEM_ALIGN(alignment)); - - /* Check if the pointer is properly aligned */ - aligned = (((uintptr_t)ptr / alignment) * alignment); - assert_ptr_equal(aligned, (uintptr_t)ptr); - - /* Check if we can resize to range */ - ptr = isc_mem_reallocatex(mctx, ptr, size * 2 + alignment, - ISC_MEM_ALIGN(alignment)); - - /* Check if the pointer is still properly aligned */ - aligned = (((uintptr_t)ptr / alignment) * alignment); - assert_ptr_equal(aligned, (uintptr_t)ptr); - - isc_mem_freex(mctx, ptr, ISC_MEM_ALIGN(alignment)); - } -} -#endif /* defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC) */ - /* zeroed memory system tests */ ISC_RUN_TEST_IMPL(isc_mem_get_zero) { uint8_t *ptr; @@ -544,10 +480,6 @@ ISC_RUN_TEST_IMPL(isc_mem_benchmark) { ISC_TEST_LIST_START ISC_TEST_ENTRY(isc_mem_get) -#if defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC) -ISC_TEST_ENTRY(isc_mem_get_align) -ISC_TEST_ENTRY(isc_mem_allocate_align) -#endif /* defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC) */ ISC_TEST_ENTRY(isc_mem_get_zero) ISC_TEST_ENTRY(isc_mem_allocate_zero) ISC_TEST_ENTRY(isc_mem_inuse) -- 2.47.3