koverstreet / bcachefs-tools

http://bcachefs.org
GNU General Public License v2.0
115 stars 88 forks source link

Subcommand to promote of file/directory subtree to cache #235

Open NikolayKuzmin opened 6 months ago

NikolayKuzmin commented 6 months ago

Some of modern videogames have been developed with SSD in mind. Other just give loading speedups, both kind benefits from SSD caching, but some just unplayable without. I've encountered this with Alan Wake 2 which datastreaming is just broken on HDD. Bcachefs offers some mechanics to address this, user can play with target attributes for game directory but this is not enough, some dropped game which user forgot to uninstall could eat up all ssd space. Another method (don't know if it usable) is to simulate read pressure on game's directory, like several times read all it content to /dev/null, but it is not obvious how many times I should do this, this will pollute disk caches and may not work because OS can just use memory cached data not issuing read command to FS driver. Also this will not play nice if Bcachefs does (or will do in some future) some kind of smart caching, prioritizing caching of short random reads. So it would be nice to have some "promote this to cache" subcommand, which will trigger promotion and ideally allow to wait until promotion finishes. This could fix games like Alan Wake 2 with just one "run this command before playing first time of before running game you haven't touched for an year" without breaking all SSD caching as target can do.

Schonhoffer commented 6 months ago

From https://bcachefs.org/bcachefs-principles-of-operation.pdf Section 4.2, seems like you can set background_target at inode level. So you can try to set the background_target to SSD for that directory using bcachefs setattr --background_target=ssd myGame/ and then run rereplicate ?

NikolayKuzmin commented 6 months ago

Thank you, but this is not a solution. As I've already mentioned, playing with *target can help with issue, but this creates more problems than solves. If user have dropped game for an year and forgot to uninstall it, or if he uninstalled but have created a snapshot before, background_target="ssd" on game's directory will eat some of his SSD space forever. And, let be honest, nobody will remember he have modified some file attributes while trying to make game work. So no, background_target must remain hdd, but with an ability to promote to cache manually.