Skip to content

Commit

Permalink
kernel/os: Fix msys allocation with multiply mpools
Browse files Browse the repository at this point in the history
When msys was configured with several mpools and one
of the pools run out of buffers, os_mbuf_get() returned
NULL even though other mpool did have buffers available.

Now search for suitable buffer checks if suitable pool
is empty and if not search continues.
  • Loading branch information
kasjer committed Aug 23, 2024
1 parent 6bd0db5 commit 3839468
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions kernel/os/src/os_msys.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,30 +86,32 @@ os_msys_reset(void)
STAILQ_INIT(&g_msys_pool_list);
}

static struct os_mbuf_pool *os_msys_find_pool(uint16_t dsize);

static struct os_mbuf_pool *
os_msys_find_biggest_pool(void)
{
/* Mempools are sorted by the blocksize, so just return last one */
return STAILQ_LAST(&g_msys_pool_list, os_mbuf_pool, omp_next);
return os_msys_find_pool(0xFFFF);
}

static struct os_mbuf_pool *
os_msys_find_pool(uint16_t dsize)
{
struct os_mbuf_pool *pool;
struct os_mbuf_pool *pool_with_free_blocks = NULL;
uint16_t pool_free_blocks;

pool = NULL;
STAILQ_FOREACH(pool, &g_msys_pool_list, omp_next) {
if (dsize <= pool->omp_databuf_len) {
break;
pool_free_blocks = pool->omp_pool->mp_num_free;
if (pool_free_blocks != 0) {
pool_with_free_blocks = pool;
if (dsize <= pool->omp_databuf_len) {
break;
}
}
}

if (!pool) {
pool = STAILQ_LAST(&g_msys_pool_list, os_mbuf_pool, omp_next);
}

return (pool);
return pool_with_free_blocks;
}


Expand Down

0 comments on commit 3839468

Please sign in to comment.