Allow customizing the scaling threshold with an environment variable
This commit is contained in:
parent
466ed42568
commit
574dbbc517
9 changed files with 82 additions and 12 deletions
24
src/util.ts
24
src/util.ts
|
|
@ -37,6 +37,11 @@ export const DEFAULT_DEBUG_ARTIFACT_NAME = "debug-artifacts";
|
|||
*/
|
||||
export const DEFAULT_DEBUG_DATABASE_NAME = "db";
|
||||
|
||||
/**
|
||||
* The default fraction of the total RAM above 8 GB that should be reserved for the system.
|
||||
*/
|
||||
const DEFAULT_RESERVED_RAM_SCALING_FACTOR = 0.05;
|
||||
|
||||
export interface SarifFile {
|
||||
version?: string | null;
|
||||
runs: SarifRun[];
|
||||
|
|
@ -161,15 +166,28 @@ function getSystemReservedMemoryMegaBytes(
|
|||
const fixedAmount = 1024 * (platform === "win32" ? 1.5 : 1);
|
||||
|
||||
if (isScalingReservedRamEnabled) {
|
||||
// Reserve an additional 5% of the amount of memory above 8 GB, since the amount used by the
|
||||
// kernel for page tables scales with the size of physical memory.
|
||||
const scaledAmount = 0.05 * Math.max(totalMemoryMegaBytes - 8 * 1024, 0);
|
||||
// Reserve an additional percentage of the amount of memory above 8 GB, since the amount used by
|
||||
// the kernel for page tables scales with the size of physical memory.
|
||||
const scaledAmount =
|
||||
getReservedRamScaleFactor() *
|
||||
Math.max(totalMemoryMegaBytes - 8 * 1024, 0);
|
||||
return fixedAmount + scaledAmount;
|
||||
} else {
|
||||
return fixedAmount;
|
||||
}
|
||||
}
|
||||
|
||||
function getReservedRamScaleFactor(): number {
|
||||
const envVar = Number.parseInt(
|
||||
process.env[EnvVar.SCALING_RESERVED_RAM_PERCENTAGE] || "",
|
||||
10,
|
||||
);
|
||||
if (envVar < 0 || envVar > 100 || Number.isNaN(envVar)) {
|
||||
return DEFAULT_RESERVED_RAM_SCALING_FACTOR;
|
||||
}
|
||||
return envVar / 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the codeql `--ram` flag as configured by the `ram` input.
|
||||
* If no value was specified, the total available memory will be used minus a
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue