Skip to content

Commit

Permalink
util/bufpool: Do not zero newly allocated buf pool memory when init f…
Browse files Browse the repository at this point in the history
…unction is present.

When a buf pool allocates a new chunk of memory, the entire memory
chunk is zeroed out via a call to memset. This can be quite costly,
occur at inconvenient times, and end up being wasteful when buf pool
users initialize their own entries.

This change skips the memset when the buf pool has an init function
specified. For users who want no initialization to take place in the
buf pool code at all, a new ofi_bufpool_init_none() function is
available to specify as the init function to use.

Signed-off-by: Ben Lynam <Ben.Lynam@cornelisnetworks.com>
  • Loading branch information
belynam committed Mar 6, 2025
1 parent f09b96d commit d406496
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions include/ofi_mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,12 @@ static inline void *ofi_ibuf_alloc_at(struct ofi_bufpool *pool, size_t index)
return buf;
}

/*
* Empty buf pool init function that can be used to avoid initializing
* newly allocated buf pool entries.
*/
void ofi_bufpool_init_noop(struct ofi_bufpool_region *region, void *buf);

/*
* Persistent memory support
*/
Expand Down
12 changes: 9 additions & 3 deletions prov/util/src/util_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ int ofi_bufpool_grow(struct ofi_bufpool *pool)
size_t mem_allocated = 0;

FI_DBG(&core_prov, FI_LOG_CORE, "%s pool %p size %ld region_size %zu "
"entry_cnt %d chuck_cnt %d\n",
"entry_cnt %d chunk_cnt %d\n",
__func__, pool, pool->alloc_size, pool->region_size,
(int)(pool->entry_cnt+pool->attr.chunk_cnt),
(int)pool->attr.chunk_cnt);
Expand All @@ -167,7 +167,8 @@ int ofi_bufpool_grow(struct ofi_bufpool *pool)

mem_allocated += buf_region->pool->alloc_size;

memset(buf_region->alloc_region, 0, pool->alloc_size);
if (!pool->attr.init_fn)
memset(buf_region->alloc_region, 0, pool->alloc_size);
buf_region->mem_region = buf_region->alloc_region + pool->entry_size;
if (pool->attr.alloc_fn) {
ret = pool->attr.alloc_fn(buf_region);
Expand Down Expand Up @@ -270,7 +271,7 @@ int ofi_bufpool_create_attr(struct ofi_bufpool_attr *attr,

FI_DBG(&core_prov, FI_LOG_CORE,
"%s alloc_size %zu region_size %zu align_entry %zu "
"entry_size %zu chuck_cnt %ld pool %p (%p)\n",
"entry_size %zu chunk_cnt %ld pool %p (%p)\n",
__func__, pool->alloc_size, pool->region_size, pool->entry_size,
attr->size, pool->attr.chunk_cnt, pool, buf_pool);

Expand Down Expand Up @@ -317,3 +318,8 @@ int ofi_ibufpool_region_is_lower(struct dlist_entry *item, const void *arg)

return reg1->index < reg2->index;
}

void ofi_bufpool_init_noop(struct ofi_bufpool_region *region, void *buf)
{
/* This function is purposely empty */
}

0 comments on commit d406496

Please sign in to comment.