heap: update the calculation of fl index max and use bitfield in control_t

The calculation of fl index max is changed to always be the smallest
number that includes the size of the registered memory.

The control_construct() function now checks for minimum size as the control structure
parameters are calculated.

There is no longer a minimum configuration for fl index max so the tlsf_config
enum is striped down to remove unecessary compile time values.

the tlsf_size() function will fail if no tlsf pointer is passed as parameter since there
is no way to calculate a default tlsf size anymore.

bitfields are now used in control_t when possible which reduces the size of the structure
from 56 bytes to 36 bytes.
This commit is contained in:
Guillaume Souchere
2022-10-13 10:02:29 +02:00
committed by BOT
parent 9f6b549dea
commit 48b0000e22
5 changed files with 97 additions and 64 deletions

View File

@@ -39,28 +39,7 @@
enum tlsf_config
{
/* log2 of number of linear subdivisions of block sizes. Larger
** values require more memory in the control structure. Values of
** 4 or 5 are typical, 3 is for very small pools.
*/
SL_INDEX_COUNT_LOG2_MIN = 3,
/* All allocation sizes and addresses are aligned to 4 bytes. */
ALIGN_SIZE_LOG2 = 2,
ALIGN_SIZE = (1 << ALIGN_SIZE_LOG2),
/*
** We support allocations of sizes up to (1 << FL_INDEX_MAX) bits.
** However, because we linearly subdivide the second-level lists, and
** our minimum size granularity is 4 bytes, it doesn't make sense to
** create first-level lists for sizes smaller than SL_INDEX_COUNT * 4,
** or (1 << (SL_INDEX_COUNT_LOG2 + 2)) bytes, as there we will be
** trying to split size ranges into more slots than we have available.
** Instead, we calculate the minimum threshold size, and place all
** blocks below that size into the 0th first-level list.
** Values below are the absolute minimum to accept a pool addition
*/
FL_INDEX_MAX_MIN = 14, // For a less than 16kB pool
SL_INDEX_COUNT_MIN = (1 << SL_INDEX_COUNT_LOG2_MIN),
FL_INDEX_COUNT_MIN = (FL_INDEX_MAX_MIN - (SL_INDEX_COUNT_LOG2_MIN + ALIGN_SIZE_LOG2) + 1),
};