Skip to content

Commit cd42e99

Browse files
shodanshoktonyhutter
authored andcommitted
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 <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Gionatan Danti <[email protected]> Closes #16343 Closes #16402
1 parent c60df6a commit cd42e99

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

man/man4/zfs.4

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,26 @@ Controls whether buffers present on special vdevs are eligible for caching
121121
into L2ARC.
122122
If set to 1, exclude dbufs on special vdevs from being cached to L2ARC.
123123
.
124-
.It Sy l2arc_mfuonly Ns = Ns Sy 0 Ns | Ns 1 Pq int
124+
.It Sy l2arc_mfuonly Ns = Ns Sy 0 Ns | Ns 1 Ns | Ns 2 Pq int
125125
Controls whether only MFU metadata and data are cached from ARC into L2ARC.
126126
This may be desired to avoid wasting space on L2ARC when reading/writing large
127127
amounts of data that are not expected to be accessed more than once.
128128
.Pp
129-
The default is off,
129+
The default is 0,
130130
meaning both MRU and MFU data and metadata are cached.
131-
When turning off this feature, some MRU buffers will still be present
132-
in ARC and eventually cached on L2ARC.
131+
When turning off this feature (setting it to 0), some MRU buffers will
132+
still be present in ARC and eventually cached on L2ARC.
133133
.No If Sy l2arc_noprefetch Ns = Ns Sy 0 ,
134134
some prefetched buffers will be cached to L2ARC, and those might later
135135
transition to MRU, in which case the
136136
.Sy l2arc_mru_asize No arcstat will not be Sy 0 .
137137
.Pp
138+
Setting it to 1 means to L2 cache only MFU data and metadata.
139+
.Pp
140+
Setting it to 2 means to L2 cache all metadata (MRU+MFU) but
141+
only MFU data (ie: MRU data are not cached). This can be the right setting
142+
to cache as much metadata as possible even when having high data turnover.
143+
.Pp
138144
Regardless of
139145
.Sy l2arc_noprefetch ,
140146
some MFU buffers might be evicted from ARC,

module/zfs/arc.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9055,12 +9055,17 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz)
90559055
*/
90569056
for (int pass = 0; pass < L2ARC_FEED_TYPES; pass++) {
90579057
/*
9058-
* If pass == 1 or 3, we cache MRU metadata and data
9059-
* respectively.
9058+
* pass == 0: MFU meta
9059+
* pass == 1: MRU meta
9060+
* pass == 2: MFU data
9061+
* pass == 3: MRU data
90609062
*/
9061-
if (l2arc_mfuonly) {
9063+
if (l2arc_mfuonly == 1) {
90629064
if (pass == 1 || pass == 3)
90639065
continue;
9066+
} else if (l2arc_mfuonly > 1) {
9067+
if (pass == 3)
9068+
continue;
90649069
}
90659070

90669071
uint64_t passed_sz = 0;

0 commit comments

Comments
 (0)