Allow for fluctuation of MemTotal for automatic swapfile size#4016
Conversation
As the reported MemTotal can fluctuate a bit on some systems, e.g. because the reserved memory changes between kernel version or other factors affect it like VRAM, the swap file can be recreated unnecessarily between boots. Allow for some fluctuation (up to +-32MB) before the swapfile is recreated. This was a problem already before the recent haos-swapfile changes, however, before it checked if the existing swapfile isn't smaller than the desired value. If the MemTotal fluctuated there, the swapfile size eventually settled on the highest value seen and it wasn't recreated anymore. With this change, things should be stable even more.
📝 WalkthroughWalkthroughThe changes modify the swap file management script by introducing a new variable, Changes
Sequence Diagram(s)sequenceDiagram
participant Script as SwapFile Script
participant FS as File System
participant Logger as Logger
Script->>FS: Check if swap file exists
alt Swap file exists
Script->>FS: Retrieve file size
Script->>Script: Compare file size with expected range (SWAPSIZE ± SWAPSIZE_TOLERANCE)
alt File size within range
Script->>Logger: Log informational message
else File size outside range
Script->>FS: Check available disk space
Script->>FS: Create/resize swap file
end
else Swap file does not exist
Script->>FS: Check available disk space
Script->>FS: Create swap file
end
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🔇 Additional comments (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Sorry, I know this is off topic, but there's no better place to ask: Is REST API the only way to control the swap in HAOS for now? |
As the reported MemTotal can fluctuate a bit on some systems, e.g. because the reserved memory changes between kernel version or other factors affect it like VRAM, the swap file can be recreated unnecessarily between boots. Allow for some fluctuation (up to +-32MB) before the swapfile is recreated.
This was a problem already before the recent haos-swapfile changes, however, before it checked if the existing swapfile isn't smaller than the desired value. If the MemTotal fluctuated there, the swapfile size eventually settled on the highest value seen and it wasn't recreated anymore. With this change, things should be stable even more.
Summary by CodeRabbit