Skip to content

Conversation

@aenertia
Copy link
Contributor

@aenertia aenertia commented Jan 25, 2026

feat(system) Memory Management Overhaul: ZRAM Tiering, Swap, and Kernel Configs

This commit introduces a comprehensive overhaul of memory management across all
supported ROCKNIX devices. It deprecates the legacy `mount-swap` script in
favor of a new, robust `rocknix-memory-manager`.

Key Changes:

  • New Memory Manager (`rocknix-memory-manager`):

    • Replaces `mount-swap` with a Tiered Memory Architecture.
    • Smart "ZSTD" Interpretation (Hybrid Tiering):
      • If `ZRAM_COMPRESSION_ALGO` is set to "zstd", the manager automatically
        configures a hybrid pipeline:
        1. Primary: LZO-RLE (Low latency) for immediate writes to prevent stutter.
        2. Secondary: ZSTD (High compression) enabled via `CONFIG_ZRAM_MULTI_COMP`
          for background recompression of idle pages.
    • Auto-Configuration & Defaults:
      • High-Performance Targets (RK3588, S922X, SM8x50): Default to "Auto" ZRAM
        sizing and "zstd" profile (Hybrid Tiering enabled).
      • Low-Power Targets (RK3326, RK3566, H700): Default to ZRAM disabled ("0")
        to conserve system resources.
      • Swap File: Defaults to disabled ("0") on all targets to preserve flash storage.
    • Tuning: Dynamic sysctl application (`swappiness=100`, `page-cluster=0`)
      optimized for the new hybrid zram setup.
  • Runtime Configuration:

    • Users on low-end targets can enable ZRAM by copying defaults:
      `cp /etc/swap.conf /storage/.config/swap.conf`
      and setting `ZRAM_SIZE="Auto"` or a specific value (e.g., "512").
    • Configuration supports user overrides for algorithm, sizing, and swap files.
  • Kernel Configuration Standardization:

    • ZRAM: Converted to modular (`=m`) to allow runtime algorithm switching.
    • Multi-Compression: Enabled `CONFIG_ZRAM_MULTI_COMP` on capable SoCs
      (Rockchip, Qualcomm, Amlogic) to support the LZO-RLE -> ZSTD pipeline.
    • Algorithms: Enabled `LZO-RLE` (default), `ZSTD`, and `LZ4` modules.
    • ZSMALLOC: Modularized (`=m`) with chain size 8.
    • THP: Standardized to `madvise` to reduce unneeded compaction latency.
    • Cgroups: Enabled `CONFIG_CGROUP_FREEZER` for consistent suspend handling.
  • Platform Specifics:

    • SDM845/SM8250: Enabled `CONFIG_PSI` and fixed toolchain versioning.
    • Rockchip/Amlogic: Enabled architecture-specific migration features.
  • System Services:

    • Added `rocknix-memory-manager.service` (oneshot, pre-shutdown).
    • Updated `util-linux` to enable `fallocate` for instant swap generation

@aenertia
Copy link
Contributor Author

Note all features can be enabled/disabled at runtime via overide on /etc/swap.conf placed into /storage/.config/swap.conf

@porschemad911
Copy link
Contributor

Thanks, the scope of this PR looks good.

aenertia added a commit to aenertia/distribution that referenced this pull request Jan 25, 2026
This commit implements Kernel Samepage Merging (KSM) orchestration as a native component of the rocknix-memory-manager, building upon the foundational infrastructure established in PR ROCKNIX#2223 (ROCKNIX#2223).

KSM provides transparent page deduplication across the system, allowing the kernel to merge identical memory pages into a single copy-on-write reference. This is critical for ARM-based emulation environments where multiple standalone emulator instances or large guest RAM mappings frequently contain redundant data structures.

Technical Implementation:

1. Kernel Configuration:
   * CONFIG_KSM is enabled across all target device kernel configurations.

2. Manager Integration:
   * Added setup_ksm() to the rocknix-memory-manager to configure scan intensity and sleep intervals via /sys/kernel/mm/ksm/ sysfs nodes.
   * The manager now executes KSM initialization during the --setup phase if ENABLE_KSM is configured.

3. Observability and Metrics:
   * Enhanced the --status command to extract and report real-time deduplication metrics.
   * Metrics include current KSM run status, pages shared (merged), and total RAM saved (shared - unique).

4. Hardware-Specific Profiling:
   * Implements tiered scan rates based on SoC performance tiers:
     * High-end (RK3588, SM8xxx): Enabled with aggressive scan rates (200 pages/200ms) to maximize RAM density.
     * Mid-range (RK3399, S922X): Enabled with moderate rates (100 pages/500ms).
     * Low-end (H700, RK3326, RK3566): Disabled by default to reserve all CPU cycles for primary emulation threads.

5. Build System Integration:
   * Extends the util-linux package overlay to propagate KSM tuning variables (ENABLE_KSM, KSM_SCAN_PAGES, KSM_SLEEP_MS) into the final /etc/swap.conf.

This deduplication layer acts as a secondary efficiency tier above ZRAM, increasing effective RAM capacity without the latency penalties associated with physical storage I/O.
@porschemad911
Copy link
Contributor

porschemad911 commented Jan 25, 2026

Can remove SWAP_TYPE entirely, always add zram tools to the build.

@aenertia aenertia force-pushed the zram-swap-core branch 2 times, most recently from cc3c6ae to b8fb013 Compare January 25, 2026 10:49
aenertia added a commit to aenertia/distribution that referenced this pull request Jan 25, 2026
This commit integrates Kernel Samepage Merging (KSM) into the unified
'rocknix-memory-manager'. KSM scans memory for identical pages and merges
them, releasing RAM back to the system. This is particularly effective
for emulators that fork processes or load redundant assets.

Features:
- Orchestration: KSM logic is injected into rocknix-memory-manager setup.
- Tuning: Configurable pages-to-scan and sleep-milliseconds via options.
- Observability: `rocknix-memory-manager --status` now reports KSM
  merge efficiency and saved RAM.

Defaults:
- High-End (RK3588, RK3399, etc): Enabled by default (Aggressive scan).
- Low-End (H700, RK3326): Disabled by default to save CPU cycles.
ref# ROCKNIX#2223
@spycat88
Copy link
Contributor

spycat88 commented Jan 25, 2026

You are still manually editing kernel configs and not updating them properly, we can't see what options are being enabled in your PR as a result of this.

You need to run DEVICE=SM8550 tools/adjust_kernel_config olddefconfig for example after editing the kernel configs so they are updated properly.

For example SM8550 had the following changes

diff --git a/projects/ROCKNIX/devices/SM8550/linux/linux.aarch64.conf b/projects/ROCKNIX/devices/SM8550/linux/linux.aarch64.conf
index a1680837d3..a1b6706f18 100644
--- a/projects/ROCKNIX/devices/SM8550/linux/linux.aarch64.conf
+++ b/projects/ROCKNIX/devices/SM8550/linux/linux.aarch64.conf
@@ -11,8 +11,8 @@ CONFIG_AS_VERSION=24400
 CONFIG_LD_IS_BFD=y
 CONFIG_LD_VERSION=24400
 CONFIG_LLD_VERSION=0
-CONFIG_RUSTC_VERSION=109200
-CONFIG_RUSTC_LLVM_VERSION=210103
+CONFIG_RUSTC_VERSION=0
+CONFIG_RUSTC_LLVM_VERSION=0
 CONFIG_CC_CAN_LINK=y
 CONFIG_CC_HAS_ASM_GOTO_OUTPUT=y
 CONFIG_CC_HAS_ASM_GOTO_TIED_OUTPUT=y
@@ -21,11 +21,6 @@ CONFIG_CC_HAS_ASM_INLINE=y
 CONFIG_CC_HAS_ASSUME=y
 CONFIG_CC_HAS_NO_PROFILE_FN_ATTR=y
 CONFIG_LD_CAN_USE_KEEP_IN_OVERLAY=y
-CONFIG_RUSTC_HAS_COERCE_POINTEE=y
-CONFIG_RUSTC_HAS_SPAN_FILE=y
-CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES=y
-CONFIG_RUSTC_HAS_FILE_WITH_NUL=y
-CONFIG_RUSTC_HAS_FILE_AS_C_STR=y
 CONFIG_PAHOLE_VERSION=0
 CONFIG_IRQ_WORK=y
 CONFIG_BUILDTIME_TABLE_SORT=y
@@ -139,7 +134,8 @@ CONFIG_TASKSTATS=y
 # CONFIG_TASK_DELAY_ACCT is not set
 CONFIG_TASK_XACCT=y
 CONFIG_TASK_IO_ACCOUNTING=y
-# CONFIG_PSI is not set
+CONFIG_PSI=y
+# CONFIG_PSI_DEFAULT_DISABLED is not set
 # end of CPU/Task time and stats accounting

 CONFIG_CPU_ISOLATION=y
@@ -1000,6 +996,18 @@ CONFIG_COREDUMP=y
 #
 CONFIG_SWAP=y
 # CONFIG_ZSWAP is not set
+CONFIG_ZSMALLOC=m
+
+#
+# Zsmalloc allocator options
+#
+
+#
+# Zsmalloc is a common backend allocator for zswap & zram
+#
+# CONFIG_ZSMALLOC_STAT is not set
+CONFIG_ZSMALLOC_CHAIN_SIZE=8
+# end of Zsmalloc allocator options

 #
 # Slab allocator options
@@ -1060,8 +1068,8 @@ CONFIG_ARCH_WANTS_THP_SWAP=y
 # CONFIG_PERSISTENT_HUGE_ZERO_FOLIO is not set
 CONFIG_MM_ID=y
 CONFIG_TRANSPARENT_HUGEPAGE=y
-CONFIG_TRANSPARENT_HUGEPAGE_ALWAYS=y
-# CONFIG_TRANSPARENT_HUGEPAGE_MADVISE is not set
+# CONFIG_TRANSPARENT_HUGEPAGE_ALWAYS is not set
+CONFIG_TRANSPARENT_HUGEPAGE_MADVISE=y
 # CONFIG_TRANSPARENT_HUGEPAGE_NEVER is not set
 CONFIG_THP_SWAP=y
 # CONFIG_READ_ONLY_THP_FOR_FS is not set
@@ -2106,7 +2114,21 @@ CONFIG_PNPACPI=y
 CONFIG_BLK_DEV=y
 # CONFIG_BLK_DEV_NULL_BLK is not set
 # CONFIG_BLK_DEV_PCIESSD_MTIP32XX is not set
-# CONFIG_ZRAM is not set
+CONFIG_ZRAM=m
+# CONFIG_ZRAM_BACKEND_LZ4 is not set
+# CONFIG_ZRAM_BACKEND_LZ4HC is not set
+# CONFIG_ZRAM_BACKEND_ZSTD is not set
+# CONFIG_ZRAM_BACKEND_DEFLATE is not set
+# CONFIG_ZRAM_BACKEND_842 is not set
+CONFIG_ZRAM_BACKEND_FORCE_LZO=y
+CONFIG_ZRAM_BACKEND_LZO=y
+CONFIG_ZRAM_DEF_COMP_LZORLE=y
+# CONFIG_ZRAM_DEF_COMP_LZO is not set
+CONFIG_ZRAM_DEF_COMP="lzo-rle"
+CONFIG_ZRAM_WRITEBACK=y
+# CONFIG_ZRAM_TRACK_ENTRY_ACTIME is not set
+# CONFIG_ZRAM_MEMORY_TRACKING is not set
+CONFIG_ZRAM_MULTI_COMP=y
 CONFIG_BLK_DEV_LOOP=y
 CONFIG_BLK_DEV_LOOP_MIN_COUNT=8
 # CONFIG_BLK_DEV_DRBD is not set

@loki666 loki666 self-assigned this Jan 25, 2026
@loki666 loki666 deployed to pr-approval January 25, 2026 14:47 — with GitHub Actions Active
@aenertia
Copy link
Contributor Author

You are still manually editing kernel configs and not updating them properly, we can't see what options are being enabled in your PR as a result of this.

You need to run DEVICE=SM8550 tools/adjust_kernel_config olddefconfig for example after editing the kernel configs so they are updated properly.

For example SM8550 had the following changes

diff --git a/projects/ROCKNIX/devices/SM8550/linux/linux.aarch64.conf b/projects/ROCKNIX/devices/SM8550/linux/linux.aarch64.conf
index a1680837d3..a1b6706f18 100644
--- a/projects/ROCKNIX/devices/SM8550/linux/linux.aarch64.conf
+++ b/projects/ROCKNIX/devices/SM8550/linux/linux.aarch64.conf
@@ -11,8 +11,8 @@ CONFIG_AS_VERSION=24400
 CONFIG_LD_IS_BFD=y
 CONFIG_LD_VERSION=24400
 CONFIG_LLD_VERSION=0
-CONFIG_RUSTC_VERSION=109200
-CONFIG_RUSTC_LLVM_VERSION=210103
+CONFIG_RUSTC_VERSION=0
+CONFIG_RUSTC_LLVM_VERSION=0
 CONFIG_CC_CAN_LINK=y
 CONFIG_CC_HAS_ASM_GOTO_OUTPUT=y
 CONFIG_CC_HAS_ASM_GOTO_TIED_OUTPUT=y
@@ -21,11 +21,6 @@ CONFIG_CC_HAS_ASM_INLINE=y
 CONFIG_CC_HAS_ASSUME=y
 CONFIG_CC_HAS_NO_PROFILE_FN_ATTR=y
 CONFIG_LD_CAN_USE_KEEP_IN_OVERLAY=y
-CONFIG_RUSTC_HAS_COERCE_POINTEE=y
-CONFIG_RUSTC_HAS_SPAN_FILE=y
-CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES=y
-CONFIG_RUSTC_HAS_FILE_WITH_NUL=y
-CONFIG_RUSTC_HAS_FILE_AS_C_STR=y
 CONFIG_PAHOLE_VERSION=0
 CONFIG_IRQ_WORK=y
 CONFIG_BUILDTIME_TABLE_SORT=y
@@ -139,7 +134,8 @@ CONFIG_TASKSTATS=y
 # CONFIG_TASK_DELAY_ACCT is not set
 CONFIG_TASK_XACCT=y
 CONFIG_TASK_IO_ACCOUNTING=y
-# CONFIG_PSI is not set
+CONFIG_PSI=y
+# CONFIG_PSI_DEFAULT_DISABLED is not set
 # end of CPU/Task time and stats accounting

 CONFIG_CPU_ISOLATION=y
@@ -1000,6 +996,18 @@ CONFIG_COREDUMP=y
 #
 CONFIG_SWAP=y
 # CONFIG_ZSWAP is not set
+CONFIG_ZSMALLOC=m
+
+#
+# Zsmalloc allocator options
+#
+
+#
+# Zsmalloc is a common backend allocator for zswap & zram
+#
+# CONFIG_ZSMALLOC_STAT is not set
+CONFIG_ZSMALLOC_CHAIN_SIZE=8
+# end of Zsmalloc allocator options

 #
 # Slab allocator options
@@ -1060,8 +1068,8 @@ CONFIG_ARCH_WANTS_THP_SWAP=y
 # CONFIG_PERSISTENT_HUGE_ZERO_FOLIO is not set
 CONFIG_MM_ID=y
 CONFIG_TRANSPARENT_HUGEPAGE=y
-CONFIG_TRANSPARENT_HUGEPAGE_ALWAYS=y
-# CONFIG_TRANSPARENT_HUGEPAGE_MADVISE is not set
+# CONFIG_TRANSPARENT_HUGEPAGE_ALWAYS is not set
+CONFIG_TRANSPARENT_HUGEPAGE_MADVISE=y
 # CONFIG_TRANSPARENT_HUGEPAGE_NEVER is not set
 CONFIG_THP_SWAP=y
 # CONFIG_READ_ONLY_THP_FOR_FS is not set
@@ -2106,7 +2114,21 @@ CONFIG_PNPACPI=y
 CONFIG_BLK_DEV=y
 # CONFIG_BLK_DEV_NULL_BLK is not set
 # CONFIG_BLK_DEV_PCIESSD_MTIP32XX is not set
-# CONFIG_ZRAM is not set
+CONFIG_ZRAM=m
+# CONFIG_ZRAM_BACKEND_LZ4 is not set
+# CONFIG_ZRAM_BACKEND_LZ4HC is not set
+# CONFIG_ZRAM_BACKEND_ZSTD is not set
+# CONFIG_ZRAM_BACKEND_DEFLATE is not set
+# CONFIG_ZRAM_BACKEND_842 is not set
+CONFIG_ZRAM_BACKEND_FORCE_LZO=y
+CONFIG_ZRAM_BACKEND_LZO=y
+CONFIG_ZRAM_DEF_COMP_LZORLE=y
+# CONFIG_ZRAM_DEF_COMP_LZO is not set
+CONFIG_ZRAM_DEF_COMP="lzo-rle"
+CONFIG_ZRAM_WRITEBACK=y
+# CONFIG_ZRAM_TRACK_ENTRY_ACTIME is not set
+# CONFIG_ZRAM_MEMORY_TRACKING is not set
+CONFIG_ZRAM_MULTI_COMP=y
 CONFIG_BLK_DEV_LOOP=y
 CONFIG_BLK_DEV_LOOP_MIN_COUNT=8
 # CONFIG_BLK_DEV_DRBD is not set

I'm calling the upstream kernel config tool with my patch apply scripts . Was not aware of the in tree tool. Will use it in future now I'm aware of it's existence and preference.

@loki666
Copy link
Contributor

loki666 commented Jan 25, 2026

unless I'm mistaken, but swap.conf is now part for the R/O SYSTEM image, and not a link to /storage/.config/swap.conf

H700:/etc # ls -la swap.conf 
-rw-r--r--    1 root     root           211 Jan 25 11:35 swap.conf

so it can't be changed


post_install () {
if [ "${SWAP_SUPPORT}" = "yes" ]; then
enable_service swap.service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swap.service file can be removed I guess

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually looking over this further I think we should remove the upstream/libreelec mount-swap install step entirely from the ROCKNIX packages/sysutils/util-linux/package.mk ; i've checked through the codebase and it's not used at all and since we have quite different set of critera than what's in that script and handle it all within the rocknix-memory-manager its presence is just going to be confusing

@aenertia
Copy link
Contributor Author

unless I'm mistaken, but swap.conf is now part for the R/O SYSTEM image, and not a link to /storage/.config/swap.conf

H700:/etc # ls -la swap.conf 
-rw-r--r--    1 root     root           211 Jan 25 11:35 swap.conf

so it can't be changed

Gah - the link logic got dropped in my refactor for @porschemad911 suggestions last night accidentally.

@porschemad911
Copy link
Contributor

porschemad911 commented Jan 25, 2026

You are still manually editing kernel configs and not updating them properly, we can't see what options are being enabled in your PR as a result of this.
You need to run DEVICE=SM8550 tools/adjust_kernel_config olddefconfig for example after editing the kernel configs so they are updated properly.
For example SM8550 had the following changes

diff --git a/projects/ROCKNIX/devices/SM8550/linux/linux.aarch64.conf b/projects/ROCKNIX/devices/SM8550/linux/linux.aarch64.conf
index a1680837d3..a1b6706f18 100644
--- a/projects/ROCKNIX/devices/SM8550/linux/linux.aarch64.conf
+++ b/projects/ROCKNIX/devices/SM8550/linux/linux.aarch64.conf
@@ -11,8 +11,8 @@ CONFIG_AS_VERSION=24400
 CONFIG_LD_IS_BFD=y
 CONFIG_LD_VERSION=24400
 CONFIG_LLD_VERSION=0
-CONFIG_RUSTC_VERSION=109200
-CONFIG_RUSTC_LLVM_VERSION=210103
+CONFIG_RUSTC_VERSION=0
+CONFIG_RUSTC_LLVM_VERSION=0
 CONFIG_CC_CAN_LINK=y
 CONFIG_CC_HAS_ASM_GOTO_OUTPUT=y
 CONFIG_CC_HAS_ASM_GOTO_TIED_OUTPUT=y
@@ -21,11 +21,6 @@ CONFIG_CC_HAS_ASM_INLINE=y
 CONFIG_CC_HAS_ASSUME=y
 CONFIG_CC_HAS_NO_PROFILE_FN_ATTR=y
 CONFIG_LD_CAN_USE_KEEP_IN_OVERLAY=y
-CONFIG_RUSTC_HAS_COERCE_POINTEE=y
-CONFIG_RUSTC_HAS_SPAN_FILE=y
-CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES=y
-CONFIG_RUSTC_HAS_FILE_WITH_NUL=y
-CONFIG_RUSTC_HAS_FILE_AS_C_STR=y
 CONFIG_PAHOLE_VERSION=0
 CONFIG_IRQ_WORK=y
 CONFIG_BUILDTIME_TABLE_SORT=y
@@ -139,7 +134,8 @@ CONFIG_TASKSTATS=y
 # CONFIG_TASK_DELAY_ACCT is not set
 CONFIG_TASK_XACCT=y
 CONFIG_TASK_IO_ACCOUNTING=y
-# CONFIG_PSI is not set
+CONFIG_PSI=y
+# CONFIG_PSI_DEFAULT_DISABLED is not set
 # end of CPU/Task time and stats accounting

 CONFIG_CPU_ISOLATION=y
@@ -1000,6 +996,18 @@ CONFIG_COREDUMP=y
 #
 CONFIG_SWAP=y
 # CONFIG_ZSWAP is not set
+CONFIG_ZSMALLOC=m
+
+#
+# Zsmalloc allocator options
+#
+
+#
+# Zsmalloc is a common backend allocator for zswap & zram
+#
+# CONFIG_ZSMALLOC_STAT is not set
+CONFIG_ZSMALLOC_CHAIN_SIZE=8
+# end of Zsmalloc allocator options

 #
 # Slab allocator options
@@ -1060,8 +1068,8 @@ CONFIG_ARCH_WANTS_THP_SWAP=y
 # CONFIG_PERSISTENT_HUGE_ZERO_FOLIO is not set
 CONFIG_MM_ID=y
 CONFIG_TRANSPARENT_HUGEPAGE=y
-CONFIG_TRANSPARENT_HUGEPAGE_ALWAYS=y
-# CONFIG_TRANSPARENT_HUGEPAGE_MADVISE is not set
+# CONFIG_TRANSPARENT_HUGEPAGE_ALWAYS is not set
+CONFIG_TRANSPARENT_HUGEPAGE_MADVISE=y
 # CONFIG_TRANSPARENT_HUGEPAGE_NEVER is not set
 CONFIG_THP_SWAP=y
 # CONFIG_READ_ONLY_THP_FOR_FS is not set
@@ -2106,7 +2114,21 @@ CONFIG_PNPACPI=y
 CONFIG_BLK_DEV=y
 # CONFIG_BLK_DEV_NULL_BLK is not set
 # CONFIG_BLK_DEV_PCIESSD_MTIP32XX is not set
-# CONFIG_ZRAM is not set
+CONFIG_ZRAM=m
+# CONFIG_ZRAM_BACKEND_LZ4 is not set
+# CONFIG_ZRAM_BACKEND_LZ4HC is not set
+# CONFIG_ZRAM_BACKEND_ZSTD is not set
+# CONFIG_ZRAM_BACKEND_DEFLATE is not set
+# CONFIG_ZRAM_BACKEND_842 is not set
+CONFIG_ZRAM_BACKEND_FORCE_LZO=y
+CONFIG_ZRAM_BACKEND_LZO=y
+CONFIG_ZRAM_DEF_COMP_LZORLE=y
+# CONFIG_ZRAM_DEF_COMP_LZO is not set
+CONFIG_ZRAM_DEF_COMP="lzo-rle"
+CONFIG_ZRAM_WRITEBACK=y
+# CONFIG_ZRAM_TRACK_ENTRY_ACTIME is not set
+# CONFIG_ZRAM_MEMORY_TRACKING is not set
+CONFIG_ZRAM_MULTI_COMP=y
 CONFIG_BLK_DEV_LOOP=y
 CONFIG_BLK_DEV_LOOP_MIN_COUNT=8
 # CONFIG_BLK_DEV_DRBD is not set

I'm calling the upstream kernel config tool with my patch apply scripts . Was not aware of the in tree tool. Will use it in future now I'm aware of it's existence and preference.

Given this change affects all platforms, as requested, when you are happy with the code, please do a CI run in your repo as per: https://rocknix.org/contribute/build-gh/

This will also create a PR in your repo with full updated kconfig changes as well as images for testing.

I know you're not a fan of GH, neither am I but this is what the project uses so we have to work with it.

@aenertia
Copy link
Contributor Author

unless I'm mistaken, but swap.conf is now part for the R/O SYSTEM image, and not a link to /storage/.config/swap.conf

H700:/etc # ls -la swap.conf 
-rw-r--r--    1 root     root           211 Jan 25 11:35 swap.conf

so it can't be changed

Gah - the link logic got dropped in my refactor for @porschemad911 suggestions last night accidentally.

Actually this is fine as is - the memory-manager checks both locations and the user config override takes precedence if it exists. I think this is desired behaviour as is, as the build time options persist in the immutable /etc/swap.conf which is what we want for resets etc.

@aenertia aenertia force-pushed the zram-swap-core branch 2 times, most recently from 727af26 to 70d18b3 Compare January 26, 2026 06:12
@aenertia aenertia force-pushed the zram-swap-core branch 5 times, most recently from aec0f83 to 13a3e6e Compare January 27, 2026 00:14
…figs

This commit introduces a comprehensive overhaul of memory management across all
supported ROCKNIX devices. It deprecates the legacy \`mount-swap\` script in
favor of a new, robust \`rocknix-memory-manager\`.

Key Changes:

* New Memory Manager (\`rocknix-memory-manager\`):
    * Replaces \`mount-swap\` with a Tiered Memory Architecture.
    * Smart "ZSTD" Interpretation (Hybrid Tiering):
        * If \`ZRAM_COMPRESSION_ALGO\` is set to "zstd", the manager automatically
          configures a hybrid pipeline:
          1. Primary: LZO-RLE (Low latency) for immediate writes to prevent stutter.
          2. Secondary: ZSTD (High compression) enabled via \`CONFIG_ZRAM_MULTI_COMP\`
             for background recompression of idle pages.
    * Auto-Configuration & Defaults:
        * High-Performance Targets (RK3588, S922X, SM8x50): Default to "Auto" ZRAM
          sizing and "zstd" profile (Hybrid Tiering enabled).
        * Low-Power Targets (RK3326, RK3566, H700): Default to ZRAM disabled ("0")
          to conserve system resources.
        * Swap File: Defaults to disabled ("0") on all targets to preserve flash storage.
    * Tuning: Dynamic sysctl application (\`swappiness=100\`, \`page-cluster=0\`)
      optimized for the new hybrid zram setup.

* Runtime Configuration:
    * Users on low-end targets can enable ZRAM by copying defaults:
      \`cp /etc/swap.conf /storage/.config/swap.conf\`
      and setting \`ZRAM_SIZE="Auto"\` or a specific value (e.g., "512").
    * Configuration supports user overrides for algorithm, sizing, and swap files.

* Kernel Configuration Standardization:
    * ZRAM: Converted to modular (\`=m\`) to allow runtime algorithm switching.
    * Multi-Compression: Enabled \`CONFIG_ZRAM_MULTI_COMP\` on capable SoCs
      (Rockchip, Qualcomm, Amlogic) to support the LZO-RLE -> ZSTD pipeline.
    * Algorithms: Enabled \`LZO-RLE\` (default), \`ZSTD\`, and \`LZ4\` modules.
    * ZSMALLOC: Modularized (\`=m\`) with chain size 8.
    * THP: Standardized to \`madvise\` to reduce unneeded compaction latency.
    * Cgroups: Enabled \`CONFIG_CGROUP_FREEZER\` for consistent suspend handling.

* Platform Specifics:
    * SDM845/SM8250: Enabled \`CONFIG_PSI\` and fixed toolchain versioning.
    * Rockchip/Amlogic: Enabled architecture-specific migration features.

* System Services:
    * Added \`rocknix-memory-manager.service\` (oneshot, pre-shutdown).
    * Updated \`util-linux\` to enable \`fallocate\` for instant swap generation
# Check case-insensitive for "auto"
if [[ "${ZRAM_SIZE,,}" == "auto" ]]; then
ZRAM_SIZE_VAL=$((TOTAL_MEM_MB / 2))
[ "$ZRAM_SIZE_VAL" -gt 4096 ] && ZRAM_SIZE_VAL=4096
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reserving 4Gb on 8Gb seems a lot to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants