3 À<×eé ã @ sn d dl mZ d dlT ddlZddlZddlZddlZddlZddl m Z ejjƒ Z e ƒ ZG dd„ dejƒZdS )é )Úbase)Ú*é N)Úcommandsc @ s˜ e Zd ZdZedd„ ƒZdd„ Zdd„ Zedd „ ƒZe d ƒdd„ ƒZ e d ƒdd„ ƒZed ƒdd„ ƒZ ed ƒdd„ ƒZe dƒdd„ ƒZedƒdd„ ƒZdS )ÚVMPlugina| `vm`:: Enables or disables transparent huge pages depending on value of the [option]`transparent_hugepages` option. The option can have one of three possible values `always`, `madvise` and `never`. + .Disable transparent hugepages ==== ---- [vm] transparent_hugepages=never ---- ==== + The [option]`transparent_hugepage.defrag` option specifies the defragmentation policy. Possible values for this option are `always`, `defer`, `defer+madvise`, `madvise` and `never`. For a detailed explanation of these values refer to link:https://www.kernel.org/doc/Documentation/vm/transhuge.txt[Transparent Hugepage Support]. c C s d d d dœS )N)Útransparent_hugepagesÚtransparent_hugepageztransparent_hugepage.defrag© )Úselfr r ú/usr/lib/python3.6/plugin_vm.pyÚ_get_config_options% s zVMPlugin._get_config_optionsc C s d|_ d|_d S )NTF)Z_has_static_tuningZ_has_dynamic_tuning)r Úinstancer r r Ú_instance_init- s zVMPlugin._instance_initc C s d S )Nr )r r r r r Ú_instance_cleanup1 s zVMPlugin._instance_cleanupc C s d}t jj|ƒsd}|S )Nz#/sys/kernel/mm/transparent_hugepagez*/sys/kernel/mm/redhat_transparent_hugepage)ÚosÚpathÚexists)r r r r r Ú _thp_path4 s zVMPlugin._thp_pathr c C s¨ |dkr"|st jdt|ƒ ƒ d S tjddd�}|jdƒd krP|sLt jd ƒ d S tjj | j ƒ dƒ}tjj|ƒr’|sŽtj|||r†t jgndd� |S |s t jd ƒ d S d S )NÚalwaysÚneverÚmadvisez-Incorrect 'transparent_hugepages' value '%s'.z /proc/cmdlineT)Úno_errorztransparent_hugepage=r zWtransparent_hugepage is already set in kernel boot cmdline, ignoring value from profileÚenabledFzDOption 'transparent_hugepages' is not supported on current hardware.)r r r )ÚlogÚwarnÚstrÚcmdÚ read_fileÚfindÚinfor r Újoinr r Ú write_to_fileÚerrnoÚENOENT)r ÚvalueÚsimÚremoveZcmdlineÚsys_filer r r Ú_set_transparent_hugepages<