From 77a797a3823c12268e7f1d73f5e024a77b2f582a Mon Sep 17 00:00:00 2001 From: shodanshok Date: Fri, 16 Aug 2024 22:34:07 +0200 Subject: [PATCH] Enable L2 cache of all (MRU+MFU) metadata but MFU data only `l2arc_mfuonly` was added to avoid wasting L2 ARC on read-once MRU data and metadata. However it can be useful to cache as much metadata as possible while, at the same time, restricting data cache to MFU buffers only. This patch allow for such behavior by setting `l2arc_mfuonly` to 2 (or higher). The list of possible values is the following: 0: cache both MRU and MFU for both data and metadata; 1: cache only MFU for both data and metadata; 2: cache both MRU and MFU for metadata, but only MFU for data. Reviewed-by: Alexander Motin Reviewed-by: Brian Behlendorf Signed-off-by: Gionatan Danti Closes #16343 Closes #16402 --- man/man4/zfs.4 | 14 ++++++++++---- module/zfs/arc.c | 11 ++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/man/man4/zfs.4 b/man/man4/zfs.4 index 075641872675..2be3a8414aac 100644 --- a/man/man4/zfs.4 +++ b/man/man4/zfs.4 @@ -132,20 +132,26 @@ Controls whether buffers present on special vdevs are eligible for caching into L2ARC. If set to 1, exclude dbufs on special vdevs from being cached to L2ARC. . -.It Sy l2arc_mfuonly Ns = Ns Sy 0 Ns | Ns 1 Pq int +.It Sy l2arc_mfuonly Ns = Ns Sy 0 Ns | Ns 1 Ns | Ns 2 Pq int Controls whether only MFU metadata and data are cached from ARC into L2ARC. This may be desired to avoid wasting space on L2ARC when reading/writing large amounts of data that are not expected to be accessed more than once. .Pp -The default is off, +The default is 0, meaning both MRU and MFU data and metadata are cached. -When turning off this feature, some MRU buffers will still be present -in ARC and eventually cached on L2ARC. +When turning off this feature (setting it to 0), some MRU buffers will +still be present in ARC and eventually cached on L2ARC. .No If Sy l2arc_noprefetch Ns = Ns Sy 0 , some prefetched buffers will be cached to L2ARC, and those might later transition to MRU, in which case the .Sy l2arc_mru_asize No arcstat will not be Sy 0 . .Pp +Setting it to 1 means to L2 cache only MFU data and metadata. +.Pp +Setting it to 2 means to L2 cache all metadata (MRU+MFU) but +only MFU data (ie: MRU data are not cached). This can be the right setting +to cache as much metadata as possible even when having high data turnover. +.Pp Regardless of .Sy l2arc_noprefetch , some MFU buffers might be evicted from ARC, diff --git a/module/zfs/arc.c b/module/zfs/arc.c index 78c2cf8ec5c3..3c657c979cdc 100644 --- a/module/zfs/arc.c +++ b/module/zfs/arc.c @@ -9158,12 +9158,17 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz) */ for (int pass = 0; pass < L2ARC_FEED_TYPES; pass++) { /* - * If pass == 1 or 3, we cache MRU metadata and data - * respectively. + * pass == 0: MFU meta + * pass == 1: MRU meta + * pass == 2: MFU data + * pass == 3: MRU data */ - if (l2arc_mfuonly) { + if (l2arc_mfuonly == 1) { if (pass == 1 || pass == 3) continue; + } else if (l2arc_mfuonly > 1) { + if (pass == 3) + continue; } uint64_t passed_sz = 0;