Skip to content

Commit 8e24992

Browse files
committed
More adaptive ARC eviction.
Traditionally ARC adaptation was limited to MRU/MFU distribution. But for years people with metadata-centric workload demanded mechanisms to also manage data/metadata distribution, that in original ZFS was just a FIFO. As result ZFS effectively got separate states for data and metadata, minimum and maximum metadata limits etc, but it all required manual tuning, was not adaptive and in its heart remained a bad FIFO. This change removes most of existing eviction logic, rewriting it from scratch. This makes MRU/MFU adaptation individual for data and meta- data, same as the distribution between data and metadata themselves. Since most of required states separation was already done, it only required to make arcs_size state field specific per data/metadata. The adaptation logic is still based on previous concept of ghost hits, just now it balances ARC capacity between 4 states: MRU data, MRU metadata, MFU data and MFU metadata. To simplify arc_c changes instead of arc_p measured in bytes, this code uses 3 variable arc_meta, arc_pd and arc_pm, representing ARC balance between metadata and data, MRU and MFU for data, and MRU and MFU for metadata respectively as 32-bit fixed point fractions. Since we care about the math result only when need to evict, this moves all the logic from arc_adapt() to arc_evict(), that reduces per-block overhead, since per-block operations are limited to stats collection, now moved from arc_adapt() to arc_access() and using cheaper wmsums. This also allows to remove ugly ARC_HDR_DO_ADAPT flag from many places. This change also removes number of metadata specific tunables, part of which were actually not functioning correctly, since not all metadata are equal and some (like L2ARC headers) are not really evictable. Instead it introduced single opaque knob zfs_arc_meta_balance, tuning ARC's reaction on ghost hits, allowing administrator give more or less preference to metadata without setting strict limits. Some of old code parts like arc_evict_meta() are just removed, because since introduction of ABD ARC they really make no sense: only headers referenced by small number of buffers are not evictable, and they are really not evictable no matter what this code do. Instead just call arc_prune_async() if too much metadata appear not evictable. Signed-off-by: Alexander Motin <mav@FreeBSD.org> Sponsored by: iXsystems, Inc.
1 parent a0105f6 commit 8e24992

File tree

10 files changed

+460
-776
lines changed

10 files changed

+460
-776
lines changed

cmd/arc_summary

Lines changed: 71 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,14 @@ def draw_graph(kstats_dict):
270270
arc_perc = f_perc(arc_stats['size'], arc_stats['c_max'])
271271
mfu_size = f_bytes(arc_stats['mfu_size'])
272272
mru_size = f_bytes(arc_stats['mru_size'])
273-
meta_limit = f_bytes(arc_stats['arc_meta_limit'])
274273
meta_size = f_bytes(arc_stats['arc_meta_used'])
275274
dnode_limit = f_bytes(arc_stats['arc_dnode_limit'])
276275
dnode_size = f_bytes(arc_stats['dnode_size'])
277276

278-
info_form = ('ARC: {0} ({1}) MFU: {2} MRU: {3} META: {4} ({5}) '
279-
'DNODE {6} ({7})')
277+
info_form = ('ARC: {0} ({1}) MFU: {2} MRU: {3} META: {4} '
278+
'DNODE {5} ({6})')
280279
info_line = info_form.format(arc_size, arc_perc, mfu_size, mru_size,
281-
meta_size, meta_limit, dnode_size,
282-
dnode_limit)
280+
meta_size, dnode_size, dnode_limit)
283281
info_spc = ' '*int((GRAPH_WIDTH-len(info_line))/2)
284282
info_line = GRAPH_INDENT+info_spc+info_line
285283

@@ -558,16 +556,28 @@ def section_arc(kstats_dict):
558556
arc_target_size = arc_stats['c']
559557
arc_max = arc_stats['c_max']
560558
arc_min = arc_stats['c_min']
561-
anon_size = arc_stats['anon_size']
562-
mfu_size = arc_stats['mfu_size']
563-
mru_size = arc_stats['mru_size']
564-
mfug_size = arc_stats['mfu_ghost_size']
565-
mrug_size = arc_stats['mru_ghost_size']
566-
unc_size = arc_stats['uncached_size']
567-
meta_limit = arc_stats['arc_meta_limit']
568-
meta_size = arc_stats['arc_meta_used']
559+
meta = arc_stats['meta']
560+
pd = arc_stats['pd']
561+
pm = arc_stats['pm']
562+
anon_data = arc_stats['anon_data']
563+
anon_metadata = arc_stats['anon_metadata']
564+
mfu_data = arc_stats['mfu_data']
565+
mfu_metadata = arc_stats['mfu_metadata']
566+
mru_data = arc_stats['mru_data']
567+
mru_metadata = arc_stats['mru_metadata']
568+
mfug_data = arc_stats['mfu_ghost_data']
569+
mfug_metadata = arc_stats['mfu_ghost_metadata']
570+
mrug_data = arc_stats['mru_ghost_data']
571+
mrug_metadata = arc_stats['mru_ghost_metadata']
572+
unc_data = arc_stats['uncached_data']
573+
unc_metadata = arc_stats['uncached_metadata']
574+
bonus_size = arc_stats['bonus_size']
569575
dnode_limit = arc_stats['arc_dnode_limit']
570576
dnode_size = arc_stats['dnode_size']
577+
dbuf_size = arc_stats['dbuf_size']
578+
hdr_size = arc_stats['hdr_size']
579+
l2_hdr_size = arc_stats['l2_hdr_size']
580+
abd_chunk_waste_size = arc_stats['abd_chunk_waste_size']
571581
target_size_ratio = '{0}:1'.format(int(arc_max) // int(arc_min))
572582

573583
prt_2('ARC size (current):',
@@ -578,25 +588,56 @@ def section_arc(kstats_dict):
578588
f_perc(arc_min, arc_max), f_bytes(arc_min))
579589
prt_i2('Max size (high water):',
580590
target_size_ratio, f_bytes(arc_max))
581-
caches_size = int(anon_size)+int(mfu_size)+int(mru_size)+int(unc_size)
582-
prt_i2('Anonymouns data size:',
583-
f_perc(anon_size, caches_size), f_bytes(anon_size))
584-
prt_i2('Most Frequently Used (MFU) cache size:',
585-
f_perc(mfu_size, caches_size), f_bytes(mfu_size))
586-
prt_i2('Most Recently Used (MRU) cache size:',
587-
f_perc(mru_size, caches_size), f_bytes(mru_size))
588-
prt_i1('Most Frequently Used (MFU) ghost size:', f_bytes(mfug_size))
589-
prt_i1('Most Recently Used (MRU) ghost size:', f_bytes(mrug_size))
591+
caches_size = int(anon_data)+int(anon_metadata)+\
592+
int(mfu_data)+int(mfu_metadata)+int(mru_data)+int(mru_metadata)+\
593+
int(unc_data)+int(unc_metadata)
594+
prt_i2('Anonymous data size:',
595+
f_perc(anon_data, caches_size), f_bytes(anon_data))
596+
prt_i2('Anonymous metadata size:',
597+
f_perc(anon_metadata, caches_size), f_bytes(anon_metadata))
598+
s = 4294967296
599+
v = (s-int(pd))*(s-int(meta))/s
600+
prt_i2('MFU data target:', f_perc(v, s),
601+
f_bytes(v / 65536 * caches_size / 65536))
602+
prt_i2('MFU data size:',
603+
f_perc(mfu_data, caches_size), f_bytes(mfu_data))
604+
prt_i1('MFU ghost data size:', f_bytes(mfug_data))
605+
v = (s-int(pm))*int(meta)/s
606+
prt_i2('MFU metadata target:', f_perc(v, s),
607+
f_bytes(v / 65536 * caches_size / 65536))
608+
prt_i2('MFU metadata size:',
609+
f_perc(mfu_metadata, caches_size), f_bytes(mfu_metadata))
610+
prt_i1('MFU ghost metadata size:', f_bytes(mfug_metadata))
611+
v = int(pd)*(s-int(meta))/s
612+
prt_i2('MRU data target:', f_perc(v, s),
613+
f_bytes(v / 65536 * caches_size / 65536))
614+
prt_i2('MRU data size:',
615+
f_perc(mru_data, caches_size), f_bytes(mru_data))
616+
prt_i1('MRU ghost data size:', f_bytes(mrug_data))
617+
v = int(pm)*int(meta)/s
618+
prt_i2('MRU metadata target:', f_perc(v, s),
619+
f_bytes(v / 65536 * caches_size / 65536))
620+
prt_i2('MRU metadata size:',
621+
f_perc(mru_metadata, caches_size), f_bytes(mru_metadata))
622+
prt_i1('MRU ghost metadata size:', f_bytes(mrug_metadata))
590623
prt_i2('Uncached data size:',
591-
f_perc(unc_size, caches_size), f_bytes(unc_size))
592-
prt_i2('Metadata cache size (hard limit):',
593-
f_perc(meta_limit, arc_max), f_bytes(meta_limit))
594-
prt_i2('Metadata cache size (current):',
595-
f_perc(meta_size, meta_limit), f_bytes(meta_size))
596-
prt_i2('Dnode cache size (hard limit):',
597-
f_perc(dnode_limit, meta_limit), f_bytes(dnode_limit))
598-
prt_i2('Dnode cache size (current):',
624+
f_perc(unc_data, caches_size), f_bytes(unc_data))
625+
prt_i2('Uncached metadata size:',
626+
f_perc(unc_metadata, caches_size), f_bytes(unc_metadata))
627+
prt_i2('Bonus size:',
628+
f_perc(bonus_size, arc_size), f_bytes(bonus_size))
629+
prt_i2('Dnode cache target:',
630+
f_perc(dnode_limit, arc_max), f_bytes(dnode_limit))
631+
prt_i2('Dnode cache size:',
599632
f_perc(dnode_size, dnode_limit), f_bytes(dnode_size))
633+
prt_i2('Dbuf size:',
634+
f_perc(dbuf_size, arc_size), f_bytes(dbuf_size))
635+
prt_i2('Header size:',
636+
f_perc(hdr_size, arc_size), f_bytes(hdr_size))
637+
prt_i2('L2 header size:',
638+
f_perc(l2_hdr_size, arc_size), f_bytes(l2_hdr_size))
639+
prt_i2('ABD chunk waste size:',
640+
f_perc(abd_chunk_waste_size, arc_size), f_bytes(abd_chunk_waste_size))
600641
print()
601642

602643
print('ARC hash breakdown:')

cmd/zdb/zdb.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ zdb_ot_name(dmu_object_type_t type)
116116

117117
extern int reference_tracking_enable;
118118
extern int zfs_recover;
119-
extern unsigned long zfs_arc_meta_min, zfs_arc_meta_limit;
120119
extern uint_t zfs_vdev_async_read_max_active;
121120
extern boolean_t spa_load_verify_dryrun;
122121
extern boolean_t spa_mode_readable_spacemaps;
@@ -8634,8 +8633,8 @@ main(int argc, char **argv)
86348633
* ZDB does not typically re-read blocks; therefore limit the ARC
86358634
* to 256 MB, which can be used entirely for metadata.
86368635
*/
8637-
zfs_arc_min = zfs_arc_meta_min = 2ULL << SPA_MAXBLOCKSHIFT;
8638-
zfs_arc_max = zfs_arc_meta_limit = 256 * 1024 * 1024;
8636+
zfs_arc_min = 2ULL << SPA_MAXBLOCKSHIFT;
8637+
zfs_arc_max = 256 * 1024 * 1024;
86398638
#endif
86408639

86418640
/*

include/sys/arc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ struct arc_buf {
201201
};
202202

203203
typedef enum arc_buf_contents {
204-
ARC_BUFC_INVALID, /* invalid type */
205204
ARC_BUFC_DATA, /* buffer contains data */
206205
ARC_BUFC_METADATA, /* buffer contains metadata */
207206
ARC_BUFC_NUMTYPES

include/sys/arc_impl.h

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,18 @@ typedef struct arc_state {
8181
* supports the "dbufs" kstat
8282
*/
8383
arc_state_type_t arcs_state;
84+
/*
85+
* total amount of data in this state.
86+
*/
87+
zfs_refcount_t arcs_size[ARC_BUFC_NUMTYPES] ____cacheline_aligned;
8488
/*
8589
* total amount of evictable data in this state
8690
*/
87-
zfs_refcount_t arcs_esize[ARC_BUFC_NUMTYPES] ____cacheline_aligned;
91+
zfs_refcount_t arcs_esize[ARC_BUFC_NUMTYPES];
8892
/*
89-
* total amount of data in this state; this includes: evictable,
90-
* non-evictable, ARC_BUFC_DATA, and ARC_BUFC_METADATA.
93+
* amount of hit bytes for this state (ghost only)
9194
*/
92-
zfs_refcount_t arcs_size;
95+
wmsum_t arcs_hits[ARC_BUFC_NUMTYPES];
9396
} arc_state_t;
9497

9598
typedef struct arc_callback arc_callback_t;
@@ -581,7 +584,9 @@ typedef struct arc_stats {
581584
kstat_named_t arcstat_hash_collisions;
582585
kstat_named_t arcstat_hash_chains;
583586
kstat_named_t arcstat_hash_chain_max;
584-
kstat_named_t arcstat_p;
587+
kstat_named_t arcstat_meta;
588+
kstat_named_t arcstat_pd;
589+
kstat_named_t arcstat_pm;
585590
kstat_named_t arcstat_c;
586591
kstat_named_t arcstat_c_min;
587592
kstat_named_t arcstat_c_max;
@@ -654,6 +659,8 @@ typedef struct arc_stats {
654659
* are all included in this value.
655660
*/
656661
kstat_named_t arcstat_anon_size;
662+
kstat_named_t arcstat_anon_data;
663+
kstat_named_t arcstat_anon_metadata;
657664
/*
658665
* Number of bytes consumed by ARC buffers that meet the
659666
* following criteria: backing buffers of type ARC_BUFC_DATA,
@@ -675,6 +682,8 @@ typedef struct arc_stats {
675682
* are all included in this value.
676683
*/
677684
kstat_named_t arcstat_mru_size;
685+
kstat_named_t arcstat_mru_data;
686+
kstat_named_t arcstat_mru_metadata;
678687
/*
679688
* Number of bytes consumed by ARC buffers that meet the
680689
* following criteria: backing buffers of type ARC_BUFC_DATA,
@@ -699,6 +708,8 @@ typedef struct arc_stats {
699708
* buffers *would have* consumed this number of bytes.
700709
*/
701710
kstat_named_t arcstat_mru_ghost_size;
711+
kstat_named_t arcstat_mru_ghost_data;
712+
kstat_named_t arcstat_mru_ghost_metadata;
702713
/*
703714
* Number of bytes that *would have been* consumed by ARC
704715
* buffers that are eligible for eviction, of type
@@ -718,6 +729,8 @@ typedef struct arc_stats {
718729
* are all included in this value.
719730
*/
720731
kstat_named_t arcstat_mfu_size;
732+
kstat_named_t arcstat_mfu_data;
733+
kstat_named_t arcstat_mfu_metadata;
721734
/*
722735
* Number of bytes consumed by ARC buffers that are eligible for
723736
* eviction, of type ARC_BUFC_DATA, and reside in the arc_mfu
@@ -736,6 +749,8 @@ typedef struct arc_stats {
736749
* arcstat_mru_ghost_size for more details.
737750
*/
738751
kstat_named_t arcstat_mfu_ghost_size;
752+
kstat_named_t arcstat_mfu_ghost_data;
753+
kstat_named_t arcstat_mfu_ghost_metadata;
739754
/*
740755
* Number of bytes that *would have been* consumed by ARC
741756
* buffers that are eligible for eviction, of type
@@ -753,6 +768,8 @@ typedef struct arc_stats {
753768
* ARC_FLAG_UNCACHED being set.
754769
*/
755770
kstat_named_t arcstat_uncached_size;
771+
kstat_named_t arcstat_uncached_data;
772+
kstat_named_t arcstat_uncached_metadata;
756773
/*
757774
* Number of data bytes that are going to be evicted from ARC due to
758775
* ARC_FLAG_UNCACHED being set.
@@ -875,10 +892,7 @@ typedef struct arc_stats {
875892
kstat_named_t arcstat_loaned_bytes;
876893
kstat_named_t arcstat_prune;
877894
kstat_named_t arcstat_meta_used;
878-
kstat_named_t arcstat_meta_limit;
879895
kstat_named_t arcstat_dnode_limit;
880-
kstat_named_t arcstat_meta_max;
881-
kstat_named_t arcstat_meta_min;
882896
kstat_named_t arcstat_async_upgrade_sync;
883897
/* Number of predictive prefetch requests. */
884898
kstat_named_t arcstat_predictive_prefetch;
@@ -986,7 +1000,7 @@ typedef struct arc_sums {
9861000
wmsum_t arcstat_memory_direct_count;
9871001
wmsum_t arcstat_memory_indirect_count;
9881002
wmsum_t arcstat_prune;
989-
aggsum_t arcstat_meta_used;
1003+
wmsum_t arcstat_meta_used;
9901004
wmsum_t arcstat_async_upgrade_sync;
9911005
wmsum_t arcstat_predictive_prefetch;
9921006
wmsum_t arcstat_demand_hit_predictive_prefetch;
@@ -1014,7 +1028,9 @@ typedef struct arc_evict_waiter {
10141028
#define ARCSTAT_BUMPDOWN(stat) ARCSTAT_INCR(stat, -1)
10151029

10161030
#define arc_no_grow ARCSTAT(arcstat_no_grow) /* do not grow cache size */
1017-
#define arc_p ARCSTAT(arcstat_p) /* target size of MRU */
1031+
#define arc_meta ARCSTAT(arcstat_meta) /* target frac of metadata */
1032+
#define arc_pd ARCSTAT(arcstat_pd) /* target frac of data MRU */
1033+
#define arc_pm ARCSTAT(arcstat_pm) /* target frac of meta MRU */
10181034
#define arc_c ARCSTAT(arcstat_c) /* target size of cache */
10191035
#define arc_c_min ARCSTAT(arcstat_c_min) /* min target cache size */
10201036
#define arc_c_max ARCSTAT(arcstat_c_max) /* max target cache size */

man/man4/zfs.4

Lines changed: 4 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -548,14 +548,6 @@ This value acts as a ceiling to the amount of dnode metadata, and defaults to
548548
which indicates that a percent which is based on
549549
.Sy zfs_arc_dnode_limit_percent
550550
of the ARC meta buffers that may be used for dnodes.
551-
.Pp
552-
Also see
553-
.Sy zfs_arc_meta_prune
554-
which serves a similar purpose but is used
555-
when the amount of metadata in the ARC exceeds
556-
.Sy zfs_arc_meta_limit
557-
rather than in response to overall demand for non-metadata.
558-
.
559551
.It Sy zfs_arc_dnode_limit_percent Ns = Ns Sy 10 Ns % Pq u64
560552
Percentage that can be consumed by dnodes of ARC meta buffers.
561553
.Pp
@@ -638,62 +630,10 @@ It cannot be set back to
638630
while running, and reducing it below the current ARC size will not cause
639631
the ARC to shrink without memory pressure to induce shrinking.
640632
.
641-
.It Sy zfs_arc_meta_adjust_restarts Ns = Ns Sy 4096 Pq uint
642-
The number of restart passes to make while scanning the ARC attempting
643-
the free buffers in order to stay below the
644-
.Sy fs_arc_meta_limit .
645-
This value should not need to be tuned but is available to facilitate
646-
performance analysis.
647-
.
648-
.It Sy zfs_arc_meta_limit Ns = Ns Sy 0 Ns B Pq u64
649-
The maximum allowed size in bytes that metadata buffers are allowed to
650-
consume in the ARC.
651-
When this limit is reached, metadata buffers will be reclaimed,
652-
even if the overall
653-
.Sy arc_c_max
654-
has not been reached.
655-
It defaults to
656-
.Sy 0 ,
657-
which indicates that a percentage based on
658-
.Sy zfs_arc_meta_limit_percent
659-
of the ARC may be used for metadata.
660-
.Pp
661-
This value my be changed dynamically, except that must be set to an explicit
662-
value
663-
.Pq cannot be set back to Sy 0 .
664-
.
665-
.It Sy zfs_arc_meta_limit_percent Ns = Ns Sy 75 Ns % Pq u64
666-
Percentage of ARC buffers that can be used for metadata.
667-
.Pp
668-
See also
669-
.Sy zfs_arc_meta_limit ,
670-
which serves a similar purpose but has a higher priority if nonzero.
671-
.
672-
.It Sy zfs_arc_meta_min Ns = Ns Sy 0 Ns B Pq u64
673-
The minimum allowed size in bytes that metadata buffers may consume in
674-
the ARC.
675-
.
676-
.It Sy zfs_arc_meta_prune Ns = Ns Sy 10000 Pq int
677-
The number of dentries and inodes to be scanned looking for entries
678-
which can be dropped.
679-
This may be required when the ARC reaches the
680-
.Sy zfs_arc_meta_limit
681-
because dentries and inodes can pin buffers in the ARC.
682-
Increasing this value will cause to dentry and inode caches
683-
to be pruned more aggressively.
684-
Setting this value to
685-
.Sy 0
686-
will disable pruning the inode and dentry caches.
687-
.
688-
.It Sy zfs_arc_meta_strategy Ns = Ns Sy 1 Ns | Ns 0 Pq uint
689-
Define the strategy for ARC metadata buffer eviction (meta reclaim strategy):
690-
.Bl -tag -compact -offset 4n -width "0 (META_ONLY)"
691-
.It Sy 0 Pq META_ONLY
692-
evict only the ARC metadata buffers
693-
.It Sy 1 Pq BALANCED
694-
additional data buffers may be evicted if required
695-
to evict the required number of metadata buffers.
696-
.El
633+
.It Sy zfs_arc_meta_balance Ns = Ns Sy 500 Pq uint
634+
Balance between metadata and data on ghost hits.
635+
Values above 100 increase metadata caching by proportionally reducing effect
636+
of ghost data hits on target data/metadata rate.
697637
.
698638
.It Sy zfs_arc_min Ns = Ns Sy 0 Ns B Pq u64
699639
Min size of ARC in bytes.
@@ -776,20 +716,6 @@ causes the ARC to start reclamation if it exceeds the target size by
776716
of the target size, and block allocations by
777717
.Em 0.6% .
778718
.
779-
.It Sy zfs_arc_p_min_shift Ns = Ns Sy 0 Pq uint
780-
If nonzero, this will update
781-
.Sy arc_p_min_shift Pq default Sy 4
782-
with the new value.
783-
.Sy arc_p_min_shift No is used as a shift of Sy arc_c
784-
when calculating the minumum
785-
.Sy arc_p No size .
786-
.
787-
.It Sy zfs_arc_p_dampener_disable Ns = Ns Sy 1 Ns | Ns 0 Pq int
788-
Disable
789-
.Sy arc_p
790-
adapt dampener, which reduces the maximum single adjustment to
791-
.Sy arc_p .
792-
.
793719
.It Sy zfs_arc_shrink_shift Ns = Ns Sy 0 Pq uint
794720
If nonzero, this will update
795721
.Sy arc_shrink_shift Pq default Sy 7

module/os/freebsd/zfs/arc_os.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ arc_prune_task(void *arg)
159159
/*
160160
* Notify registered consumers they must drop holds on a portion of the ARC
161161
* buffered they reference. This provides a mechanism to ensure the ARC can
162-
* honor the arc_meta_limit and reclaim otherwise pinned ARC buffers. This
162+
* honor the metadata limit and reclaim otherwise pinned ARC buffers. This
163163
* is analogous to dnlc_reduce_cache() but more generic.
164164
*
165165
* This operation is performed asynchronously so it may be safely called

0 commit comments

Comments
 (0)