diff --git a/src/paths.js b/src/paths.js index 5d3c03bf7..0cd9c7000 100644 --- a/src/paths.js +++ b/src/paths.js @@ -60,6 +60,8 @@ exports = module.exports = { GHOST_USER_FILE: path.join(baseDir(), 'platformdata/cloudron_ghost.json'), + SWAP_RATIO_FILE: path.join(baseDir(), 'platformdata/swap-ratio'), + // this pattern is for the cloudron logs API route to work BACKUP_LOG_FILE: path.join(baseDir(), 'platformdata/logs/backup/app.log'), UPDATER_LOG_FILE: path.join(baseDir(), 'platformdata/logs/updater/app.log'), diff --git a/src/system.js b/src/system.js index d93e7cfde..47d8b840a 100644 --- a/src/system.js +++ b/src/system.js @@ -166,7 +166,12 @@ function getMemory(callback) { } function getMemoryAllocation(limit) { - const pc = os.totalmem() / (os.totalmem() + getSwapSize()); - const ratio = Math.round(pc * 10) / 10; // a simple ratio + let ratio = parseFloat(safe.fs.readFileSync(paths.SWAP_RATIO_FILE, 'utf8'), 10); + + if (!ratio) { + const pc = os.totalmem() / (os.totalmem() + getSwapSize()); + ratio = Math.round(pc * 10) / 10; // a simple ratio + } + return Math.round(Math.round(limit * ratio) / 1048576) * 1048576; // nearest MB }