Skip to content

Commit

Permalink
allocate memory based on physical cores
Browse files Browse the repository at this point in the history
  • Loading branch information
kmd-fl committed Aug 29, 2024
1 parent 9a87b57 commit c279460
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
8 changes: 8 additions & 0 deletions crates/core-distributor/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ impl Assignment {
.collect::<Vec<_>>()
}

pub fn physical_core_count(&self) -> usize {
self.cuid_cores
.values()
.map(|cores| cores.physical_core_id)
.collect::<BTreeSet<PhysicalCoreId>>()
.len()
}

pub fn pin_current_thread_with(&self, thread_pinner: &dyn ThreadPinner) {
thread_pinner.pin_current_thread_to_cpuset(&self.logical_core_ids());
}
Expand Down
5 changes: 4 additions & 1 deletion crates/vm-utils/src/vm_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct CreateVMDomainParams {
name: String,
image: PathBuf,
cpus: NonEmpty<LogicalCoreId>,
cores_num: usize,
bridge_name: String,
allow_gpu: bool,
}
Expand All @@ -26,13 +27,15 @@ impl CreateVMDomainParams {
name: String,
image: PathBuf,
cpus: NonEmpty<LogicalCoreId>,
cores_num: usize,
bridge_name: String,
allow_gpu: bool,
) -> Self {
Self {
name,
image,
cpus,
cores_num,
bridge_name,
allow_gpu,
}
Expand Down Expand Up @@ -346,7 +349,7 @@ fn prepare_xml(
}
mapping.push_str(format!("<vcpupin vcpu='{index}' cpuset='{logical_id}'/>").as_str());
}
let memory_in_kb = params.cpus.len() * 4 * 1024 * 1024; // 4Gbs per core
let memory_in_kb = params.cores_num * 4 * 1024 * 1024; // 4Gbs per core
let gpu_pci_configuration = gpu_pci_location
.iter()
.map(prepare_pci_config)
Expand Down
8 changes: 5 additions & 3 deletions crates/workers/src/workers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,14 +673,16 @@ impl Workers {
image: &Path,
vm_config: &VmConfig,
) -> Result<String, WorkersError> {
let assignment = {
let (cores_count, assignment) = {
let guard = self.assignments.read();
let assignment = guard
.get(&worker_id)
.ok_or_else(|| WorkersError::WorkerNotFound(worker_id))?;

NonEmpty::from_vec(assignment.logical_core_ids())
.ok_or_else(|| WorkersError::WrongAssignment)?
let logical_cores = NonEmpty::from_vec(assignment.logical_core_ids())
.ok_or_else(|| WorkersError::WrongAssignment)?;
let physical_cores_count = assignment.physical_core_count();
(physical_cores_count, logical_cores)
};

let file_name = &image
Expand Down

0 comments on commit c279460

Please sign in to comment.