Skip to content

Commit 31de904

Browse files
committed
Set up plugin so that it can use mem_avail, if sent by host, to present realistic limit: minimum of what's actually available on teh host and what has been set in the configuration.
1 parent ed745da commit 31de904

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

packages/labextension/src/model.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,25 @@ export namespace ResourceUsage {
254254
this._memoryAvailable = numBytes !== undefined;
255255
this._currentMemory = currentMemory;
256256
this._memUnits = memUnits;
257-
this._memoryLimit = memoryLimit
258-
? memoryLimit / MEMORY_UNIT_LIMITS[memUnits]
257+
258+
// Use mem_avail if the host exposes it.
259+
const hostAvailBytes = value.mem_avail ?? null ;
260+
let minMemAvailable = null;
261+
let hostMaxBytes = hostAvailBytes ? ( hostAvailBytes + numBytes ) : null;
262+
263+
if ( memoryLimit && hostMaxBytes ) { minMemAvailable = Math.min(hostMaxBytes,memoryLimit); }
264+
else if ( hostMaxBytes ) { minMemAvailable = hostMaxBytes }
265+
else if ( memoryLimit ) { minMemAvailable = memoryLimit }
266+
else if ( hostAvailBytes ) { minMemAvailable = hostAvailBytes + numBytes; }
267+
268+
this._memoryLimit = minMemAvailable
269+
? minMemAvailable / MEMORY_UNIT_LIMITS[memUnits]
259270
: null;
271+
272+
// this._memoryLimit = memoryLimit
273+
// ? memoryLimit / MEMORY_UNIT_LIMITS[memUnits]
274+
// : null;
275+
260276
const memoryPercent = this.memoryLimit
261277
? Math.min(this._currentMemory / this.memoryLimit, 1)
262278
: 0;
@@ -373,6 +389,7 @@ namespace Private {
373389
export interface IMetricRequestResult {
374390
rss: number;
375391
pss?: number;
392+
mem_avail?: number;
376393
cpu_percent?: number;
377394
cpu_count?: number;
378395
disk_total?: number;

0 commit comments

Comments
 (0)