{"action":"created","issue":{"url":"https://api.github.com/repos/raspberrypi/linux/issues/2649","repository_url":"https://api.github.com/repos/raspberrypi/linux","labels_url":"https://api.github.com/repos/raspberrypi/linux/issues/2649/labels{/name}","comments_url":"https://api.github.com/repos/raspberrypi/linux/issues/2649/comments","events_url":"https://api.github.com/repos/raspberrypi/linux/issues/2649/events","html_url":"https://github.com/raspberrypi/linux/issues/2649","id":351025327,"node_id":"MDU6SXNzdWUzNTEwMjUzMjc=","number":2649,"title":"Add zswap support to the kernel to improve swap performance","user":{"login":"Syonyk","id":20114411,"node_id":"MDQ6VXNlcjIwMTE0NDEx","avatar_url":"https://avatars2.githubusercontent.com/u/20114411?v=4","gravatar_id":"","url":"https://api.github.com/users/Syonyk","html_url":"https://github.com/Syonyk","followers_url":"https://api.github.com/users/Syonyk/followers","following_url":"https://api.github.com/users/Syonyk/following{/other_user}","gists_url":"https://api.github.com/users/Syonyk/gists{/gist_id}","starred_url":"https://api.github.com/users/Syonyk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Syonyk/subscriptions","organizations_url":"https://api.github.com/users/Syonyk/orgs","repos_url":"https://api.github.com/users/Syonyk/repos","events_url":"https://api.github.com/users/Syonyk/events{/privacy}","received_events_url":"https://api.github.com/users/Syonyk/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":16,"created_at":"2018-08-16T01:42:12Z","updated_at":"2018-08-21T17:13:30Z","closed_at":null,"author_association":"NONE","body":"In personal experimentation working towards \"Using the Raspberry Pi 3B/3B+ as a light duty desktop,\" I've discovered that fronting my swap file with zswap makes a _huge_ difference in system capability, most notably in how Chromium functions.  With stock settings, Chromium on the Pi 3B cannot load Google Inbox (https://inbox.google.com, assuming one's account is enabled) or Google Docs properly.  With zswap enabled, I can load both, simultaneously, and still have a usable system.\r\n\r\nUnder normal operation, with Chromium running, I have a fully responsive system with 300-500MB of memory swapped out - this being memory that, while not able to be discarded, is not actively in use.\r\n\r\nI'm aware of the concerns about thrashing the SD card (and the glacial performance of said SD card under swap use), which is why zswap works so well.\r\n\r\nzswap, in a nutshell, is a compressed frontend for swap.  It's quite configurable, with multiple compression options (lzo and lz4 being the most useful), several ways of storing compressed pages in memory (two and three \"slots\" per 4k page for compressed data), configurable in terms of percent of total system memory it will cache, etc.\r\n\r\nIt also includes a LRU (Least Recently Used) algorithm for evicting pages from compressed swap to physical disk swap when the cache is full, which prevents the priority inversion issues one can run into when using zram and physical swap with priorities set (zram fills up with the first stuff swapped out, which is typically least important, leaving physical disk to handle the later, higher priority swap that you'd like to keep in RAM).\r\n\r\nEnabling zswap in the kernel requires the following changes to .config:\r\nCONFIG_ZSWAP=y\r\nCONFIG_ZPOOL=y\r\nCONFIG_ZBUD=y\r\nCONFIG_Z3FOLD=y\r\n\r\nAnd, optionally, if you want lzo compression (somewhat better than lz4, but somewhat slower):\r\nCONFIG_CRYPTO_LZO=y\r\n\r\nI believe these can be built as modules as well, with no loss of functionality.  If the defaults are not zswap, they should be modules, but if the decision is made to use zswap on all installs, these should be built in.\r\n\r\nTo enable zswap, there needs to be a backing swapfile (already the case, though 100MB is a bit small in 2018), and the kernel needs to have zswap configured.  I've done this in /boot/cmdline.txt, though other locations would probably work as well.\r\n\r\nAt a minimum, this requires: zswap.enabled=1\r\n\r\nI've also set the following on my install, though a smaller value may be a better default initially.  With Chromium being as memory hungry as it is, I normally raise this at runtime.\r\nzswap.max_pool_percent=15\r\n\r\nOne can also set:\r\nzswap.zpool=z3fold\r\n\r\nHowever, while this worked properly on 4.9, with 4.14, I've seen a few kernel oopses related to this (buddy ID of 0 - I haven't worked out the details on this bug), so I have reverted to using zbud for now.  The effective compression is worse than using z3fold, but the stability is better.\r\n\r\nCurrent zswap parameters on my light desktop:\r\n\r\nroot@raspberrypi:/sys/kernel/debug/zswap# grep -R .\r\nstored_pages:68856\r\npool_total_size:151773184\r\nduplicate_entry:0\r\nwritten_back_pages:0\r\nreject_compress_poor:1091\r\nreject_kmemcache_fail:0\r\nreject_alloc_fail:0\r\nreject_reclaim_fail:0\r\npool_limit_hit:0\r\n\r\nThis works out to 282MB of data swapped into 151MB, for a compression ratio of 1.86:1.  z3fold is better, but, as previously noted, seems somewhat unstable right now.  I will investigate that further when I have time.\r\n\r\nI encourage the maintainers to build a kernel with zswap enabled, and use Chromium for a while to observe the difference.  It makes a substantial difference in what can be loaded without grinding the system to a halt.  If you still run into memory pressure, try adding more swapfile.  I currently have a 4GB swapfile, which is entirely excessive and mostly unused, but I'm experimenting and have no particular storage pressures at the moment.  I would suggest increasing the default swapfile size to 200MB if zswap is used, although this may be something to simply note for users.\r\n\r\nUnlike zram, zswap allows data to overflow out of RAM to physical swap, which allows for better system performance and a higher ratio of \"Getting stuff that's actually unused out of RAM.\"\r\n\r\nSome relevant documentation for reading:\r\nhttps://www.kernel.org/doc/Documentation/vm/zswap.txt\r\nhttps://lwn.net/Articles/537422/\r\n\r\nLet me know what sort of benchmarking or other testing you would like to see in this thread.  I understand that the maintainers are touchy about adding anything that requires additional kernel size, but experimentally, zswap is a massive win in terms of usability with the new default browser of Chromium."},"comment":{"url":"https://api.github.com/repos/raspberrypi/linux/issues/comments/414751244","html_url":"https://github.com/raspberrypi/linux/issues/2649#issuecomment-414751244","issue_url":"https://api.github.com/repos/raspberrypi/linux/issues/2649","id":414751244,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNDc1MTI0NA==","user":{"login":"Syonyk","id":20114411,"node_id":"MDQ6VXNlcjIwMTE0NDEx","avatar_url":"https://avatars2.githubusercontent.com/u/20114411?v=4","gravatar_id":"","url":"https://api.github.com/users/Syonyk","html_url":"https://github.com/Syonyk","followers_url":"https://api.github.com/users/Syonyk/followers","following_url":"https://api.github.com/users/Syonyk/following{/other_user}","gists_url":"https://api.github.com/users/Syonyk/gists{/gist_id}","starred_url":"https://api.github.com/users/Syonyk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Syonyk/subscriptions","organizations_url":"https://api.github.com/users/Syonyk/orgs","repos_url":"https://api.github.com/users/Syonyk/repos","events_url":"https://api.github.com/users/Syonyk/events{/privacy}","received_events_url":"https://api.github.com/users/Syonyk/received_events","type":"User","site_admin":false},"created_at":"2018-08-21T17:13:30Z","updated_at":"2018-08-21T17:13:30Z","author_association":"NONE","body":"I don't appear to have access to all of the commits.  Is there a chance you could paste the fully updated z3fold.c file to try against 4.14, if you have access?  Or I can try a 4.19 build."}}
{"actor":{"display_login":"Syonyk"}}