lvmcache not promoting blocks when there's free RAM
Hello,
I have an x86-64 PC acting as a NAS, it has 2x 3TB HDDs in md(4) RAID1, with LVM on top, and LVs for various types of data. It also has an NVME SSD with rootfs and 16GB of RAM. I spin down the HDDs to minimize idle power draw, and to make them spin up less often I tried to use lvmcache for one of the LVs, with cache volume on the SSD.
However, barely anything gets cached in the lvmcache. Blocks aren't getting promoted (based on dmsetup status), despite the cache volume being mostly empty.
When a file is read for the first time, it gets cached in RAM by page cache, but not on SSD by lvmcache. Subsequent reads never hit the block layer, because the data is already in RAM, until I need to reboot the machine. After a reboot, when something tries to read that file again, HDDs will have to be spun up again, because it never got promoted to SSD by lvmcache.
I looked into dm-cache's smq policy code[1], and it looks like for a block to be promoted to the cache volume, it needs to be read at least twice:
- first read - block gets added to the bottom of the hotspot queue
- some time passes, queue tick triggers a redistribute, some blocks get moved to the top of the queue
- second read - block is found to be on top of the queue, gets promoted
Unfortunately in my case the second read never comes.
I'm working it around by setting very low memory limit in cgroups that often read small files, but I'm curious if a better solution exists.
Also, I'm guessing I'm not the first one discovering this - is there any bugtracker where I can find or submit an issue like this?
I have a few ideas on how this could be fixed in the kernel, but I don't know if such patches would be welcome or where to reach device-mapper developers to ask them about it.
I'd be thankful for guidance on how to proceed with this.
Here are more details about the setup:
$ uname -a
Linux roy 5.10.0-20-amd64 #1 SMP Debian 5.10.158-2 (2022-12-13) x86_64 GNU/Linux
$ head -n1 /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
$ sudo lvs -a
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
archive greed Cwi-aoC--- 250,00g [archive_cache_cvol] [archive_corig] 1,83 24,09 0,00
[archive_cache_cvol] greed Cwi-aoC--- 50,00g
[archive_corig] greed owi-aoC--- 250,00g
[...]
$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/md126 greed lvm2 a-- <2,00t <473,00g
/dev/nvme0n1p3 greed lvm2 a-- <200,00g <150,00gI have graphs showing IO metrics from /proc/diskstats
and dmsetup status, but I don't know if/how one should send pictures to the list.
This is my first time posting to the list so please let me know if I made any mistakes. I can provide more details about my usecase, or my ideas for fixes, but I wasn't sure if this is the right place or how much detail is appropriate. I'll appreciate any guidance.
Regards
Wolf480pl
[1]: https://elixir.bootlin.com/linux/v5.10.200/source/drivers/md/dm-cache-policy-smq.c
A part your whole description
Our 15 years experience on hard disks data recovery, suggests to avoid the spin down and spin up of the storage's HDDs
Just make sure you have a vibrations free environment, yes, that is a must
Any noise in any fan , mean vibrations.
Contemporary HDDs (mean manufactured after 2016-2017) , are high density and heads sliders are now at few air molecules of distance from the platters surfaces
Just that
Meanwhile the drives are really low power consumption, so for just 2 or 4 drives, it is better to avoid those spin cycles. We don't put standby neither our 12 and 24 bays storages.
Kind regards
Roberto Gini
Technical Manager
https://www.RecuperoDatiRAIDFAsTec.it
Il giorno 19 dic 2023, 23:28, alle ore 23:28, Wolf480pl <[email protected]> ha scritto:
Quoted 78 lines
Hello,
I have an x86-64 PC acting as a NAS, it has 2x 3TB HDDs in md(4) RAID1, with LVM on top, and LVs for various types of data. It also has an NVME SSD with rootfs and 16GB of RAM. I spin down the HDDs to minimize idle power draw, and to make them spin up less often I tried to use lvmcache for one of the LVs, with cache volume on the SSD.
However, barely anything gets cached in the lvmcache. Blocks aren't getting promoted (based on dmsetup status), despite the cache volume being mostly empty.
When a file is read for the first time, it gets cached in RAM by page cache, but not on SSD by lvmcache. Subsequent reads never hit the block layer, because the data is already in RAM, until I need to reboot the machine. After a reboot, when something tries to read that file again, HDDs will have to be spun up again, because it never got promoted to SSD by lvmcache.
I looked into dm-cache's smq policy code[1], and it looks like for a block to be promoted to the cache volume, it needs to be read at least twice:
- first read - block gets added to the bottom of the hotspot queue
- some time passes, queue tick triggers a redistribute, some blocks get moved to the top of the queue
- second read - block is found to be on top of the queue, gets promotedUnfortunately in my case the second read never comes.
I'm working it around by setting very low memory limit in cgroups that often read small files, but I'm curious if a better solution exists.
Also, I'm guessing I'm not the first one discovering this - is there any bugtracker where I can find or submit an issue like this?
I have a few ideas on how this could be fixed in the kernel, but I don't know if such patches would be welcome or where to reach device-mapper developers to ask them about it.
I'd be thankful for guidance on how to proceed with this.
Here are more details about the setup:
$ uname -a Linux roy 5.10.0-20-amd64 #1 SMP Debian 5.10.158-2 (2022-12-13) x86_64 GNU/Linux $ head -n1 /etc/os-release PRETTY_NAME="Debian GNU/Linux 11 (bullseye)" $ sudo lvs -a LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert archive greed Cwi-aoC--- 250,00g [archive_cache_cvol] [archive_corig] 1,83 24,09 0,00 [archive_cache_cvol] greed Cwi-aoC--- 50,00g [archive_corig] greed owi-aoC--- 250,00g [...] $ sudo pvs PV VG Fmt Attr PSize PFree /dev/md126 greed lvm2 a-- <2,00t <473,00g /dev/nvme0n1p3 greed lvm2 a-- <200,00g <150,00gI have graphs showing IO metrics from
/proc/diskstats
anddmsetup status, but I don't know if/how one should send pictures to the list.This is my first time posting to the list so please let me know if I made any mistakes. I can provide more details about my usecase, or my ideas for fixes, but I wasn't sure if this is the right place or how much detail is appropriate. I'll appreciate any guidance.
Regards
Wolf480pl
[1]:
https://elixir.bootlin.com/linux/v5.10.200/source/drivers/md/dm-cache-policy-smq.c
Dne 19. 12. 23 v 23:28 Wolf480pl napsal(a):
Quoted 11 lines
Hello,
I have an x86-64 PC acting as a NAS, it has 2x 3TB HDDs in md(4) RAID1, with LVM on top, and LVs for various types of data. It also has an NVME SSD with rootfs and 16GB of RAM. I spin down the HDDs to minimize idle power draw, and to make them spin up less often I tried to use lvmcache for one of the LVs, with cache volume on the SSD.
However, barely anything gets cached in the lvmcache. Blocks aren't getting promoted (based on dmsetup status), despite the cache volume being mostly empty.
Hi
dm-cache target (ATM) is focusing on figuring out 'hotspot' areas of your disk readings.
So it doesn't cache what is currently 'present' and satisfied from page-cache.
So normally to promote the disk area (cache chunk) to be promoted to the cache it needs to be repeatedly physically accessed from your origin device.
So on a 'naive' example - if you read file A - and then such file is being held by page cache and you just read data from this file while page cache still keeps it in RAM - this will not 'rise' access counter on block level.
There are some 'requests' to accelerate a promotion of blocks to the empty cache where some of them have been upstream - but overal the 'dm-cache'
is not designed as 'page-cache' like layer on top of your HDD - it really is focusing on getting there blocks frequently accessed and it take some time to populate the cache with 'worthy' content.
Quoted 12 lines
When a file is read for the first time, it gets cached in RAM by page cache, but not on SSD by lvmcache. Subsequent reads never hit the block layer, because the data is already in RAM, until I need to reboot the machine. After a reboot, when something tries to read that file again, HDDs will have to be spun up again, because it never got promoted to SSD by lvmcache.
I looked into dm-cache's smq policy code[1], and it looks like for a block to be promoted to the cache volume, it needs to be read at least twice:
Quoted 6 lines
- first read - block gets added to the bottom of the hotspot queue
- some time passes, queue tick triggers a redistribute, some blocks get moved to the top of the queue
- second read - block is found to be on top of the queue, gets promotedUnfortunately in my case the second read never comes.
As said - the dm-cache is not targeted to solve this problem.
Quoted 3 lines
I have a few ideas on how this could be fixed in the kernel, but I don't know if such patches would be welcome or where to reach device-mapper developers to ask them about it.
It would be more like a new target.
It might be worth to check dm-writecache - which is solving opposite issue - how to efficiently writeback dirty pagecache.
Regards
Zdenek
Il 2023-12-20 16:42 Zdenek Kabelac ha scritto:
Quoted 2 lines
dm-cache target (ATM) is focusing on figuring out 'hotspot' areas of your disk readings.
Hi Zdenek,
back in the mq days, read_promote_adjustment and write_promote_adjustment could be tuned to get more aggressive caching.
Does smq have something similar? I can not find anything in the docs...
Regards.
Signature · 4 lines
Danti Gionatan Supporto Tecnico Assyoma S.r.l. - www.assyoma.it email: [email protected] - [email protected]