Skip to content

Commit 26b10bd

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 in the future. 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. Signed-off-by: George Amanakis <[email protected]>
1 parent 2b07c5a commit 26b10bd

File tree

13 files changed

+438
-27
lines changed

13 files changed

+438
-27
lines changed

cmd/arc_summary/arc_summary2

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,11 @@ def get_l2arc_summary(Kstat):
677677
l2_writes_done = Kstat["kstat.zfs.misc.arcstats.l2_writes_done"]
678678
l2_writes_error = Kstat["kstat.zfs.misc.arcstats.l2_writes_error"]
679679
l2_writes_sent = Kstat["kstat.zfs.misc.arcstats.l2_writes_sent"]
680+
l2_mfu_asize = Kstat["kstat.zfs.misc.arcstats.l2_mfu_asize"]
681+
l2_mru_asize = Kstat["kstat.zfs.misc.arcstats.l2_mru_asize"]
682+
l2_prefetch_asize = Kstat["kstat.zfs.misc.arcstats.l2_prefetch_asize"]
683+
l2_bufc_data_asize = Kstat["kstat.zfs.misc.arcstats.l2_bufc_data_asize"]
684+
l2_bufc_metadata_asize = Kstat["kstat.zfs.misc.arcstats.l2_bufc_metadata_asize"]
680685

681686
l2_access_total = (l2_hits + l2_misses)
682687
output['l2_health_count'] = (l2_writes_error + l2_cksum_bad + l2_io_error)
@@ -699,7 +704,7 @@ def get_l2arc_summary(Kstat):
699704
output["io_errors"] = fHits(l2_io_error)
700705

701706
output["l2_arc_size"] = {}
702-
output["l2_arc_size"]["adative"] = fBytes(l2_size)
707+
output["l2_arc_size"]["adaptive"] = fBytes(l2_size)
703708
output["l2_arc_size"]["actual"] = {
704709
'per': fPerc(l2_asize, l2_size),
705710
'num': fBytes(l2_asize)
@@ -708,6 +713,26 @@ def get_l2arc_summary(Kstat):
708713
'per': fPerc(l2_hdr_size, l2_size),
709714
'num': fBytes(l2_hdr_size),
710715
}
716+
output["l2_arc_size"]["mfu_asize"] = {
717+
'per': fPerc(l2_mfu_asize, l2_asize),
718+
'num': fBytes(l2_mfu_asize),
719+
}
720+
output["l2_arc_size"]["mru_asize"] = {
721+
'per': fPerc(l2_mru_asize, l2_asize),
722+
'num': fBytes(l2_mru_asize),
723+
}
724+
output["l2_arc_size"]["prefetch_asize"] = {
725+
'per': fPerc(l2_prefetch_asize, l2_asize),
726+
'num': fBytes(l2_prefetch_asize),
727+
}
728+
output["l2_arc_size"]["bufc_data_asize"] = {
729+
'per': fPerc(l2_bufc_data_asize, l2_asize),
730+
'num': fBytes(l2_bufc_data_asize),
731+
}
732+
output["l2_arc_size"]["bufc_metadata_asize"] = {
733+
'per': fPerc(l2_bufc_metadata_asize, l2_asize),
734+
'num': fBytes(l2_bufc_metadata_asize),
735+
}
711736

712737
output["l2_arc_evicts"] = {}
713738
output["l2_arc_evicts"]['lock_retries'] = fHits(l2_evict_lock_retry)
@@ -772,7 +797,7 @@ def _l2arc_summary(Kstat):
772797
sys.stdout.write("\n")
773798

774799
sys.stdout.write("L2 ARC Size: (Adaptive)\t\t\t\t%s\n" %
775-
arc["l2_arc_size"]["adative"])
800+
arc["l2_arc_size"]["adaptive"])
776801
sys.stdout.write("\tCompressed:\t\t\t%s\t%s\n" % (
777802
arc["l2_arc_size"]["actual"]["per"],
778803
arc["l2_arc_size"]["actual"]["num"],
@@ -783,6 +808,31 @@ def _l2arc_summary(Kstat):
783808
arc["l2_arc_size"]["head_size"]["num"],
784809
)
785810
)
811+
sys.stdout.write("\tMFU Size:\t\t\t%s\t%s\n" % (
812+
arc["l2_arc_size"]["mfu_asize"]["per"],
813+
arc["l2_arc_size"]["mfu_asize"]["num"],
814+
)
815+
)
816+
sys.stdout.write("\tMRU Size:\t\t\t%s\t%s\n" % (
817+
arc["l2_arc_size"]["mru_asize"]["per"],
818+
arc["l2_arc_size"]["mru_asize"]["num"],
819+
)
820+
)
821+
sys.stdout.write("\tPrefetch Size:\t\t\t%s\t%s\n" % (
822+
arc["l2_arc_size"]["prefetch_asize"]["per"],
823+
arc["l2_arc_size"]["prefetch_asize"]["num"],
824+
)
825+
)
826+
sys.stdout.write("\tData (buf content) Size:\t%s\t%s\n" % (
827+
arc["l2_arc_size"]["bufc_data_asize"]["per"],
828+
arc["l2_arc_size"]["bufc_data_asize"]["num"],
829+
)
830+
)
831+
sys.stdout.write("\tMetadata (buf content) Size:\t%s\t%s\n" % (
832+
arc["l2_arc_size"]["bufc_metadata_asize"]["per"],
833+
arc["l2_arc_size"]["bufc_metadata_asize"]["num"],
834+
)
835+
)
786836
sys.stdout.write("\n")
787837

788838
if arc["l2_arc_evicts"]['lock_retries'] != '0' or \

cmd/arc_summary/arc_summary3

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,21 @@ def section_l2arc(kstats_dict):
736736
prt_i2('Header size:',
737737
f_perc(arc_stats['l2_hdr_size'], arc_stats['l2_size']),
738738
f_bytes(arc_stats['l2_hdr_size']))
739+
prt_i2('MFU aligned size:',
740+
f_perc(arc_stats['l2_mfu_asize'], arc_stats['l2_asize']),
741+
f_bytes(arc_stats['l2_mfu_asize']))
742+
prt_i2('MRU aligned size:',
743+
f_perc(arc_stats['l2_mru_asize'], arc_stats['l2_asize']),
744+
f_bytes(arc_stats['l2_mru_asize']))
745+
prt_i2('Prefetch aligned size:',
746+
f_perc(arc_stats['l2_prefetch_asize'], arc_stats['l2_asize']),
747+
f_bytes(arc_stats['l2_prefetch_asize']))
748+
prt_i2('Data (buffer content) aligned size:',
749+
f_perc(arc_stats['l2_bufc_data_asize'], arc_stats['l2_asize']),
750+
f_bytes(arc_stats['l2_bufc_data_asize']))
751+
prt_i2('Metadata (buffer content) aligned size:',
752+
f_perc(arc_stats['l2_bufc_metadata_asize'], arc_stats['l2_asize']),
753+
f_bytes(arc_stats['l2_bufc_metadata_asize']))
739754

740755
print()
741756
prt_1('L2ARC breakdown:', f_hits(l2_access_total))

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\tstate: %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 & 0 deletions
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_arcstats/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

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 { \
@@ -446,6 +448,7 @@ typedef struct l2arc_buf_hdr {
446448
uint64_t b_daddr; /* disk address, offset byte */
447449
uint32_t b_hits;
448450
list_node_t b_l2node;
451+
arc_state_type_t b_arcs_state;
449452
} l2arc_buf_hdr_t;
450453

451454
typedef struct l2arc_write_callback {
@@ -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+
* Aligned 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+
* Aligned 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)