cache_dirs - an attempt to keep directory entries in RAM to prevent disk spin-up


Recommended Posts

On 2/4/2021 at 3:35 AM, Alex R. Berg said:

As Hoopster (partially) writes above, a solution to the CPU spikes is to turn of the /mnt/user scanning.

 

  

On 3/1/2021 at 10:45 PM, BRiT said:

/mnt/user/ is just an aggregate of /mnt/disk#/ and /mnt/cache/, so if those are covered you don't need to explicitly cover /mnt/user/.

 

 

Unfortunately that doesn't seem to be the case for me, at least while moving around files on cache/pool via SMB.  With /mnt/user scanning on it works beautifully with no disk spinups.  With it off, every array disk with the relevant directory has to spin up, even if it's staying on the SSD cache in the same share.

 

Why does unraid even need to query array disks if it's just moving a file between cache/pool directories?  I guess to check for duplicates?  Would be nice if you could just make Mover handle that later when all the disks are spun up and throw an error if there's an issue.

Edited by acosmichippo
Link to comment
On 2/20/2021 at 10:53 AM, Alex R. Berg said:

Hi yo all,

 


I appreciate the thanks, you are welcome.

I've done some more testing myself, and I have not seen any spin-ups. So also think it is working now, without scanning of user. It's really good to get rid of that as it was CPU intensive.

Its relatively easy to test, by checking disk status in unRaids' Main dashbard. I can click the dots to spin disks down, and see if they are spun up. I then find folder on eg. disk3 and access it though user-share and see if it spins up. So far I have not reproduced any spin-ups on unRaid 6.8.3. So I think we are good, since it also sounds like it works for you out there.

Regarding maintenance, life moves on for all of us. I'm not really maintaining it anymore, but fortunately it does not need any maintenance. I might fix it though if a problem occurs that I can fix.

==== Custom Mover Script ===
Regarding @papnikol Q1, what I do if I have many disks? Well actually regardless of cache_dirs, I use my own custom mover before the official mover script. My custom mover moves certain folders to certain disks. That way I can keep all my most used files on disk1. I have 'ton' of files that consumes little space by todays standard, whereas mostly movies and backups consume huge chunks. So I just keep all those important things on disk1 and configured unRaid to never spin down disk1. It works far better for me than UnRaids default strategy. If my script hasn't chosen the location for a folder, it will be moved by the official mover. I only move to my allocated disks by custom mover when there's at least 50 GB available, and fall back to default strategy, moving to other disks. When space becomes available, my script moves it to correct disk later. All without me having to do anything besides the initial allocation of which folder goes where. If I want to move a share from one disk to another, I typically also just add a rule, and let it sort it out in the background automatically 

My custom mover also reduces risk of loss, if I lose two disks in unRaid. Because if a git repository/program is spread across many disks, I'll probably lose it all if one of the disks data is lost. UnRaid GUI cannot do that, while still falling back to using any disks, when I go full.



 

 

custom_mover 8.11 kB · 4 downloads move_if_idle 743 B · 1 download mover_all 113 B · 1 download

 

Sorry @Alex R. Berg, somehow I missed your comment (and, again, thank you for your contribution).

 

Your strategy is useful for cases like yours, but for cases like mine, where I cannot foresee which file I will need to use, It is not very helpful. Additionally - and this might be less important - in my windows machine I use Everything for indexing/searching, and cache_dirs works well with it... Still, thanks for sharing your scripts, one additional value for me is that they can help improve my shell scripting....
 

Link to comment
17 hours ago, papnikol said:

 

Sorry @Alex R. Berg, somehow I missed your comment (and, again, thank you for your contribution).

 

Your strategy is useful for cases like yours, but for cases like mine, where I cannot foresee which file I will need to use, It is not very helpful. Additionally - and this might be less important - in my windows machine I use Everything for indexing/searching, and cache_dirs works well with it... Still, thanks for sharing your scripts, one additional value for me is that they can help improve my shell scripting....
 

 

 

I also like Everything. I've set it to scan daily, but I do also have lots of non-windows shared files like subversion repositories and backups that I don't need it to touch. I don't really think its relevant for me for that usage to use cache-dirs as its only a daily scan for me, but of cause its nice that its there.
 

 

On 4/2/2021 at 5:50 PM, acosmichippo said:

 

  

 

 

Unfortunately that doesn't seem to be the case for me, at least while moving around files on cache/pool via SMB.  With /mnt/user scanning on it works beautifully with no disk spinups.  With it off, every array disk with the relevant directory has to spin up, even if it's staying on the SSD cache in the same share.

 

Why does unraid even need to query array disks if it's just moving a file between cache/pool directories?  I guess to check for duplicates?  Would be nice if you could just make Mover handle that later when all the disks are spun up and throw an error if there's an issue.

 

I don't know why that happens. I do believe unRaid (with some settings) delete empty folders on array disks after moving, but it doesn't delete empty folders that we, the users, have left there. I had some share settings set to Use Cache: Prefer or Only. I do believe after moving, unRaid deletes empty folders in the source-disk. But I also experienced that unRaid does not move files to reflect changed settings, so maybe you have to manually delete empty dirs. 

 

`find /mnt/disk* /mnt/cache -type d -empty -mindepth 1 -delete`

 

should delete empty dirs and only that, and thus cleanup your entire array. I advice testing such commands first in a safe location. Maybe with -maxdepth 1 to see root-deletes, and maybe delete mindepth 1 so you also cleanup empty root. You can play around a bit without the -delete option to see what it finds. 

 

I have no idea whether this has anything to do with your problem, I just noticed you mentioned it scanning empty dirs.

I'm using unRaid 6.8.3.

  • Like 1
Link to comment

Well I spoke too soon.  Sometimes it seems to work, others not.  I just tried moving a new file between directories on a share with "cache: Yes" (so it was on SSD cache), and it had to wake up almost the whole array to do it.  A few days ago it seemed to work fine. 

 

Maybe it's just not holding all the directories in memory?  But I have cache pressure set to 1, and I never go above ~30% usage of 32GB of memory.  Also tried turning on "fixed" with maximum depth of 0.  Increased timeout to 1500.  Added user defined options to skip recycle bin, etc.  Not sure there's much else I can do at this point other than lowering pressure to 0.

 

 

Screen Shot 2021-04-07 at 12.51.37 PM.png

Screen Shot 2021-04-07 at 12.53.11 PM.png

Edited by acosmichippo
Link to comment

I'm trying to exclude my "_CCC SafetyNet" folders, using the following command in the GUI...

 

-a '-noleaf \( -name "_CCC SafetyNet" -prune \) -o -print'

 

However, the GUI doesn't like the quotation marks and I end up with just "-a '-noleaf \( -name" in the box.

 

The command seems to be issued correctly however according to the logs, but it STILL looks through the CCC Archive folders (I'm watching lsof!)

 

How can I exclude folders like "_CCC SafetyNet" in the GUI?

 

Thanks!

Edited by Interstellar
Link to comment

I'm not sure its possible, that has never been tested. But most likely some of these work

You can double-escape with "\"foo bar\"".

Also you can escape the space instead: "_CCC\ SafetyNet". This should be equivalent to above.

And maybe you need to escape the backspace as well, so you add '\\' which might turn into "\":  "_CCC\\\ SafetyNet".

 

It depends on how many layers of quote-removing happens from the gui to the execution. Bash sucks when it comes to spaces in names, as bash operates on strings and interprets spaces as new arguments when calling another function. And unfortunately the script is written in bash, probably it grew from something small to something substantial.

Link to comment
On 4/7/2021 at 6:51 PM, acosmichippo said:

Well I spoke too soon.  Sometimes it seems to work, others not.  I just tried moving a new file between directories on a share with "cache: Yes" (so it was on SSD cache), and it had to wake up almost the whole array to do it.  A few days ago it seemed to work fine. 

 

Maybe it's just not holding all the directories in memory?  But I have cache pressure set to 1, and I never go above ~30% usage of 32GB of memory.  Also tried turning on "fixed" with maximum depth of 0.  Increased timeout to 1500.  Added user defined options to skip recycle bin, etc.  Not sure there's much else I can do at this point other than lowering pressure to 0.

 

 

Screen Shot 2021-04-07 at 12.51.37 PM.png

Screen Shot 2021-04-07 at 12.53.11 PM.png

 

 

cache-dirs will never be a real proper caching. Its a hack, where we try to poke linux to cache dirs. Maybe that's what you encounter. You can try to enable logging. You can find some info in this thread somewhere on the logging I believe, also see /var/log/cachedirs or something. It says when it scans everthing again, which on my system happens daily and esp. during large operations like parity check which puts load on the system.

 

Or it could be it just works really bad for you for unknown reasons.

What you tried with cache-pressure is also my experience, and for safety I use 1, but also tried 0 shortly.

 

Link to comment

Hi

 

Does this look correct?

Folder Caching is setup on Movies and TVShows as the primary purpose is a PLEX server.

Excluded are appdatam domains, isos, system, www as these are on my cache drive.

 

I think I sae this setup from a video, but cant find it and now just the clarify with the pro's.

 

Thanks

Chris

 

image.thumb.png.a6c992f9d891930d555373f293758839.png

Link to comment
18 minutes ago, SmokeyColes said:

Hi

 

Does this look correct?

Folder Caching is setup on Movies and TVShows as the primary purpose is a PLEX server.

Excluded are appdatam domains, isos, system, www as these are on my cache drive.

 

I think I sae this setup from a video, but cant find it and now just the clarify with the pro's.

 

Thanks

Chris

 

image.thumb.png.a6c992f9d891930d555373f293758839.png

Just include the shares you want cache_dirs to handle, all others are then excluded.  No need to specify the excluded shares.

Link to comment
Just now, dlandon said:

Just include the shares you want cache_dirs to handle, all others are then excluded.  No need to specify the excluded shares.

Thank you for your help. 

 

So if my: appdatam domains, isos, system, www

folders are on the cache drive like the following image.

I will remove them from excluded. 

Is this meaning that these folders and constantly fast access on the cache drive.

 

And the TVshows/movies remain on the array but cached for quicker read access?

 

image.thumb.png.fd7829385707d723e32e5c1ff6e2dd48.png

Link to comment
25 minutes ago, SmokeyColes said:

Is this meaning that these folders and constantly fast access on the cache drive.

 

And the TVshows/movies remain on the array but cached for quicker read access?

If your cache is a SSD, cache dirs is not really necessary for cache only shares.  Cache dirs is intended for spinning disks.  The idea is to not spin up a disk when accessing directories - like browsing a share.  This keeps disks from spinning up unnecessarily and you don't have a delay while waiting for a disk to spin up.

  • Like 2
Link to comment
  • 2 weeks later...
On 4/11/2021 at 4:38 AM, Alex R. Berg said:

 

 

cache-dirs will never be a real proper caching. Its a hack, where we try to poke linux to cache dirs. Maybe that's what you encounter. You can try to enable logging. You can find some info in this thread somewhere on the logging I believe, also see /var/log/cachedirs or something. It says when it scans everthing again, which on my system happens daily and esp. during large operations like parity check which puts load on the system.

 

Or it could be it just works really bad for you for unknown reasons.

What you tried with cache-pressure is also my experience, and for safety I use 1, but also tried 0 shortly.

 

 

 

I took another approach with this and tried moving the files via unraid's CLI and they seem to be moving consistently without waking up the array.  I guess there is something in MacOS's finder that is waking up the array when I use it to move cached files around.  Keeping .DS_Store files on the cache did not solve the issue like I hoped it would (although maybe it helps a little, not sure).

 

So for now I have just set up an hourly user script to move files between cached directories.

Edited by acosmichippo
Link to comment
  • 5 months later...
  • 3 weeks later...
  • 4 weeks later...
On 4/18/2021 at 2:00 PM, dlandon said:

If your cache is a SSD, cache dirs is not really necessary for cache only shares.  Cache dirs is intended for spinning disks.  The idea is to not spin up a disk when accessing directories - like browsing a share.  This keeps disks from spinning up unnecessarily and you don't have a delay while waiting for a disk to spin up.

 

But if i want to use cache dirs for logs that in SSD cache for save SSD wear is it good choice ?

Link to comment
18 hours ago, JonathanM said:

No. SSD reads are "free", they don't add measurable wear. It's only writes that wear out SSD's. There is a reason TBW is specified for SSD's.

 

Yes , i know i meaned to use cache dirs for save writes wear of SDD .

i thought if cache dirs using directory in RAM we can also write to it.

is cache dirs only used for read only ?

Link to comment
On 4/30/2021 at 2:09 PM, acosmichippo said:

I took another approach with this and tried moving the files via unraid's CLI and they seem to be moving consistently without waking up the array.  I guess there is something in MacOS's finder that is waking up the array when I use it to move cached files around.  Keeping .DS_Store files on the cache did not solve the issue like I hoped it would (although maybe it helps a little, not sure).

 

So for now I have just set up an hourly user script to move files between cached directories.

 

You can minimize it by:

  • caching .DS_Store (which you want to do anyway to avoid waking parity)
  • excluding each share from spotlight
  • disabling calculate all sizes and show icon preview in folders and subfolders (probably easiest to set it as default then clear out .DS_Stores)

And after all that Finder will still occasionally wake the drives. I decided it wasn't worth it.

  • Like 1
Link to comment
  • 2 weeks later...

Just to clarify, this is intended to cache files (not the whole file, just the name etc.) as well as directories? The reason I ask is that it still takes a few seconds to open folders with lots of actual files (like pictures) in. Directories with lots of sub directories load instantly so not sure if I have a problem or if this is just working as it should. I have disabled thumbnail loading etc as has been mentioned in this thread.

  • Like 1
Link to comment
  • 4 months later...
1 hour ago, Reva said:

It's been a while since the last post here. Is the plugin supported for Unraid 6.10.0/still being developed?

It is still supported and working for Unraid 6.10.  It may look like there is no development because it just works and doesn't need anything.

Link to comment
  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.