Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scx_rustland: reduce overhead by caching host topology #238

Merged
merged 2 commits into from
Apr 24, 2024

Conversation

arighi
Copy link
Collaborator

@arighi arighi commented Apr 23, 2024

Looking at perf top it seems that the scheduler can spend a significant amount of time in topology::Cache::span(), especially when the system is running a significant amount of tasks:

5.46% scx_rustland [.] scx_utils::topology::Cache::span

Considering that scx_rustland doesn't support CPU hotplugging yet (it requires a full restart to properly handle CPU hotplug events), we can completely avoid this overhead by caching the cores/CPUs mapping at the beginning, when the scheduler starts, instead of constantly re-evaluating the CPU topology information.

This allows to reduce the scheduler overhead by ~10% CPU utilization under heavy load conditions (from ~68% -> ~60%, according to top).

Copy link
Contributor

@Byte-Lab Byte-Lab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but we should probably also make the Cpumask implementation more efficient. I'll work on that

@Byte-Lab
Copy link
Contributor

In case you want to give it a try, this might help: #241

@arighi
Copy link
Collaborator Author

arighi commented Apr 24, 2024

In case you want to give it a try, this might help: #241

Updated this PR on top of #241, also introducing a new TopologyMap object, that can be used to cache Topology information (instead of implementing a custom local caching in scx_rustland).

Introuce a TopologyMap object, represented as an array of arrays, where
each inner array corresponds to a core containing its associated CPU
IDs.

This object can be used as a cache to facilitate efficient iteration
over the entire host's topology.

Example usage:

  let topo = Topology::new()?;
  let topo_map = TopologyMap::new(topo)?;
  for (core_id, core) in topo_map.iter().enumerate() {
      for cpu in core {
          println!("core={} cpu={}", core_id, cpu);
      }
  }

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
Looking at perf top it seems that the scheduler can spend a significant
amount of time iterating over the CPU topology/cpumask information,
especially when the system is running a significant amount of tasks:

  2.57% scx_rustland [.] <scx_utils::cpumask::CpumaskIntoIterator as core::iter::traits::iterator::Iterator>::next

Considering that scx_rustland doesn't support CPU hotplugging yet (it
requires a full restart to properly handle CPU hotplug events), we can
completely avoid this overhead by caching a TopologyMap object at the
beginning, when the scheduler starts, instead of constantly
re-evaluating the CPU topology information.

This allows to reduce the scheduler overhead by ~5% CPU utilization
under heavy load conditions (from ~65% -> ~60%, according to top).

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
@arighi arighi force-pushed the rustland-reduce-topology-overhead branch from 538232c to 5302ff1 Compare April 24, 2024 15:10
@arighi
Copy link
Collaborator Author

arighi commented Apr 24, 2024

(meh... pushed the wrong branch, should be good now)

@arighi arighi merged commit 973aded into main Apr 24, 2024
1 check passed
@arighi arighi deleted the rustland-reduce-topology-overhead branch April 24, 2024 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants