<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
3
<e                 @   sn   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Zddl	m
Z
 ej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 )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_hugepageztransparent_hugepage.defrag )selfr	   r	   /usr/lib/python3.6/plugin_vm.py_get_config_options%   s    zVMPlugin._get_config_optionsc             C   s   d|_ d|_d S )NTF)Z_has_static_tuningZ_has_dynamic_tuning)r
   instancer	   r	   r   _instance_init-   s    zVMPlugin._instance_initc             C   s   d S )Nr	   )r
   r   r	   r	   r   _instance_cleanup1   s    zVMPlugin._instance_cleanupc             C   s   d}t j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_path4   s    zVMPlugin._thp_pathr   c             C   s   |dkr"|st jdt|  d S tjddd}|jdd	krP|sLt jd
 d S tjj	| j
 d}tjj|r|stj|||rtjgndd |S |st jd d S 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, 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removeZcmdlinesys_filer	   r	   r   _set_transparent_hugepages<   s$    

z#VMPlugin._set_transparent_hugepagesr   c             C   s   | j ||| d S )N)r(   )r
   r$   r%   r&   r	   r	   r   _set_transparent_hugepageU   s    z"VMPlugin._set_transparent_hugepagec             C   s6   t jj| j d}t jj|r.tjtj|S d S d S )Nr   )r   r   r    r   r   r   get_active_optionr   )r
   r'   r	   r	   r   _get_transparent_hugepagesY   s    z#VMPlugin._get_transparent_hugepagesc             C   s   | j  S )N)r+   )r
   r	   r	   r   _get_transparent_hugepageb   s    z"VMPlugin._get_transparent_hugepageztransparent_hugepage.defragc             C   sX   t jj| j d}t jj|rB|s>tj|||r6tjgndd |S |sPt	j
d d S d S )NdefragF)r   zJOption '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'   r	   r	   r    _set_transparent_hugepage_defragf   s    
z)VMPlugin._set_transparent_hugepage_defragc             C   s6   t jj| j d}t jj|r.tjtj|S d S d S )Nr-   )r   r   r    r   r   r   r*   r   )r
   r'   r	   r	   r    _get_transparent_hugepage_defrags   s    z)VMPlugin._get_transparent_hugepage_defragN)__name__
__module____qualname____doc__classmethodr   r   r   r   Zcommand_setr(   r)   Zcommand_getr+   r,   r.   r/   r	   r	   r	   r   r      s   	r   ) r   Z
decoratorsZ
tuned.logsZtunedr   r"   structZglobZtuned.utils.commandsr   Zlogsgetr   r   ZPluginr   r	   r	   r	   r   <module>   s   
