Skip to content

Add guide for increasing swap on UGREEN NAS#31

Open
sliekens wants to merge 6 commits intoUGREEN-NASync:mainfrom
sliekens:patch-1
Open

Add guide for increasing swap on UGREEN NAS#31
sliekens wants to merge 6 commits intoUGREEN-NASync:mainfrom
sliekens:patch-1

Conversation

@sliekens
Copy link
Copy Markdown
Contributor

@sliekens sliekens commented Apr 20, 2026

Document the process of increasing swap on UGREEN NAS devices, including symptoms of low swap, earlyoom behavior, and creating a swapfile.

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Documentation/Content changes

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Other information

Summary by Sourcery

Add an advanced guide describing how to increase and persist swap space on UGREEN NAS devices to alleviate memory pressure issues.

Documentation:

  • Document symptoms and diagnosis of low swap and earlyoom-related process kills on UGREEN NAS systems.
  • Provide step-by-step instructions for creating, enabling, and sizing a swapfile on the /overlay NVMe partition, including verification and rollback steps.
  • Explain why common fstab- and swap.target-based approaches fail on UGOS and document a robust systemd-based activation method.

Copilot AI review requested due to automatic review settings April 20, 2026 13:40
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 20, 2026

Reviewer's Guide

Adds a new advanced guide documenting how to increase swap on UGREEN NAS devices, including detection of low-swap conditions, interaction with earlyoom, creating a swapfile on /overlay, making it persistent with a custom systemd service, and operational guidance (verification, sizing, and rollback).

Sequence diagram for systemd swapfile activation with polling service

sequenceDiagram
  participant Boot as Boot_Process
  participant Systemd as Systemd
  participant OverlayMount as Overlay_mount
  participant SwapService as overlay_swapfile_service
  participant Kernel as Kernel
  participant Earlyoom as earlyoom

  Boot->>Systemd: Start_boot_sequence
  Systemd->>OverlayMount: Mount_/overlay
  Note over OverlayMount,Systemd: Mounting_may_complete_late_in_boot

  Systemd->>SwapService: Start_service_(multi_user_target)
  activate SwapService
  SwapService->>SwapService: Loop_until_mountpoint_q_/overlay
  SwapService->>OverlayMount: mountpoint_-q_/overlay
  OverlayMount-->>SwapService: Not_mounted_yet
  SwapService->>SwapService: sleep_2s_and_retry
  SwapService->>OverlayMount: mountpoint_-q_/overlay
  OverlayMount-->>SwapService: /overlay_is_mounted

  SwapService->>Kernel: Check_/proc/swaps_for_/overlay/swapfile
  alt swapfile_not_active
    SwapService->>Kernel: swapon_/overlay/swapfile
    Kernel-->>SwapService: Swapfile_activated
  else swapfile_already_active
    SwapService->>SwapService: Skip_swapon
  end
  deactivate SwapService

  Kernel-->>Earlyoom: Update_total_swap_and_free_swap
  Earlyoom->>Earlyoom: Recalculate_kill_threshold_based_on_-s_20
  Earlyoom-->>Systemd: Fewer_SIGKILL_events_as_swap_headroom_increases
Loading

Flow diagram for creating and managing swapfile on UGREEN NAS

flowchart TD
  A[Start:
Detect_containers_with_exit_code_137
and_high_swap_usage] --> B[Confirm_earlyoom_is_killing_processes
via_ps_and_syslog]
  B --> C[Check_storage_layout_with_lsblk_and_df]
  C --> D{Is_/overlay_on_fast_NVMe
with_enough_free_space?}
  D -- No --> E[Do_not_create_swapfile_here
Reduce_container_load_or_add_RAM]
  D -- Yes --> F[Decide_swapfile_size
based_on_RAM_and_sizing_table]

  F --> G[Create_swapfile:
fallocate_-l_SIZE_/overlay/swapfile]
  G --> H[Secure_and_format:
chmod_600
mkswap_/overlay/swapfile]
  H --> I[Activate_temporarily:
swapon_/overlay/swapfile]
  I --> J[Verify_with_free_-h
and_swapon_--show]

  J --> K[Create_systemd_service:
/etc/systemd/system/overlay-swapfile.service
with_polling_ExecStart]
  K --> L[Enable_and_start:
systemctl_daemon-reload
systemctl_enable_--now_overlay-swapfile.service]
  L --> M[Reboot_and_confirm_swapfile_active
via_free_-h]
  M --> N[Monitor_earlyoom_logs
and_container_stability]

  N --> O{Need_to_revert?}
  O -- No --> P[Keep_configuration
and_continue_monitoring]
  O -- Yes --> Q[Disable_and_remove:
systemctl_disable_--now_overlay-swapfile.service
rm_service_file
rm_/overlay/swapfile]
  Q --> R[End]
  P --> R
Loading

File-Level Changes

Change Details Files
Introduce an advanced documentation guide that explains diagnosing low-swap issues and earlyoom behavior on UGREEN NAS systems.
  • Describe default RAM/zram/swap partition setup on UGREEN NAS devices and typical exhaustion patterns under container load.
  • List observable symptoms of swap exhaustion, including Docker exit code 137 without OOMKilled, truncated logs, high load, and swap saturation.
  • Explain how earlyoom works, why Docker reports OOMKilled=false, and how to inspect earlyoom thresholds and recent kills.
  • Provide commands and snippets (free, vmstat, docker stats, /proc inspection) for confirming memory and swap pressure and identifying high swap users.
docs/advanced-guides/increasing-swap.md
Document where and how to safely create and enable an additional swapfile on UGREEN NAS, including persistence across reboots using a custom systemd unit.
  • Explain disk layout and why /overlay on NVMe is preferred for swap, while HDD arrays or network filesystems should be avoided.
  • Show step-by-step commands to create, permission, format, and temporarily activate a swapfile on /overlay, and verify its activation.
  • Detail why using /etc/fstab or standard .swap units is unreliable on UGOS due to boot ordering, and justify a polling-based oneshot systemd service instead.
  • Provide a complete overlay-swapfile.service unit definition that waits for /overlay to be mounted, activates the swapfile if not already active, supports clean shutdown via swapoff, and is enabled via multi-user.target.
  • Include guidance for validating that earlyoom stops killing processes after extra swap is added, safe removal of the swapfile and service, and sizing recommendations for additional swap based on RAM and container count.
docs/advanced-guides/increasing-swap.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The overlay-swapfile.service unit packs a lot of logic into a single ExecStart shell one-liner; consider moving that into a small dedicated script (e.g. /usr/local/sbin/overlay-swapfile.sh) to improve readability and make future adjustments safer.
  • Since the guide recommends putting a relatively large swapfile on the system NVMe, it may be worth briefly calling out potential SSD wear implications and advising users not to rely on swap as a long‑term substitute for adding RAM.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `overlay-swapfile.service` unit packs a lot of logic into a single `ExecStart` shell one-liner; consider moving that into a small dedicated script (e.g. `/usr/local/sbin/overlay-swapfile.sh`) to improve readability and make future adjustments safer.
- Since the guide recommends putting a relatively large swapfile on the system NVMe, it may be worth briefly calling out potential SSD wear implications and advising users not to rely on swap as a long‑term substitute for adding RAM.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new advanced guide documenting how to diagnose swap exhaustion on UGREEN NAS (incl. earlyoom behavior) and how to add a persistent swapfile on /overlay using a polling systemd unit.

Changes:

  • Document symptoms and diagnostics for swap thrashing / earlyoom-triggered kills (exit 137 with OOMKilled: false)
  • Provide step-by-step creation of an /overlay swapfile and verification commands
  • Add a persistence approach via a oneshot systemd service that waits for /overlay to mount

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/advanced-guides/increasing-swap-space.md Outdated
Comment thread docs/advanced-guides/increasing-swap-space.md Outdated
Comment thread docs/advanced-guides/increasing-swap-space.md Outdated
Comment thread docs/advanced-guides/increasing-swap-space.md
Document the process of increasing swap on UGREEN NAS devices, including symptoms of low swap, earlyoom behavior, and creating a swapfile.
@topiga
Copy link
Copy Markdown
Member

topiga commented Apr 20, 2026

Please add a small text about what the goal is for the project, and add credit to yourself for this guide. Please also add a warning: if some user doesn't follow the instructions properly, the machine may break.
Also, some instructions and/or explanation are not clear. Please rephrase and elaborate (symptoms for example).
Please add a warning for which version of UGOS this was tested, and on which hardware.

The guide is looking very good though, thank you so much for sharing! Don't hesitate to @ me if you need any help.

@sliekens
Copy link
Copy Markdown
Contributor Author

@topiga agreed, it was filled with too much technical jargon and unclear about what problem this solves, it should be a lot better now, let me know if this makes more sense.

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.

3 participants