Created
June 1, 2022 14:43
-
-
Save wd5gnr/9af32eff7fad5d4057b2698fb9606868 to your computer and use it in GitHub Desktop.
A script to move baloo to a cgroup to limit both memory and disk I/O
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#baloo-nice by Al Williams | |
if [ "$1" == "fast" ] | |
then | |
RLIMIT=100048576 # bps limit (read) | |
WLIMIT=100048576 # bps limit (write) | |
else | |
RLIMIT=548576 # bps limit (read) | |
WLIMIT=548576 # bps limit (write) | |
fi | |
if [ "$1" == "med" ] | |
then | |
RLIMIT=12048576 # bps limit (read) | |
WLIMIT=12048576 # bps limit (write) | |
fi | |
#DEVICES="8 252 253 259" | |
DEVICES="8 253 259" | |
SEARCH=baloo | |
MEMLIMIT=1024M | |
if [ ! -d /sys/fs/cgroup/blkio/baloo ] | |
then | |
mkdir /sys/fs/cgroup/blkio/baloo # assume you need to be root to do this | |
fi | |
if [ ! -d /sys/fs/cgroup/memory/baloo ] | |
then | |
mkdir /sys/fs/cgroup/memory/baloo | |
fi | |
echo $MEMLIMIT >/sys/fs/cgroup/memory/baloo/memory.limit_in_bytes | |
for I in $DEVICES | |
do | |
echo "$I:0 $RLIMIT" >/sys/fs/cgroup/blkio/baloo/blkio.throttle.read_bps_device | |
echo "$I:0 $WLIMIT" >/sys/fs/cgroup/blkio/baloo/blkio.throttle.write_bps_device | |
done | |
for I in `pgrep $SEARCH` | |
do | |
echo $I >/sys/fs/cgroup/blkio/baloo/cgroup.procs | |
echo $I >/sys/fs/cgroup/memory/baloo/cgroup.procs | |
done | |
SEARCH=baloo_file | |
for I in `pgrep $SEARCH` | |
do | |
echo $I >/sys/fs/cgroup/blkio/baloo/cgroup.procs | |
echo $I >/sys/fs/cgroup/memory/baloo/cgroup.procs | |
done | |
SEARCH=baloo_file_extractor | |
for I in `pgrep $SEARCH` | |
do | |
echo $I >/sys/fs/cgroup/blkio/baloo/cgroup.procs | |
echo $I >/sys/fs/cgroup/memory/baloo/cgroup.procs | |
done | |
exit 0 |
touch: cannot touch '/sys/fs/cgroup/memory/baloo/memory.limit_in_bytes': Permission denied
bash: /sys/fs/cgroup/memory/baloo/memory.limit_in_bytes: Permission denied
You need to be root or fix your permissions as root
That was done as root and the fs and path is well mounted, ownershiped and permissionned
@bphd, it worked for me when I was using ubuntu bionic. The only issue was setting up the limits for a device which is not present on the system.
My understanding about issues writing on /sys/fs/cgroup/memory/baloo/memory.limit_in_bytes seems to be with the version cgroup and/or kernel. I hope that will give you helpful tip
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://medium.com/for-linux-users/slash-kde-baloos-disk-throughput-with-cgroups-dc67b43da01a?sk=4664dfdb238e0fb43e0a6776b50da00d