Skip to content

Commit 48807d8

Browse files
committed
UCP/RNDV: align max frags to mpool chunk size
1 parent 099a795 commit 48807d8

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/ucp/rndv/rndv_mtype.inl

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,21 +179,40 @@ static unsigned ucp_proto_rndv_mtype_fc_reschedule_cb(void *arg)
179179

180180
/**
181181
* Compute maximum number of fragments allowed based on configured max memory
182-
* and fragment size for the given memory type.
182+
* and fragment size for the given memory type. The result is rounded down to
183+
* the allocation chunk granularity (rndv_num_frags).
183184
*
184185
* @param context The UCP context.
185186
* @param frag_mem_type Memory type used for fragments.
186187
*
187-
* @return Maximum number of fragments that fit within the configured memory limit.
188+
* @return Maximum number of fragments that fit within the configured memory
189+
* limit, aligned to allocation chunk size.
188190
*/
189191
static UCS_F_ALWAYS_INLINE size_t
190192
ucp_proto_rndv_mtype_fc_max_frags(ucp_context_h context,
191193
ucs_memory_type_t frag_mem_type)
192194
{
193-
size_t max_mem = context->config.ext.rndv_mtype_worker_max_mem;
194-
size_t frag_size = context->config.ext.rndv_frag_size[frag_mem_type];
195+
size_t max_mem = context->config.ext.rndv_mtype_worker_max_mem;
196+
size_t frag_size = context->config.ext.rndv_frag_size[frag_mem_type];
197+
size_t frags_in_chunk = context->config.ext.rndv_num_frags[frag_mem_type];
198+
size_t max_frags;
199+
200+
/* frag_size must be > 0 for mtype protocols - validated during proto init */
201+
ucs_assert(frag_size > 0);
202+
203+
/* Compute max fragments and round down to allocation chunk granularity */
204+
max_frags = max_mem / frag_size;
205+
max_frags = (max_frags / frags_in_chunk) * frags_in_chunk;
206+
207+
if (max_frags == 0) {
208+
ucs_warn("RNDV_MTYPE_WORKER_MAX_MEM (%zu) is too low for %s "
209+
"(frag_size=%zu, frags_per_alloc=%zu), using minimum %zu "
210+
"frags", max_mem, ucs_memory_type_names[frag_mem_type],
211+
frag_size, frags_in_chunk, frags_in_chunk);
212+
return frags_in_chunk;
213+
}
195214

196-
return (frag_size > 0) ? (max_mem / frag_size) : SIZE_MAX;
215+
return max_frags;
197216
}
198217

199218
/**

0 commit comments

Comments
 (0)