#!/bin/bash

# omfs configuration file

function omfs_sysctl_config_pmpo() {

    local sys_mem_in_mb=`free -t -m | grep Mem | awk '{ print $2 }'`
    # Per current setting, 128G (system ram) --> 8000M (omfs cache size)
    local omfs_cache_size_in_mb=$(($sys_mem_in_mb*8000/128773))
    echo "omfs_cache_size_in_mb=$omfs_cache_size_in_mb"

    # Performance tuning parameters
    # See discussion in MG-10535 comments - omfs_cache_max_mem_MB
    # and omfs_cache_allocate_limit need to obey a certain
    # relationship between each other. For now, the formula is
    # omfs_cache_allocate_limit must be >=
    # omfs_cache_max_mem_MB * 4 + 512. The current values fit this
    # formula, so this comment is just for any future changes
    sysctl -w omfs_cache_max_mem_MB=$omfs_cache_size_in_mb

    sysctl -w omfs_cache_allocate_limit=32768
    sysctl -w omfs_cwthreads=32
    sysctl -w omfs_aggressive_readahead=1
    sysctl -w omfs_max_cache_entries_per_file=1000
    sysctl -w omfs_max_caches_cached=1000
    sysctl -w omfs_max_conn_per_server=32
    sysctl -w omfs_worker_threads=64
    sysctl -w omfs_slicemap_expire_ms=10000
    sysctl -w omfs_fail_if_no_mds=1
    sysctl -w omfs_force_data_flush_ms=5000
    sysctl -w omfs_node_status_validity=5000
    sysctl -w omfs_max_node_status_record=10
    sysctl -w omfs_deferred_close_secs=15000
    sysctl -w omfs_readdir_cache_status=0

}

function omfs_sysctl_config_acp() {

    local sys_mem_in_mb=`free -t -m | grep Mem | awk '{ print $2 }'`
    # Per current setting, 32G (system ram) --> 500M (omfs cache size)
    local omfs_cache_size_in_mb=$(($sys_mem_in_mb*500/33088))
    echo "omfs_cache_size_in_mb=$omfs_cache_size_in_mb"

    # Performance tuning parameters
    # See discussion in MG-10535 comments - omfs_cache_max_mem_MB
    # and omfs_cache_allocate_limit need to obey a certain
    # relationship between each other. For now, the formula is
    # omfs_cache_allocate_limit must be >=
    # omfs_cache_max_mem_MB * 4 + 512. The current values fit this
    # formula, so this comment is just for any future changes
    sysctl -w omfs_cache_max_mem_MB=$omfs_cache_size_in_mb

    sysctl -w omfs_cache_allocate_limit=5764
    sysctl -w omfs_cwthreads=12
    sysctl -w omfs_aggressive_readahead=1
    sysctl -w omfs_max_cache_entries_per_file=1000
    sysctl -w omfs_max_caches_cached=32
    sysctl -w omfs_max_conn_per_server=12
    sysctl -w omfs_worker_threads=32
    sysctl -w omfs_slicemap_expire_ms=10000
    sysctl -w omfs_fail_if_no_mds=0
    sysctl -w omfs_force_data_flush_ms=1000
    sysctl -w omfs_node_status_validity=500
    sysctl -w omfs_max_node_status_record=10
    sysctl -w omfs_deferred_close_secs=3
    sysctl -w omfs_readdir_cache_status=0

}



case $(whatami) in 
    pml_acp)
        OMFS_MOUNT_PARAMETERS="mdsconn=8,readahead=5,filelimit=1000,actimeout=500"
        DO_OMFS_SYSCTL_CONFIG="omfs_sysctl_config_acp"
        ;;
    *)
        OMFS_MOUNT_PARAMETERS="mdsconn=64,readahead=1,filelimit=8192,actimeout=5000"
        DO_OMFS_SYSCTL_CONFIG="omfs_sysctl_config_pmpo"
        ;;
esac

