xref: /freebsd/sys/contrib/openzfs/include/sys/spa_log_spacemap.h (revision 22649d4dba730d46244fd2dff4fd174903c8379f)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * This file and its contents are supplied under the terms of the
4  * Common Development and Distribution License ("CDDL"), version 1.0.
5  * You may only use this file in accordance with the terms of version
6  * 1.0 of the CDDL.
7  *
8  * A full copy of the text of the CDDL should have accompanied this
9  * source.  A copy of the CDDL is also available via the Internet at
10  * https://opensource.org/license/CDDL-1.0.
11  */
12 
13 /*
14  * Copyright (c) 2018, 2019 by Delphix. All rights reserved.
15  * Copyright (c) 2024-2026, Klara, Inc.
16  * Copyright (c) 2026, TrueNAS.
17  */
18 
19 #ifndef _SYS_SPA_LOG_SPACEMAP_H
20 #define	_SYS_SPA_LOG_SPACEMAP_H
21 
22 #include <sys/avl.h>
23 
24 typedef struct log_summary_entry {
25 	uint64_t lse_start;	/* start TXG */
26 	uint64_t lse_end;	/* last TXG */
27 	uint64_t lse_txgcount;	/* # of TXGs */
28 	uint64_t lse_mscount;	/* # of metaslabs needed to be flushed */
29 	uint64_t lse_msdcount;	/* # of dirty metaslabs needed to be flushed */
30 	uint64_t lse_blkcount;	/* blocks held by this entry  */
31 	list_node_t lse_node;
32 } log_summary_entry_t;
33 
34 typedef struct spa_unflushed_stats  {
35 	/* used for memory heuristic */
36 	uint64_t sus_memused;	/* current memory used for unflushed trees */
37 	uint64_t sus_nmetaslabs;	/* # metaslabs with unflushed trees */
38 
39 	/* used for block heuristic */
40 	uint64_t sus_blocklimit;	/* max # of log blocks allowed */
41 	uint64_t sus_nblocks;	/* # of blocks in log space maps currently */
42 } spa_unflushed_stats_t;
43 
44 typedef struct spa_log_sm {
45 	uint64_t sls_sm_obj;	/* space map object ID */
46 	uint64_t sls_txg;	/* txg logged on the space map */
47 	uint64_t sls_nblocks;	/* number of blocks in this log */
48 	uint64_t sls_mscount;	/* # of metaslabs flushed in the log's txg */
49 	avl_node_t sls_node;	/* node in spa_sm_logs_by_txg */
50 	space_map_t *sls_sm;	/* space map pointer, if open */
51 } spa_log_sm_t;
52 
53 typedef enum spa_log_flushall_mode {
54 	SPA_LOG_FLUSHALL_NONE = 0,	/* flushall inactive */
55 	SPA_LOG_FLUSHALL_REQUEST,	/* flushall active by admin request */
56 	SPA_LOG_FLUSHALL_EXPORT,	/* flushall active for pool export */
57 } spa_log_flushall_mode_t;
58 
59 int spa_ld_log_spacemaps(spa_t *);
60 
61 void spa_generate_syncing_log_sm(spa_t *, dmu_tx_t *);
62 void spa_flush_metaslabs(spa_t *, dmu_tx_t *);
63 void spa_sync_close_syncing_log_sm(spa_t *);
64 
65 void spa_cleanup_old_sm_logs(spa_t *, dmu_tx_t *);
66 
67 uint64_t spa_log_sm_blocklimit(spa_t *);
68 void spa_log_sm_set_blocklimit(spa_t *);
69 uint64_t spa_log_sm_nblocks(spa_t *);
70 uint64_t spa_log_sm_memused(spa_t *);
71 
72 uint64_t spa_log_sm_unflushed_metaslabs(spa_t *);
73 void spa_log_sm_increment_unflushed_metaslabs(spa_t *);
74 void spa_log_sm_decrement_unflushed_metaslabs(spa_t *);
75 
76 void spa_log_sm_decrement_mscount(spa_t *, uint64_t);
77 void spa_log_sm_increment_current_mscount(spa_t *);
78 
79 void spa_log_summary_add_flushed_metaslab(spa_t *, boolean_t);
80 void spa_log_summary_dirty_flushed_metaslab(spa_t *, uint64_t);
81 void spa_log_summary_decrement_mscount(spa_t *, uint64_t, boolean_t);
82 void spa_log_summary_decrement_blkcount(spa_t *, uint64_t);
83 
84 void spa_log_flushall_start(spa_t *spa, spa_log_flushall_mode_t mode,
85     uint64_t txg);
86 void spa_log_flushall_done(spa_t *spa);
87 void spa_log_flushall_cancel(spa_t *spa);
88 boolean_t spa_log_flushall_active(spa_t *spa);
89 
90 extern int zfs_keep_log_spacemaps_at_export;
91 
92 #endif /* _SYS_SPA_LOG_SPACEMAP_H */
93