관리-도구
편집 파일: plugin_vm.cpython-39.pyc
a ����,�g ����������������������@���sn���d�dl�mZ�d�dlT�ddlZddlZddlZddlZddlZddl m Z �ej���Z e ��ZG�dd��dej�ZdS�)����)�base)�*�����N)�commandsc�������������������@���s��e�Zd�ZdZedd���Zedd���Zedd���Zdd ��Z d d��Z edd ���Zed�dd���Z ed�dd���Zed�dd���Zed�dd���Zed�dd���Zed�dd���Zdd��Zdd ��Zd!d"��Zed#�d$d%���Zed&�d'd(���Zed)�d*d+���Zed,�d-d.���Zd/d0��Zd1S�)2�VMPlugina��� Tunes selected sysctl options in `/proc/sys/vm`, currently [option]`dirty_ratio`, [option]`dirty_background_ratio`, [option]`dirty_bytes`, and [option]`dirty_background_bytes`. See https://docs.kernel.org/admin-guide/sysctl/vm.html for detailed documentation of these options. Additionaly enables or disables transparent huge pages depending on the 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�d�d�d�d�S�)N)�transparent_hugepages�transparent_hugepage�transparent_hugepage.defrag�dirty_bytes�dirty_ratio�dirty_background_bytes�dirty_background_ratio��)�selfr���r����;/usr/lib/python3.9/site-packages/tuned/plugins/plugin_vm.py�_get_config_options)���s�����zVMPlugin._get_config_optionsc�����������������C���s2���|�j�|�d�ur.|�j�|�d�ur.t�d||f���d�S�)NzEConflicting options '%s' and '%s', this may cause undefined behavior.)�options�log�error)�instance�first�secondr���r���r���� _check_conflicting_dirty_options5���s����z)VMPlugin._check_conflicting_dirty_optionsc�����������������C���s���t�j�d|��S�)Nz/proc/sys/vm)�os�path�join)�optionr���r���r����_proc_sys_vm_option_path:���s����z!VMPlugin._proc_sys_vm_option_pathc�����������������C���s,���d|_�d|_|��|dd��|��|dd��d�S�)NTFr ���r���r���r ���)Z_has_static_tuningZ_has_dynamic_tuningr����r���r���r���r���r����_instance_init>���s����zVMPlugin._instance_initc�����������������C���s���d�S��Nr���r���r���r���r����_instance_cleanupD���s����zVMPlugin._instance_cleanupc�����������������C���s���d}t�j�|�sd}|S�)Nz#/sys/kernel/mm/transparent_hugepagez*/sys/kernel/mm/redhat_transparent_hugepage)r���r����exists)r���r���r���r���r���� _thp_pathG���s����zVMPlugin._thp_pathr���c�����������������C���s����|dvr"|st��dt|����d�S�tjddd�}|�d�dkrP|sLt��d��d�S�tj� |�� ��d �}tj�|�r�|s�tj|||r�t jgnd d��|S�|s�t��d��d�S�d�S�)N)�always�neverZmadvisez-Incorrect 'transparent_hugepages' value '%s'.z /proc/cmdlineT�Zno_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����warning�str�cmd� read_file�find�infor���r���r���r#���r"���� write_to_file�errno�ENOENT)r����valuer����sim�removeZcmdline�sys_filer���r���r����_set_transparent_hugepagesO���s&���� � z#VMPlugin._set_transparent_hugepagesr���c�����������������C���s���|���||||��d�S�r ���)r5���)r���r1���r���r2���r3���r���r���r����_set_transparent_hugepageh���s����z"VMPlugin._set_transparent_hugepagec�����������������C���s6���t�j�|����d�}t�j�|�r.t�t�|��S�d�S�d�S�)Nr'����r���r���r���r#���r"���r*���Zget_active_optionr+����r���r���r4���r���r���r����_get_transparent_hugepagesl���s����z#VMPlugin._get_transparent_hugepagesc�����������������C���s ���|���|�S�r ���)r9���r���r���r���r����_get_transparent_hugepageu���s����z"VMPlugin._get_transparent_hugepager ���c�����������������C���sX���t�j�|����d�}t�j�|�rB|s>tj|||r6tjgndd��|S�|sPt � d��d�S�d�S�)N�defragFr&���zJOption 'transparent_hugepage.defrag' is not supported on current hardware.)r���r���r���r#���r"���r*���r.���r/���r0���r���r(���)r���r1���r���r2���r3���r4���r���r���r���� _set_transparent_hugepage_defragy���s����� z)VMPlugin._set_transparent_hugepage_defragc�����������������C���s6���t�j�|����d�}t�j�|�r.t�t�|��S�d�S�d�S�)Nr;���r7���r8���r���r���r���� _get_transparent_hugepage_defrag����s����z)VMPlugin._get_transparent_hugepage_defragc�����������������C���s4���dt�t�d���}||k�r0t�d||f���dS�dS�)N����ZPAGESIZEz<The value of '%s' must be at least twice the page size (%s).FT)�intr*���Zgetconfr���r���)r���r���� int_valueZ min_bytesr���r���r����_check_twice_pagesize����s ����zVMPlugin._check_twice_pagesizec�����������������C���s���|dkrt��d|���dS�dS�)Nr���z#The value of '%s' must be positive.FT�r���r����r���r���r@���r���r���r����_check_positive����s����zVMPlugin._check_positivec�����������������C���s,���d|��krdks(n�t��d|���dS�dS�)Nr����d���z,The value of '%s' must be between 0 and 100.FTrB���rC���r���r���r����_check_ratio����s����zVMPlugin._check_ratior ���c�����������������C���s���|���dd|�j|||�S�)Nr ���r���)� _dirty_optionrA����r����enablingr1����verifyZignore_missingr���r���r���r����_dirty_bytes����s����zVMPlugin._dirty_bytesr���c�����������������C���s���|���dd|�j|||�S�)Nr���r ����rG���rF���rH���r���r���r����_dirty_ratio����s����zVMPlugin._dirty_ratior���c�����������������C���s���|���dd|�j|||�S�)Nr���r ���)rG���rD���rH���r���r���r����_dirty_background_bytes����s����z VMPlugin._dirty_background_bytesr ���c�����������������C���s���|���dd|�j|||�S�)Nr ���r���rL���rH���r���r���r����_dirty_background_ratio����s����z VMPlugin._dirty_background_ratioc�����������������C���s���|���|�}|���|�}|�j|d�} |�j|d�} tj�|�sFt�d|���t�|�� ��}|r`||kS�|�rzt |�}W�n �ty����t�d|���Y�n0�|||�s�d�S�||kr�t� d||f���|S�t |�dkr�t�|�� ��} |�j�| | ��n|�j�| |��t� d||f���t�||��|S�|�j�| �}|�j�| �}|d�u�r\t� d||f���t�||��n8|d�u�r�t� d||f���t�||��nt� d|���d�S�) N)Zcommand_namez5Option '%s' is not supported on the current hardware.z%The value of '%s' must be an integer.z-Not setting option '%s' to '%s', already set.r���zSetting option '%s' to '%s'.zSetting option '%s' to '%s'z:Not restoring '%s', previous value is the same or unknown.)r���Z_storage_keyr���r����isfiler���r(���r*���r+����stripr?���� ValueErrorr���r-���Z_storage�setr.����get)r���r���ZcounterpartZ check_funrI���r1���rJ���Zoption_pathZcounterpart_pathZ option_keyZcounterpart_keyZ current_valuer@���Zcurrent_counterpart_value� old_valueZold_counterpart_valuer���r���r���rG�������sH���� zVMPlugin._dirty_optionN)�__name__� __module__�__qualname__�__doc__�classmethodr����staticmethodr���r���r���r!���r#���Zcommand_setr5���r6���Zcommand_getr9���r:���r<���r=���rA���rD���rF���Zcommand_customrK���rM���rN���rO���rG���r���r���r���r���r������sF��� r���)��r���Z decoratorsZ tuned.logsZtunedr���r/����struct�globZtuned.utils.commandsr���ZlogsrT���r���r*���ZPluginr���r���r���r���r����<module>���s���