Skip to content

Instantly share code, notes, and snippets.

@wd5gnr
Created June 1, 2022 14:43
Show Gist options
  • Save wd5gnr/9af32eff7fad5d4057b2698fb9606868 to your computer and use it in GitHub Desktop.
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
#!/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
@bphd
Copy link

bphd commented Jul 16, 2022

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

@wd5gnr
Copy link
Author

wd5gnr commented Jul 16, 2022

You need to be root or fix your permissions as root

@bphd
Copy link

bphd commented Jul 16, 2022

That was done as root and the fs and path is well mounted, ownershiped and permissionned

@fcojperez
Copy link

@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