Skip to content

Commit 45152dc

Browse files
committed
Add L2ARC arcstats for MFU/MRU buffers and buffer content type
Currently the ARC state (MFU/MRU) of cached L2ARC buffer and their content type is unknown. Knowing this information may prove beneficial in adjusting the L2ARC caching policy. This commit adds L2ARC arcstats that display the aligned size (in bytes) of L2ARC buffers according to their content type (data/metadata) and according to their ARC state (MRU/MFU or prefetch). It also expands the existing evict_l2_eligible arcstat to differentiate between MFU and MRU buffers. L2ARC caches buffers from the MRU and MFU lists of ARC. Upon caching a buffer, its ARC state (MRU/MFU) is stored in the L2 header (b_arcs_state). The l2_m{f,r}u_asize arcstats reflect the aligned size (in bytes) of L2ARC buffers according to their ARC state (based on b_arcs_state). We also account for the case where an L2ARC and ARC cached MRU or MRU_ghost buffer transitions to MFU. The l2_prefetch_asize reflects the alinged size (in bytes) of L2ARC buffers that were cached while they had the prefetch flag set in ARC. This is dynamically updated as the prefetch flag of L2ARC buffers changes. When buffers are evicted from ARC, if they are determined to be L2ARC eligible then their logical size is recorded in evict_l2_eligible_m{r,f}u arcstats according to their ARC state upon eviction. Persistent L2ARC: When commiting an L2ARC buffer to a log block (L2ARC metadata) its b_arcs_state and prefetch flag is also stored. If the buffer changes its arcstate or prefetch flag this is reflected in the above arcstats. However, the L2ARC metadata cannot currently be updated to reflect this change. Example: L2ARC caches an MRU buffer. L2ARC metadata and arcstats count this as an MRU buffer. The buffer transitions to MFU. The arcstats are updated to reflect this. Upon pool re-import or on/offlining the L2ARC device the arcstats are cleared and the buffer will now be counted as an MRU buffer, as the L2ARC metadata were not updated. Bug fix: - If l2arc_noprefetch is set, arc_read_done clears the L2CACHE flag of an ARC buffer. However, prefetches may be issued in a way that arc_read_done() is bypassed. Instead, move the related code in l2arc_write_eligible() to account for those cases too. Also add a test and update manpages for l2arc_mfuonly module parameter, and update the manpages and code comments for l2arc_noprefetch. Move persist_l2arc tests to l2arc. Signed-off-by: George Amanakis <[email protected]>
1 parent 8e7fe49 commit 45152dc

26 files changed

+656
-71
lines changed

cmd/arc_summary/arc_summary2

Lines changed: 92 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,30 @@ def get_arc_summary(Kstat):
219219
deleted = Kstat["kstat.zfs.misc.arcstats.deleted"]
220220
mutex_miss = Kstat["kstat.zfs.misc.arcstats.mutex_miss"]
221221
evict_skip = Kstat["kstat.zfs.misc.arcstats.evict_skip"]
222+
evict_l2_cached = Kstat["kstat.zfs.misc.arcstats.evict_l2_cached"]
223+
evict_l2_eligible = Kstat["kstat.zfs.misc.arcstats.evict_l2_eligible"]
224+
evict_l2_eligible_mfu = Kstat["kstat.zfs.misc.arcstats.evict_l2_eligible_mfu"]
225+
evict_l2_eligible_mru = Kstat["kstat.zfs.misc.arcstats.evict_l2_eligible_mru"]
226+
evict_l2_ineligible = Kstat["kstat.zfs.misc.arcstats.evict_l2_ineligible"]
227+
evict_l2_skip = Kstat["kstat.zfs.misc.arcstats.evict_l2_skip"]
222228

223229
# ARC Misc.
224230
output["arc_misc"] = {}
225231
output["arc_misc"]["deleted"] = fHits(deleted)
226-
output["arc_misc"]['mutex_miss'] = fHits(mutex_miss)
227-
output["arc_misc"]['evict_skips'] = fHits(evict_skip)
232+
output["arc_misc"]["mutex_miss"] = fHits(mutex_miss)
233+
output["arc_misc"]["evict_skips"] = fHits(evict_skip)
234+
output["arc_misc"]["evict_l2_skip"] = fHits(evict_l2_skip)
235+
output["arc_misc"]["evict_l2_cached"] = fBytes(evict_l2_cached)
236+
output["arc_misc"]["evict_l2_eligible"] = fBytes(evict_l2_eligible)
237+
output["arc_misc"]["evict_l2_eligible_mfu"] = {
238+
'per': fPerc(evict_l2_eligible_mfu, evict_l2_eligible),
239+
'num': fBytes(evict_l2_eligible_mfu),
240+
}
241+
output["arc_misc"]["evict_l2_eligible_mru"] = {
242+
'per': fPerc(evict_l2_eligible_mru, evict_l2_eligible),
243+
'num': fBytes(evict_l2_eligible_mru),
244+
}
245+
output["arc_misc"]["evict_l2_ineligible"] = fBytes(evict_l2_ineligible)
228246

229247
# ARC Sizing
230248
arc_size = Kstat["kstat.zfs.misc.arcstats.size"]
@@ -340,8 +358,26 @@ def _arc_summary(Kstat):
340358
sys.stdout.write("\tDeleted:\t\t\t\t%s\n" % arc['arc_misc']['deleted'])
341359
sys.stdout.write("\tMutex Misses:\t\t\t\t%s\n" %
342360
arc['arc_misc']['mutex_miss'])
343-
sys.stdout.write("\tEvict Skips:\t\t\t\t%s\n" %
361+
sys.stdout.write("\tEviction Skips:\t\t\t\t%s\n" %
344362
arc['arc_misc']['evict_skips'])
363+
sys.stdout.write("\tEviction Skips Due to L2 Writes:\t%s\n" %
364+
arc['arc_misc']['evict_l2_skip'])
365+
sys.stdout.write("\tL2 Cached Evictions:\t\t\t%s\n" %
366+
arc['arc_misc']['evict_l2_cached'])
367+
sys.stdout.write("\tL2 Eligible Evictions:\t\t\t%s\n" %
368+
arc['arc_misc']['evict_l2_eligible'])
369+
sys.stdout.write("\tL2 Eligible MFU Evictions:\t%s\t%s\n" % (
370+
arc['arc_misc']['evict_l2_eligible_mfu']['per'],
371+
arc['arc_misc']['evict_l2_eligible_mfu']['num'],
372+
)
373+
)
374+
sys.stdout.write("\tL2 Eligible MRU Evictions:\t%s\t%s\n" % (
375+
arc['arc_misc']['evict_l2_eligible_mru']['per'],
376+
arc['arc_misc']['evict_l2_eligible_mru']['num'],
377+
)
378+
)
379+
sys.stdout.write("\tL2 Ineligible Evictions:\t\t%s\n" %
380+
arc['arc_misc']['evict_l2_ineligible'])
345381
sys.stdout.write("\n")
346382

347383
# ARC Sizing
@@ -677,6 +713,11 @@ def get_l2arc_summary(Kstat):
677713
l2_writes_done = Kstat["kstat.zfs.misc.arcstats.l2_writes_done"]
678714
l2_writes_error = Kstat["kstat.zfs.misc.arcstats.l2_writes_error"]
679715
l2_writes_sent = Kstat["kstat.zfs.misc.arcstats.l2_writes_sent"]
716+
l2_mfu_asize = Kstat["kstat.zfs.misc.arcstats.l2_mfu_asize"]
717+
l2_mru_asize = Kstat["kstat.zfs.misc.arcstats.l2_mru_asize"]
718+
l2_prefetch_asize = Kstat["kstat.zfs.misc.arcstats.l2_prefetch_asize"]
719+
l2_bufc_data_asize = Kstat["kstat.zfs.misc.arcstats.l2_bufc_data_asize"]
720+
l2_bufc_metadata_asize = Kstat["kstat.zfs.misc.arcstats.l2_bufc_metadata_asize"]
680721

681722
l2_access_total = (l2_hits + l2_misses)
682723
output['l2_health_count'] = (l2_writes_error + l2_cksum_bad + l2_io_error)
@@ -699,7 +740,7 @@ def get_l2arc_summary(Kstat):
699740
output["io_errors"] = fHits(l2_io_error)
700741

701742
output["l2_arc_size"] = {}
702-
output["l2_arc_size"]["adative"] = fBytes(l2_size)
743+
output["l2_arc_size"]["adaptive"] = fBytes(l2_size)
703744
output["l2_arc_size"]["actual"] = {
704745
'per': fPerc(l2_asize, l2_size),
705746
'num': fBytes(l2_asize)
@@ -708,6 +749,26 @@ def get_l2arc_summary(Kstat):
708749
'per': fPerc(l2_hdr_size, l2_size),
709750
'num': fBytes(l2_hdr_size),
710751
}
752+
output["l2_arc_size"]["mfu_asize"] = {
753+
'per': fPerc(l2_mfu_asize, l2_asize),
754+
'num': fBytes(l2_mfu_asize),
755+
}
756+
output["l2_arc_size"]["mru_asize"] = {
757+
'per': fPerc(l2_mru_asize, l2_asize),
758+
'num': fBytes(l2_mru_asize),
759+
}
760+
output["l2_arc_size"]["prefetch_asize"] = {
761+
'per': fPerc(l2_prefetch_asize, l2_asize),
762+
'num': fBytes(l2_prefetch_asize),
763+
}
764+
output["l2_arc_size"]["bufc_data_asize"] = {
765+
'per': fPerc(l2_bufc_data_asize, l2_asize),
766+
'num': fBytes(l2_bufc_data_asize),
767+
}
768+
output["l2_arc_size"]["bufc_metadata_asize"] = {
769+
'per': fPerc(l2_bufc_metadata_asize, l2_asize),
770+
'num': fBytes(l2_bufc_metadata_asize),
771+
}
711772

712773
output["l2_arc_evicts"] = {}
713774
output["l2_arc_evicts"]['lock_retries'] = fHits(l2_evict_lock_retry)
@@ -772,7 +833,7 @@ def _l2arc_summary(Kstat):
772833
sys.stdout.write("\n")
773834

774835
sys.stdout.write("L2 ARC Size: (Adaptive)\t\t\t\t%s\n" %
775-
arc["l2_arc_size"]["adative"])
836+
arc["l2_arc_size"]["adaptive"])
776837
sys.stdout.write("\tCompressed:\t\t\t%s\t%s\n" % (
777838
arc["l2_arc_size"]["actual"]["per"],
778839
arc["l2_arc_size"]["actual"]["num"],
@@ -783,11 +844,36 @@ def _l2arc_summary(Kstat):
783844
arc["l2_arc_size"]["head_size"]["num"],
784845
)
785846
)
847+
sys.stdout.write("\tMFU Alloc. Size:\t\t%s\t%s\n" % (
848+
arc["l2_arc_size"]["mfu_asize"]["per"],
849+
arc["l2_arc_size"]["mfu_asize"]["num"],
850+
)
851+
)
852+
sys.stdout.write("\tMRU Alloc. Size:\t\t%s\t%s\n" % (
853+
arc["l2_arc_size"]["mru_asize"]["per"],
854+
arc["l2_arc_size"]["mru_asize"]["num"],
855+
)
856+
)
857+
sys.stdout.write("\tPrefetch Alloc. Size:\t\t%s\t%s\n" % (
858+
arc["l2_arc_size"]["prefetch_asize"]["per"],
859+
arc["l2_arc_size"]["prefetch_asize"]["num"],
860+
)
861+
)
862+
sys.stdout.write("\tData (buf content) Alloc. Size:\t%s\t%s\n" % (
863+
arc["l2_arc_size"]["bufc_data_asize"]["per"],
864+
arc["l2_arc_size"]["bufc_data_asize"]["num"],
865+
)
866+
)
867+
sys.stdout.write("\tMetadata (buf content) Size:\t%s\t%s\n" % (
868+
arc["l2_arc_size"]["bufc_metadata_asize"]["per"],
869+
arc["l2_arc_size"]["bufc_metadata_asize"]["num"],
870+
)
871+
)
786872
sys.stdout.write("\n")
787873

788874
if arc["l2_arc_evicts"]['lock_retries'] != '0' or \
789875
arc["l2_arc_evicts"]["reading"] != '0':
790-
sys.stdout.write("L2 ARC Evicts:\n")
876+
sys.stdout.write("L2 ARC Evictions:\n")
791877
sys.stdout.write("\tLock Retries:\t\t\t\t%s\n" %
792878
arc["l2_arc_evicts"]['lock_retries'])
793879
sys.stdout.write("\tUpon Reading:\t\t\t\t%s\n" %

cmd/arc_summary/arc_summary3

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,20 @@ def section_arc(kstats_dict):
598598
prt_i1('Deleted:', f_hits(arc_stats['deleted']))
599599
prt_i1('Mutex misses:', f_hits(arc_stats['mutex_miss']))
600600
prt_i1('Eviction skips:', f_hits(arc_stats['evict_skip']))
601+
prt_i1('Eviction skips due to L2 writes:',
602+
f_hits(arc_stats['evict_l2_skip']))
603+
prt_i1('L2 cached evictions:', f_bytes(arc_stats['evict_l2_cached']))
604+
prt_i1('L2 eligible evictions:', f_bytes(arc_stats['evict_l2_eligible']))
605+
prt_i2('L2 eligible MFU evictions:',
606+
f_perc(arc_stats['evict_l2_eligible_mfu'],
607+
arc_stats['evict_l2_eligible']),
608+
f_bytes(arc_stats['evict_l2_eligible_mfu']))
609+
prt_i2('L2 eligible MRU evictions:',
610+
f_perc(arc_stats['evict_l2_eligible_mru'],
611+
arc_stats['evict_l2_eligible']),
612+
f_bytes(arc_stats['evict_l2_eligible_mru']))
613+
prt_i1('L2 ineligible evictions:',
614+
f_bytes(arc_stats['evict_l2_ineligible']))
601615
print()
602616

603617

@@ -736,6 +750,21 @@ def section_l2arc(kstats_dict):
736750
prt_i2('Header size:',
737751
f_perc(arc_stats['l2_hdr_size'], arc_stats['l2_size']),
738752
f_bytes(arc_stats['l2_hdr_size']))
753+
prt_i2('MFU allocated size:',
754+
f_perc(arc_stats['l2_mfu_asize'], arc_stats['l2_asize']),
755+
f_bytes(arc_stats['l2_mfu_asize']))
756+
prt_i2('MRU allocated size:',
757+
f_perc(arc_stats['l2_mru_asize'], arc_stats['l2_asize']),
758+
f_bytes(arc_stats['l2_mru_asize']))
759+
prt_i2('Prefetch allocated size:',
760+
f_perc(arc_stats['l2_prefetch_asize'], arc_stats['l2_asize']),
761+
f_bytes(arc_stats['l2_prefetch_asize']))
762+
prt_i2('Data (buffer content) allocated size:',
763+
f_perc(arc_stats['l2_bufc_data_asize'], arc_stats['l2_asize']),
764+
f_bytes(arc_stats['l2_bufc_data_asize']))
765+
prt_i2('Metadata (buffer content) allocated size:',
766+
f_perc(arc_stats['l2_bufc_metadata_asize'], arc_stats['l2_asize']),
767+
f_bytes(arc_stats['l2_bufc_metadata_asize']))
739768

740769
print()
741770
prt_1('L2ARC breakdown:', f_hits(l2_access_total))

cmd/arcstat/arcstat.in

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ cols = {
8888
"mfug": [4, 1000, "MFU ghost list hits per second"],
8989
"mrug": [4, 1000, "MRU ghost list hits per second"],
9090
"eskip": [5, 1000, "evict_skip per second"],
91+
"el2skip": [7, 1000, "evict skip, due to l2 writes, per second"],
92+
"el2cach": [7, 1024, "Size of L2 cached evictions per second"],
93+
"el2el": [5, 1024, "Size of L2 eligible evictions per second"],
94+
"el2mfu": [6, 1024, "Size of L2 eligible MFU evictions per second"],
95+
"el2mru": [6, 1024, "Size of L2 eligible MRU evictions per second"],
96+
"el2inel": [7, 1024, "Size of L2 ineligible evictions per second"],
9197
"mtxmis": [6, 1000, "mutex_miss per second"],
9298
"dread": [5, 1000, "Demand accesses per second"],
9399
"pread": [5, 1000, "Prefetch accesses per second"],
@@ -96,6 +102,16 @@ cols = {
96102
"l2read": [6, 1000, "Total L2ARC accesses per second"],
97103
"l2hit%": [6, 100, "L2ARC access hit percentage"],
98104
"l2miss%": [7, 100, "L2ARC access miss percentage"],
105+
"l2pref": [6, 1024, "L2ARC prefetch allocated size"],
106+
"l2mfu": [5, 1024, "L2ARC MFU allocated size"],
107+
"l2mru": [5, 1024, "L2ARC MRU allocated size"],
108+
"l2data": [6, 1024, "L2ARC data allocated size"],
109+
"l2meta": [6, 1024, "L2ARC metadata allocated size"],
110+
"l2pref%": [7, 100, "L2ARC prefetch percentage"],
111+
"l2mfu%": [6, 100, "L2ARC MFU percentage"],
112+
"l2mru%": [6, 100, "L2ARC MRU percentage"],
113+
"l2data%": [7, 100, "L2ARC data percentage"],
114+
"l2meta%": [7, 100, "L2ARC metadata percentage"],
99115
"l2asize": [7, 1024, "Actual (compressed) size of the L2ARC"],
100116
"l2size": [6, 1024, "Size of the L2ARC"],
101117
"l2bytes": [7, 1024, "Bytes read per second from the L2ARC"],
@@ -436,6 +452,12 @@ def calculate():
436452
v["mrug"] = d["mru_ghost_hits"] / sint
437453
v["mfug"] = d["mfu_ghost_hits"] / sint
438454
v["eskip"] = d["evict_skip"] / sint
455+
v["el2skip"] = d["evict_l2_skip"] / sint
456+
v["el2cach"] = d["evict_l2_cached"] / sint
457+
v["el2el"] = d["evict_l2_eligible"] / sint
458+
v["el2mfu"] = d["evict_l2_eligible_mfu"] / sint
459+
v["el2mru"] = d["evict_l2_eligible_mru"] / sint
460+
v["el2inel"] = d["evict_l2_ineligible"] / sint
439461
v["mtxmis"] = d["mutex_miss"] / sint
440462

441463
if l2exist:
@@ -449,6 +471,17 @@ def calculate():
449471
v["l2size"] = cur["l2_size"]
450472
v["l2bytes"] = d["l2_read_bytes"] / sint
451473

474+
v["l2pref"] = cur["l2_prefetch_asize"]
475+
v["l2mfu"] = cur["l2_mfu_asize"]
476+
v["l2mru"] = cur["l2_mru_asize"]
477+
v["l2data"] = cur["l2_bufc_data_asize"]
478+
v["l2meta"] = cur["l2_bufc_metadata_asize"]
479+
v["l2pref%"] = 100 * v["l2pref"] / v["l2asize"]
480+
v["l2mfu%"] = 100 * v["l2mfu"] / v["l2asize"]
481+
v["l2mru%"] = 100 * v["l2mru"] / v["l2asize"]
482+
v["l2data%"] = 100 * v["l2data"] / v["l2asize"]
483+
v["l2meta%"] = 100 * v["l2meta"] / v["l2asize"]
484+
452485
v["grow"] = 0 if cur["arc_no_grow"] else 1
453486
v["need"] = cur["arc_need_free"]
454487
v["free"] = cur["memory_free_bytes"]

cmd/zdb/zdb.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4188,6 +4188,8 @@ dump_l2arc_log_entries(uint64_t log_entries,
41884188
(u_longlong_t)L2BLK_GET_PREFETCH((&le[j])->le_prop));
41894189
(void) printf("|\t\t\t\taddress: %llu\n",
41904190
(u_longlong_t)le[j].le_daddr);
4191+
(void) printf("|\t\t\t\tARC state: %llu\n",
4192+
(u_longlong_t)L2BLK_GET_STATE((&le[j])->le_prop));
41914193
(void) printf("|\n");
41924194
}
41934195
(void) printf("\n");

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ AC_CONFIG_FILES([
338338
tests/zfs-tests/tests/functional/inheritance/Makefile
339339
tests/zfs-tests/tests/functional/inuse/Makefile
340340
tests/zfs-tests/tests/functional/io/Makefile
341+
tests/zfs-tests/tests/functional/l2arc/Makefile
341342
tests/zfs-tests/tests/functional/large_files/Makefile
342343
tests/zfs-tests/tests/functional/largest_pool/Makefile
343344
tests/zfs-tests/tests/functional/libzfs/Makefile
@@ -354,7 +355,6 @@ AC_CONFIG_FILES([
354355
tests/zfs-tests/tests/functional/nopwrite/Makefile
355356
tests/zfs-tests/tests/functional/online_offline/Makefile
356357
tests/zfs-tests/tests/functional/pam/Makefile
357-
tests/zfs-tests/tests/functional/persist_l2arc/Makefile
358358
tests/zfs-tests/tests/functional/pool_checkpoint/Makefile
359359
tests/zfs-tests/tests/functional/pool_names/Makefile
360360
tests/zfs-tests/tests/functional/poolversion/Makefile

include/sys/arc_impl.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ typedef struct l2arc_lb_ptr_buf {
350350
#define L2BLK_SET_TYPE(field, x) BF64_SET((field), 48, 8, x)
351351
#define L2BLK_GET_PROTECTED(field) BF64_GET((field), 56, 1)
352352
#define L2BLK_SET_PROTECTED(field, x) BF64_SET((field), 56, 1, x)
353+
#define L2BLK_GET_STATE(field) BF64_GET((field), 57, 4)
354+
#define L2BLK_SET_STATE(field, x) BF64_SET((field), 57, 4, x)
353355

354356
#define PTR_SWAP(x, y) \
355357
do { \
@@ -445,6 +447,7 @@ typedef struct l2arc_buf_hdr {
445447
l2arc_dev_t *b_dev; /* L2ARC device */
446448
uint64_t b_daddr; /* disk address, offset byte */
447449
uint32_t b_hits;
450+
arc_state_type_t b_arcs_state;
448451
list_node_t b_l2node;
449452
} l2arc_buf_hdr_t;
450453

@@ -546,6 +549,8 @@ typedef struct arc_stats {
546549
kstat_named_t arcstat_evict_not_enough;
547550
kstat_named_t arcstat_evict_l2_cached;
548551
kstat_named_t arcstat_evict_l2_eligible;
552+
kstat_named_t arcstat_evict_l2_eligible_mfu;
553+
kstat_named_t arcstat_evict_l2_eligible_mru;
549554
kstat_named_t arcstat_evict_l2_ineligible;
550555
kstat_named_t arcstat_evict_l2_skip;
551556
kstat_named_t arcstat_hash_elements;
@@ -744,6 +749,18 @@ typedef struct arc_stats {
744749
kstat_named_t arcstat_mfu_ghost_evictable_metadata;
745750
kstat_named_t arcstat_l2_hits;
746751
kstat_named_t arcstat_l2_misses;
752+
/*
753+
* Allocated size (in bytes) of L2ARC cached buffers by ARC state.
754+
*/
755+
kstat_named_t arcstat_l2_prefetch_asize;
756+
kstat_named_t arcstat_l2_mru_asize;
757+
kstat_named_t arcstat_l2_mfu_asize;
758+
/*
759+
* Allocated size (in bytes) of L2ARC cached buffers by buffer content
760+
* type.
761+
*/
762+
kstat_named_t arcstat_l2_bufc_data_asize;
763+
kstat_named_t arcstat_l2_bufc_metadata_asize;
747764
kstat_named_t arcstat_l2_feeds;
748765
kstat_named_t arcstat_l2_rw_clash;
749766
kstat_named_t arcstat_l2_read_bytes;

0 commit comments

Comments
 (0)