Ticket 9431 - Node Features: should prefer using available nodes
Summary: Node Features: should prefer using available nodes
Status: RESOLVED FIXED
Alias: None
Product: Slurm
Classification: Unclassified
Component: Scheduling (show other tickets)
Version: 20.02.3
Hardware: Linux Linux
: 4 - Minor Issue
Assignee: Marcin Stolarek
QA Contact: Danny Auble
URL:
Depends on:
Blocks:
 
Reported: 2020-07-20 15:51 MDT by Felix Abecassis
Modified: 2020-10-12 00:42 MDT (History)
2 users (show)

See Also:
Site: NVIDIA (PSLA)
Slinky Site: ---
Alineos Sites: ---
Atos/Eviden Sites: ---
Confidential Site: ---
Coreweave sites: ---
Cray Sites: ---
DS9 clusters: ---
Google sites: ---
HPCnow Sites: ---
HPE Sites: ---
IBM Sites: ---
NOAA SIte: ---
NoveTech Sites: ---
Nvidia HWinf-CS Sites: ---
OCF Sites: ---
Recursion Pharma Sites: ---
SFW Sites: ---
SNIC sites: ---
Tzag Elita Sites: ---
Linux Distro: ---
Machine Name:
CLE Version:
Version Fixed: 20.02.6 20.11pre1
Target Release: ---
DevPrio: ---
Emory-Cloud Sites: ---


Attachments
v1 (1.25 KB, patch)
2020-08-04 08:26 MDT, Marcin Stolarek
Details | Diff

Note You need to log in before you can comment on or make changes to this ticket.
Description Felix Abecassis 2020-07-20 15:51:09 MDT
On our Selene cluster, the CPU is 2x AMD EPYC 7742. For performance, we use the NPS4 mode (4 NUMA nodes per socket) for this CPU. See the following links for more details:
https://www.servethehome.com/amd-epyc-7002-series-rome-delivers-a-knockout/6/
https://developer.amd.com/wp-content/resources/56827-1-0.pdf

But not all applications work well with this configuration, we want to allow users to switch to the NPS2 and NPS1 modes for testing purposes, NPS4 being the default. We have implemented a Slurm Node Features Plugin (https://slurm.schedmd.com/node_features_plugins.html) for this purpose. Users can then do "srun --constraint nps=1" to request a different mode for their jobs, the node will be rebooted if needed.

However, it seems the Slurm scheduler does not consider the current state of the nodes when selecting them for the job. For example, let's say we have two nodes with active feature "nps=4", when doing "srun --constraint nps=1", the first node will be selected and it will reboot into nps=1 mode.
We now have one node with nps=1 and one node with nps=4. The job completes and the first node becomes idle. If another job comes in and requests "--constraint nps=4", then we see Slurm selecting the first node again, triggering another reboot (from nps=1 to nps=4), delaying the job start for multiple minutes. Whereas it could have picked the second node to start immediately.

We expected the scheduler to first allocate from nodes that don't require a reboot. Can you please confirm that it's the current behavior, and advise on a way to improve it? Thanks

Note that our plugin returns "300" for node_features_p_boot_time, but it doesn't seem to impact the decision made by the scheduler. From a quick look at the code, it seems the boot time is only used by the backfill scheduler:
https://github.com/SchedMD/slurm/blob/slurm-20-02-3-1/src/plugins/sched/backfill/backfill.c#L2302-L2304
Is that right? If so, could we have this behavior for higher priority jobs?
Comment 1 Marcin Stolarek 2020-07-23 07:49:33 MDT
Felix,

Did you properly implement node_features_p_reboot_weight[1] in your plugin? How returned value compares with node weight you have in slurm.conf? 

cheers,
Marcin
Comment 2 Felix Abecassis 2020-07-23 11:41:10 MDT
I currently have the following in the plugin:
uint32_t node_features_p_reboot_weight(void)                                                                                                            
{                                                                                                                                                       
        return (INFINITE - 1);                                                                                                                          
}

The goal being to reboot only as a last resort. Can you confirm I didn't get the logic backward here?

Surprisingly, testing again on my local workstation, it seems the scheduler is now behaving as expected. But I often tweak my config for development purposes; so perhaps it's related to my setup. I'll do a bit more testing on our cluster soon. But lowering the importance to "Low", since it might have been an unrelated problem.
Comment 3 Felix Abecassis 2020-07-23 12:43:14 MDT
Testing a bit more (locally, not on the cluster). I can see the problem happens when a node is still in "completing" mode; so not "idle" like I described it in the original report. Perhaps it was just a race condition when I initially tested.

But I'll double check on our cluster as I mentioned, while being mindful of the state of each node.
Comment 4 Marcin Stolarek 2020-07-24 04:56:19 MDT
>The goal being to reboot only as a last resort. Can you confirm I didn't get the logic backward here?

Yes - nodes with lower priority should be allocated first(if possible)[1].

>[...]node is still in "completing" mode[...]
Yes - nodes in completing state are not allocated new jobs.

>But I'll double check on our cluster as I mentioned, while being mindful of the state of each node.
Please keep me posted.

cheers,
Marcin

[1]https://slurm.schedmd.com/slurm.conf.html#OPT_Weight
Comment 5 Felix Abecassis 2020-07-28 19:43:20 MDT
Marcin,

I can definitely reproduce the problem on our cluster. But I still can't reproduce it on a local machine running 2 slurm daemons.

It's even weirder, as it seems the scheduler actually goes out of its way to choose the *wrong* node and always reboot.

On the cluster, I'm using two nodes in a reservation: node-0098 and node-0099, with the following config:
node-0098 has active feature nps=4
node-0099 has active feature nps=1

When submitting a job with --constraint nps=4, it lands on node-0099, causing a reboot.
When submitting a job with --constraint nps=1, it lands on node-0098, also causing a reboot. 

If the initial node states are reversed (node-0098 with nps=1 and node-0099 with nps=4), then it's the same observation: the wrong node is always selected.

Any suggestion on how to debug this further?
Comment 6 Felix Abecassis 2020-07-28 22:01:29 MDT
I think it has no functional impact, but this variable should probably be uint32_t like "node_features_p_reboot_weight" and the function itself:
https://github.com/SchedMD/slurm/blob/slurm-20-02-3-1/src/common/node_features.c#L627
Comment 7 Felix Abecassis 2020-07-28 22:31:55 MDT
Another piece of the puzzle. In the situation described above:
>>>
node-0098 has active feature nps=4
node-0099 has active feature nps=1

When submitting a job with --constraint nps=4, it lands on node-0099, causing a reboot.
>>>
I just found out that if I do --constraint nps=4 --delay-boot=1; then node-0098 is taken instead, so no reboot is needed.

From the code, looks like it forces the nodes requiring a reboot to be excluded.
https://github.com/SchedMD/slurm/blob/ec43c1ec389058e6730d432b42ff7db4da05d7c9/src/slurmctld/node_scheduler.c#L1048-L1070
So that's a useful workaround, but not really a fix.

I guess a bug might be lurking in node_scheduler.c, since a node that requires a reboot should have a much higher weight:
https://github.com/SchedMD/slurm/blob/ec43c1ec389058e6730d432b42ff7db4da05d7c9/src/slurmctld/node_scheduler.c#L4159-L4176
Comment 8 Felix Abecassis 2020-07-29 12:02:06 MDT
Another important piece of information (maybe): we are using the topology/tree plugin on our cluster. But node-0098 and node-0099 are under the same leaf switch, and I'm requesting a single node.

But I thought, it might matter, given that it seems there was a bug in the past:
https://github.com/SchedMD/slurm/commit/5c5300d4eebbb6fe909c88441b9971c885d4e848
(note: I can't view bug 2284)
Comment 9 Marcin Stolarek 2020-07-30 05:07:43 MDT
Felix,

I'm looking at the code and preparing an environment where I can reproduce the issue.

Are you able to perform some tests in your environment? I'm interested if any of:
1) Defining nodes in slurm.conf with separate entries with different weights - can be node number as a weihgt.
2) Disabling topology/tree plugin
will change it to expected behavior.

cheers,
Marcin
Comment 10 Felix Abecassis 2020-07-30 14:03:33 MDT
We tried your suggestion 1) first:
node-0098 was assigned Weight=1 (the default)
node-0099 was assigned Weight=2

Testing the same combinations of initial states / job requests than in https://bugs.schedmd.com/show_bug.cgi?id=9431#c5 ; I saw no difference.

Also, while we're doing small code fixes, this line should be fixed too:
https://github.com/SchedMD/slurm/blob/ec43c1ec389058e6730d432b42ff7db4da05d7c9/src/slurmctld/node_scheduler.c#L4169

node_set_ptr->node_weight should be cast to uint64_t first; otherwise the left shift will be applied to a 32-bit value and in the case of, let's say INFINITY (0xffffffff), it will just lose the 8 MSBs.
So this function will return the same sched_weight for node_weight=0xffffffff and node_weight=0x00ffffff. I doubt it's the cause of the bug, since we are not modifying node weights, but it would still be good to cleanup imo.

For suggestion 2), we would have to try during a maintenance... so next week at a minimum.
Comment 11 Felix Abecassis 2020-07-30 18:27:20 MDT
I *finally* found the root cause of the problem, at least I hope so.

I was able to reproduce the problem on my local system, the key part was to use the topology/tree plugin. A simple config like that worked:
$ cat /etc/slurm/topology.conf
SwitchName=sw01  Nodes=ioctl-1,ioctl-2

After that, I was getting the same behavior: the wrong node was always selected.
That made it easier to dig in the code. I started by enabling "DEBUG 1" in src/slurmctld/node_scheduler.c, I saw the following:
slurmctld: NodeSet[0] Nodes:ioctl-1 NodeWeight:1 Flags:0 FeatureBits:0 SchedWeight:511
slurmctld: NodeSet[1] Nodes:ioctl-2 NodeWeight:4294967294 Flags:1 FeatureBits:0 SchedWeight:2203318222591
slurmctld: _pick_best_nodes: JobId=878 err:0 nodes:1:1:1 mode:0 select ioctl-2 from ioctl-[1-2]

That was surprising: ioctl-2 has a very high NodeWeight and Flags=1 (reboot required), but somehow _pick_best_nodes thought it was the best node.

Afterwards, I also found out that the problem only happens with cons_tres. cons_res behaved as expected for this particular scenario.

Going deeper into cons_tres, I saw this code snippet that is only executed when there is a topology present:
https://github.com/SchedMD/slurm/blob/slurm-20-02-3-1/src/plugins/select/cons_tres/job_test.c

This function sorts the list of nodes per sched_weight, but the sorting function seemed fishy:
https://github.com/SchedMD/slurm/blob/slurm-20-02-3-1/src/plugins/select/cons_tres/job_test.c#L1428-L1433
The sched weights are both uint64_t. When the difference is large, like it's our case here, it will not fit in a "int" type, and then the comparison will wrong.

This is the correct pattern for implementing the sort function without overflows:
https://github.com/SchedMD/slurm/blob/ec43c1ec389058e6730d432b42ff7db4da05d7c9/src/slurmctld/node_scheduler.c#L4178-L4188

I modified _topo_weight_sort to use the same pattern, and it seems to have fixed the scheduling problem on my local machine. I can't test on the cluster, so please review the change and push it if you think it's acceptable. I know very little about how cons_tres works.

Also, it seems this function has the same problem but with uint32_t values:
https://github.com/SchedMD/slurm/blob/ec43c1ec389058e6730d432b42ff7db4da05d7c9/src/plugins/select/cons_tres/job_test.c#L128-L133
Comment 13 Felix Abecassis 2020-07-31 10:03:15 MDT
I would like to humbly suggest to have Slurm tested under the "integer" sanitizer of Clang, if that's not the case already. See https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
> -fsanitize=integer: Checks for undefined or suspicious integer behavior (e.g. unsigned integer overflow).


Even if this particular code path (with a reboot needed) might have not been tested in the first place, this is a good tool to detect truncation/overflows. e.g. for this particular bug, with Slurm configured with CC=clang CFLAGS='-fsanitize=integer', it indeed reports a suspicious behavior in the comparison function:

slurmctld: debug2: select/cons_tres: select_p_job_test: evaluating JobId=921
job_test.c:1432:29: runtime error: unsigned integer overflow: 511 - 2203318222591 cannot be represented in type 'unsigned long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior job_test.c:1432:29 in
Comment 14 Marcin Stolarek 2020-08-04 05:25:09 MDT
Felix,
> I would like to humbly suggest to have Slurm tested under the "integer" sanitizer of Clang,
Thanks for that. I'll open a separate internal ticket to go through it.

>Going deeper into cons_tres, I saw this code snippet that is only executed when there is a topology present
Yes - _eval_nodes_topo it's the code path I suspected as having the issue.

I think that your approach is correct. I'll prepare a patch based on your suggestions from comment 11 (setting an author field to Felix Abecassis <fabecassis@nvidia.com>?) and move it to reviewers queue.

cheers,
Marcin
Comment 15 Marcin Stolarek 2020-08-04 08:26:04 MDT
Created attachment 15296 [details]
v1

Author: Felix Abecassis <fabecassis@nvidia.com>
Date:   Tue Aug 4 14:19:09 2020 +0000

    Fix potential overflow in cons_tres node sort functions

    Bug 9431
Comment 16 Felix Abecassis 2020-08-04 09:34:24 MDT
> I'll prepare a patch based on your suggestions from comment 11 (setting an author field to ?)

I think you should be the commit author, and then you can use the following:
Co-authored-by: Felix Abecassis <fabecassis@nvidia.com>

See https://stackoverflow.com/questions/7442112/how-to-attribute-a-single-commit-to-multiple-developers

Please consider what I suggested in https://bugs.schedmd.com/show_bug.cgi?id=9431#c10 too, thanks.
Comment 17 Felix Abecassis 2020-08-11 12:52:53 MDT
@Marcin

Is there any chance the overflow fix will make it to the next release of Slurm 20.02?

Thanks
Comment 18 Marcin Stolarek 2020-08-13 03:51:55 MDT
I'll try to bring our senior developers attention to the case, but I cannot guarantee that it will happen.

Cheers,
Marcin
Comment 24 Marcin Stolarek 2020-10-12 00:42:23 MDT
Felix,

The fix was merged ahead of 20.02.6 release[1].

cheers,
Marcin

[1]https://github.com/SchedMD/slurm/commit/8e26765d73b174b58f8702d7417acfe4b9e1cdd2