Add guide for increasing swap on UGREEN NAS#31
Add guide for increasing swap on UGREEN NAS#31sliekens wants to merge 6 commits intoUGREEN-NASync:mainfrom
Conversation
Reviewer's GuideAdds 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 servicesequenceDiagram
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
Flow diagram for creating and managing swapfile on UGREEN NASflowchart 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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
overlay-swapfile.serviceunit packs a lot of logic into a singleExecStartshell 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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
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
/overlayswapfile and verification commands - Add a persistence approach via a oneshot systemd service that waits for
/overlayto mount
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Document the process of increasing swap on UGREEN NAS devices, including symptoms of low swap, earlyoom behavior, and creating a swapfile.
|
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. The guide is looking very good though, thank you so much for sharing! Don't hesitate to @ me if you need any help. |
|
@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. |
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:
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: