Skip to content

Commit 8838180

Browse files
committed
More RAM: better behavior during updates
1 parent d2f358d commit 8838180

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

apps/More RAM/install

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -179,31 +179,37 @@ if ! lsmod | awk "{print $1}" | grep -qxF zram ;then
179179
fi
180180
fi
181181
182-
# disable all zram devices
183-
echo -n "Disabling zram... "
184-
IFS=$'\n'
185-
for device_number in $(find /dev/ -name zram* -type b | tr -cd "0123456789\n") ;do
186-
#if zram device is a swap device, disable it
187-
swapoff /dev/zram${device_number} 2>/dev/null
188-
if [ $? == 137 ];then
189-
error "Cannot disable ZRAM because doing so would overflow your RAM. Try closing some programs, then run this script again."
190-
fi
191-
192-
#if zram device is mounted, unmount it
193-
umount /dev/zram${device_number} 2>/dev/null
194-
195-
#remove device
196-
echo $device_number > /sys/class/zram-control/hot_remove
197-
if [ $? != 0 ];then
198-
error "Cannot disable ZRAM because doing so would overflow your RAM. Try closing some programs, then run this script again."
199-
fi
200-
done
201-
echo Done
182+
# prepare to disable all zram devices (after making new ones)
183+
old_zram="$(find /dev/ -name zram* -type b | tr -cd "0123456789\n")"
202184
203-
rm -rf /zram
185+
disable_old_zram() { #put this into a function so it can be run in 2 different places cleanly
186+
187+
local IFS=$'\n'
188+
for device_number in $old_zram ;do
189+
#if zram device is a swap device, disable it
190+
echo -n "Disabling zram${device_number}... "
191+
swapoff /dev/zram${device_number} 2>/dev/null
192+
if [ $? == 137 ];then
193+
error "Cannot disable ZRAM because doing so would overflow your RAM. Try closing some programs, then run this script again."
194+
fi
195+
196+
#if zram device is mounted, unmount it
197+
umount /dev/zram${device_number} 2>/dev/null
198+
199+
#remove device
200+
#non-fatal because sometimes the file-storage zram device gets stuck with "Device or resource busy" forever until reboot
201+
echo $device_number > /sys/class/zram-control/hot_remove || true
202+
#if [ $? != 0 ];then
203+
# error "Cannot disable ZRAM${device_number} because doing so would overflow your RAM. Try closing some programs, then run this script again."
204+
#fi
205+
echo Done
206+
done
207+
rm -rf /zram
208+
}
204209
205210
#exit script now if "exit" flag passed
206211
if [ "$1" == stop ]; then
212+
disable_old_zram
207213
exit 0
208214
fi
209215
@@ -232,7 +238,9 @@ for i in $drive_num1 $drive_num2 $drive_num3 $drive_num4 ;do
232238
swapon /dev/zram${i} -d -p 1
233239
done
234240
235-
#create second zram drive: for temporary user-storage at /zram
241+
disable_old_zram
242+
243+
#create zram drive for temporary user-storage at /zram
236244
if ! grep -qxF "ExecStart=/usr/bin/zram.sh storage-off" /etc/systemd/system/zram-swap.service ;then
237245
echo "Setting up ZRAM-powered file storage at /zram"
238246
#create new zram drive
@@ -245,10 +253,11 @@ if ! grep -qxF "ExecStart=/usr/bin/zram.sh storage-off" /etc/systemd/system/zram
245253
echo $((totalmem * 1024 * 4)) > /sys/block/zram${storage_drive_num}/disksize
246254
247255
#create a partition and mount it
248-
mkfs.ext4 /dev/zram${storage_drive_num} >/dev/null
256+
mkfs.ext4 -F -O ^has_journal,^metadata_csum,^orphan_file -b 4096 /dev/zram${storage_drive_num} >/dev/null
249257
mkdir -p /zram
250258
mount /dev/zram${storage_drive_num} /zram
251259
chmod -R 777 /zram #make writable for any user
260+
rmdir /zram/lost+found || true
252261
fi
253262
EOF
254263

0 commit comments

Comments
 (0)