Skip to content

Make container swap limit configurable independently of memory limit #424

@goruklu

Description

@goruklu

Summary

The OCI config templates currently hard-code the cgroup memory.memsw.limit_in_bytes (swap) to the same value as memory.limit_in_bytes, making it impossible to configure swap independently of the memory limit.

"memory": {
    "limit": {{MEM_LIMIT}},
    "swap": {{MEM_LIMIT}},   <-- always tied to memLimit
    "swappiness": 60
},

Proposed Change

New optional swapLimit spec field

Add a new top-level swapLimit field to the Dobby JSON spec. When present it sets the cgroup swap limit independently of memLimit. When absent the behaviour is unchanged — swap defaults to the same value as memLimit (i.e. no additional swap beyond the memory limit).

{
    "memLimit": 2998272,
    "swapLimit": 5996544
}

The kernel requires memory.memsw.limit_in_bytes >= memory.limit_in_bytes, so an error is returned if swapLimit is set lower than memLimit.

Files to change

File Change
bundle/lib/source/DobbySpecConfig.cpp New MEM_SWAP ctemplate constant; JSON_FLAG_SWAPLIMIT flag; new processSwapLimit() processor registered in the field map; step-5 default sets MEM_SWAP = memLimit when swapLimit is absent
bundle/lib/include/DobbySpecConfig.h Declaration of processSwapLimit()
bundle/lib/source/templates/OciConfigJson1.0.2-dobby.template "swap": {{MEM_SWAP}} (was {{MEM_LIMIT}})
bundle/lib/source/templates/OciConfigJsonVM1.0.2-dobby.template Same template fix

Backward compatibility

Fully backward compatible. Existing specs that only specify memLimit produce identical OCI output to before.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions