{
  "slug": "memory-swap-max",
  "term": "memory.swap.max",
  "aliases": [
    "cgroup v2 swap limit",
    "cgroup swap hard limit"
  ],
  "definition": "memory.swap.max is the cgroup v2 control that limits charged swap usage separately from resident-memory usage.",
  "note": "In Linux 6.12, the default is max; numeric limits are expressed in bytes. memory.swap.high is a separate throttling threshold, not the normal hard limit. memory.zswap.max instead caps memory used by the compressed pool. These counters describe different resources. [cgroup-v612]\n\nWriting a smaller swap limit does not synchronously empty existing swap entries. swap_max_write changes the limit and returns; later swap charging checks the swap counter. Setting it to zero prevents new swap charges, including those needed for new zswap-backed entries, but is not a command to cancel already-submitted device I/O. [memcontrol-v612]\n\nWith zswap enabled, memory.zswap.writeback=0 still permits zswap stores but disallows backing-device fallback after a failed store and zswap writeback. An ancestor's disabled setting also applies. This differs from denying new swap charges altogether; recurring compression failures can make reclaim inefficient. [cgroup-v612]\n\nThe disabled-backend exception is decisive: mem_cgroup_zswap_writeback_enabled returns true when zswap is disabled, before examining the cgroup hierarchy. Therefore memory.zswap.writeback=0 alone does not prohibit ordinary swap-device writes in that configuration. [memcontrol-v612]\n\nZero-filled pages are a separate case. After swap-slot allocation and preparation, swap_writepage can record a zero-filled folio in a bitmap and return before calling zswap_store or checking writeback permission. No device write on that path is not evidence that zswap compressed the page. This does not bypass the earlier swap charge. [page-io-v612]",
  "advantages": [],
  "limitations": [
    {
      "text": "These version-scoped controls do not guarantee application latency, recovery durability or absence of all host I/O.",
      "citationIds": [
        "cgroup-v612",
        "page-io-v612"
      ]
    }
  ],
  "related": [
    "zswap",
    "swapfile"
  ],
  "citations": [
    {
      "id": "cgroup-v612",
      "title": "Linux 6.12 cgroup v2: swap and zswap controls",
      "url": "https://docs.kernel.org/6.12/admin-guide/cgroup-v2.html",
      "accessed": "2026-12-01"
    },
    {
      "id": "memcontrol-v612",
      "title": "Linux v6.12 memcontrol.c: swap_max_write, swap charging and mem_cgroup_zswap_writeback_enabled",
      "url": "https://github.com/torvalds/linux/blob/v6.12/mm/memcontrol.c",
      "accessed": "2026-12-01"
    },
    {
      "id": "page-io-v612",
      "title": "Linux v6.12 page_io.c: swap_writepage zeromap, zswap and writeback ordering",
      "url": "https://github.com/torvalds/linux/blob/v6.12/mm/page_io.c",
      "accessed": "2026-12-01"
    }
  ],
  "provenance": [
    "Source review of Linux v6.12; no memory-pressure experiment, kernel reconfiguration or swap activation was performed."
  ],
  "status": "shipping",
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-12-01"
}
