Ereswap

Contents

[edit] Introduction

ereswap is a set of scripts, allowing to detect swap fragmentation and to refresh it, by re-enabling swap, when needed (or doing the latter no matter of conditions, if user decide to).

The appliction is a terminal tool and requires knowledge of using terminal commands. Although ereswap has no GUI it is easily customizable and extendable. The user can create a .desktop shortcut for it, invoke via QueenBeeconWidget, shortcutd, or any other way.

[edit] Partition Requirements

To work properly, ereswap require existence of 2 swap partitions (on microSD or eMMC, all combinations allowed). For maximum performance of Maemo, using swap on microSD *only* and keeping backup, unused swap on eMMC is recommended - the later can be of default size (768 MB), or anything of 200MB or more (in case someone want to repartition and reclaim space for other partitions).

[edit] Fragmentation

Swap fragmentation starts to occur, when total number of megabytes written during swap's life time exceed it's maximum size. Until that, swap is written in purely sequential manner (blocks that are no longer needed, are marked as free, but never used) - hoever, after reaching end of swap space, previously used (freed) blocks are rewritten, using new content. This mean no longer writing sequentially, causing massive slowdowns, to already slow (compared to RAM) swap. A workaround to this is to disable and enable swap again - linuxswap filesystem content doesn't live through restarts, and once re-enabled, is written sequentially again.

ereswap achieve it, by counting - via iostat - number of megabytes saved to swap partition during runtime (*not* current swap usage) and comparing it to adjacent numbers during last reswap (or boot). If it's higher than set value, swap is re-enabled, and user informed via Maemo notification system. In case of failure, the same notification system is used to inform user about step, that created problems. Location of swaps and it's sizes are fully configurable.

[edit] Main Swap Partition on Micro SD

Putting the Main Swap space on your microSD saves the device from I/O conflicts between swap and /opt requests. Also flash based devices don't handle simultaneous, autonomous requests very well. Another huge advantage is that it reduces a large amount of wear & tear from the devices non-replaceable flash device, at expense of a cheap and replaceable microSD card.

More information on [Swap on Micro SD]

Please note:- Some parts of the Swap on Micro SD wiki are baised towards Easy Debian installation and may not be applicable.

[edit] More

More information on the package can be found ...

talk.maemo.org ereswap

ereswap Package Page

[edit] Installation

The latest versions can be found in the Devel repository and can be installed using the N900 Application Manager (HAM).

[edit] Operation

After installation...

edit:

/home/user/.config/ereswap/config

...providing locations for main swap, it's size, and backup swap.

Then, run:

/home/user/.config/ereswap/adjust-rcS-late.sh

It will adjust Your "/etc/event.d/rcS-late", to - during boot - enable Your main swap and to reset Mb's-written-to-swap counter. This step must be done only once.

Now, at any time, invoke:

ereswap

...from terminal. It will check counter and inform You about amount of data left before hitting swap fragmentation (or any arbitrary value set in config file), or, how many Mb's after it You are. In second case, it will also re-enable swap.

To re-enable swap at any time, unconditionally, invoke:

freswap

...it's useful, if You're close to hit limit, and planning to do memory-hungry stuff.

If You ever change Your swap's location, just edit config file and invoke:

/home/user/.config/ereswap/update-rcS-late.sh

It will update Your rcS-late with respect to new swap locations and/or size.

[edit] Note on changes made to rcS-late

After invoking adjust-rcS-late.sh

This script replaces line:

swapon -a || "Failed to enable paging partition"

...with a superior code, that check if our main swap is functional, and in case of main swap's failure (for example, it's partition on microSD, and the latter got screwed), it enables backup swap. This approach ensures, that no reboot loop will occur, in case of swap failures- as long as user provide sane settings (using main and backup swap on, lets say, same microSD card isn't most failsafe solution, for example).

Patching rcS-late was thoroughly tested, yet, for maximum safety, backup it before adjusting.

[edit] Bugs

Link to Maintainer's Bugtracker information is available here

ereswap Package Page

[edit] FAQ

Q: Something went wrong with my main swap, and backup swap got enabled. Why ereswap doesn't properly count Mb's to hit swap fragmentation?

A: It's by design - written data counter is *always* set to Your main swap. Using backup swap is just a failsafe, and everything is done to make You know about it, the sooner, the better. If You can't fix issue with main swap quickly, yet, you desperately need capabilities to refresh swap, either use freswap, or edit config, and enable Your backup swap as main.

Q: I changed my swap layout, so I wanted to run update-rcS-late.sh, but, by mistake, I've executed adjust-rcS-late.sh, on already patched rcS-late! Is my rcS-late damaged? will I get into bootloop, after reboot?

A: Scripts are written in an intelligent way, that should result on absolutely no problems, after executing on wrong version of rcS-late (i.e. trying to update stock rcS-late, or trying to patch already adjusted one) - script will end with exit 0 (success), but without commuting changes to file.

For maximum safety, You may want to restore rcS-late from backup, though. Also, I can't predict what will happen, if You use any of rcS-late patcher scripts on custom-modified rcS-late (one modified *not* by this program) - generally, You should be ok, as long as default swap enabling line wasn't changed, but be extra careful in such case.

[edit] License/Disclaimer

ereswap is licensed under terms of GPL (latest). It is provided as-is, without any warranty whatsoever. Using it, You're able to modify critical system components, responsible for booting device - doing it all on your risk. You've been warned.

[edit] Credits

  • Thanks to shadowjk for swap refreshing concept and proof' implementation.
  • Thanks to Hurrian for pointing to a concept of backup swap mechanism in rcS-late, created by GameboyRMH.
  • Huge thanks for merlin1991, DocScrutinizer, Sicelo and everyone else answering my countless questions and providing working code samples on #maemo. Guys, You rox! Also, thanks to merlin1991 (again) and X-Fade, for help with proper packaging.
  • Especially huge thanks for Sc0rpius, for sitting with me for hours and working to fix sed's commands in update/adjust-rcS-late.sh scripts. I would be nowhere, without Your help!
  • Thanks to sixwheeledbeast, for creating this wiki page.

[edit] Versions/Change Log

1.2 (Current Devel)

  • Fix to another issue preventing system from boot ;) (tried to save reswap stat on optfs, before it's mounted...)
  • Another try to add busybox-power as dependency

1.1

  • Fix for method of validating swap, that could lead to non-bootable device (via faulthy /etc/event.d/rcS-late)
  • Program's folder changed to "/home/user/.config/ereswap/config". Config and rcS-late's adjusters now live there. Changed, due to popular request.
  • Program's executables changed from "ereswap.sh" and "freswap.sh" to "ereswap" and "freswap". Changed, due to popular request.
  • Depends on busybox-power[/list]

1.0

  • Initial Release.

[edit] Wiki Update Info

Last Updated - sixwheeledbeast - 28 May 2012 17:47 UTC
Wiki Created - sixwheeledbeast - 24 May 2012 20:20 UTC