Skip to content

Commit bf71b6f

Browse files
riptlripatel-fd
authored andcommitted
restore: async O_DIRECT via worker thread
1 parent 9f04233 commit bf71b6f

24 files changed

+1341
-81
lines changed

book/api/metrics-generated.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,3 +1093,14 @@
10931093
| <span class="metrics-name">exec_&#8203;progcache_&#8203;invalidations</span> | counter | Number of program cache invalidations |
10941094

10951095
</div>
1096+
1097+
## Snapwr Tile
1098+
1099+
<div class="metrics">
1100+
1101+
| Metric | Type | Description |
1102+
|--------|------|-------------|
1103+
| <span class="metrics-name">snapwr_&#8203;state</span> | gauge | State of the tile. 0=IDLE, 1=PROCESSING, 4=SHUTDOWN |
1104+
| <span class="metrics-name">snapwr_&#8203;vinyl_&#8203;bytes_&#8203;written</span> | gauge | Number of bytes written so far to the vinyl snapshot file. Might decrease if snapshot creation is aborted and restarted |
1105+
1106+
</div>

src/app/firedancer-dev/commands/backtest.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ backtest_cmd_topo( config_t * config ) {
333333
backtest_topo( config );
334334
}
335335

336+
extern configure_stage_t fd_cfg_stage_vinyl;
337+
336338
static args_t
337339
configure_args( void ) {
338340
args_t args = {
@@ -342,6 +344,7 @@ configure_args( void ) {
342344
ulong stage_idx = 0UL;
343345
args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_hugetlbfs;
344346
args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_snapshots;
347+
args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_vinyl;
345348
args.configure.stages[ stage_idx++ ] = NULL;
346349

347350
return args;

src/app/firedancer-dev/commands/snapshot_load.c

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "../../../disco/topo/fd_topob.h"
88
#include "../../../disco/pack/fd_pack.h"
99
#include "../../../disco/pack/fd_pack_cost.h"
10-
#include "../../../util/tile/fd_tile_private.h"
1110
#include "../../../util/pod/fd_pod_format.h"
1211
#include "../../../discof/restore/utils/fd_ssctrl.h"
1312
#include "../../../discof/restore/utils/fd_ssmsg.h"
@@ -25,8 +24,7 @@ fd_topo_run_tile_t
2524
fdctl_tile_run( fd_topo_tile_t const * tile );
2625

2726
static void
28-
snapshot_load_topo( config_t * config,
29-
args_t const * args ) {
27+
snapshot_load_topo( config_t * config ) {
3028
fd_topo_t * topo = &config->topo;
3129
fd_topob_new( &config->topo, config->name );
3230
topo->max_page_size = fd_cstr_to_shmem_page_sz( config->hugetlbfs.max_page_size );
@@ -47,50 +45,56 @@ snapshot_load_topo( config_t * config,
4745
setup_topo_vinyl( topo, &config->firedancer );
4846
}
4947

50-
static ushort tile_to_cpu[ FD_TILE_MAX ] = {0};
51-
if( args->snapshot_load.tile_cpus[0] ) {
52-
ulong cpu_cnt = fd_tile_private_cpus_parse( args->snapshot_load.tile_cpus, tile_to_cpu );
53-
if( FD_UNLIKELY( cpu_cnt<4UL ) ) FD_LOG_ERR(( "--tile-cpus specifies %lu CPUs, but need at least 4", cpu_cnt ));
54-
}
55-
5648
/* metrics tile *****************************************************/
5749
fd_topob_wksp( topo, "metric_in" );
5850
fd_topob_wksp( topo, "metric" );
59-
fd_topob_tile( topo, "metric", "metric", "metric_in", tile_to_cpu[0], 0, 0 );
51+
fd_topob_tile( topo, "metric", "metric", "metric_in", ULONG_MAX, 0, 0 );
6052

6153
/* read() tile */
6254
fd_topob_wksp( topo, "snapct" );
63-
fd_topo_tile_t * snapct_tile = fd_topob_tile( topo, "snapct", "snapct", "snapct", tile_to_cpu[1], 0, 0 );
55+
fd_topo_tile_t * snapct_tile = fd_topob_tile( topo, "snapct", "snapct", "metric_in", ULONG_MAX, 0, 0 );
6456
snapct_tile->allow_shutdown = 1;
6557

6658
/* load tile */
6759
fd_topob_wksp( topo, "snapld" );
68-
fd_topo_tile_t * snapld_tile = fd_topob_tile( topo, "snapld", "snapld", "snapld", tile_to_cpu[2], 0, 0 );
60+
fd_topo_tile_t * snapld_tile = fd_topob_tile( topo, "snapld", "snapld", "metric_in", ULONG_MAX, 0, 0 );
6961
snapld_tile->allow_shutdown = 1;
7062

7163
/* "snapdc": Zstandard decompress tile */
7264
fd_topob_wksp( topo, "snapdc" );
73-
fd_topo_tile_t * snapdc_tile = fd_topob_tile( topo, "snapdc", "snapdc", "snapdc", tile_to_cpu[3], 0, 0 );
65+
fd_topo_tile_t * snapdc_tile = fd_topob_tile( topo, "snapdc", "snapdc", "metric_in", ULONG_MAX, 0, 0 );
7466
snapdc_tile->allow_shutdown = 1;
7567

7668
/* "snapin": Snapshot parser tile */
7769
fd_topob_wksp( topo, "snapin" );
78-
fd_topo_tile_t * snapin_tile = fd_topob_tile( topo, "snapin", "snapin", "snapin", tile_to_cpu[4], 0, 0 );
70+
fd_topo_tile_t * snapin_tile = fd_topob_tile( topo, "snapin", "snapin", "metric_in", ULONG_MAX, 0, 0 );
7971
snapin_tile->allow_shutdown = 1;
8072

73+
/* "snapwr": Snapshot writer tile */
74+
int vinyl_enabled = config->firedancer.vinyl.enabled;
75+
if( vinyl_enabled ) {
76+
fd_topob_wksp( topo, "snapwr" );
77+
fd_topo_tile_t * snapwr_tile = fd_topob_tile( topo, "snapwr", "snapwr", "metric_in", ULONG_MAX, 0, 0 );
78+
snapwr_tile->allow_shutdown = 1;
79+
}
80+
8181
fd_topob_wksp( topo, "snapct_ld" );
8282
fd_topob_wksp( topo, "snapld_dc" );
8383
fd_topob_wksp( topo, "snapdc_in" );
8484
fd_topob_wksp( topo, "snapin_ct" );
8585
fd_topob_wksp( topo, "snapin_manif" );
8686
fd_topob_wksp( topo, "snapct_repr" );
87+
if( vinyl_enabled ) fd_topob_wksp( topo, "snapin_wr" );
8788

8889
fd_topob_link( topo, "snapct_ld", "snapct_ld", 128UL, sizeof(fd_ssctrl_init_t), 1UL );
8990
fd_topob_link( topo, "snapld_dc", "snapld_dc", 16384UL, USHORT_MAX, 1UL );
9091
fd_topob_link( topo, "snapdc_in", "snapdc_in", 16384UL, USHORT_MAX, 1UL );
9192
fd_topob_link( topo, "snapin_ct", "snapin_ct", 128UL, 0UL, 1UL );
9293
fd_topob_link( topo, "snapin_manif", "snapin_manif", 2UL, sizeof(fd_snapshot_manifest_t), 1UL )->permit_no_consumers = 1;
9394
fd_topob_link( topo, "snapct_repr", "snapct_repr", 128UL, 0UL, 1UL )->permit_no_consumers = 1;
95+
if( vinyl_enabled ) {
96+
fd_topob_link( topo, "snapin_wr", "snapin_wr", 4UL, 16UL<<20, 1UL );
97+
}
9498

9599
fd_topob_tile_in ( topo, "snapct", 0UL, "metric_in", "snapin_ct", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
96100
fd_topob_tile_in ( topo, "snapct", 0UL, "metric_in", "snapld_dc", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
@@ -103,6 +107,10 @@ snapshot_load_topo( config_t * config,
103107
fd_topob_tile_in ( topo, "snapin", 0UL, "metric_in", "snapdc_in", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
104108
fd_topob_tile_out( topo, "snapin", 0UL, "snapin_ct", 0UL );
105109
fd_topob_tile_out( topo, "snapin", 0UL, "snapin_manif", 0UL );
110+
if( vinyl_enabled ) {
111+
fd_topob_tile_out( topo, "snapin", 0UL, "snapin_wr", 0UL );
112+
fd_topob_tile_in ( topo, "snapwr", 0UL, "metric_in", "snapin_wr", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
113+
}
106114

107115
/* snapin funk / txncache access */
108116
fd_topob_tile_uses( topo, snapin_tile, funk_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
@@ -127,34 +135,19 @@ snapshot_load_topo( config_t * config,
127135
fd_topo_configure_tile( tile, config );
128136
}
129137

130-
if( !args->snapshot_load.tile_cpus[0] ) {
131-
fd_topob_auto_layout( topo, 0 );
132-
}
138+
fd_topob_auto_layout( topo, 0 );
133139
fd_topob_finish( topo, CALLBACKS );
134140
}
135141

136-
static void
137-
snapshot_load_cmd_args( int * pargc,
138-
char *** pargv,
139-
args_t * args ) {
140-
char const * tile_cpus = fd_env_strip_cmdline_cstr( pargc, pargv, "--tile-cpus", "FD_TILE_CPUS", NULL );
141-
142-
if( tile_cpus ) {
143-
ulong tile_cpus_strlen = strlen( tile_cpus );
144-
if( FD_UNLIKELY( tile_cpus_strlen>=sizeof(args->snapshot_load.tile_cpus) ) ) FD_LOG_ERR(( "--tile-cpus: flag too long" ));
145-
fd_cstr_fini( fd_cstr_append_text( fd_cstr_init( args->snapshot_load.tile_cpus ), tile_cpus, tile_cpus_strlen ) );
146-
}
147-
}
148-
149142
extern int * fd_log_private_shared_lock;
150143

151144
static void
152145
snapshot_load_cmd_fn( args_t * args,
153146
config_t * config ) {
147+
(void)args;
154148
if( FD_UNLIKELY( config->firedancer.snapshots.sources.gossip.allow_any || 0UL!=config->firedancer.snapshots.sources.gossip.allow_list_cnt ) ) {
155149
FD_LOG_ERR(( "snapshot-load command is incompatible with gossip snapshot sources" ));
156150
}
157-
snapshot_load_topo( config, args );
158151
fd_topo_t * topo = &config->topo;
159152

160153
args_t configure_args = {
@@ -181,14 +174,18 @@ snapshot_load_cmd_fn( args_t * args,
181174
fd_topo_tile_t * snapld_tile = &topo->tiles[ fd_topo_find_tile( topo, "snapld", 0UL ) ];
182175
fd_topo_tile_t * snapdc_tile = &topo->tiles[ fd_topo_find_tile( topo, "snapdc", 0UL ) ];
183176
fd_topo_tile_t * snapin_tile = &topo->tiles[ fd_topo_find_tile( topo, "snapin", 0UL ) ];
177+
ulong snapwr_idx = fd_topo_find_tile( topo, "snapwr", 0UL );
178+
fd_topo_tile_t * snapwr_tile = snapwr_idx!=ULONG_MAX ? &topo->tiles[ snapwr_idx ] : NULL;
184179

185180
ulong volatile * const snapct_metrics = fd_metrics_tile( snapct_tile->metrics );
186181
ulong volatile * const snapld_metrics = fd_metrics_tile( snapld_tile->metrics );
187182
ulong volatile * const snapdc_metrics = fd_metrics_tile( snapdc_tile->metrics );
188183
ulong volatile * const snapin_metrics = fd_metrics_tile( snapin_tile->metrics );
184+
ulong volatile * const snapwr_metrics = snapwr_tile ? fd_metrics_tile( snapwr_tile->metrics ) : NULL;
189185

190186
ulong total_off_old = 0UL;
191187
ulong decomp_off_old = 0UL;
188+
ulong vinyl_off_old = 0UL;
192189
ulong snapct_backp_old = 0UL;
193190
ulong snapct_wait_old = 0UL;
194191
ulong snapld_backp_old = 0UL;
@@ -197,6 +194,7 @@ snapshot_load_cmd_fn( args_t * args,
197194
ulong snapdc_wait_old = 0UL;
198195
ulong snapin_backp_old = 0UL;
199196
ulong snapin_wait_old = 0UL;
197+
ulong snapwr_wait_old = 0UL;
200198
ulong acc_cnt_old = 0UL;
201199
sleep( 1 );
202200
puts( "" );
@@ -207,7 +205,11 @@ snapshot_load_cmd_fn( args_t * args,
207205
puts( "- stall: Waiting on upstream tile" );
208206
puts( "- acc: Number of accounts" );
209207
puts( "" );
210-
puts( "--------------------------------------------[ct],[ld],[dc],[in]--------[ct],[ld],[dc],[in]--------------" );
208+
fputs( "--------------------------------------------", stdout );
209+
if( snapwr_tile ) fputs( "--------------", stdout );
210+
fputs( "[ct],[ld],[dc],[in]--------[ct],[ld],[dc],[in]", stdout );
211+
if( snapwr_tile ) fputs( ",[wr]" , stdout );
212+
puts( "--------------" );
211213
long next = start+1000L*1000L*1000L;
212214
for(;;) {
213215
ulong snapct_status = FD_VOLATILE_CONST( snapct_metrics[ MIDX( GAUGE, TILE, STATUS ) ] );
@@ -228,6 +230,7 @@ snapshot_load_cmd_fn( args_t * args,
228230
snapct_metrics[ MIDX( GAUGE, SNAPCT, INCREMENTAL_BYTES_READ ) ];
229231
ulong decomp_off = snapdc_metrics[ MIDX( GAUGE, SNAPDC, FULL_DECOMPRESSED_BYTES_READ ) ] +
230232
snapdc_metrics[ MIDX( GAUGE, SNAPDC, INCREMENTAL_DECOMPRESSED_BYTES_READ ) ];
233+
ulong vinyl_off = snapwr_tile ? snapwr_metrics[ MIDX( GAUGE, SNAPWR, VINYL_BYTES_WRITTEN ) ] : 0UL;
231234
ulong snapct_backp = snapct_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_PREFRAG ) ];
232235
ulong snapct_wait = snapct_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_CAUGHT_UP_POSTFRAG ) ] + snapct_backp;
233236
ulong snapld_backp = snapld_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_PREFRAG ) ];
@@ -236,26 +239,42 @@ snapshot_load_cmd_fn( args_t * args,
236239
ulong snapdc_wait = snapdc_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_CAUGHT_UP_POSTFRAG ) ] + snapdc_backp;
237240
ulong snapin_backp = snapin_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_PREFRAG ) ];
238241
ulong snapin_wait = snapin_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_CAUGHT_UP_POSTFRAG ) ] + snapin_backp;
242+
ulong snapwr_wait = 0UL;
243+
if( snapwr_tile ) {
244+
snapwr_wait = snapwr_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_CAUGHT_UP_POSTFRAG ) ] +
245+
snapwr_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_PREFRAG ) ];
246+
}
239247

240248
double progress = 100.0 * (double)snapct_metrics[ MIDX( GAUGE, SNAPCT, FULL_BYTES_READ ) ] / (double)snapct_metrics[ MIDX( GAUGE, SNAPCT, FULL_BYTES_TOTAL ) ];
241249

242250
ulong acc_cnt = snapin_metrics[ MIDX( GAUGE, SNAPIN, ACCOUNTS_INSERTED ) ];
243-
printf( "%5.1f %% comp=%4.0f MB/s raw=%4.0f MB/s backp=(%3.0f%%,%3.0f%%,%3.0f%%,%3.0f%%) busy=(%3.0f%%,%3.0f%%,%3.0f%%,%3.0f%%) acc=%4.1f M/s\n",
251+
printf( "%5.1f %% comp=%4.0fMB/s snap=%4.0fMB/s",
244252
progress,
245253
(double)( total_off -total_off_old )/1e6,
246-
(double)( decomp_off-decomp_off_old )/1e6,
254+
(double)( decomp_off-decomp_off_old )/1e6 );
255+
if( snapwr_tile ) {
256+
printf( " vinyl=%4.0fMB/s", (double)( vinyl_off - vinyl_off_old )/1e6 );
257+
}
258+
printf( " backp=(%3.0f%%,%3.0f%%,%3.0f%%,%3.0f%%",
247259
( (double)( snapct_backp-snapct_backp_old )*ns_per_tick )/1e7,
248260
( (double)( snapld_backp-snapld_backp_old )*ns_per_tick )/1e7,
249261
( (double)( snapdc_backp-snapdc_backp_old )*ns_per_tick )/1e7,
250-
( (double)( snapin_backp-snapin_backp_old )*ns_per_tick )/1e7,
262+
( (double)( snapin_backp-snapin_backp_old )*ns_per_tick )/1e7 );
263+
printf( ") busy=(%3.0f%%,%3.0f%%,%3.0f%%,%3.0f%%",
251264
100-( ( (double)( snapct_wait-snapct_wait_old )*ns_per_tick )/1e7 ),
252265
100-( ( (double)( snapld_wait-snapld_wait_old )*ns_per_tick )/1e7 ),
253266
100-( ( (double)( snapdc_wait-snapdc_wait_old )*ns_per_tick )/1e7 ),
254-
100-( ( (double)( snapin_wait-snapin_wait_old )*ns_per_tick )/1e7 ),
267+
100-( ( (double)( snapin_wait-snapin_wait_old )*ns_per_tick )/1e7 ) );
268+
if( snapwr_tile ) {
269+
printf( ",%3.0f%%",
270+
100-( ( (double)( snapwr_wait-snapwr_wait_old )*ns_per_tick )/1e7 ) );
271+
}
272+
printf( ") acc=%4.1f M/s\n",
255273
(double)( acc_cnt-acc_cnt_old )/1e6 );
256274
fflush( stdout );
257275
total_off_old = total_off;
258276
decomp_off_old = decomp_off;
277+
vinyl_off_old = vinyl_off;
259278
snapct_backp_old = snapct_backp;
260279
snapct_wait_old = snapct_wait;
261280
snapld_backp_old = snapld_backp;
@@ -264,6 +283,7 @@ snapshot_load_cmd_fn( args_t * args,
264283
snapdc_wait_old = snapdc_wait;
265284
snapin_backp_old = snapin_backp;
266285
snapin_wait_old = snapin_wait;
286+
snapwr_wait_old = snapwr_wait;
267287
acc_cnt_old = acc_cnt;
268288

269289
next+=1000L*1000L*1000L;
@@ -272,7 +292,7 @@ snapshot_load_cmd_fn( args_t * args,
272292

273293
action_t fd_action_snapshot_load = {
274294
.name = NAME,
275-
.args = snapshot_load_cmd_args,
295+
.topo = snapshot_load_topo,
276296
.perm = dev_cmd_perm,
277297
.fn = snapshot_load_cmd_fn
278298
};

src/app/firedancer-dev/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ fd_topo_obj_callbacks_t * CALLBACKS[] = {
5050
NULL,
5151
};
5252

53+
extern configure_stage_t fd_cfg_stage_vinyl;
54+
5355
configure_stage_t * STAGES[] = {
5456
&fd_cfg_stage_kill,
5557
&fd_cfg_stage_netns,
@@ -61,6 +63,7 @@ configure_stage_t * STAGES[] = {
6163
&fd_cfg_stage_keys,
6264
&fd_cfg_stage_genesis,
6365
&fd_cfg_stage_snapshots,
66+
&fd_cfg_stage_vinyl,
6467
NULL,
6568
};
6669

@@ -108,6 +111,7 @@ extern fd_topo_run_tile_t fd_tile_snapct;
108111
extern fd_topo_run_tile_t fd_tile_snapld;
109112
extern fd_topo_run_tile_t fd_tile_snapdc;
110113
extern fd_topo_run_tile_t fd_tile_snapin;
114+
extern fd_topo_run_tile_t fd_tile_snapwr;
111115

112116
fd_topo_run_tile_t * TILES[] = {
113117
&fd_tile_net,
@@ -154,6 +158,7 @@ fd_topo_run_tile_t * TILES[] = {
154158
&fd_tile_snapld,
155159
&fd_tile_snapdc,
156160
&fd_tile_snapin,
161+
&fd_tile_snapwr,
157162
&fd_tile_genesi,
158163
&fd_tile_ipecho,
159164
NULL,

src/app/firedancer/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ extern fd_topo_run_tile_t fd_tile_snapct;
9090
extern fd_topo_run_tile_t fd_tile_snapld;
9191
extern fd_topo_run_tile_t fd_tile_snapdc;
9292
extern fd_topo_run_tile_t fd_tile_snapin;
93+
extern fd_topo_run_tile_t fd_tile_snapwr;
9394

9495
fd_topo_run_tile_t * TILES[] = {
9596
&fd_tile_net,
@@ -121,6 +122,7 @@ fd_topo_run_tile_t * TILES[] = {
121122
&fd_tile_snapld,
122123
&fd_tile_snapdc,
123124
&fd_tile_snapin,
125+
&fd_tile_snapwr,
124126
&fd_tile_genesi,
125127
&fd_tile_ipecho,
126128
NULL,

0 commit comments

Comments
 (0)