LCOV - code coverage report
Current view: top level - app/fdctl/configure - sysctl.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 47 0.0 %
Date: 2024-11-13 11:58:15 Functions: 0 3 0.0 %

          Line data    Source code
       1             : #include "configure.h"
       2             : 
       3           0 : #define NAME "sysctl"
       4             : 
       5             : #include <stdio.h>
       6             : #include <linux/capability.h>
       7             : 
       8             : static void
       9             : init_perm( fd_caps_ctx_t *  caps,
      10           0 :            config_t * const config ) {
      11           0 :   (void)config;
      12           0 :   fd_caps_check_capability( caps, NAME, CAP_SYS_ADMIN, "set kernel parameters in `/proc/sys`" );
      13           0 : }
      14             : 
      15           0 : #define ENFORCE_MINIMUM 0
      16           0 : #define WARN_MINIMUM    1
      17           0 : #define WARN_EXACT      2
      18             : 
      19             : typedef struct {
      20             :   char const * path;
      21             :   uint         value;
      22             :   int          mode;
      23             : } sysctl_param_t;
      24             : 
      25             : static const sysctl_param_t params[] = {
      26             :   {
      27             :     "/proc/sys/vm/max_map_count",
      28             :     1000000,
      29             :     ENFORCE_MINIMUM,
      30             :   },
      31             :   {
      32             :     "/proc/sys/fs/file-max",
      33             :     CONFIGURE_NR_OPEN_FILES,
      34             :     ENFORCE_MINIMUM,
      35             :   },
      36             :   {
      37             :     "/proc/sys/fs/nr_open",
      38             :     CONFIGURE_NR_OPEN_FILES,
      39             :     ENFORCE_MINIMUM,
      40             :   },
      41             :   {
      42             :     "/proc/sys/net/ipv4/conf/lo/rp_filter",
      43             :     2,
      44             :     ENFORCE_MINIMUM,
      45             :   },
      46             :   {
      47             :     "/proc/sys/net/ipv4/conf/lo/accept_local",
      48             :     1,
      49             :     ENFORCE_MINIMUM,
      50             :   },
      51             :   {
      52             :     "/proc/sys/net/core/bpf_jit_enable",
      53             :     1,
      54             :     WARN_MINIMUM,
      55             :   },
      56             :   {
      57             :     "/proc/sys/kernel/numa_balancing",
      58             :     0,
      59             :     WARN_EXACT,
      60             :   }
      61             : };
      62             : 
      63             : static const char * ERR_MSG = "system might not support configuring sysctl,";
      64             : 
      65             : 
      66             : /* Some of these sysctl limits are needed for the Agave client, not
      67             :    Firedancer.  We set them on their behalf to make configuration easier
      68             :    for users. */
      69             : 
      70             : static void
      71           0 : init( config_t * const config ) {
      72           0 :   (void)config;
      73           0 :   for( ulong i=0; i<sizeof( params ) / sizeof( params[ 0 ] ); i++ ) {
      74           0 :     uint param = read_uint_file( params[ i ].path, ERR_MSG );
      75           0 :     switch( params[ i ].mode ) {
      76           0 :       case ENFORCE_MINIMUM:
      77           0 :         if( FD_UNLIKELY( param<params[ i ].value ) ) {
      78           0 :           FD_LOG_NOTICE(( "RUN: `echo \"%u\" > %s`", params[ i ].value, params[ i ].path ) );
      79           0 :           write_uint_file( params[ i ].path, params[ i ].value );
      80           0 :         }
      81           0 :         break;
      82           0 :       default:
      83           0 :         break;
      84           0 :     }
      85           0 :   }
      86           0 : }
      87             : 
      88             : static configure_result_t
      89           0 : check( config_t * const config ) {
      90           0 :   static int has_warned = 0;
      91             : 
      92           0 :   (void)config;
      93           0 :   for( ulong i=0; i<sizeof( params ) / sizeof( params[ 0 ] ); i++ ) {
      94           0 :     uint param = read_uint_file( params[ i ].path, ERR_MSG );
      95           0 :     switch( params[ i ].mode ) {
      96           0 :       case ENFORCE_MINIMUM:
      97           0 :         if( FD_UNLIKELY( param<params[ i ].value ) )
      98           0 :           NOT_CONFIGURED( "kernel parameter `%s` is too low (got %u but expected at least %u)", params[ i ].path, param, params[ i ].value );
      99           0 :         break;
     100           0 :       case WARN_MINIMUM:
     101           0 :         if( FD_UNLIKELY( !has_warned && param<params[ i ].value ) )
     102           0 :           FD_LOG_WARNING(( "kernel parameter `%s` is too low (got %u but expected at least %u). Proceeding but performance may be reduced.", params[ i ].path, param, params[ i ].value ));
     103           0 :         break;
     104           0 :       case WARN_EXACT:
     105           0 :         if( FD_UNLIKELY( !has_warned && param!=params[ i ].value ) )
     106           0 :           FD_LOG_WARNING(( "kernel parameter `%s` is set to %u, not the expected value of %u. Proceeding but performance may be reduced.", params[ i ].path, param, params[ i ].value ));
     107           0 :         break;
     108           0 :     }
     109           0 :   }
     110             : 
     111           0 :   has_warned = 1;
     112             : 
     113           0 :   CONFIGURE_OK();
     114           0 : }
     115             : 
     116             : configure_stage_t sysctl = {
     117             :   .name            = NAME,
     118             :   .always_recreate = 0,
     119             :   .enabled         = NULL,
     120             :   .init_perm       = init_perm,
     121             :   .fini_perm       = NULL,
     122             :   .init            = init,
     123             :   .fini            = NULL,
     124             :   .check           = check,
     125             : };
     126             : 
     127             : #undef NAME

Generated by: LCOV version 1.14