mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-01 06:55:30 +00:00
[master] fix 'total use' accounting
4046. [bug] Accounting of "total use" in memory context statistics was not correct. [RT #38370]
This commit is contained in:
3
CHANGES
3
CHANGES
@@ -1,3 +1,6 @@
|
||||
4046. [bug] Accounting of "total use" in memory context
|
||||
statistics was not correct. [RT #38370]
|
||||
|
||||
4045. [bug] Skip to next master on dns_request_createvia4 failure.
|
||||
[RT #25185]
|
||||
|
||||
|
@@ -81,6 +81,7 @@
|
||||
|
||||
#ifdef OPENSSL
|
||||
#include <openssl/opensslv.h>
|
||||
#include <openssl/crypto.h>
|
||||
#endif
|
||||
#ifdef HAVE_LIBXML2
|
||||
#include <libxml/xmlversion.h>
|
||||
@@ -605,12 +606,16 @@ parse_command_line(int argc, char *argv[]) {
|
||||
printf("compiled by Solaris Studio %x\n", __SUNPRO_C);
|
||||
#endif
|
||||
#ifdef OPENSSL
|
||||
printf("using OpenSSL version: %s\n",
|
||||
printf("compiled with OpenSSL version: %s\n",
|
||||
OPENSSL_VERSION_TEXT);
|
||||
printf("linked to OpenSSL version: %s\n",
|
||||
SSLeay_version(SSLEAY_VERSION));
|
||||
#endif
|
||||
#ifdef HAVE_LIBXML2
|
||||
printf("using libxml2 version: %s\n",
|
||||
printf("compiled with libxml2 version: %s\n",
|
||||
LIBXML_DOTTED_VERSION);
|
||||
printf("linked to libxml2 version: %s\n",
|
||||
xmlParserVersion);
|
||||
#endif
|
||||
exit(0);
|
||||
case 'x':
|
||||
|
@@ -741,9 +741,8 @@ mem_putunlocked(isc__mem_t *ctx, void *mem, size_t size) {
|
||||
(ctx->memfree)(ctx->arg, mem);
|
||||
INSIST(ctx->stats[ctx->max_size].gets != 0U);
|
||||
ctx->stats[ctx->max_size].gets--;
|
||||
INSIST(size <= ctx->total);
|
||||
INSIST(size <= ctx->inuse);
|
||||
ctx->inuse -= size;
|
||||
ctx->total -= size;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -40,7 +40,7 @@ SRCS = isctest.c taskpool_test.c socket_test.c hash_test.c \
|
||||
sockaddr_test.c symtab_test.c task_test.c queue_test.c \
|
||||
parse_test.c pool_test.c print_test.c regex_test.c \
|
||||
socket_test.c safe_test.c time_test.c aes_test.c \
|
||||
file_test.c buffer_test.c counter_test.c
|
||||
file_test.c buffer_test.c counter_test.c mem_test.c
|
||||
|
||||
SUBDIRS =
|
||||
TARGETS = taskpool_test@EXEEXT@ socket_test@EXEEXT@ hash_test@EXEEXT@ \
|
||||
@@ -49,7 +49,8 @@ TARGETS = taskpool_test@EXEEXT@ socket_test@EXEEXT@ hash_test@EXEEXT@ \
|
||||
queue_test@EXEEXT@ parse_test@EXEEXT@ pool_test@EXEEXT@ \
|
||||
print_test@EXEEXT@ regex_test@EXEEXT@ socket_test@EXEEXT@ \
|
||||
safe_test@EXEEXT@ time_test@EXEEXT@ aes_test@EXEEXT@ \
|
||||
file_test@EXEEXT@ buffer_test@EXEEXT@ counter_test@EXEEXT@
|
||||
file_test@EXEEXT@ buffer_test@EXEEXT@ counter_test@EXEEXT@ \
|
||||
mem_test@EXEEXT@
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
|
||||
@@ -133,6 +134,10 @@ counter_test@EXEEXT@: counter_test.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
counter_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
|
||||
|
||||
mem_test@EXEEXT@: mem_test.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
mem_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
|
||||
|
||||
unit::
|
||||
sh ${top_srcdir}/unit/unittest.sh
|
||||
|
||||
|
156
lib/isc/tests/mem_test.c
Normal file
156
lib/isc/tests/mem_test.c
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
||||
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
||||
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
|
||||
#include "isctest.h"
|
||||
|
||||
#include <isc/mem.h>
|
||||
#include <isc/result.h>
|
||||
|
||||
static void *
|
||||
default_memalloc(void *arg, size_t size) {
|
||||
UNUSED(arg);
|
||||
if (size == 0U)
|
||||
size = 1;
|
||||
return (malloc(size));
|
||||
}
|
||||
|
||||
static void
|
||||
default_memfree(void *arg, void *ptr) {
|
||||
UNUSED(arg);
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
ATF_TC(isc_mem_total);
|
||||
ATF_TC_HEAD(isc_mem_total, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test TotalUse calculation");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(isc_mem_total, tc) {
|
||||
isc_result_t result;
|
||||
isc_mem_t *mctx2 = NULL;
|
||||
size_t before, after;
|
||||
ssize_t diff;
|
||||
int i;
|
||||
|
||||
result = isc_test_begin(NULL, ISC_TRUE);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
/* Local alloc, free */
|
||||
mctx2 = NULL;
|
||||
result = isc_mem_createx2(0, 0, default_memalloc, default_memfree,
|
||||
NULL, &mctx2, 0);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto out;
|
||||
|
||||
before = isc_mem_total(mctx2);
|
||||
|
||||
for (i = 0; i < 100000; i++) {
|
||||
void *ptr;
|
||||
|
||||
ptr = isc_mem_allocate(mctx2, 2048);
|
||||
isc_mem_free(mctx2, ptr);
|
||||
}
|
||||
|
||||
after = isc_mem_total(mctx2);
|
||||
diff = after - before;
|
||||
|
||||
printf("total_before=%lu, total_after=%lu, total_diff=%lu\n",
|
||||
before, after, diff);
|
||||
/* 2048 +8 bytes extra for size_info */
|
||||
ATF_CHECK_EQ(diff, (2048 + 8) * 100000);
|
||||
|
||||
/* ISC_MEMFLAG_INTERNAL */
|
||||
|
||||
before = isc_mem_total(mctx);
|
||||
|
||||
for (i = 0; i < 100000; i++) {
|
||||
void *ptr;
|
||||
|
||||
ptr = isc_mem_allocate(mctx, 2048);
|
||||
isc_mem_free(mctx, ptr);
|
||||
}
|
||||
|
||||
after = isc_mem_total(mctx);
|
||||
diff = after - before;
|
||||
|
||||
printf("total_before=%lu, total_after=%lu, total_diff=%lu\n",
|
||||
before, after, diff);
|
||||
/* 2048 +8 bytes extra for size_info */
|
||||
ATF_CHECK_EQ(diff, (2048 + 8) * 100000);
|
||||
|
||||
out:
|
||||
if (mctx2 != NULL)
|
||||
isc_mem_destroy(&mctx2);
|
||||
|
||||
isc_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(isc_mem_inuse);
|
||||
ATF_TC_HEAD(isc_mem_inuse, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test InUse calculation");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(isc_mem_inuse, tc) {
|
||||
isc_result_t result;
|
||||
isc_mem_t *mctx2 = NULL;
|
||||
size_t before, during, after;
|
||||
ssize_t diff;
|
||||
void *ptr;
|
||||
|
||||
result = isc_test_begin(NULL, ISC_TRUE);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
mctx2 = NULL;
|
||||
result = isc_mem_createx2(0, 0, default_memalloc, default_memfree,
|
||||
NULL, &mctx2, 0);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto out;
|
||||
|
||||
before = isc_mem_inuse(mctx2);
|
||||
ptr = isc_mem_allocate(mctx2, 1024000);
|
||||
during = isc_mem_inuse(mctx2);
|
||||
isc_mem_free(mctx2, ptr);
|
||||
after = isc_mem_inuse(mctx2);
|
||||
|
||||
diff = after - before;
|
||||
|
||||
printf("inuse_before=%lu, inuse_during=%lu, inuse_after=%lu\n",
|
||||
before, during, after);
|
||||
ATF_REQUIRE_EQ(diff, 0);
|
||||
|
||||
out:
|
||||
if (mctx2 != NULL)
|
||||
isc_mem_destroy(&mctx2);
|
||||
|
||||
isc_test_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, isc_mem_total);
|
||||
ATF_TP_ADD_TC(tp, isc_mem_inuse);
|
||||
|
||||
return (atf_no_error());
|
||||
}
|
Reference in New Issue
Block a user