On Sun, Mar 30, 2014 at 9:55 PM, Tito <[email protected]> wrote: > Hi to all, > this patch started as a personal fun and learning project on swapon/swapoff > after > Matt Whitlock's patches. I was curios if there was a way to remove all the > #ifdefs > from within the code as for my personal taste this unindented stuff in > indented > code makes the code harder to read. > So I tried hard by using the preprocessor and compilers dead code elimination > and in the end I was able to achieve my goal: a ifdef free code. > During the process as side effects I spotted a few differences between > our swapon/swapoff inplementation and the one on my debian box > so I added this fixes/improvements to the code: > > 1) real swapon/swapoff handles also devices on the commandline with -a; > 2) xstat(device) in swap_enable_disable aborts on error when cycling > through > fstab so some devices are not handled; > 3) duplicated code for ENABLE_FEATURE_SWAPON_DISCARD and > ENABLE_FEATURE_SWAPON_PRI was moved to functions. > 4) silence some error messages with -a; > 5) minor cleanups and code refactoring reduced the size as per bloat-check: > > ./scripts/bloat-o-meter busybox_unstripped.old busybox_unstripped > function old new delta > set_discard_flag - 106 +106 > set_priority_flag - 75 +75 > swap_enable_disable 149 219 +70 > .rodata 141270 141260 -10 > swap_on_off_main 638 325 -313 > ------------------------------------------------------------------------------ > (add/remove: 2/0 grow/shrink: 1/2 up/down: 251/-323) Total: -72 bytes > > 6) I also added support for /proc/swaps handling to swapoff: > > "When the -a flag is given, swapping is disabled on all known swap devices > and files (as found in /proc/swaps or /etc/fstab)." > > So now swapoff first cycles through /proc/swaps and then through fstab > to swapoff all devices. > With this additional feature bloat-check is: > > ./scripts/bloat-o-meter busybox_unstripped.old busybox_unstripped > function old new delta > set_discard_flag - 106 +106 > set_priority_flag - 75 +75 > swap_enable_disable 149 219 +70 > .rodata 141270 141272 +2 > swap_on_off_main 638 416 -222 > ------------------------------------------------------------------------------ > (add/remove: 2/0 grow/shrink: 2/1 up/down: 253/-222) Total: 31 bytes > > so it comes at almost no extra size cost. > I've decided not to add an extra config option for that, but it could > be easily added if needed.
Applied with some edits. Thanks! _______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
