Skip to content

Commit

Permalink
limit test cycles (UDP socket buffer) + small stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
boazsegev committed Dec 30, 2023
1 parent 1cd307d commit 9a13ce8
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 50 deletions.
52 changes: 27 additions & 25 deletions fio-stl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2297,10 +2297,6 @@ Memory Allocation - FIO_MALLOC defines a FIOBJ dedicated memory allocator
/* fight fragmentation */
#define FIO_MEMORY_BLOCKS_PER_ALLOCATION_LOG 4
#endif
#ifndef FIO_MEMORY_ALIGN_LOG
/* align on 8 bytes, it's enough for FIOBJ types */
#define FIO_MEMORY_ALIGN_LOG 3
#endif
#ifndef FIO_MEMORY_CACHE_SLOTS
/* cache up to 64Mb */
#define FIO_MEMORY_CACHE_SLOTS 16
Expand Down Expand Up @@ -12012,7 +12008,7 @@ Memory Allocation - Setup Alignment Info
#define FIO_MEMORY_ALIGN_LOG 3
#elif FIO_MEMORY_ALIGN_LOG > 10
#undef FIO_MEMORY_ALIGN_LOG
#define FIO_MEMORY_ALIGN_LOG 6
#define FIO_MEMORY_ALIGN_LOG 10
#endif

/* Helper macro, don't change this */
Expand Down Expand Up @@ -12201,7 +12197,7 @@ NOTE: most configuration values should be a power of 2 or a logarithmic value.

#ifndef FIO_MEMORY_USE_THREAD_MUTEX
#if FIO_USE_THREAD_MUTEX_TMP
#define FIO_MEMORY_USE_THREAD_MUTEX 1
#define FIO_MEMORY_USE_THREAD_MUTEX FIO_USE_THREAD_MUTEX
#else
#if FIO_MEMORY_ARENA_COUNT > 0
/**
Expand Down Expand Up @@ -12958,7 +12954,7 @@ FIO_SFUNC FIO_NAME(FIO_MEMORY_NAME, __mem_arena_s) *
" Consider recompiling with more arenas."); \
warning_printed = 1; \
} while (0)
#else
#else /* !DEBUG || FIO_MEMORY_ARENA_COUNT <= 0 */
#define FIO___MEMORY_ARENA_LOCK_WARNING()
#endif
/** thread arena value */
Expand All @@ -12970,9 +12966,9 @@ FIO_SFUNC FIO_NAME(FIO_MEMORY_NAME, __mem_arena_s) *
void *p;
fio_thread_t t;
} u = {.t = fio_thread_current()};
arena_index = fio_risky_ptr(u.p) %
arena_index = (fio_risky_ptr(u.p) & 127) %
FIO_NAME(FIO_MEMORY_NAME, __mem_state)->arena_count;
#if defined(DEBUG) && 0
#if (defined(DEBUG) && 0)
static void *pthread_last = NULL;
if (pthread_last != u.p) {
FIO_LOG_DEBUG(
Expand Down Expand Up @@ -13072,10 +13068,10 @@ FIO_IFUNC size_t FIO_NAME(FIO_MEMORY_NAME, __mem_ptr2index)(
/* *****************************************************************************
Allocator State Initialization & Cleanup
***************************************************************************** */
#define FIO_MEMORY_STATE_SIZE(arean_count) \
#define FIO_MEMORY_STATE_SIZE(arena_count) \
FIO_MEM_BYTES2PAGES( \
(sizeof(*FIO_NAME(FIO_MEMORY_NAME, __mem_state)) + \
(sizeof(FIO_NAME(FIO_MEMORY_NAME, __mem_arena_s)) * (arean_count))))
(sizeof(FIO_NAME(FIO_MEMORY_NAME, __mem_arena_s)) * (arena_count))))

/* function declarations for functions called during cleanup */
FIO_IFUNC void FIO_NAME(FIO_MEMORY_NAME, __mem_chunk_dealloc)(
Expand Down Expand Up @@ -13202,37 +13198,41 @@ FIO_CONSTRUCTOR(FIO_NAME(FIO_MEMORY_NAME, __mem_state_setup)) {
/* allocate the state machine */
{
#if FIO_MEMORY_ARENA_COUNT > 0
size_t const arean_count = FIO_MEMORY_ARENA_COUNT;
size_t const arena_count = FIO_MEMORY_ARENA_COUNT;
#else
size_t arean_count = FIO_MEMORY_ARENA_COUNT_FALLBACK;
size_t arena_count = FIO_MEMORY_ARENA_COUNT_FALLBACK;
#ifdef _SC_NPROCESSORS_ONLN
arean_count = sysconf(_SC_NPROCESSORS_ONLN);
if (arean_count == (size_t)-1UL)
arean_count = FIO_MEMORY_ARENA_COUNT_FALLBACK;
arena_count = sysconf(_SC_NPROCESSORS_ONLN);
if (arena_count == (size_t)-1UL)
arena_count = FIO_MEMORY_ARENA_COUNT_FALLBACK;
else /* arenas !> threads (birthday) */
arean_count = (arean_count << 1) + 2;
#else
arena_count = (arena_count << 1) + 2;
#else /* FIO_MEMORY_ARENA_COUNT <= 0 */
#if _MSC_VER || __MINGW32__
/* https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-system_info
*/
SYSTEM_INFO win_system_info;
GetSystemInfo(&win_system_info);
arean_count = (size_t)win_system_info.dwNumberOfProcessors;
arena_count = (size_t)win_system_info.dwNumberOfProcessors;
#else
#warning Dynamic CPU core count is unavailable - assuming FIO_MEMORY_ARENA_COUNT_FALLBACK cores.
#endif
#endif /* _SC_NPROCESSORS_ONLN */
#if FIO_MEMORY_ARENA_COUNT < -1
arena_count = arena_count / (0 - FIO_MEMORY_ARENA_COUNT);
#endif
if (arena_count >= FIO_MEMORY_ARENA_COUNT_MAX)
arena_count = FIO_MEMORY_ARENA_COUNT_MAX;
if (!arena_count)
arena_count = 1;

if (arean_count >= FIO_MEMORY_ARENA_COUNT_MAX)
arean_count = FIO_MEMORY_ARENA_COUNT_MAX;

#endif /* FIO_MEMORY_ARENA_COUNT > 0 */
#endif /* FIO_MEMORY_ARENA_COUNT <= 0 */

const size_t s = FIO_MEMORY_STATE_SIZE(arean_count);
const size_t s = FIO_MEMORY_STATE_SIZE(arena_count);
FIO_NAME(FIO_MEMORY_NAME, __mem_state) =
(FIO_NAME(FIO_MEMORY_NAME, __mem_state_s *))FIO_MEM_SYS_ALLOC(s, 0);
FIO_ASSERT_ALLOC(FIO_NAME(FIO_MEMORY_NAME, __mem_state));
FIO_NAME(FIO_MEMORY_NAME, __mem_state)->arena_count = arean_count;
FIO_NAME(FIO_MEMORY_NAME, __mem_state)->arena_count = arena_count;
}
FIO_NAME(FIO_MEMORY_NAME, __mem_state)->blocks =
FIO_LIST_INIT(FIO_NAME(FIO_MEMORY_NAME, __mem_state)->blocks);
Expand Down Expand Up @@ -47263,6 +47263,8 @@ FIO_SFUNC void FIO_NAME_TEST(stl, sock)(void) {
}
do {
n += 16 * 1024; /* at 16Kb at a time */
if (n >= 32 * 1024 * 1024)
break;
} while (setsockopt(srv, SOL_SOCKET, SO_RCVBUF, (void *)&n, sn) != -1);
if (-1 != getsockopt(srv, SOL_SOCKET, SO_RCVBUF, (void *)&n, &sn) &&
sizeof(n) == sn)
Expand Down
4 changes: 0 additions & 4 deletions fio-stl/000 dependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,6 @@ Memory Allocation - FIO_MALLOC defines a FIOBJ dedicated memory allocator
/* fight fragmentation */
#define FIO_MEMORY_BLOCKS_PER_ALLOCATION_LOG 4
#endif
#ifndef FIO_MEMORY_ALIGN_LOG
/* align on 8 bytes, it's enough for FIOBJ types */
#define FIO_MEMORY_ALIGN_LOG 3
#endif
#ifndef FIO_MEMORY_CACHE_SLOTS
/* cache up to 64Mb */
#define FIO_MEMORY_CACHE_SLOTS 16
Expand Down
46 changes: 25 additions & 21 deletions fio-stl/010 mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Memory Allocation - Setup Alignment Info
#define FIO_MEMORY_ALIGN_LOG 3
#elif FIO_MEMORY_ALIGN_LOG > 10
#undef FIO_MEMORY_ALIGN_LOG
#define FIO_MEMORY_ALIGN_LOG 6
#define FIO_MEMORY_ALIGN_LOG 10
#endif

/* Helper macro, don't change this */
Expand Down Expand Up @@ -222,7 +222,7 @@ NOTE: most configuration values should be a power of 2 or a logarithmic value.

#ifndef FIO_MEMORY_USE_THREAD_MUTEX
#if FIO_USE_THREAD_MUTEX_TMP
#define FIO_MEMORY_USE_THREAD_MUTEX 1
#define FIO_MEMORY_USE_THREAD_MUTEX FIO_USE_THREAD_MUTEX
#else
#if FIO_MEMORY_ARENA_COUNT > 0
/**
Expand Down Expand Up @@ -979,7 +979,7 @@ FIO_SFUNC FIO_NAME(FIO_MEMORY_NAME, __mem_arena_s) *
" Consider recompiling with more arenas."); \
warning_printed = 1; \
} while (0)
#else
#else /* !DEBUG || FIO_MEMORY_ARENA_COUNT <= 0 */
#define FIO___MEMORY_ARENA_LOCK_WARNING()
#endif
/** thread arena value */
Expand All @@ -991,9 +991,9 @@ FIO_SFUNC FIO_NAME(FIO_MEMORY_NAME, __mem_arena_s) *
void *p;
fio_thread_t t;
} u = {.t = fio_thread_current()};
arena_index = fio_risky_ptr(u.p) %
arena_index = (fio_risky_ptr(u.p) & 127) %
FIO_NAME(FIO_MEMORY_NAME, __mem_state)->arena_count;
#if defined(DEBUG) && 0
#if (defined(DEBUG) && 0)
static void *pthread_last = NULL;
if (pthread_last != u.p) {
FIO_LOG_DEBUG(
Expand Down Expand Up @@ -1093,10 +1093,10 @@ FIO_IFUNC size_t FIO_NAME(FIO_MEMORY_NAME, __mem_ptr2index)(
/* *****************************************************************************
Allocator State Initialization & Cleanup
***************************************************************************** */
#define FIO_MEMORY_STATE_SIZE(arean_count) \
#define FIO_MEMORY_STATE_SIZE(arena_count) \
FIO_MEM_BYTES2PAGES( \
(sizeof(*FIO_NAME(FIO_MEMORY_NAME, __mem_state)) + \
(sizeof(FIO_NAME(FIO_MEMORY_NAME, __mem_arena_s)) * (arean_count))))
(sizeof(FIO_NAME(FIO_MEMORY_NAME, __mem_arena_s)) * (arena_count))))

/* function declarations for functions called during cleanup */
FIO_IFUNC void FIO_NAME(FIO_MEMORY_NAME, __mem_chunk_dealloc)(
Expand Down Expand Up @@ -1223,37 +1223,41 @@ FIO_CONSTRUCTOR(FIO_NAME(FIO_MEMORY_NAME, __mem_state_setup)) {
/* allocate the state machine */
{
#if FIO_MEMORY_ARENA_COUNT > 0
size_t const arean_count = FIO_MEMORY_ARENA_COUNT;
size_t const arena_count = FIO_MEMORY_ARENA_COUNT;
#else
size_t arean_count = FIO_MEMORY_ARENA_COUNT_FALLBACK;
size_t arena_count = FIO_MEMORY_ARENA_COUNT_FALLBACK;
#ifdef _SC_NPROCESSORS_ONLN
arean_count = sysconf(_SC_NPROCESSORS_ONLN);
if (arean_count == (size_t)-1UL)
arean_count = FIO_MEMORY_ARENA_COUNT_FALLBACK;
arena_count = sysconf(_SC_NPROCESSORS_ONLN);
if (arena_count == (size_t)-1UL)
arena_count = FIO_MEMORY_ARENA_COUNT_FALLBACK;
else /* arenas !> threads (birthday) */
arean_count = (arean_count << 1) + 2;
#else
arena_count = (arena_count << 1) + 2;
#else /* FIO_MEMORY_ARENA_COUNT <= 0 */
#if _MSC_VER || __MINGW32__
/* https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-system_info
*/
SYSTEM_INFO win_system_info;
GetSystemInfo(&win_system_info);
arean_count = (size_t)win_system_info.dwNumberOfProcessors;
arena_count = (size_t)win_system_info.dwNumberOfProcessors;
#else
#warning Dynamic CPU core count is unavailable - assuming FIO_MEMORY_ARENA_COUNT_FALLBACK cores.
#endif
#endif /* _SC_NPROCESSORS_ONLN */
#if FIO_MEMORY_ARENA_COUNT < -1
arena_count = arena_count / (0 - FIO_MEMORY_ARENA_COUNT);
#endif
if (arena_count >= FIO_MEMORY_ARENA_COUNT_MAX)
arena_count = FIO_MEMORY_ARENA_COUNT_MAX;
if (!arena_count)
arena_count = 1;

if (arean_count >= FIO_MEMORY_ARENA_COUNT_MAX)
arean_count = FIO_MEMORY_ARENA_COUNT_MAX;

#endif /* FIO_MEMORY_ARENA_COUNT > 0 */
#endif /* FIO_MEMORY_ARENA_COUNT <= 0 */

const size_t s = FIO_MEMORY_STATE_SIZE(arean_count);
const size_t s = FIO_MEMORY_STATE_SIZE(arena_count);
FIO_NAME(FIO_MEMORY_NAME, __mem_state) =
(FIO_NAME(FIO_MEMORY_NAME, __mem_state_s *))FIO_MEM_SYS_ALLOC(s, 0);
FIO_ASSERT_ALLOC(FIO_NAME(FIO_MEMORY_NAME, __mem_state));
FIO_NAME(FIO_MEMORY_NAME, __mem_state)->arena_count = arean_count;
FIO_NAME(FIO_MEMORY_NAME, __mem_state)->arena_count = arena_count;
}
FIO_NAME(FIO_MEMORY_NAME, __mem_state)->blocks =
FIO_LIST_INIT(FIO_NAME(FIO_MEMORY_NAME, __mem_state)->blocks);
Expand Down
2 changes: 2 additions & 0 deletions fio-stl/902 sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ FIO_SFUNC void FIO_NAME_TEST(stl, sock)(void) {
}
do {
n += 16 * 1024; /* at 16Kb at a time */
if (n >= 32 * 1024 * 1024)
break;
} while (setsockopt(srv, SOL_SOCKET, SO_RCVBUF, (void *)&n, sn) != -1);
if (-1 != getsockopt(srv, SOL_SOCKET, SO_RCVBUF, (void *)&n, &sn) &&
sizeof(n) == sn)
Expand Down
4 changes: 4 additions & 0 deletions tests/malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ int main(int argc, char const *argv[]) {
"(please wait):\n\n",
thread_count);
if (warmup) {
fprintf(stderr, "Warming up... ");
for (size_t i = 0; i < thread_count; ++i) {
FIO_ASSERT(fio_thread_create(threads + i, test_facil_malloc, NULL) == 0,
"Couldn't spawn thread.");
Expand All @@ -384,6 +385,7 @@ int main(int argc, char const *argv[]) {
errno);
}
test_mem_functions(NULL, calloc, NULL, NULL);
fprintf(stderr, "Finished.\n");
}

for (size_t i = 0; i < thread_count; ++i) {
Expand All @@ -405,6 +407,7 @@ int main(int argc, char const *argv[]) {
"(please wait):\n\n",
thread_count);
if (warmup) {
fprintf(stderr, "Warming up... ");
for (size_t i = 0; i < thread_count; ++i) {
FIO_ASSERT(fio_thread_create(threads + i, test_system_malloc, NULL) == 0,
"Couldn't spawn thread.");
Expand All @@ -416,6 +419,7 @@ int main(int argc, char const *argv[]) {
errno);
}
test_mem_functions(NULL, calloc, NULL, NULL);
fprintf(stderr, "Finished.\n");
}
for (size_t i = 0; i < thread_count; ++i) {
FIO_ASSERT(fio_thread_create(threads + i, test_system_malloc, NULL) == 0,
Expand Down

0 comments on commit 9a13ce8

Please sign in to comment.