https://github.com/hakavlad/prelockd Skip to content Sign up * Why GitHub? Features - + Mobile - + Actions - + Codespaces - + Packages - + Security - + Code review - + Project management - + Integrations - + GitHub Sponsors - + Customer stories- * Team * Enterprise * Explore + Explore GitHub - Learn and contribute + Topics - + Collections - + Trending - + Learning Lab - + Open source guides - Connect with others + The ReadME Project - + Events - + Community forum - + GitHub Education - + GitHub Stars program - * Marketplace * Pricing Plans - + Compare plans - + Contact Sales - + Education - [ ] [search-key] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} hakavlad / prelockd * Notifications * Star 28 * Fork 2 Lock executables and shared libraries in memory to improve system responsiveness under low-memory conditions MIT License 28 stars 2 forks Star Notifications * Code * Issues 1 * Pull requests 0 * Discussions * Actions * Wiki * Security * Insights More * Code * Issues * Pull requests * Discussions * Actions * Wiki * Security * Insights master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags 2 branches 10 tags Code Clone HTTPS GitHub CLI [https://github.com/h] Use Git or checkout with SVN using the web URL. [gh repo clone hakavl] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching Xcode If nothing happens, download Xcode and try again. Go back Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit Alexey Avramov Update README ... 2c408bd May 2, 2021 Update README 2c408bd Git stats * 52 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github/workflows Create codeql-analysis.yml Jan 16, 2021 deb Update DEBIAN/control Dec 3, 2020 .gitignore Add scripts to build deb package Nov 4, 2020 LICENSE Initial commit Jul 16, 2020 MANPAGE.md Update description Dec 7, 2020 Makefile Update Makefile and DEBIAN/postinstall Nov 19, 2020 README.md Update README May 3, 2021 prelockd Various fixes Dec 1, 2020 prelockd.8 Update description Dec 7, 2020 prelockd.conf Update conf Dec 2, 2020 prelockd.service.in Update description Dec 7, 2020 View code prelockd What is the problem? Effects Demo Install For Arch Linux there's an AUR package To install on Debian and Ubuntu-based systems: On other distros: How to configure TODO Report bugs and ask any questions README.md prelockd CodeQL Total alerts Packaging status prelockd is a daemon that locks memory mapped executables and shared libraries in memory to improve system responsiveness under low-memory conditions. What is the problem? Would it be possible to reserve a fixed (configurable) amount of RAM for caches, and trigger OOM killer earlier, before most UI code is evicted from memory? In my use case, I am happy sacrificing e.g. 0.5GB and kill runaway tasks before the system freezes. Potentially OOM killer would also work better in such conditions. I almost never work at close to full memory capacity, it's always a single task that goes wrong and brings the system down. -- lkml Why not fix the problem in the kernel? Like not swap executable code when the system is near-OOM? -- www.phoronix.com No caches means all executable pages, ro pages (e.g. fonts) are evicted from memory and have to be constantly reloaded on every user action. It is indeed a difficult problem - some cached pages (streaming IO) will likely not be needed again and should be discarded asap, other (like mmapped executable/ro pages of UI utilities) will cause thrashing when evicted under high memory pressure. -- lkml.org I would like to try disabling/limiting eviction of some/all file pages (for example exec pages) akin to disabling swapping, but there is no such mechanism. Yes, there would likely be problems with large RO mmapped files that would need to be addressed, but in many applications users would be interested in having such options. -- lkml.org Once swap runs out, the kernel stops having a choice. It can only make room by reclaiming important caches. And this will turn bad quickly, as it will eventually include the executables/libraries that must be loaded as they are doing work! So, we don't want to get the kernel into the situation where it must remove executables/libraries from main memory. If that happens, you can end up hitting the disk for every function call. -- lists.fedoraproject.org Effects * OOM killer comes faster (especially with noswap). * Fast system reclaiming after OOM. * Improved system responsiveness under low-memory conditions. Demo https://www.youtube.com/watch?v=vykUrP1UvcI On this video: running fast memory hogs in a loop on Debian 10 GNOME, 4 GiB MemTotal without swap space. * prelockd enabled: about 500 MiB mlocked. Starting while true; do tail /dev/zero; done: no freezes. The OOM killer comes quickly, the system recovers quickly. * prelockd disabled: system hangs with while true; do tail /dev/ zero; done. See also https://youtu.be/fPnbnNX9CPE, https://youtu.be/O8QNnfb_Vm0. Install For Arch Linux there's an AUR package Use your favorite AUR helper. For example, $ yay -S prelockd $ sudo systemctl enable --now prelockd.service prelockd-git is also available. To install on Debian and Ubuntu-based systems: It's easy to build a deb package with the latest git snapshot. Install build dependencies: $ sudo apt install make fakeroot Clone the latest git snapshot and run the build script to build the package: $ git clone https://github.com/hakavlad/prelockd.git && cd prelockd $ deb/build.sh Install the package: $ sudo apt install --reinstall ./deb/package.deb Start and enable prelockd.service after installing the package: $ sudo systemctl enable --now prelockd.service On other distros: Install: $ git clone https://github.com/hakavlad/prelockd.git && cd prelockd $ sudo make install $ sudo systemctl enable --now prelockd.service Uninstall: $ sudo make uninstall How to configure Edit the config (/etc/prelockd.conf or /usr/local/etc/prelockd.conf) and restart the service. TODO * Improve the documentation. Report bugs and ask any questions https://github.com/hakavlad/prelockd/issues About Lock executables and shared libraries in memory to improve system responsiveness under low-memory conditions Topics mmap mlock Resources Readme License MIT License Releases 10 v0.9 Latest Dec 3, 2020 + 9 releases Contributors 2 * @hakavlad hakavlad Alexey Avramov * @tim77 tim77 Artem Polishchuk Languages * Python 86.2% * Makefile 8.5% * Roff 4.6% * Shell 0.7% * (c) 2021 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.