Skip to content

Commit df87fce

Browse files
funk, topo, util: make Funk workspace use unpinned pages
1 parent fdadb8e commit df87fce

File tree

23 files changed

+290
-39
lines changed

23 files changed

+290
-39
lines changed

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ configure_stage_t * STAGES[] = {
5959
&fd_cfg_stage_kill,
6060
&fd_cfg_stage_netns,
6161
&fd_cfg_stage_hugetlbfs,
62+
&fd_cfg_stage_normalpage,
6263
&fd_cfg_stage_sysctl,
6364
&fd_cfg_stage_hyperthreads,
6465
&fd_cfg_stage_ethtool_channels,

src/app/firedancer/topology.c

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

118119
return obj;
119120
}

src/app/shared/Local.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ $(call add-objs,commands/configure/ethtool-channels,fdctl_shared)
2424
$(call add-objs,commands/configure/ethtool-gro,fdctl_shared)
2525
$(call add-objs,commands/configure/ethtool-loopback,fdctl_shared)
2626
$(call add-objs,commands/configure/hugetlbfs,fdctl_shared)
27+
$(call add-objs,commands/configure/normalpage,fdctl_shared)
2728
$(call add-objs,commands/configure/hyperthreads,fdctl_shared)
2829
$(call add-objs,commands/configure/sysctl,fdctl_shared)
2930
$(call add-objs,commands/monitor/monitor commands/monitor/helper,fdctl_shared)

src/app/shared/commands/configure/configure.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ typedef struct configure_stage {
6666
} configure_stage_t;
6767

6868
extern configure_stage_t fd_cfg_stage_hugetlbfs;
69+
extern configure_stage_t fd_cfg_stage_normalpage;
6970
extern configure_stage_t fd_cfg_stage_sysctl;
7071
extern configure_stage_t fd_cfg_stage_hyperthreads;
7172
extern configure_stage_t fd_cfg_stage_ethtool_channels;

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

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

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
@@ -241,6 +241,7 @@ struct fd_config {
241241
struct {
242242
char gigantic_page_mount_path[ PATH_MAX ];
243243
char huge_page_mount_path[ PATH_MAX ];
244+
char normal_page_mount_path[ PATH_MAX ];
244245
char mount_path[ PATH_MAX ];
245246
char max_page_size[ 16 ];
246247
ulong gigantic_page_threshold_mib;

0 commit comments

Comments
 (0)