Libtorrent v2.x memory limiting on linux
Posted: Tue Mar 14, 2023 11:32 pm
Just wanted add that I tested following working on linux(with systemd), to restrict page-caching not growing indefinitely, possibly making performance issues as been reported previously by some, just like on windows.
Add file named e.g. 'wslimit.conf' under '/etc/systemd/system/deluged.service.d' (make dir if not already there):
(Change e.g. to '1G' etc, after personal preference)
Finally run 'sudo systemctl daemon-reload'.
(Alternate way being simply running 'sudo systemctl edit deluged', adding the part in codebox above(both lines, added between the two comment-blocks where cursor initially is) and save/exit, which automatically generates 'deluged.service.d' dir if not there, the override file therein, and runs daemon-reload too).
To remove this fix, then simply delete wslimit.conf(override.conf if used alternate way above), and if made the deluged.service.d dir yourself for this, then delete that too, and end with 'sudo systemctl daemon-reload'.
Same trick can be done for dockers through adding the '-m 512m' option to the commands generating the docker image e.g.:
Last, one can also do this manually by starting deluged through systemd-run with limiting enabled e.g.:
This generates a temp unit with scope extension, which by default a bunch random numbers for name, hence the '-u deluged' option(which isn't for specifying user, as that is the '--uid' option instead here), so can stop deluged again in same session through 'sudo systemctl stop deluged.scope', instead of specifying said random numbers.
Anyway, for all solutions you can check 'free -m' now doesn't use up all your memory during torrenting(listed in 'buff/cache' section, not 'used', and where 'free' very small without this trick). Also, under 'Memory' section of 'sudo systemctl status deluged'(service extension is implied when not given, so need specify 'deluged.scope' specifically for 'systemd-run'), or 'sudo systemd-cgtop', and for dockers under 'mem usage / limit' section of 'sudo docker stats deluge'.
Sorry no solution yet for non-systemd systems, but hope helps somewhat at least still.
Edit: Just stumbled over easiest method, just simply run:
Can rerun with new value to change, or 'MemoryMax=' to reset to infinity, or just delete generated '/etc/systemd/system.control/deluged.service.d' dir. Also can add '--runtime' switch for testing it just in current session.
Add file named e.g. 'wslimit.conf' under '/etc/systemd/system/deluged.service.d' (make dir if not already there):
Code: Select all
[Service]
MemoryMax=512M
Finally run 'sudo systemctl daemon-reload'.
(Alternate way being simply running 'sudo systemctl edit deluged', adding the part in codebox above(both lines, added between the two comment-blocks where cursor initially is) and save/exit, which automatically generates 'deluged.service.d' dir if not there, the override file therein, and runs daemon-reload too).
To remove this fix, then simply delete wslimit.conf(override.conf if used alternate way above), and if made the deluged.service.d dir yourself for this, then delete that too, and end with 'sudo systemctl daemon-reload'.
Same trick can be done for dockers through adding the '-m 512m' option to the commands generating the docker image e.g.:
Code: Select all
sudo docker run -d \
--name deluge \
[...] \
-m 512m \
lscr.io/linuxserver/deluge:latest
Code: Select all
sudo systemd-run --scope -p MemoryMax=512M --uid=deluge -u deluged deluged
Anyway, for all solutions you can check 'free -m' now doesn't use up all your memory during torrenting(listed in 'buff/cache' section, not 'used', and where 'free' very small without this trick). Also, under 'Memory' section of 'sudo systemctl status deluged'(service extension is implied when not given, so need specify 'deluged.scope' specifically for 'systemd-run'), or 'sudo systemd-cgtop', and for dockers under 'mem usage / limit' section of 'sudo docker stats deluge'.
Sorry no solution yet for non-systemd systems, but hope helps somewhat at least still.
Edit: Just stumbled over easiest method, just simply run:
Code: Select all
sudo systemctl set-property deluged MemoryMax=512M