1
0
mirror of https://github.com/adtools/clib2.git synced 2025-12-08 14:59:05 +00:00

Maximum slab size limited, debug mode errors fixed

The maximum slab size is now 2^17 bytes (= 131072). If you request a slab size larger than this, you will get slab sizes of 131072 bytes instead.

Enabling the memory management debugging code no longer produces compiler errors.
This commit is contained in:
Olaf Barthel
2016-11-21 12:27:40 +01:00
parent 799ee705e8
commit 7e201fea06
19 changed files with 90 additions and 73 deletions

View File

@ -1,6 +1,6 @@
#define VERSION 1
#define REVISION 208
#define DATE "19.11.2016"
#define VERS "amiga.lib 1.208"
#define VSTRING "amiga.lib 1.208 (19.11.2016)\r\n"
#define VERSTAG "\0$VER: amiga.lib 1.208 (19.11.2016)"
#define REVISION 209
#define DATE "21.11.2016"
#define VERS "amiga.lib 1.209"
#define VSTRING "amiga.lib 1.209 (21.11.2016)\r\n"
#define VERSTAG "\0$VER: amiga.lib 1.209 (21.11.2016)"

View File

@ -1 +1 @@
208
209

View File

@ -1,6 +1,6 @@
#define VERSION 1
#define REVISION 208
#define DATE "19.11.2016"
#define VERS "c.lib 1.208"
#define VSTRING "c.lib 1.208 (19.11.2016)\r\n"
#define VERSTAG "\0$VER: c.lib 1.208 (19.11.2016)"
#define REVISION 209
#define DATE "21.11.2016"
#define VERS "c.lib 1.209"
#define VSTRING "c.lib 1.209 (21.11.2016)\r\n"
#define VERSTAG "\0$VER: c.lib 1.209 (21.11.2016)"

View File

@ -1 +1 @@
208
209

View File

@ -1,3 +1,13 @@
c.lib 1.209 (21.11.2016)
- The maximum slab size is now 2^17 bytes (= 131072). If you request
a slab size larger than this, you will get slab sizes of 131072
bytes instead.
- Enabling the memory management debugging code no longer produces
compiler errors.
c.lib 1.208 (19.11.2016)
- Updated <stdlib.h> with new functions and data structures for

View File

@ -1,6 +1,6 @@
#define VERSION 1
#define REVISION 208
#define DATE "19.11.2016"
#define VERS "debug.lib 1.208"
#define VSTRING "debug.lib 1.208 (19.11.2016)\r\n"
#define VERSTAG "\0$VER: debug.lib 1.208 (19.11.2016)"
#define REVISION 209
#define DATE "21.11.2016"
#define VERS "debug.lib 1.209"
#define VSTRING "debug.lib 1.209 (21.11.2016)\r\n"
#define VERSTAG "\0$VER: debug.lib 1.209 (21.11.2016)"

View File

@ -1 +1 @@
208
209

View File

@ -1,6 +1,6 @@
#define VERSION 1
#define REVISION 208
#define DATE "19.11.2016"
#define VERS "m.lib 1.208"
#define VSTRING "m.lib 1.208 (19.11.2016)\r\n"
#define VERSTAG "\0$VER: m.lib 1.208 (19.11.2016)"
#define REVISION 209
#define DATE "21.11.2016"
#define VERS "m.lib 1.209"
#define VSTRING "m.lib 1.209 (21.11.2016)\r\n"
#define VERSTAG "\0$VER: m.lib 1.209 (21.11.2016)"

View File

@ -1 +1 @@
208
209

View File

@ -1,6 +1,6 @@
#define VERSION 1
#define REVISION 208
#define DATE "19.11.2016"
#define VERS "m881.lib 1.208"
#define VSTRING "m881.lib 1.208 (19.11.2016)\r\n"
#define VERSTAG "\0$VER: m881.lib 1.208 (19.11.2016)"
#define REVISION 209
#define DATE "21.11.2016"
#define VERS "m881.lib 1.209"
#define VSTRING "m881.lib 1.209 (21.11.2016)\r\n"
#define VERSTAG "\0$VER: m881.lib 1.209 (21.11.2016)"

View File

@ -1 +1 @@
208
209

View File

@ -1,6 +1,6 @@
#define VERSION 1
#define REVISION 208
#define DATE "19.11.2016"
#define VERS "net.lib 1.208"
#define VSTRING "net.lib 1.208 (19.11.2016)\r\n"
#define VERSTAG "\0$VER: net.lib 1.208 (19.11.2016)"
#define REVISION 209
#define DATE "21.11.2016"
#define VERS "net.lib 1.209"
#define VSTRING "net.lib 1.209 (21.11.2016)\r\n"
#define VERSTAG "\0$VER: net.lib 1.209 (21.11.2016)"

View File

@ -1 +1 @@
208
209

View File

@ -55,7 +55,7 @@ __get_slab_usage(__slab_usage_callback callback)
__memory_lock();
sui.sui_slab_size = __slab_data.sd_MaxSlabSize;
sui.sui_slab_size = __slab_data.sd_StandardSlabSize;
sui.sui_num_single_allocations = __slab_data.sd_NumSingleAllocations;
sui.sui_total_single_allocation_size = __slab_data.sd_TotalSingleAllocationSize;
@ -72,7 +72,7 @@ __get_slab_usage(__slab_usage_callback callback)
sui.sui_num_slabs++;
sui.sui_total_slab_allocation_size += sizeof(*sn) + __slab_data.sd_MaxSlabSize;
sui.sui_total_slab_allocation_size += sizeof(*sn) + __slab_data.sd_StandardSlabSize;
}
}

View File

@ -92,7 +92,7 @@ __get_allocation_size(size_t size)
/****************************************************************************/
void *
__allocate_memory(size_t size,BOOL never_free,const char * UNUSED unused_file,int UNUSED unused_line)
__allocate_memory(size_t size,BOOL never_free,const char * UNUSED debug_file_name,int UNUSED debug_line_number)
{
struct MemoryNode * mn;
size_t allocation_size;
@ -215,8 +215,8 @@ __allocate_memory(size_t size,BOOL never_free,const char * UNUSED unused_file,in
mn->mn_AlreadyFree = FALSE;
mn->mn_Allocation = body;
mn->mn_AllocationSize = allocation_size;
mn->mn_File = (char *)file;
mn->mn_Line = line;
mn->mn_File = (char *)debug_file_name;
mn->mn_Line = debug_line_number;
mn->mn_FreeFile = NULL;
mn->mn_FreeLine = 0;
@ -228,7 +228,7 @@ __allocate_memory(size_t size,BOOL never_free,const char * UNUSED unused_file,in
{
kprintf("[%s] + %10ld 0x%08lx [",__program_name,size,body);
kprintf("allocated at %s:%ld]\n",file,line);
kprintf("allocated at %s:%ld]\n",debug_file_name,debug_line_number);
}
#endif /* __MEM_DEBUG_LOG */
@ -264,7 +264,7 @@ __allocate_memory(size_t size,BOOL never_free,const char * UNUSED unused_file,in
{
kprintf("[%s] + %10ld 0x%08lx [",__program_name,size,NULL);
kprintf("FAILED: allocated at %s:%ld]\n",file,line);
kprintf("FAILED: allocated at %s:%ld]\n",debug_file_name,debug_line_number);
}
}
#endif /* __MEM_DEBUG_LOG */

View File

@ -200,7 +200,7 @@ struct MemoryTree
/* This keeps track of individual slabs. Each slab begins with this
* header and is followed by the memory it manages. The size of that
* memory "slab" is fixed and matches what is stored in
* SlabData.sd_MaxSlabSize.
* SlabData.sd_StandardSlabSize.
*
* Each slab manages allocations of a specific maximum size, e.g. 8, 16, 32,
* 64, etc. bytes. Multiple slabs can exist which manage allocations of the same
@ -245,13 +245,13 @@ struct SlabData
* which are 8 bytes in size, sd_Slabs[4] is for 16 byte
* chunks, etc. The minimum chunk size is 8, which is why
* lists 0..2 are not used. Currently, there is an upper limit
* of 2^31 bytes per chunk, but you should not be using slab
* of 2^17 bytes per chunk, but you should not be using slab
* chunks much larger than 4096 bytes.
*/
struct MinList sd_Slabs[31];
struct MinList sd_Slabs[17];
/* Memory allocations which are larger than the limit
* found in the sd_MaxSlabSize field are kept in this list.
* found in the sd_StandardSlabSize field are kept in this list.
* They are never associated with a slab.
*/
struct MinList sd_SingleAllocations;
@ -262,13 +262,13 @@ struct SlabData
*/
struct MinList sd_EmptySlabs;
/* This is the maximum size of a memory allocation which may
/* This is the standard size of a memory allocation which may
* be made from a slab that can accommodate it. This number
* is initialized from the __slab_max_size global variable,
* if > 0, and unless it already is a power of two, it will
* be rounded up to the next largest power of two.
*/
size_t sd_MaxSlabSize;
size_t sd_StandardSlabSize;
/* These fields kees track of how many entries there are in
* the sd_SingleAllocations list, and how much memory these

View File

@ -54,17 +54,17 @@ __slab_allocate(size_t allocation_size)
D(("allocating %lu bytes of memory",allocation_size));
assert( __slab_data.sd_MaxSlabSize > 0 );
assert( __slab_data.sd_StandardSlabSize > 0 );
/* Number of bytes to allocate exceeds the slab size?
* If so, allocate this memory chunk separately and
* keep track of it.
*/
if(allocation_size > __slab_data.sd_MaxSlabSize)
if(allocation_size > __slab_data.sd_StandardSlabSize)
{
struct MinNode * single_allocation;
D(("allocation size is > %ld; this will be stored separately",__slab_data.sd_MaxSlabSize));
D(("allocation size is > %ld; this will be stored separately",__slab_data.sd_StandardSlabSize));
D(("allocating %ld (MinNode) + %ld = %ld bytes",sizeof(*single_allocation),allocation_size,sizeof(*single_allocation) + allocation_size));
#if defined(__amigaos4__)
@ -103,7 +103,7 @@ __slab_allocate(size_t allocation_size)
ULONG chunk_size;
int slab_index;
D(("allocation size is <= %ld; this will be allocated from a slab",__slab_data.sd_MaxSlabSize));
D(("allocation size is <= %ld; this will be allocated from a slab",__slab_data.sd_StandardSlabSize));
/* Chunks must be at least as small as a MinNode, because
* that's what we use for keeping track of the chunks which
@ -230,15 +230,15 @@ __slab_allocate(size_t allocation_size)
*/
if(new_sn == NULL)
{
D(("no slab is available for reuse; allocating a new slab (%lu bytes)",sizeof(*sn) + __slab_data.sd_MaxSlabSize));
D(("no slab is available for reuse; allocating a new slab (%lu bytes)",sizeof(*sn) + __slab_data.sd_StandardSlabSize));
#if defined(__amigaos4__)
{
new_sn = (struct SlabNode *)AllocVec(sizeof(*sn) + __slab_data.sd_MaxSlabSize,MEMF_PRIVATE);
new_sn = (struct SlabNode *)AllocVec(sizeof(*sn) + __slab_data.sd_StandardSlabSize,MEMF_PRIVATE);
}
#else
{
new_sn = (struct SlabNode *)AllocVec(sizeof(*sn) + __slab_data.sd_MaxSlabSize,MEMF_ANY);
new_sn = (struct SlabNode *)AllocVec(sizeof(*sn) + __slab_data.sd_StandardSlabSize,MEMF_ANY);
}
#endif /* __amigaos4__ */
@ -257,7 +257,7 @@ __slab_allocate(size_t allocation_size)
D(("setting up slab 0x%08lx", new_sn));
assert( chunk_size <= __slab_data.sd_MaxSlabSize );
assert( chunk_size <= __slab_data.sd_StandardSlabSize );
memset(new_sn,0,sizeof(*new_sn));
@ -270,7 +270,7 @@ __slab_allocate(size_t allocation_size)
* SlabNode header.
*/
first_byte = (BYTE *)&new_sn[1];
last_byte = &first_byte[__slab_data.sd_MaxSlabSize - chunk_size];
last_byte = &first_byte[__slab_data.sd_StandardSlabSize - chunk_size];
for(free_chunk = (struct MinNode *)first_byte ;
free_chunk <= (struct MinNode *)last_byte;
@ -356,16 +356,16 @@ __slab_free(void * address,size_t allocation_size)
{
D(("freeing allocation at 0x%08lx, %lu bytes",address,allocation_size));
assert( __slab_data.sd_MaxSlabSize > 0 );
assert( __slab_data.sd_StandardSlabSize > 0 );
/* Number of bytes allocated exceeds the slab size?
* Then the chunk was allocated separately.
*/
if(allocation_size > __slab_data.sd_MaxSlabSize)
if(allocation_size > __slab_data.sd_StandardSlabSize)
{
struct MinNode * mn = address;
D(("allocation size is > %ld; this was stored separately",__slab_data.sd_MaxSlabSize));
D(("allocation size is > %ld; this was stored separately",__slab_data.sd_StandardSlabSize));
Remove((struct Node *)&mn[-1]);
@ -389,7 +389,7 @@ __slab_free(void * address,size_t allocation_size)
ULONG chunk_size;
int slab_index;
D(("allocation size is <= %ld; this was allocated from a slab",__slab_data.sd_MaxSlabSize));
D(("allocation size is <= %ld; this was allocated from a slab",__slab_data.sd_StandardSlabSize));
/* Chunks must be at least as small as a MinNode, because
* that's what we use for keeping track of the chunks which
@ -422,13 +422,13 @@ __slab_free(void * address,size_t allocation_size)
/* Find the slab which contains the memory chunk. */
if(slab_list != NULL)
{
const size_t usable_range = __slab_data.sd_MaxSlabSize - chunk_size;
const size_t usable_range = __slab_data.sd_StandardSlabSize - chunk_size;
struct SlabNode * sn;
BYTE * first_byte;
BYTE * last_byte;
BOOL freed = FALSE;
assert( chunk_size <= __slab_data.sd_MaxSlabSize );
assert( chunk_size <= __slab_data.sd_StandardSlabSize );
for(sn = (struct SlabNode *)slab_list->mlh_Head ;
sn->sn_MinNode.mln_Succ != NULL ;
@ -495,15 +495,22 @@ __slab_free(void * address,size_t allocation_size)
void
__slab_init(size_t slab_size)
{
const size_t max_slab_size = (1UL << (NUM_ENTRIES(__slab_data.sd_Slabs)));
size_t size;
SETDEBUGLEVEL(2);
D(("slab_size = %ld",slab_size));
/* Do not allow for a slab size that is larger than
* what we support.
*/
if(slab_size > max_slab_size)
slab_size = max_slab_size;
/* If the maximum allocation size to be made from the slab
* is not already a power of 2, round it up. We do not
* support allocations larger than 2^31, and the maximum
* support allocations larger than 2^17, and the maximum
* allocation size should be much smaller.
*
* Note that the maximum allocation size also defines the
@ -533,8 +540,8 @@ __slab_init(size_t slab_size)
NewList((struct List *)&__slab_data.sd_SingleAllocations);
NewList((struct List *)&__slab_data.sd_EmptySlabs);
__slab_data.sd_MaxSlabSize = size;
__slab_data.sd_InUse = TRUE;
__slab_data.sd_StandardSlabSize = size;
__slab_data.sd_InUse = TRUE;
}
}

View File

@ -1,6 +1,6 @@
#define VERSION 1
#define REVISION 208
#define DATE "19.11.2016"
#define VERS "unix.lib 1.208"
#define VSTRING "unix.lib 1.208 (19.11.2016)\r\n"
#define VERSTAG "\0$VER: unix.lib 1.208 (19.11.2016)"
#define REVISION 209
#define DATE "21.11.2016"
#define VERS "unix.lib 1.209"
#define VSTRING "unix.lib 1.209 (21.11.2016)\r\n"
#define VERSTAG "\0$VER: unix.lib 1.209 (21.11.2016)"

View File

@ -1 +1 @@
208
209