Posts #51 and #53 are wrong: this bug is NOT FIXED in either 3.2.0-54.82
or 3.8.0-31.46 from the 12.04 (precise) repositories. There might be
something fixed about zram in there (as suggested by the changelog), but
the last sector of /dev/zram0 is still bad (as reported in #43), and
this will lead to crashes if /dev/zram0 is used 'blindly' to create a
swap partition.
NOTE1: Before all, if you're running one of these kernels ('uname -a',
last number is shown later in the line) and if 'swapon -s' shows
/dev/zram0, do immediately a 'sudo swapoff /dev/zram0'. Otherwise your
machine can crash at any time.
NOTE2: Potentially all 12.04 & derivative installations that include the
package lupin-casper (and have not altered the zram configuration) will
experience the bug.
I performed a clean install of Mint 13, followed by a switch to the 12.04.3
stack (as explained here: https://wiki.ubuntu.com/Kernel/LTSEnablementStack). I
also switched an Ubuntu 12.04.2 to 12.04.3. Here are my findings. If you only
want a summary of workarounds, scroll to the bottom. Ref:
http://askubuntu.com/questions/346545/how-to-detect-which-init-script-starts-zram
FINDINGS:
1. Package versions: A Mint 13 clean install is based on 12.04.(0 or 1).
Using updates only gets you up to 3.2.0-54.82. A Mint 13 switched to the
12.04.3 stack gets you up to 3.8.0-31.46. An Ubuntu 12.04.2 switched to
12.04.3 get you up to 3.8.0-31.46 as well.
2. zram is broken in both 3.2.0-54.82 and 3.8.0-31.46, as explained in
#43: the last sector of /dev/zram0 is bad. However, you might not notice
this because zram is not always used by default (see 3 below). To check
zram is broken, first make sure it's loaded (but not for swapping!! see
NOTE1 above):
lsmod | grep zram
If it doesn't show, do this to create a 1GB zram:
sudo modprobe zram
echo '1024^3' | bc | sudo tee /sys/block/zram0/disksize
With zram loaded, run:
sudo dd if=/dev/zram0 of=/dev/null bs=4096
I get:
dd: reading `/dev/zram0': Input/output error
262143+0 records in
262143+0 records out
1073737728 bytes (1.1 GB) copied, 0.400378 s, 2.7 GB/s
Compare the 262143 above with:
sudo fdisk -l /dev/zram0 | grep -o "total [0-9]* sectors"
I get:
total 262144 sectors
3. zram usage: The zram-config package is NOT installed by default by either
Mint 13 or Ubuntu 12.04. Regardless of that(!), in some configurations, zram is
loaded by the initramfs image. By default, Mint 13 DOES use zram, whereas
Ubuntu 12.04 DOES NOT use zram.
- check if module loaded: 'lsmod | grep zram'
- check if zram is used for swap: 'swapon -s | grep zram' (if it is, see NOTE1
above)
- check if zram-config package installed: 'dpkg -l zram-config'
4. If zram is loaded by initramfs, the zram-config package is useless.
By the time /etc/init/zram-config.conf runs, the zram module is already
loaded, so 'modprobe' won't do anything, and setting the size by writing
to /sys/block/zram0/disksize will not work. Thus, the solution in
#43/#45/#49 won't work. If you really want zram-config to take over zram
allocation, you need to add:
# remove swaps
for dev in $(swapon -s | grep /dev/zram | cut -d ' ' -f 1); do
swapoff $dev || exit 1
done
# remove module
if lsmod | grep -q zram; then
rmmod zram || exit 1
fi
just before:
modprobe zram $MODPROBE_ARGS
Note, the version I have sets up one zram per CPU core. Not sure why
you'd need that. If you don't, also replace:
NRDEVICES=$(grep -c ^processor /proc/cpuinfo | sed 's/^0$/1/')
by:
#NRDEVICES=$(grep -c ^processor /proc/cpuinfo | sed 's/^0$/1/')
NRDEVICES=1
Also, don't forget to add '-c' to mkswap, as explained in #43.
5. The culprit which makes the difference between Mint 13 using zram in
initramfs and Ubuntu 12.04 not using it is the package lupin-casper. This one
depends on casper, which contains the file
/usr/share/initramfs-tools/conf.d/compcache. This file contains only:
COMPCACHE_SIZE="50%"
If this file is absent, the script /usr/share/initramfs-tools/hooks/compcache
(part of initramfs-tools) won't do anything, because its 'eval' will return
'number=""; suffix=""', which will trigger early termination just below 'eval'.
If the COMPCACHE_SIZE setting file is present, the script will add zram to the
initramfs. Thus, potentially all 12.04 & derivative installations which include
lupin-casper will experience the bug. Furthermore, you might get the bug by
installing lupin-casper later on, before the bug is fixed.
WORKAROUNDS: (either one should be enough!)
1. Disable zram.
Pro: Definitely clears the zram bug.
Con: Need to undo changes by hand to re-enable it later on, once the zram bug
is fixed.
1a. Add at the top of /etc/rc.local:
swapoff /dev/zram0
rmmod zram
1b. Blacklist zram and run 'update-initramfs'.
1c. Find zram.ko and rename it to zram.ko.DONTUSE and run 'update-
initramfs' (thx Dan)
2. Use zram, but avoid the last sector. For this you need to make sure the
relevant 'mkswap' runs with '-c' (see #43).
Pro: zram still u