mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 02:48:37 +08:00
mm_grantable.c: Fix infinite loop due to memory fragmentation
The search algorithm does not work with the ctz approach at all, if there is a free range of granules that does not fit a specific allocation (i.e. the granule allocation is fragmented) it will cause an infinite loop as the algorithm will try to find free space from the same (free) starting granule, causing an infinite loop. The clz approach works for all cases, it will find the last used granule and the search will continue from the next free granule. Also, offsetting a full GAT must be sizeof(gat[0] - 1), which is 31 in this case. The reason is that the upper level search function increments the value by +1.
This commit is contained in:
parent
f313ee5715
commit
fed3da9f03
1 changed files with 1 additions and 15 deletions
|
@ -232,21 +232,7 @@ failure:
|
|||
{
|
||||
/* Handle full GAT quickly */
|
||||
|
||||
tmp = 32;
|
||||
}
|
||||
else if (c == r.sidx)
|
||||
{
|
||||
/* offset of first unused when matching for free */
|
||||
|
||||
v = ~v;
|
||||
#ifdef CONFIG_HAVE_BUILTIN_CTZ
|
||||
tmp = __builtin_ctz(v);
|
||||
#else
|
||||
tmp = (uint32_t)((lsb_mask(v)) * DEBRUJIN_NUM) >> 27;
|
||||
DEBUGASSERT(tmp < sizeof(DEBRUJIN_LUT));
|
||||
tmp = DEBRUJIN_LUT[tmp];
|
||||
#endif
|
||||
tmp = tmp - 1; /* Ok, because v >= 1 */
|
||||
tmp = 31;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue