Skip to content

Commit 778802e

Browse files
committed
Use wmsum for arc, abd, dbuf and zfetch statistics.
wmsum was designed exactly for cases like these with many updates and rare reads. It allows to completely avoid atomic operations on congested global variables. Signed-off-by: Alexander Motin <[email protected]> Sponsored-By: iXsystems, Inc.
1 parent 8d5f211 commit 778802e

File tree

8 files changed

+778
-216
lines changed

8 files changed

+778
-216
lines changed

include/sys/abd_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define _ABD_IMPL_H
2828

2929
#include <sys/abd.h>
30+
#include <sys/wmsum.h>
3031

3132
#ifdef __cplusplus
3233
extern "C" {
@@ -82,9 +83,8 @@ void abd_iter_unmap(struct abd_iter *);
8283
/*
8384
* Helper macros
8485
*/
85-
#define ABDSTAT(stat) (abd_stats.stat.value.ui64)
8686
#define ABDSTAT_INCR(stat, val) \
87-
atomic_add_64(&abd_stats.stat.value.ui64, (val))
87+
wmsum_add(&abd_wmsums.stat, (val))
8888
#define ABDSTAT_BUMP(stat) ABDSTAT_INCR(stat, 1)
8989
#define ABDSTAT_BUMPDOWN(stat) ABDSTAT_INCR(stat, -1)
9090

include/sys/arc_impl.h

Lines changed: 93 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <sys/zio_crypt.h>
3434
#include <sys/zthr.h>
3535
#include <sys/aggsum.h>
36+
#include <sys/wmsum.h>
3637

3738
#ifdef __cplusplus
3839
extern "C" {
@@ -563,7 +564,6 @@ typedef struct arc_stats {
563564
kstat_named_t arcstat_c;
564565
kstat_named_t arcstat_c_min;
565566
kstat_named_t arcstat_c_max;
566-
/* Not updated directly; only synced in arc_kstat_update. */
567567
kstat_named_t arcstat_size;
568568
/*
569569
* Number of compressed bytes stored in the arc_buf_hdr_t's b_pabd.
@@ -592,37 +592,31 @@ typedef struct arc_stats {
592592
* (allocated via arc_buf_hdr_t_full and arc_buf_hdr_t_l2only
593593
* caches), and arc_buf_t structures (allocated via arc_buf_t
594594
* cache).
595-
* Not updated directly; only synced in arc_kstat_update.
596595
*/
597596
kstat_named_t arcstat_hdr_size;
598597
/*
599598
* Number of bytes consumed by ARC buffers of type equal to
600599
* ARC_BUFC_DATA. This is generally consumed by buffers backing
601600
* on disk user data (e.g. plain file contents).
602-
* Not updated directly; only synced in arc_kstat_update.
603601
*/
604602
kstat_named_t arcstat_data_size;
605603
/*
606604
* Number of bytes consumed by ARC buffers of type equal to
607605
* ARC_BUFC_METADATA. This is generally consumed by buffers
608606
* backing on disk data that is used for internal ZFS
609607
* structures (e.g. ZAP, dnode, indirect blocks, etc).
610-
* Not updated directly; only synced in arc_kstat_update.
611608
*/
612609
kstat_named_t arcstat_metadata_size;
613610
/*
614611
* Number of bytes consumed by dmu_buf_impl_t objects.
615-
* Not updated directly; only synced in arc_kstat_update.
616612
*/
617613
kstat_named_t arcstat_dbuf_size;
618614
/*
619615
* Number of bytes consumed by dnode_t objects.
620-
* Not updated directly; only synced in arc_kstat_update.
621616
*/
622617
kstat_named_t arcstat_dnode_size;
623618
/*
624619
* Number of bytes consumed by bonus buffers.
625-
* Not updated directly; only synced in arc_kstat_update.
626620
*/
627621
kstat_named_t arcstat_bonus_size;
628622
#if defined(COMPAT_FREEBSD11)
@@ -637,47 +631,41 @@ typedef struct arc_stats {
637631
* arc_anon state. This includes *all* buffers in the arc_anon
638632
* state; e.g. data, metadata, evictable, and unevictable buffers
639633
* are all included in this value.
640-
* Not updated directly; only synced in arc_kstat_update.
641634
*/
642635
kstat_named_t arcstat_anon_size;
643636
/*
644637
* Number of bytes consumed by ARC buffers that meet the
645638
* following criteria: backing buffers of type ARC_BUFC_DATA,
646639
* residing in the arc_anon state, and are eligible for eviction
647640
* (e.g. have no outstanding holds on the buffer).
648-
* Not updated directly; only synced in arc_kstat_update.
649641
*/
650642
kstat_named_t arcstat_anon_evictable_data;
651643
/*
652644
* Number of bytes consumed by ARC buffers that meet the
653645
* following criteria: backing buffers of type ARC_BUFC_METADATA,
654646
* residing in the arc_anon state, and are eligible for eviction
655647
* (e.g. have no outstanding holds on the buffer).
656-
* Not updated directly; only synced in arc_kstat_update.
657648
*/
658649
kstat_named_t arcstat_anon_evictable_metadata;
659650
/*
660651
* Total number of bytes consumed by ARC buffers residing in the
661652
* arc_mru state. This includes *all* buffers in the arc_mru
662653
* state; e.g. data, metadata, evictable, and unevictable buffers
663654
* are all included in this value.
664-
* Not updated directly; only synced in arc_kstat_update.
665655
*/
666656
kstat_named_t arcstat_mru_size;
667657
/*
668658
* Number of bytes consumed by ARC buffers that meet the
669659
* following criteria: backing buffers of type ARC_BUFC_DATA,
670660
* residing in the arc_mru state, and are eligible for eviction
671661
* (e.g. have no outstanding holds on the buffer).
672-
* Not updated directly; only synced in arc_kstat_update.
673662
*/
674663
kstat_named_t arcstat_mru_evictable_data;
675664
/*
676665
* Number of bytes consumed by ARC buffers that meet the
677666
* following criteria: backing buffers of type ARC_BUFC_METADATA,
678667
* residing in the arc_mru state, and are eligible for eviction
679668
* (e.g. have no outstanding holds on the buffer).
680-
* Not updated directly; only synced in arc_kstat_update.
681669
*/
682670
kstat_named_t arcstat_mru_evictable_metadata;
683671
/*
@@ -688,64 +676,55 @@ typedef struct arc_stats {
688676
* don't actually have ARC buffers linked off of these headers.
689677
* Thus, *if* the headers had associated ARC buffers, these
690678
* buffers *would have* consumed this number of bytes.
691-
* Not updated directly; only synced in arc_kstat_update.
692679
*/
693680
kstat_named_t arcstat_mru_ghost_size;
694681
/*
695682
* Number of bytes that *would have been* consumed by ARC
696683
* buffers that are eligible for eviction, of type
697684
* ARC_BUFC_DATA, and linked off the arc_mru_ghost state.
698-
* Not updated directly; only synced in arc_kstat_update.
699685
*/
700686
kstat_named_t arcstat_mru_ghost_evictable_data;
701687
/*
702688
* Number of bytes that *would have been* consumed by ARC
703689
* buffers that are eligible for eviction, of type
704690
* ARC_BUFC_METADATA, and linked off the arc_mru_ghost state.
705-
* Not updated directly; only synced in arc_kstat_update.
706691
*/
707692
kstat_named_t arcstat_mru_ghost_evictable_metadata;
708693
/*
709694
* Total number of bytes consumed by ARC buffers residing in the
710695
* arc_mfu state. This includes *all* buffers in the arc_mfu
711696
* state; e.g. data, metadata, evictable, and unevictable buffers
712697
* are all included in this value.
713-
* Not updated directly; only synced in arc_kstat_update.
714698
*/
715699
kstat_named_t arcstat_mfu_size;
716700
/*
717701
* Number of bytes consumed by ARC buffers that are eligible for
718702
* eviction, of type ARC_BUFC_DATA, and reside in the arc_mfu
719703
* state.
720-
* Not updated directly; only synced in arc_kstat_update.
721704
*/
722705
kstat_named_t arcstat_mfu_evictable_data;
723706
/*
724707
* Number of bytes consumed by ARC buffers that are eligible for
725708
* eviction, of type ARC_BUFC_METADATA, and reside in the
726709
* arc_mfu state.
727-
* Not updated directly; only synced in arc_kstat_update.
728710
*/
729711
kstat_named_t arcstat_mfu_evictable_metadata;
730712
/*
731713
* Total number of bytes that *would have been* consumed by ARC
732714
* buffers in the arc_mfu_ghost state. See the comment above
733715
* arcstat_mru_ghost_size for more details.
734-
* Not updated directly; only synced in arc_kstat_update.
735716
*/
736717
kstat_named_t arcstat_mfu_ghost_size;
737718
/*
738719
* Number of bytes that *would have been* consumed by ARC
739720
* buffers that are eligible for eviction, of type
740721
* ARC_BUFC_DATA, and linked off the arc_mfu_ghost state.
741-
* Not updated directly; only synced in arc_kstat_update.
742722
*/
743723
kstat_named_t arcstat_mfu_ghost_evictable_data;
744724
/*
745725
* Number of bytes that *would have been* consumed by ARC
746726
* buffers that are eligible for eviction, of type
747727
* ARC_BUFC_METADATA, and linked off the arc_mru_ghost state.
748-
* Not updated directly; only synced in arc_kstat_update.
749728
*/
750729
kstat_named_t arcstat_mfu_ghost_evictable_metadata;
751730
kstat_named_t arcstat_l2_hits;
@@ -779,7 +758,6 @@ typedef struct arc_stats {
779758
kstat_named_t arcstat_l2_io_error;
780759
kstat_named_t arcstat_l2_lsize;
781760
kstat_named_t arcstat_l2_psize;
782-
/* Not updated directly; only synced in arc_kstat_update. */
783761
kstat_named_t arcstat_l2_hdr_size;
784762
/*
785763
* Number of L2ARC log blocks written. These are used for restoring the
@@ -860,7 +838,6 @@ typedef struct arc_stats {
860838
kstat_named_t arcstat_tempreserve;
861839
kstat_named_t arcstat_loaned_bytes;
862840
kstat_named_t arcstat_prune;
863-
/* Not updated directly; only synced in arc_kstat_update. */
864841
kstat_named_t arcstat_meta_used;
865842
kstat_named_t arcstat_meta_limit;
866843
kstat_named_t arcstat_dnode_limit;
@@ -876,6 +853,96 @@ typedef struct arc_stats {
876853
kstat_named_t arcstat_abd_chunk_waste_size;
877854
} arc_stats_t;
878855

856+
typedef struct arc_wmsums {
857+
wmsum_t arcstat_hits;
858+
wmsum_t arcstat_misses;
859+
wmsum_t arcstat_demand_data_hits;
860+
wmsum_t arcstat_demand_data_misses;
861+
wmsum_t arcstat_demand_metadata_hits;
862+
wmsum_t arcstat_demand_metadata_misses;
863+
wmsum_t arcstat_prefetch_data_hits;
864+
wmsum_t arcstat_prefetch_data_misses;
865+
wmsum_t arcstat_prefetch_metadata_hits;
866+
wmsum_t arcstat_prefetch_metadata_misses;
867+
wmsum_t arcstat_mru_hits;
868+
wmsum_t arcstat_mru_ghost_hits;
869+
wmsum_t arcstat_mfu_hits;
870+
wmsum_t arcstat_mfu_ghost_hits;
871+
wmsum_t arcstat_deleted;
872+
wmsum_t arcstat_mutex_miss;
873+
wmsum_t arcstat_access_skip;
874+
wmsum_t arcstat_evict_skip;
875+
wmsum_t arcstat_evict_not_enough;
876+
wmsum_t arcstat_evict_l2_cached;
877+
wmsum_t arcstat_evict_l2_eligible;
878+
wmsum_t arcstat_evict_l2_eligible_mfu;
879+
wmsum_t arcstat_evict_l2_eligible_mru;
880+
wmsum_t arcstat_evict_l2_ineligible;
881+
wmsum_t arcstat_evict_l2_skip;
882+
wmsum_t arcstat_hash_collisions;
883+
wmsum_t arcstat_hash_chains;
884+
aggsum_t arcstat_size;
885+
wmsum_t arcstat_compressed_size;
886+
wmsum_t arcstat_uncompressed_size;
887+
wmsum_t arcstat_overhead_size;
888+
wmsum_t arcstat_hdr_size;
889+
wmsum_t arcstat_data_size;
890+
wmsum_t arcstat_metadata_size;
891+
wmsum_t arcstat_dbuf_size;
892+
aggsum_t arcstat_dnode_size;
893+
wmsum_t arcstat_bonus_size;
894+
wmsum_t arcstat_l2_hits;
895+
wmsum_t arcstat_l2_misses;
896+
wmsum_t arcstat_l2_prefetch_asize;
897+
wmsum_t arcstat_l2_mru_asize;
898+
wmsum_t arcstat_l2_mfu_asize;
899+
wmsum_t arcstat_l2_bufc_data_asize;
900+
wmsum_t arcstat_l2_bufc_metadata_asize;
901+
wmsum_t arcstat_l2_feeds;
902+
wmsum_t arcstat_l2_rw_clash;
903+
wmsum_t arcstat_l2_read_bytes;
904+
wmsum_t arcstat_l2_write_bytes;
905+
wmsum_t arcstat_l2_writes_sent;
906+
wmsum_t arcstat_l2_writes_done;
907+
wmsum_t arcstat_l2_writes_error;
908+
wmsum_t arcstat_l2_writes_lock_retry;
909+
wmsum_t arcstat_l2_evict_lock_retry;
910+
wmsum_t arcstat_l2_evict_reading;
911+
wmsum_t arcstat_l2_evict_l1cached;
912+
wmsum_t arcstat_l2_free_on_write;
913+
wmsum_t arcstat_l2_abort_lowmem;
914+
wmsum_t arcstat_l2_cksum_bad;
915+
wmsum_t arcstat_l2_io_error;
916+
wmsum_t arcstat_l2_lsize;
917+
wmsum_t arcstat_l2_psize;
918+
aggsum_t arcstat_l2_hdr_size;
919+
wmsum_t arcstat_l2_log_blk_writes;
920+
wmsum_t arcstat_l2_log_blk_asize;
921+
wmsum_t arcstat_l2_log_blk_count;
922+
wmsum_t arcstat_l2_rebuild_success;
923+
wmsum_t arcstat_l2_rebuild_abort_unsupported;
924+
wmsum_t arcstat_l2_rebuild_abort_io_errors;
925+
wmsum_t arcstat_l2_rebuild_abort_dh_errors;
926+
wmsum_t arcstat_l2_rebuild_abort_cksum_lb_errors;
927+
wmsum_t arcstat_l2_rebuild_abort_lowmem;
928+
wmsum_t arcstat_l2_rebuild_size;
929+
wmsum_t arcstat_l2_rebuild_asize;
930+
wmsum_t arcstat_l2_rebuild_bufs;
931+
wmsum_t arcstat_l2_rebuild_bufs_precached;
932+
wmsum_t arcstat_l2_rebuild_log_blks;
933+
wmsum_t arcstat_memory_throttle_count;
934+
wmsum_t arcstat_memory_direct_count;
935+
wmsum_t arcstat_memory_indirect_count;
936+
wmsum_t arcstat_prune;
937+
aggsum_t arcstat_meta_used;
938+
wmsum_t arcstat_async_upgrade_sync;
939+
wmsum_t arcstat_demand_hit_predictive_prefetch;
940+
wmsum_t arcstat_demand_hit_prescient_prefetch;
941+
wmsum_t arcstat_raw_size;
942+
wmsum_t arcstat_cached_only_in_progress;
943+
wmsum_t arcstat_abd_chunk_waste_size;
944+
} arc_wmsums_t;
945+
879946
typedef struct arc_evict_waiter {
880947
list_node_t aew_node;
881948
kcondvar_t aew_cv;
@@ -885,7 +952,7 @@ typedef struct arc_evict_waiter {
885952
#define ARCSTAT(stat) (arc_stats.stat.value.ui64)
886953

887954
#define ARCSTAT_INCR(stat, val) \
888-
atomic_add_64(&arc_stats.stat.value.ui64, (val))
955+
wmsum_add(&arc_wmsums.stat, (val))
889956

890957
#define ARCSTAT_BUMP(stat) ARCSTAT_INCR(stat, 1)
891958
#define ARCSTAT_BUMPDOWN(stat) ARCSTAT_INCR(stat, -1)
@@ -899,14 +966,14 @@ typedef struct arc_evict_waiter {
899966

900967
extern taskq_t *arc_prune_taskq;
901968
extern arc_stats_t arc_stats;
969+
extern arc_wmsums_t arc_wmsums;
902970
extern hrtime_t arc_growtime;
903971
extern boolean_t arc_warm;
904972
extern int arc_grow_retry;
905973
extern int arc_no_grow_shift;
906974
extern int arc_shrink_shift;
907975
extern kmutex_t arc_prune_mtx;
908976
extern list_t arc_prune_list;
909-
extern aggsum_t arc_size;
910977
extern arc_state_t *arc_mfu;
911978
extern arc_state_t *arc_mru;
912979
extern uint_t zfs_arc_pc_percent;

0 commit comments

Comments
 (0)