xref: /freebsd/sys/contrib/openzfs/include/sys/spa_log_spacemap.h (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or https://opensource.org/licenses/CDDL-1.0.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright (c) 2018, 2019 by Delphix. All rights reserved.
25  */
26 
27 #ifndef _SYS_SPA_LOG_SPACEMAP_H
28 #define	_SYS_SPA_LOG_SPACEMAP_H
29 
30 #include <sys/avl.h>
31 
32 typedef struct log_summary_entry {
33 	uint64_t lse_start;	/* start TXG */
34 	uint64_t lse_end;	/* last TXG */
35 	uint64_t lse_txgcount;	/* # of TXGs */
36 	uint64_t lse_mscount;	/* # of metaslabs needed to be flushed */
37 	uint64_t lse_msdcount;	/* # of dirty metaslabs needed to be flushed */
38 	uint64_t lse_blkcount;	/* blocks held by this entry  */
39 	list_node_t lse_node;
40 } log_summary_entry_t;
41 
42 typedef struct spa_unflushed_stats  {
43 	/* used for memory heuristic */
44 	uint64_t sus_memused;	/* current memory used for unflushed trees */
45 
46 	/* used for block heuristic */
47 	uint64_t sus_blocklimit;	/* max # of log blocks allowed */
48 	uint64_t sus_nblocks;	/* # of blocks in log space maps currently */
49 } spa_unflushed_stats_t;
50 
51 typedef struct spa_log_sm {
52 	uint64_t sls_sm_obj;	/* space map object ID */
53 	uint64_t sls_txg;	/* txg logged on the space map */
54 	uint64_t sls_nblocks;	/* number of blocks in this log */
55 	uint64_t sls_mscount;	/* # of metaslabs flushed in the log's txg */
56 	avl_node_t sls_node;	/* node in spa_sm_logs_by_txg */
57 	space_map_t *sls_sm;	/* space map pointer, if open */
58 } spa_log_sm_t;
59 
60 int spa_ld_log_spacemaps(spa_t *);
61 
62 void spa_generate_syncing_log_sm(spa_t *, dmu_tx_t *);
63 void spa_flush_metaslabs(spa_t *, dmu_tx_t *);
64 void spa_sync_close_syncing_log_sm(spa_t *);
65 
66 void spa_cleanup_old_sm_logs(spa_t *, dmu_tx_t *);
67 
68 uint64_t spa_log_sm_blocklimit(spa_t *);
69 void spa_log_sm_set_blocklimit(spa_t *);
70 uint64_t spa_log_sm_nblocks(spa_t *);
71 uint64_t spa_log_sm_memused(spa_t *);
72 
73 void spa_log_sm_decrement_mscount(spa_t *, uint64_t);
74 void spa_log_sm_increment_current_mscount(spa_t *);
75 
76 void spa_log_summary_add_flushed_metaslab(spa_t *, boolean_t);
77 void spa_log_summary_dirty_flushed_metaslab(spa_t *, uint64_t);
78 void spa_log_summary_decrement_mscount(spa_t *, uint64_t, boolean_t);
79 void spa_log_summary_decrement_blkcount(spa_t *, uint64_t);
80 
81 boolean_t spa_flush_all_logs_requested(spa_t *);
82 
83 extern int zfs_keep_log_spacemaps_at_export;
84 
85 #endif /* _SYS_SPA_LOG_SPACEMAP_H */
86