cvmts: Allow specifying cgroup cpu period
probably limited utility wise but it's there now
This commit is contained in:
@@ -19,8 +19,8 @@ export class CGroupController {
|
||||
WriteValue(key: string, value: string) {
|
||||
try {
|
||||
writeFileSync(path.join(this.cg.Path(), `${this.controller}.${key}`), value);
|
||||
} catch(e) {
|
||||
logger.error({error: e, controller_key: `${this.controller}.${key}`, value: value }, 'Failed to set CGroup controller value')
|
||||
} catch (e) {
|
||||
logger.error({ error: e, controller_name: this.controller, controller_key: `${this.controller}.${key}`, value: value }, 'Failed to set CGroup controller value');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,11 +35,11 @@ export class CGroup {
|
||||
InitControllers(wants_cpuset: boolean) {
|
||||
// Configure this "root" cgroup to provide cpu and cpuset controllers to the leaf
|
||||
// QEMU cgroups. A bit iffy but whatever.
|
||||
if(wants_cpuset) {
|
||||
if (wants_cpuset) {
|
||||
try {
|
||||
writeFileSync(path.join(this.path, 'cgroup.subtree_control'), '+cpu +cpuset');
|
||||
} catch(err) {
|
||||
logger.error({error: err}, 'Could not provide cpuset controller to subtree');
|
||||
} catch (err) {
|
||||
logger.error({ error: err }, 'Could not provide cpuset controller to subtree. runOnCpus will not function.');
|
||||
// just give up if this fails
|
||||
writeFileSync(path.join(this.path, 'cgroup.subtree_control'), '+cpu');
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { CGroup } from '../util/cgroup.js';
|
||||
export interface CgroupLimits {
|
||||
cpuUsageMax?: number;
|
||||
runOnCpus?: number[];
|
||||
periodMs?: number;
|
||||
limitProcess?: boolean;
|
||||
}
|
||||
|
||||
@@ -19,12 +20,19 @@ interface CGroupValue {
|
||||
function MakeValuesFromLimits(limits: CgroupLimits): CGroupValue[] {
|
||||
let option_array = [];
|
||||
|
||||
// The default period is 100 ms, which matches cgroups2 defaults.
|
||||
let periodUs = 100 * 1000;
|
||||
|
||||
// Convert a user-configured period to us, since that's what cgroups2 expects.
|
||||
if(limits.periodMs)
|
||||
periodUs = limits.periodMs * 1000;
|
||||
|
||||
if (limits.cpuUsageMax) {
|
||||
// cpu.max
|
||||
option_array.push({
|
||||
controller: 'cpu',
|
||||
key: 'max',
|
||||
value: `${(limits.cpuUsageMax / 100) * 100000} 100000`
|
||||
value: `${(limits.cpuUsageMax / 100) * periodUs} ${periodUs}`
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user