o
    _
                     @   sf   d dl mZ d dlT ddlZddlZddlZddlZddlm	Z	 ej
 Ze	 ZG dd dejZdS )   )base)*    N)commandsc                   @   s   e Zd ZdZedd Zdd Zdd Zedd	 Ze	d
dd Z
e	ddd Zed
dd Zeddd Ze	ddd Zeddd ZdS )VMPluginz(
	Plugin for tuning memory management.
	c                 C   s   d d d dS )N)transparent_hugepagestransparent_hugepagetransparent_hugepage.defrag selfr
   r
   9/usr/lib/python3/dist-packages/tuned/plugins/plugin_vm.py_get_config_options   s   zVMPlugin._get_config_optionsc                 C   s   d|_ d|_d S )NTF)_has_static_tuning_has_dynamic_tuningr   instancer
   r
   r   _instance_init   s   
zVMPlugin._instance_initc                 C   s   d S Nr
   r   r
   r
   r   _instance_cleanup   s   zVMPlugin._instance_cleanupc                 C   s   d}t j|s
d}|S )Nz#/sys/kernel/mm/transparent_hugepagez*/sys/kernel/mm/redhat_transparent_hugepage)ospathexists)r   r   r
   r
   r   	_thp_path!   s   zVMPlugin._thp_pathr   c                 C   s   |dvr|st dt|  d S tjddd}|ddkr(|s&t d d S tj	| 
 d	}tj|rA|s?t|| |S |sHt d
 d S )N)alwaysnevermadvisez-Incorrect 'transparent_hugepages' value '%s'.z/proc/cmdlineT)no_errorztransparent_hugepage=r   zWtransparent_hugepage is already set in kernel boot cmdline, ingoring value from profileenabledzDOption 'transparent_hugepages' is not supported on current hardware.)logwarnstrcmd	read_filefindinfor   r   joinr   r   write_to_file)r   valuesimcmdlinesys_filer
   r
   r   _set_transparent_hugepages)   s"   

z#VMPlugin._set_transparent_hugepagesr   c                 C   s   |  || d S r   )r,   )r   r(   r)   r
   r
   r   _set_transparent_hugepageA   s   z"VMPlugin._set_transparent_hugepagec                 C   2   t j|  d}t j|rtt|S d S )Nr   r   r   r&   r   r   r"   get_active_optionr#   r   r+   r
   r
   r   _get_transparent_hugepagesE      z#VMPlugin._get_transparent_hugepagesc                 C   s   |   S r   )r2   r   r
   r
   r   _get_transparent_hugepageN   s   z"VMPlugin._get_transparent_hugepager	   c                 C   sD   t j|  d}t j|r|st|| |S |s td d S )NdefragzJOption 'transparent_hugepage.defrag' is not supported on current hardware.)	r   r   r&   r   r   r"   r'   r   r    )r   r(   r)   r+   r
   r
   r    _set_transparent_hugepage_defragR   s   
z)VMPlugin._set_transparent_hugepage_defragc                 C   r.   )Nr5   r/   r1   r
   r
   r    _get_transparent_hugepage_defrag^   r3   z)VMPlugin._get_transparent_hugepage_defragN)__name__
__module____qualname____doc__classmethodr   r   r   r   command_setr,   r-   command_getr2   r4   r6   r7   r
   r
   r
   r   r      s(    






r   ) r   
decorators
tuned.logstunedr   structglobtuned.utils.commandsr   logsgetr   r"   Pluginr   r
   r
   r
   r   <module>   s    
