]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Remove ISC_MEM_ALIGN() memory flag
authorOndřej Surý <ondrej@isc.org>
Wed, 23 Aug 2023 08:05:30 +0000 (10:05 +0200)
committerOndřej Surý <ondrej@isc.org>
Thu, 31 Aug 2023 20:08:35 +0000 (22:08 +0200)
The ISC_MEM_ALIGN() was not used anywhere (except mem.c itself), so just
remove the unused flag.

lib/isc/include/isc/mem.h
lib/isc/mem.c
tests/isc/mem_test.c

index 9dde53c6d5fa021a3cbabe17af5b286c2c814475..9532b2ae6d47c535936923b22a49d6e2149b7e16 100644 (file)
@@ -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)
index 2689965a0dfe47b5f4eb2ee77e3482cf4f296323..e3242f92e066e9b4565ceb457a2956fe72bb7d7c 100644 (file)
@@ -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
index 4e80db0111a17f2b081d0d2e0fbb8904561a0f81..6d781ddba0aa502661a3e35722ff9c0a2b131518 100644 (file)
@@ -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 <alignment, 2*alignment> 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 <alignment, 2*alignment> 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)