#!/bin/bash

# Notice: Only Use For UDB

HUGEPAGE_PATH="/etc/rc.local.d/alter_hugepage.sh"

_install() {
	if [[ -d /sys/kernel/mm/redhat_transparent_hugepage/ ]] && [[ $Usage == udb ]]; then
        	echo 'never' > /sys/kernel/mm/redhat_transparent_hugepage/enabled
        	echo 'never' > /sys/kernel/mm/redhat_transparent_hugepage/defrag
        	echo "2000000" >/proc/sys/vm/max_map_count
		\cp -f $BASEDIR/optools/alter_redhat_transparent_hugepage.sh $HUGEPAGE_PATH
		
    	fi

    	if [[ -d /sys/kernel/mm/transparent_hugepage/ ]] && [[ $Usage == udb ]]; then
        	echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled
        	echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag
        	echo "2000000" >/proc/sys/vm/max_map_count
		\cp -f $BASEDIR/optools/alter_transparent_hugepage.sh $HUGEPAGE_PATH
    	fi

    	if [[ -f $HUGEPAGE_PATH ]] && [[ $Usage == udb ]];then
        	chmod a+x $HUGEPAGE_PATH
    	fi
}


_check() {
	_check="PASS"

    	if [[ ! -f $HUGEPAGE_PATH ]] && [[ $Usage == udb ]];then
		_check="FAIL"
		PRINT_ERR "[ERROR] File $HUGEPAGE_PATH Not Found."
    	fi
}
