Skip to content

Commit 4a41d10

Browse files
funk, topo, util: make Funk workspace use unpinned pages
1 parent fb8f219 commit 4a41d10

File tree

23 files changed

+301
-39
lines changed

23 files changed

+301
-39
lines changed

.github/workflows/backtest.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,8 @@ jobs:
4343
sudo prlimit --pid=$$ --nofile=1048576
4444
sudo prlimit --pid=$$ --memlock=unlimited
4545
DUMP_DIR=../dump make run-runtime-backtest
46+
47+
- name: fini
48+
if: always()
49+
run: |
50+
sudo firedancer-dev configure fini all

contrib/offline-replay/offline_replay.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@
4040
[paths]
4141
identity_key = "{identity_key_path}"
4242
vote_account = "{vote_account_path}"
43+
[hugetlbfs]
44+
mount_path = "/data/firedancer/mnt"

src/app/firedancer-dev/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ extern configure_stage_t fd_cfg_stage_kill;
5454
extern configure_stage_t fd_cfg_stage_netns;
5555
extern configure_stage_t fd_cfg_stage_genesis;
5656
extern configure_stage_t fd_cfg_stage_keys;
57+
extern configure_stage_t fd_cfg_stage_normalpage;
5758

5859
configure_stage_t * STAGES[] = {
5960
&fd_cfg_stage_kill,
6061
&fd_cfg_stage_netns,
6162
&fd_cfg_stage_hugetlbfs,
63+
&fd_cfg_stage_normalpage,
6264
&fd_cfg_stage_sysctl,
6365
&fd_cfg_stage_hyperthreads,
6466
&fd_cfg_stage_ethtool_channels,

src/app/firedancer/topology.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ setup_topo_funk( fd_topo_t * topo,
112112
ulong wksp_idx = fd_topo_find_wksp( topo, wksp_name );
113113
FD_TEST( wksp_idx!=ULONG_MAX );
114114
fd_topo_wksp_t * wksp = &topo->workspaces[ wksp_idx ];
115-
ulong part_max = fd_wksp_part_max_est( funk_footprint, 1U<<14U );
115+
ulong part_max = fd_wksp_part_max_est( funk_footprint+(heap_size_gib*(1UL<<30)), 1U<<14U );
116116
if( FD_UNLIKELY( !part_max ) ) FD_LOG_ERR(( "fd_wksp_part_max_est(%lu,16KiB) failed", funk_footprint ));
117117
wksp->part_max += part_max;
118+
wksp->is_locked = 0;
118119

119120
return obj;
120121
}

src/app/shared/commands/configure/hugetlbfs.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,16 +233,12 @@ fini( config_t const * config,
233233
/* Not used by fdctl but might be created by other debugging tools
234234
on the system. */
235235

236-
char normal_page_mount_path[ PATH_MAX ];
237-
FD_TEST( fd_cstr_printf_check( normal_page_mount_path, PATH_MAX, NULL, "%s/.normal", config->hugetlbfs.mount_path ) );
238-
239-
const char * mount_path[ 3 ] = {
236+
const char * mount_path[ 2 ] = {
240237
config->hugetlbfs.huge_page_mount_path,
241238
config->hugetlbfs.gigantic_page_mount_path,
242-
normal_page_mount_path,
243239
};
244240

245-
for( ulong i=0UL; i<3UL; i++ ) {
241+
for( ulong i=0UL; i<2UL; i++ ) {
246242
FILE * fp = fopen( "/proc/self/mounts", "r" );
247243
if( FD_UNLIKELY( !fp ) ) FD_LOG_ERR(( "failed to open `/proc/self/mounts`" ));
248244

src/app/shared/commands/run/run.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,9 @@ workspace_path( config_t const * config,
472472
case FD_SHMEM_GIGANTIC_PAGE_SZ:
473473
mount_path = config->hugetlbfs.gigantic_page_mount_path;
474474
break;
475+
case FD_SHMEM_NORMAL_PAGE_SZ:
476+
mount_path = config->hugetlbfs.normal_page_mount_path;
477+
break;
475478
default:
476479
FD_LOG_ERR(( "invalid page size %lu", wksp->page_sz ));
477480
}
@@ -511,6 +514,7 @@ warn_unknown_files( config_t const * config,
511514
int known_file = 0;
512515
for( ulong i=0UL; i<config->topo.wksp_cnt; i++ ) {
513516
fd_topo_wksp_t const * wksp = &config->topo.workspaces[ i ];
517+
if( !wksp->is_locked ) continue;
514518

515519
char expected_path[ PATH_MAX ];
516520
workspace_path( config, wksp, expected_path );

src/app/shared/fd_config.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,11 @@ fd_config_fill( fd_config_t * config,
292292
NULL,
293293
"%s/.huge",
294294
config->hugetlbfs.mount_path ) );
295+
FD_TEST( fd_cstr_printf_check( config->hugetlbfs.normal_page_mount_path,
296+
sizeof(config->hugetlbfs.normal_page_mount_path),
297+
NULL,
298+
"%s/.normal",
299+
config->hugetlbfs.mount_path ) );
295300

296301
ulong max_page_sz = fd_cstr_to_shmem_page_sz( config->hugetlbfs.max_page_size );
297302
if( FD_UNLIKELY( max_page_sz!=FD_SHMEM_HUGE_PAGE_SZ && max_page_sz!=FD_SHMEM_GIGANTIC_PAGE_SZ ) ) FD_LOG_ERR(( "[hugetlbfs.max_page_size] must be \"huge\" or \"gigantic\"" ));

src/app/shared/fd_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ struct fd_config {
253253
struct {
254254
char gigantic_page_mount_path[ PATH_MAX ];
255255
char huge_page_mount_path[ PATH_MAX ];
256+
char normal_page_mount_path[ PATH_MAX ];
256257
char mount_path[ PATH_MAX ];
257258
char max_page_size[ 16 ];
258259
ulong gigantic_page_threshold_mib;

src/app/shared_dev/Local.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ $(call add-objs,commands/configure/kill,fddev_shared)
3030
ifdef FD_HAS_INT128
3131
$(call add-objs,commands/configure/genesis,fddev_shared)
3232
endif
33+
$(call add-objs,commands/configure/normalpage,fddev_shared)
3334

3435
endif
3536
endif
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/* This stage configures the normal pages directory, which is where the
2+
files backing memory-mapped unlocked workspaces should be stored.
3+
4+
The files backing these workspaces are stored in the normal pages
5+
directory configured by this command, and follow the normal workspace
6+
shmem file naming convention. */
7+
8+
#include "../../../shared/commands/configure/configure.h"
9+
10+
#include "../../../platform/fd_file_util.h"
11+
12+
#include <unistd.h>
13+
#include <errno.h>
14+
#include <stdio.h>
15+
#include <stdlib.h> /* strtoul */
16+
#include <dirent.h>
17+
#include <sys/stat.h>
18+
#include <sys/mount.h>
19+
#include <linux/capability.h>
20+
21+
static void
22+
init( config_t const * config ) {
23+
char const * path = config->hugetlbfs.normal_page_mount_path;
24+
25+
FD_LOG_NOTICE(( "RUN: `mkdir -p %s`", path ));
26+
if( FD_UNLIKELY( -1==fd_file_util_mkdir_all( path, config->uid, config->gid ) ) ) {
27+
FD_LOG_ERR(( "could not create normal page directory `%s` (%i-%s)", path, errno, fd_io_strerror( errno ) ));
28+
}
29+
if( FD_UNLIKELY( chown( path, config->uid, config->gid ) ) )
30+
FD_LOG_ERR(( "chown of normal page directory `%s` failed (%i-%s)", path, errno, fd_io_strerror( errno ) ));
31+
if( FD_UNLIKELY( chmod( config->hugetlbfs.normal_page_mount_path, S_IRUSR | S_IWUSR | S_IXUSR ) ) )
32+
FD_LOG_ERR(( "chmod of normal page directory `%s` failed (%i-%s)", config->hugetlbfs.normal_page_mount_path, errno, fd_io_strerror( errno ) ));
33+
}
34+
35+
/* Removes all top-level files in the given directory. */
36+
static int
37+
empty_dir_top_level( const char *dir_path ) {
38+
DIR *dir = opendir( dir_path );
39+
if( FD_UNLIKELY( !dir ) ) return (errno == ENOENT) ? 0 : -1;
40+
41+
struct dirent *entry;
42+
while( ( entry = readdir(dir) ) ) {
43+
if( FD_UNLIKELY( !strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..") ) ) continue;
44+
45+
char path[PATH_MAX];
46+
FD_TEST( fd_cstr_printf_check( path, PATH_MAX, NULL, "%s/%s", dir_path, entry->d_name ) );
47+
48+
struct stat st;
49+
if( stat(path, &st) == 0 && S_ISREG(st.st_mode)) {
50+
FD_LOG_NOTICE(( "RUN: `rm %s`", path ));
51+
if( FD_UNLIKELY( unlink(path) && errno != ENOENT ) ) {
52+
FD_LOG_WARNING(( "failed to remove file `%s` (%i-%s)", path, errno, fd_io_strerror(errno) ));
53+
}
54+
}
55+
}
56+
57+
if( FD_UNLIKELY( -1==closedir( dir ) ) ) FD_LOG_ERR(( "closedir (%i-%s)", errno, fd_io_strerror( errno ) ));
58+
return 0;
59+
}
60+
61+
static void
62+
fini( config_t const * config,
63+
int pre_init ) {
64+
(void)pre_init;
65+
char const * path = config->hugetlbfs.normal_page_mount_path;
66+
67+
/* The hugetlbfs normal pages mount directory may have been mounted by a different process,
68+
so we umount it just to be on the safe side. */
69+
if( FD_UNLIKELY( !umount( path ) ) ) {
70+
FD_LOG_DEBUG(( "error unmounting normal pages directory at `%s` (%i-%s). this is expected in normal operation",
71+
path, errno, fd_io_strerror( errno ) ));
72+
}
73+
if( FD_UNLIKELY( empty_dir_top_level(path) && errno != ENOENT ) )
74+
FD_LOG_ERR(( "error emptying normal pages directory at `%s` (%i-%s)",
75+
path, errno, fd_io_strerror(errno) ));
76+
77+
FD_LOG_NOTICE(( "RUN: `rmdir %s`", path ));
78+
if( FD_UNLIKELY( rmdir( path ) && errno!=ENOENT ) )
79+
FD_LOG_ERR(( "error removing normal pages directory at `%s` (%i-%s)",
80+
path, errno, fd_io_strerror( errno ) ));
81+
}
82+
83+
static configure_result_t
84+
check( config_t const * config ) {
85+
char const * path = config->hugetlbfs.normal_page_mount_path;
86+
87+
struct stat st;
88+
int result = stat( path, &st );
89+
if( FD_UNLIKELY( result && errno!=ENOENT ) )
90+
PARTIALLY_CONFIGURED( "failed to stat `%s` (%i-%s)", path, errno, fd_io_strerror( errno ) );
91+
92+
if( FD_UNLIKELY( result ) )
93+
NOT_CONFIGURED( "normal pages directory `%s` does not exist", path );
94+
95+
CHECK( check_dir( path, config->uid, config->gid, S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR ) );
96+
97+
CONFIGURE_OK();
98+
}
99+
100+
configure_stage_t fd_cfg_stage_normalpage = {
101+
.name = "normalpage",
102+
.always_recreate = 0,
103+
.enabled = NULL,
104+
.init_perm = NULL,
105+
.fini_perm = NULL,
106+
.init = init,
107+
.fini = fini,
108+
.check = check,
109+
};

0 commit comments

Comments
 (0)