0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-27 19:28:52 +02:00

libratbox: disable the block allocator, but keep it as a stub for now

This commit is contained in:
William Pitcock 2016-01-08 07:16:23 -06:00
parent 190a59706e
commit e575ed5193
9 changed files with 0 additions and 353 deletions

17
configure vendored
View file

@ -852,7 +852,6 @@ with_custom_version
enable_assert
enable_iodebug
enable_profile
enable_balloc
with_nicklen
with_topiclen
enable_warnings
@ -1513,7 +1512,6 @@ Optional Features:
hard(aborts the daemon)
--enable-iodebug Enable IO Debugging hooks
--enable-profile Enable profiling
--disable-balloc Disable the block allocator.
--enable-warnings Enable all sorts of warnings for debugging.
Optional Packages:
@ -16525,20 +16523,6 @@ else
$as_echo "no" >&6; }
fi
# Check whether --enable-balloc was given.
if test "${enable_balloc+set}" = set; then :
enableval=$enable_balloc; balloc=$enableval
else
balloc=yes
fi
if test "$balloc" = no; then
$as_echo "#define NOBALLOC 1" >>confdefs.h
fi
$as_echo "#define NICKNAMEHISTORYLENGTH 15000" >>confdefs.h
@ -20308,7 +20292,6 @@ Configuration of ${BRANDING_NAME}-${BRANDING_VERSION}:
Ziplinks : $zlib
OpenSSL : $openssl
Block allocator : $balloc
Nickname length : $NICKLEN
Topic length : $TOPICLEN

View file

@ -538,14 +538,6 @@ else
AC_MSG_RESULT(no)
fi
AC_ARG_ENABLE(balloc,
AC_HELP_STRING([--disable-balloc],[Disable the block allocator.]),
[balloc=$enableval], [balloc=yes])
if test "$balloc" = no; then
AC_DEFINE([NOBALLOC], 1, [Define to 1 if you wish to disable the block allocator.])
fi
AC_DEFINE([NICKNAMEHISTORYLENGTH], 15000, [Size of the WHOWAS array.])
AC_DEFINE([CHANNEL_HEAP_SIZE], 8192, [Size of the channel heap.])
AC_DEFINE([BAN_HEAP_SIZE], 4096, [Size of the ban heap.])
@ -696,7 +688,6 @@ Configuration of ${BRANDING_NAME}-${BRANDING_VERSION}:
Ziplinks : $zlib
OpenSSL : $openssl
Block allocator : $balloc
Nickname length : $NICKLEN
Topic length : $TOPICLEN

View file

@ -300,9 +300,6 @@
/* Size of the WHOWAS array. */
#undef NICKNAMEHISTORYLENGTH
/* Define to 1 if you wish to disable the block allocator. */
#undef NOBALLOC
/* Name of package */
#undef PACKAGE

17
libratbox/configure vendored
View file

@ -793,7 +793,6 @@ enable_mbedtls
enable_gnutls
enable_assert
enable_profile
enable_balloc
enable_warnings
'
ac_precious_vars='build_alias
@ -1453,7 +1452,6 @@ Optional Features:
--enable-assert Enable assert(). Choose between soft(warnings) and
hard(aborts the daemon)
--enable-profile Enable profiling
--disable-balloc Disable the block allocator.
--enable-warnings Enable all sorts of warnings for debugging.
Optional Packages:
@ -15378,20 +15376,6 @@ else
$as_echo "no" >&6; }
fi
# Check whether --enable-balloc was given.
if test "${enable_balloc+set}" = set; then :
enableval=$enable_balloc; balloc=$enableval
else
balloc=yes
fi
if test "$balloc" = no; then
$as_echo "#define NOBALLOC 1" >>confdefs.h
fi
# Check whether --enable-warnings was given.
if test "${enable_warnings+set}" = set; then :
enableval=$enable_warnings; CFLAGS="$CFLAGS -Wall -Werror -Wcast-qual -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wshadow -Wwrite-strings -W -Wno-unused -Wunused-function -Wunused-variable"
@ -17928,7 +17912,6 @@ echo "Installing into: $prefix"
echo "IPv6 support ................... $have_v6"
echo "Assert debugging ............... $assert"
echo "Block allocator ................ $balloc"
echo "SSL Type........................ $SSL_TYPE"
echo

View file

@ -447,14 +447,6 @@ else
AC_MSG_RESULT(no)
fi
AC_ARG_ENABLE(balloc,
AC_HELP_STRING([--disable-balloc],[Disable the block allocator.]),
[balloc=$enableval], [balloc=yes])
if test "$balloc" = no; then
AC_DEFINE([NOBALLOC], 1, [Define to 1 if you wish to disable the block allocator.])
fi
AC_ARG_ENABLE(warnings,
AC_HELP_STRING([--enable-warnings],[Enable all sorts of warnings for debugging.]),
[CFLAGS="$CFLAGS -Wall -Werror -Wcast-qual -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wshadow -Wwrite-strings -W -Wno-unused -Wunused-function -Wunused-variable"],[])
@ -693,7 +685,6 @@ echo "Installing into: $prefix"
echo "IPv6 support ................... $have_v6"
echo "Assert debugging ............... $assert"
echo "Block allocator ................ $balloc"
echo "SSL Type........................ $SSL_TYPE"
echo

View file

@ -237,9 +237,6 @@
/* Define this to disable debugging support. */
#undef NDEBUG
/* Define to 1 if you wish to disable the block allocator. */
#undef NOBALLOC
/* Name of package */
#undef PACKAGE

View file

@ -43,7 +43,6 @@ void *rb_bh_alloc(rb_bh *);
rb_bh *rb_bh_create(size_t elemsize, int elemsperblock, const char *desc);
int rb_bh_destroy(rb_bh *bh);
int rb_bh_gc(rb_bh *bh);
void rb_init_bh(void);
void rb_bh_usage(rb_bh *bh, size_t *bused, size_t *bfree, size_t *bmemusage, const char **desc);
void rb_bh_usage_all(rb_bh_usage_cb *cb, void *data);

View file

@ -59,18 +59,6 @@
#include <libratbox_config.h>
#include <ratbox_lib.h>
#ifndef NOBALLOC
#ifdef HAVE_MMAP /* We've got mmap() that is good */
#include <sys/mman.h>
/* HP-UX sucks */
#ifdef MAP_ANONYMOUS
#ifndef MAP_ANON
#define MAP_ANON MAP_ANONYMOUS
#endif
#endif
#endif
#endif
static uintptr_t offset_pad;
/* status information for an allocated block in heap */
@ -94,16 +82,8 @@ struct rb_bh
char *desc;
};
#ifndef NOBALLOC
static int newblock(rb_bh *bh);
static void rb_bh_gc_event(void *unused);
#endif /* !NOBALLOC */
static rb_dlink_list *heap_lists;
#if defined(WIN32)
static HANDLE block_heap;
#endif
#define rb_bh_fail(x) _rb_bh_fail(x, __FILE__, __LINE__)
static void
@ -113,29 +93,6 @@ _rb_bh_fail(const char *reason, const char *file, int line)
abort();
}
#ifndef NOBALLOC
/*
* static inline void free_block(void *ptr, size_t size)
*
* Inputs: The block and its size
* Output: None
* Side Effects: Returns memory for the block back to the OS
*/
static inline void
free_block(void *ptr, size_t size)
{
#ifdef HAVE_MMAP
munmap(ptr, size);
#else
#ifdef _WIN32
HeapFree(block_heap, 0, ptr);
#else
free(ptr);
#endif
#endif
}
#endif /* !NOBALLOC */
/*
* void rb_init_bh(void)
*
@ -159,104 +116,8 @@ rb_init_bh(void)
offset_pad &= ~(__alignof__(long long) - 1);
}
#endif
#ifndef NOBALLOC
#ifdef _WIN32
block_heap = HeapCreate(HEAP_NO_SERIALIZE, 0, 0);
#endif
rb_event_addish("rb_bh_gc_event", rb_bh_gc_event, NULL, 300);
#endif /* !NOBALLOC */
}
#ifndef NOBALLOC
/*
* static inline void *get_block(size_t size)
*
* Input: Size of block to allocate
* Output: Pointer to new block
* Side Effects: None
*/
static inline void *
get_block(size_t size)
{
void *ptr;
#ifdef HAVE_MMAP
#ifdef MAP_ANON
ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
#else
int zero_fd;
zero_fd = open("/dev/zero", O_RDWR);
if(zero_fd < 0)
rb_bh_fail("Failed opening /dev/zero");
ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, zero_fd, 0);
close(zero_fd);
#endif /* MAP_ANON */
if(ptr == MAP_FAILED)
ptr = NULL;
#else
#ifdef _WIN32
ptr = HeapAlloc(block_heap, 0, size);
#else
ptr = malloc(size);
#endif
#endif
return (ptr);
}
static void
rb_bh_gc_event(void *unused)
{
rb_dlink_node *ptr;
RB_DLINK_FOREACH(ptr, heap_lists->head)
{
rb_bh_gc(ptr->data);
}
}
/* ************************************************************************ */
/* FUNCTION DOCUMENTATION: */
/* newblock */
/* Description: */
/* Allocates a new block for addition to a blockheap */
/* Parameters: */
/* bh (IN): Pointer to parent blockheap. */
/* Returns: */
/* 0 if successful, 1 if not */
/* ************************************************************************ */
static int
newblock(rb_bh *bh)
{
rb_heap_block *b;
unsigned long i;
uintptr_t offset;
rb_dlink_node *node;
/* Setup the initial data structure. */
b = rb_malloc(sizeof(rb_heap_block));
b->alloc_size = bh->elemsPerBlock * bh->elemSize;
b->elems = get_block(b->alloc_size);
if(rb_unlikely(b->elems == NULL))
{
rb_free(b);
return (1);
}
offset = (uintptr_t)b->elems;
/* Setup our blocks now */
for(i = 0; i < bh->elemsPerBlock; i++, offset += bh->elemSize)
{
*((void **)offset) = b;
node = (void *)(offset + offset_pad);
rb_dlinkAdd((void *)offset, node, &bh->free_list);
}
rb_dlinkAdd(b, &b->node, &bh->block_list);
b->free_count = bh->elemsPerBlock;
return (0);
}
#endif /* !NOBALLOC */
/* ************************************************************************ */
/* FUNCTION DOCUMENTATION: */
/* rb_bh_create */
@ -290,32 +151,11 @@ rb_bh_create(size_t elemsize, int elemsperblock, const char *desc)
/* Allocate our new rb_bh */
bh = rb_malloc(sizeof(rb_bh));
#ifndef NOBALLOC
elemsize += offset_pad;
if((elemsize % sizeof(void *)) != 0)
{
/* Pad to even pointer boundary */
elemsize += sizeof(void *);
elemsize &= ~(sizeof(void *) - 1);
}
#endif
bh->elemSize = elemsize;
bh->elemsPerBlock = elemsperblock;
if(desc != NULL)
bh->desc = rb_strdup(desc);
#ifndef NOBALLOC
/* Be sure our malloc was successful */
if(newblock(bh))
{
if(bh != NULL)
free(bh);
rb_lib_log("newblock() failed");
rb_outofmemory(); /* die.. out of memory */
}
#endif /* !NOBALLOC */
if(bh == NULL)
{
rb_bh_fail("bh == NULL when it shouldn't be");
@ -339,45 +179,13 @@ rb_bh_create(size_t elemsize, int elemsperblock, const char *desc)
void *
rb_bh_alloc(rb_bh *bh)
{
#ifndef NOBALLOC
rb_dlink_node *new_node;
rb_heap_block **block;
void *ptr;
#endif
lrb_assert(bh != NULL);
if(rb_unlikely(bh == NULL))
{
rb_bh_fail("Cannot allocate if bh == NULL");
}
#ifdef NOBALLOC
return (rb_malloc(bh->elemSize));
#else
if(bh->free_list.head == NULL)
{
/* Allocate new block and assign */
/* newblock returns 1 if unsuccessful, 0 if not */
if(rb_unlikely(newblock(bh)))
{
rb_lib_log("newblock() failed");
rb_outofmemory(); /* Well that didn't work either...bail */
}
if(bh->free_list.head == NULL)
{
rb_lib_log("out of memory after newblock()...");
rb_outofmemory();
}
}
new_node = bh->free_list.head;
block = (rb_heap_block **) new_node->data;
ptr = (void *)((uintptr_t)new_node->data + (uintptr_t)offset_pad);
rb_dlinkDelete(new_node, &bh->free_list);
(*block)->free_count--;
memset(ptr, 0, bh->elemSize - offset_pad);
return (ptr);
#endif
}
@ -395,10 +203,6 @@ rb_bh_alloc(rb_bh *bh)
int
rb_bh_free(rb_bh *bh, void *ptr)
{
#ifndef NOBALLOC
rb_heap_block *block;
void *data;
#endif
lrb_assert(bh != NULL);
lrb_assert(ptr != NULL);
@ -414,22 +218,7 @@ rb_bh_free(rb_bh *bh, void *ptr)
return (1);
}
#ifdef NOBALLOC
rb_free(ptr);
#else
data = (void *)((uintptr_t)ptr - (uintptr_t)offset_pad);
block = *(rb_heap_block **) data;
/* XXX */
if(rb_unlikely
(!((uintptr_t)ptr >= (uintptr_t)block->elems
&& (uintptr_t)ptr < (uintptr_t)block->elems + (uintptr_t)block->alloc_size)))
{
rb_bh_fail("rb_bh_free() bogus pointer");
}
block->free_count++;
rb_dlinkAdd(data, (rb_dlink_node *)ptr, &bh->free_list);
#endif /* !NOBALLOC */
return (0);
}
@ -447,22 +236,9 @@ rb_bh_free(rb_bh *bh, void *ptr)
int
rb_bh_destroy(rb_bh *bh)
{
#ifndef NOBALLOC
rb_dlink_node *ptr, *next;
rb_heap_block *b;
#endif
if(bh == NULL)
return (1);
#ifndef NOBALLOC
RB_DLINK_FOREACH_SAFE(ptr, next, bh->block_list.head)
{
b = ptr->data;
free_block(b->elems, b->alloc_size);
rb_free(b);
}
#endif /* !NOBALLOC */
rb_dlinkDelete(&bh->hlist, heap_lists);
rb_free(bh->desc);
rb_free(bh);
@ -473,26 +249,6 @@ rb_bh_destroy(rb_bh *bh)
void
rb_bh_usage(rb_bh *bh, size_t *bused, size_t *bfree, size_t *bmemusage, const char **desc)
{
#ifndef NOBALLOC
size_t used, freem, memusage;
if(bh == NULL)
{
return;
}
freem = rb_dlink_list_length(&bh->free_list);
used = (rb_dlink_list_length(&bh->block_list) * bh->elemsPerBlock) - freem;
memusage = used * bh->elemSize;
if(bused != NULL)
*bused = used;
if(bfree != NULL)
*bfree = freem;
if(bmemusage != NULL)
*bmemusage = memusage;
if(desc != NULL)
*desc = bh->desc;
#else
if(bused != NULL)
*bused = 0;
if(bfree != NULL)
@ -501,7 +257,6 @@ rb_bh_usage(rb_bh *bh, size_t *bused, size_t *bfree, size_t *bmemusage, const ch
*bmemusage = 0;
if(desc != NULL)
*desc = "no blockheap";
#endif
}
void
@ -551,51 +306,3 @@ rb_bh_total_usage(size_t *total_alloc, size_t *total_used)
if(total_used != NULL)
*total_used = used_memory;
}
#ifndef NOBALLOC
int
rb_bh_gc(rb_bh *bh)
{
rb_heap_block *b;
rb_dlink_node *ptr, *next;
unsigned long i;
uintptr_t offset;
if(bh == NULL)
{
/* somebody is smoking some craq..(probably lee, but don't tell him that) */
return (1);
}
if((rb_dlink_list_length(&bh->free_list) < bh->elemsPerBlock)
|| rb_dlink_list_length(&bh->block_list) == 1)
{
/* There couldn't possibly be an entire free block. Return. */
return (0);
}
RB_DLINK_FOREACH_SAFE(ptr, next, bh->block_list.head)
{
b = ptr->data;
if(rb_dlink_list_length(&bh->block_list) == 1)
return (0);
if(b->free_count == bh->elemsPerBlock)
{
/* i'm seriously going to hell for this.. */
offset = (uintptr_t)b->elems;
for(i = 0; i < bh->elemsPerBlock; i++, offset += (uintptr_t)bh->elemSize)
{
rb_dlinkDelete((rb_dlink_node *)(offset + offset_pad),
&bh->free_list);
}
rb_dlinkDelete(&b->node, &bh->block_list);
free_block(b->elems, b->alloc_size);
rb_free(b);
}
}
return (0);
}
#endif /* !NOBALLOC */

View file

@ -2,7 +2,6 @@ rb_bh_alloc
rb_bh_create
rb_bh_destroy
rb_bh_free
rb_bh_gc
rb_bh_total_usage
rb_bh_usage
rb_bh_usage_all