Skip to content

Commit

Permalink
Minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
marinosi committed Nov 8, 2023
1 parent 2341d07 commit 384ebed
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/ext/machnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ static inline MachnetRingSlot_t *_machnet_buffers_alloc(
// Try to allocate from the application cache.
uint32_t index = 0;
while (index < cnt) {
if (ctx->app_buffer_cache.count == 0) {
if (unlikely(ctx->app_buffer_cache.count == 0)) {
// The cache is empty, so we need to allocate from the global pool.
ctx->app_buffer_cache.count += __machnet_channel_buf_alloc_bulk(
ctx, NUM_CACHED_BUFS, ctx->app_buffer_cache.indices, NULL);
if (ctx->app_buffer_cache.count == 0) {
if (unlikely(ctx->app_buffer_cache.count == 0)) {
// We failed to allocate from the global pool.
goto fail;
}
Expand Down Expand Up @@ -215,15 +215,16 @@ static inline void _machnet_buffers_release(MachnetChannelCtx_t *ctx,
uint32_t index = 0;
while (index < cnt) {
uint32_t retries = 5;
while (ctx->app_buffer_cache.count == NUM_CACHED_BUFS) {
while (unlikely(ctx->app_buffer_cache.count == NUM_CACHED_BUFS)) {
// The cache is full, free to global pool.
uint32_t elements_to_free = ctx->app_buffer_cache.count / 2;
MachnetRingSlot_t *indices_to_free =
ctx->app_buffer_cache.indices + (NUM_CACHED_BUFS - elements_to_free);
ctx->app_buffer_cache.count -= __machnet_channel_buf_free_bulk(
ctx, elements_to_free, indices_to_free);

if (retries-- == 0 && ctx->app_buffer_cache.count == NUM_CACHED_BUFS) {
if (unlikely(retries-- == 0 &&
ctx->app_buffer_cache.count == NUM_CACHED_BUFS)) {
/*
* XXX (ilias): If we reach here, we have failed to free the buffers to
* the global pool and we are going to leak them. Terminate execution.
Expand Down

0 comments on commit 384ebed

Please sign in to comment.