From db143022244cb76d4efbc2a3de88b250ebe105f9 Mon Sep 17 00:00:00 2001 From: Gurdal Oruklu Date: Mon, 29 Sep 2025 22:14:13 +0000 Subject: [PATCH] RDKEMW-8825: App not killed when container reaches memory limit Added "swap" limit in the OCI config templates to enable OOM killing when memory limit is reached when swap memory is enabled. Signed-off-by: Gurdal Oruklu --- bundle/lib/source/DobbySpecConfig.cpp | 5 +++++ .../lib/source/templates/OciConfigJson1.0.2-dobby.template | 4 +++- .../lib/source/templates/OciConfigJsonVM1.0.2-dobby.template | 4 +++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/bundle/lib/source/DobbySpecConfig.cpp b/bundle/lib/source/DobbySpecConfig.cpp index 326d428a3..d339dfd9e 100644 --- a/bundle/lib/source/DobbySpecConfig.cpp +++ b/bundle/lib/source/DobbySpecConfig.cpp @@ -62,6 +62,10 @@ static const ctemplate::StaticTemplateString USERNS_DISABLED = static const ctemplate::StaticTemplateString MEM_LIMIT = STS_INIT(MEM_LIMIT, "MEM_LIMIT"); +static const ctemplate::StaticTemplateString MEM_SWAP_LIMIT = + STS_INIT(MEM_SWAP_LIMIT, "MEM_SWAP_LIMIT"); + +static constexpr unsigned MEM_SWAP_LIMIT_EXTRA_BYTES = 200u * 1024u * 1024u; static const ctemplate::StaticTemplateString CPU_SHARES_ENABLED = STS_INIT(CPU_SHARES_ENABLED, "CPU_SHARES_ENABLED"); @@ -1274,6 +1278,7 @@ bool DobbySpecConfig::processMemLimit(const Json::Value& value, } dictionary->SetIntValue(MEM_LIMIT, memLimit); + dictionary->SetIntValue(MEM_SWAP_LIMIT, memLimit + MEM_SWAP_LIMIT_EXTRA_BYTES); return true; } diff --git a/bundle/lib/source/templates/OciConfigJson1.0.2-dobby.template b/bundle/lib/source/templates/OciConfigJson1.0.2-dobby.template index 381017098..6b9dd85f9 100644 --- a/bundle/lib/source/templates/OciConfigJson1.0.2-dobby.template +++ b/bundle/lib/source/templates/OciConfigJson1.0.2-dobby.template @@ -327,7 +327,9 @@ static const char* ociJsonTemplate = R"JSON( {{/DEV_WHITELIST_SECTION}} ], "memory": { - "limit": {{MEM_LIMIT}} + "limit": {{MEM_LIMIT}}, + "swap": {{MEM_SWAP_LIMIT}}, + "swappiness": 60 }, "cpu": { {{#CPU_SHARES_ENABLED}} diff --git a/bundle/lib/source/templates/OciConfigJsonVM1.0.2-dobby.template b/bundle/lib/source/templates/OciConfigJsonVM1.0.2-dobby.template index ed1bc177f..1dc6eb3bd 100644 --- a/bundle/lib/source/templates/OciConfigJsonVM1.0.2-dobby.template +++ b/bundle/lib/source/templates/OciConfigJsonVM1.0.2-dobby.template @@ -338,7 +338,9 @@ static const char* ociJsonTemplate = R"JSON( {{/DEV_WHITELIST_SECTION}} ], "memory": { - "limit": {{MEM_LIMIT}} + "limit": {{MEM_LIMIT}}, + "swap": {{MEM_SWAP_LIMIT}}, + "swappiness": 60 }, "cpu": { {{#CPU_SHARES_ENABLED}}