ó
ć\c           @   s   d  d l  m Z d  d l Td d l Z d d l Z d d l Z d d l Z d d l m	 Z	 e j
 j   Z e	   Z d e j f d     YZ d S(   i   (   t   base(   t   *i˙˙˙˙N(   t   commandst   VMPluginc           B   sź   e  Z d  Z e d    Z d   Z d   Z e d    Z e d  d    Z	 e d  d    Z
 e d  d	    Z e d  d
    Z e d  d    Z e d  d    Z RS(   s(   
	Plugin for tuning memory management.
	c         C   s   i d  d 6d  d 6d  d 6S(   Nt   transparent_hugepagest   transparent_hugepages   transparent_hugepage.defrag(   t   None(   t   self(    (    s;   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_vm.pyt   _get_config_options   s    c         C   s   t  | _ t | _ d  S(   N(   t   Truet   _has_static_tuningt   Falset   _has_dynamic_tuning(   R   t   instance(    (    s;   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_vm.pyt   _instance_init   s    	c         C   s   d  S(   N(    (   R   R   (    (    s;   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_vm.pyt   _instance_cleanup   s    c         C   s%   d } t  j j |  s! d } n  | S(   Ns#   /sys/kernel/mm/transparent_hugepages*   /sys/kernel/mm/redhat_transparent_hugepage(   t   ost   patht   exists(   R   R   (    (    s;   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_vm.pyt	   _thp_path!   s    	R   c         C   sÜ   | d k r0 | s, t  j d t |   n  d  St j d d t } | j d  d k rt | sp t  j d	  n  d  St	 j
 j |  j   d
  } t	 j
 j |  rž | sş t j | |  n  | S| sÔ t  j d  n  d  Sd  S(   Nt   alwayst   nevert   madvises-   Incorrect 'transparent_hugepages' value '%s'.s   /proc/cmdlinet   no_errors   transparent_hugepage=i    sW   transparent_hugepage is already set in kernel boot cmdline, ingoring value from profilet   enabledsD   Option 'transparent_hugepages' is not supported on current hardware.(   s   alwaysR   R   (   t   logt   warnt   strR   t   cmdt	   read_fileR	   t   findt   infoR   R   t   joinR   R   t   write_to_file(   R   t   valuet   simt   cmdlinet   sys_file(    (    s;   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_vm.pyt   _set_transparent_hugepages)   s"    R   c         C   s   |  j  | |  d  S(   N(   R&   (   R   R"   R#   (    (    s;   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_vm.pyt   _set_transparent_hugepageA   s    c         C   sK   t  j j |  j   d  } t  j j |  rC t j t j |   Sd  Sd  S(   NR   (	   R   R   R    R   R   R   t   get_active_optionR   R   (   R   R%   (    (    s;   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_vm.pyt   _get_transparent_hugepagesE   s    c         C   s
   |  j    S(   N(   R)   (   R   (    (    s;   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_vm.pyt   _get_transparent_hugepageN   s    s   transparent_hugepage.defragc         C   sh   t  j j |  j   d  } t  j j |  rJ | sF t j | |  n  | S| s` t j d  n  d  Sd  S(   Nt   defragsJ   Option 'transparent_hugepage.defrag' is not supported on current hardware.(
   R   R   R    R   R   R   R!   R   R   R   (   R   R"   R#   R%   (    (    s;   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_vm.pyt    _set_transparent_hugepage_defragR   s    c         C   sK   t  j j |  j   d  } t  j j |  rC t j t j |   Sd  Sd  S(   NR+   (	   R   R   R    R   R   R   R(   R   R   (   R   R%   (    (    s;   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_vm.pyt    _get_transparent_hugepage_defrag^   s    (   t   __name__t
   __module__t   __doc__t   classmethodR   R   R   R   t   command_setR&   R'   t   command_getR)   R*   R,   R-   (    (    (    s;   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_vm.pyR      s   			(   t    R    t
   decoratorst
   tuned.logst   tunedR   t   structt   globt   tuned.utils.commandsR   t   logst   getR   R   t   PluginR   (    (    (    s;   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_vm.pyt   <module>   s   
	