fix(scheduler): percent-limit capacity reads maxmem/maxswap, not mem/swap (bug-1834)

update_limit_res_value() computed a percent-based limit's capacity from
the resource's own live, fluctuating value (e.g. "mem"), letting the
enforced cap drift with unrelated memory pressure instead of staying
pinned to a stable fraction of total capacity. instantiate_limit() now
resolves a static capacity-source resource once at instantiation time
(mem->maxmem, swap->maxswap, table-driven), stored on a new
xce_vres_t.percent_res field; a missing counterpart falls back to
today's behavior rather than failing instantiation.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RLSNJhNoULvVcUhXEFafQC
This commit is contained in:
Rongsong Shen 2026-09-20 13:18:05 +00:00
parent 7982f28557
commit ea76f4771f
No known key found for this signature in database
GPG key ID: 5BCDAAE0123E9FE2
8 changed files with 368 additions and 15 deletions

View file

@ -141,8 +141,9 @@ typedef struct {
static int update_limit_res_value(zarray_t* array, xce_vres_t* vres)
{
float val = 0.0;
int rc = 0;
float val = 0.0;
int rc = 0;
xce_resource_t* capacity_res;
if ((array == NULL) || (vres == NULL)) {
return -EINVAL;
@ -151,7 +152,16 @@ static int update_limit_res_value(zarray_t* array, xce_vres_t* vres)
if (vres->limit->val.percent == 0) {
val = vres->limit->val.val;
} else {
rc = get_resvals(array, 1, &(vres->res->idx), &val);
/* bug-1834: prefer the resolved static capacity-source resource
* (e.g. "maxmem" for a "mem" limit) over `res` (the limit's own,
* possibly-dynamic resname) so this limit's capacity is a stable
* fraction of total capacity, not a fraction of whatever the
* resource's live value happens to be right now. `percent_res` is
* NULL (falls back to `res`, today's behavior) whenever
* instantiate_limit() found no known static counterpart. */
capacity_res = (vres->percent_res != NULL) ? vres->percent_res : vres->res;
rc = get_resvals(array, 1, &(capacity_res->idx), &val);
if (rc < 0) {
return rc;
}