%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3.9/site-packages/tuned/plugins/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3.9/site-packages/tuned/plugins/__pycache__/plugin_vm.cpython-39.pyc

a

���h�"�@snddlmZddlTddlZddlZddlZddlZddlZddl	m
Z
ej��Z
e
�ZGdd�dej�ZdS)�)�base)�*�N)�commandsc@seZdZdZedd��Zedd��Zedd��Zdd	�Z	d
d�Z
edd
��Zed�dd��Z
ed�dd��Zed�dd��Zed�dd��Zed�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].
	cCsdddddddd�S)N)�transparent_hugepages�transparent_hugepage�transparent_hugepage.defrag�dirty_bytes�dirty_ratio�dirty_background_bytes�dirty_background_ratio�)�selfrr�;/usr/lib/python3.9/site-packages/tuned/plugins/plugin_vm.py�_get_config_options)s�zVMPlugin._get_config_optionscCs2|j|dur.|j|dur.t�d||f�dS)NzEConflicting options '%s' and '%s', this may cause undefined behavior.)�options�log�warning)�instance�first�secondrrr� _check_conflicting_dirty_options5sz)VMPlugin._check_conflicting_dirty_optionscCstj�d|�S)Nz/proc/sys/vm)�os�path�join)�optionrrr�_proc_sys_vm_option_path:sz!VMPlugin._proc_sys_vm_option_pathcCs,d|_d|_|�|dd�|�|dd�dS)NTFr
rrr
)Z_has_static_tuningZ_has_dynamic_tuningr�rrrrr�_instance_init>szVMPlugin._instance_initcCsdS�Nrrrrr�_instance_cleanupDszVMPlugin._instance_cleanupcCsd}tj�|�sd}|S)Nz#/sys/kernel/mm/transparent_hugepagez*/sys/kernel/mm/redhat_transparent_hugepage)rr�exists)rrrrr�	_thp_pathGszVMPlugin._thp_pathrcCs�|dvr"|st�dt|��dStjddd�}|�d�dkrP|sLt�d�dStj�	|�
�d	�}tj�|�r�|s�tj|||r�t
jgnd
d�|S|s�t�d�dSdS)N)�always�neverZmadvisez-Incorrect 'transparent_hugepages' value '%s'.z
/proc/cmdlineT�Zno_errorztransparent_hugepage=rzWtransparent_hugepage is already set in kernel boot cmdline, ignoring value from profile�enabledFzDOption 'transparent_hugepages' is not supported on current hardware.)rr�str�cmd�	read_file�find�inforrrr#r"�
write_to_file�errno�ENOENT)r�valuer�sim�removeZcmdline�sys_filerrr�_set_transparent_hugepagesOs&
�
z#VMPlugin._set_transparent_hugepagesrcCs|�||||�dSr )r4)rr0rr1r2rrr�_set_transparent_hugepagehsz"VMPlugin._set_transparent_hugepagecCs6tj�|��d�}tj�|�r.t�t�|��SdSdS)Nr'�rrrr#r"r)Zget_active_optionr*�rrr3rrr�_get_transparent_hugepageslsz#VMPlugin._get_transparent_hugepagescCs
|�|�Sr )r8rrrr�_get_transparent_hugepageusz"VMPlugin._get_transparent_hugepager	cCsXtj�|��d�}tj�|�rB|s>tj|||r6tjgndd�|S|sPt	�
d�dSdS)N�defragFr&zJOption 'transparent_hugepage.defrag' is not supported on current hardware.)rrrr#r"r)r-r.r/rr)rr0rr1r2r3rrr� _set_transparent_hugepage_defragys�
z)VMPlugin._set_transparent_hugepage_defragcCs6tj�|��d�}tj�|�r.t�t�|��SdSdS)Nr:r6r7rrr� _get_transparent_hugepage_defrag�sz)VMPlugin._get_transparent_hugepage_defragcCs4dtt�d��}||kr0t�d||f�dSdS)N�ZPAGESIZEz<The value of '%s' must be at least twice the page size (%s).FT)�intr)Zgetconfr�error)rr�	int_valueZ	min_bytesrrr�_check_twice_pagesize�s
zVMPlugin._check_twice_pagesizecCs|dkrt�d|�dSdS)Nrz#The value of '%s' must be positive.FT�rr?�rrr@rrr�_check_positive�szVMPlugin._check_positivecCs,d|krdks(nt�d|�dSdS)Nr�dz,The value of '%s' must be between 0 and 100.FTrBrCrrr�_check_ratio�szVMPlugin._check_ratior
c	CsL|dur6|���d�r6|�dd|j||���d�|�S|�dd|j|||�S)N�%rr
)�strip�endswith�
_dirty_optionrF�rstriprA�r�enablingr0�verifyZignore_missingrrrr�_dirty_bytes�s zVMPlugin._dirty_bytesrcCs t�d�|�dd|j|||�S)NzlThe 'dirty_ratio' option is deprecated and does not support inheritance, use 'dirty_bytes' with '%' instead.rr
�rrrJrFrLrrr�_dirty_ratio�s
zVMPlugin._dirty_ratiorc	CsL|dur6|���d�r6|�dd|j||���d�|�S|�dd|j|||�S)NrGr
r)rHrIrJrFrKrDrLrrr�_dirty_background_bytes�s z VMPlugin._dirty_background_bytesr
cCs t�d�|�dd|j|||�S)Nz�The 'dirty_background_ratio' option is deprecated and does not support inheritance, use 'dirty_background_bytes' with '%' instead.r
rrPrLrrr�_dirty_background_ratio�s
z VMPlugin._dirty_background_ratiocCs�|�|�}|�|�}|j|d�}	|j|d�}
tj�|�sFt�d|�t�|��	�}|r`||kS|�rzt
|�}Wn"ty�t�d|�YdS0|||�s�dS||kr�t�
d||f�|St
|�dkr�t�|��	�}
|j�|
|
�n|j�|	|�t�
d||f�t�||�|S|j�|	�}|j�|
�}|du�r^t�
d||f�t�||�n8|du�r�t�
d||f�t�||�nt�
d|�dS)	N)Zcommand_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.rzSetting option '%s' to '%s'.zSetting option '%s' to '%s'z:Not restoring '%s', previous value is the same or unknown.)rZ_storage_keyrr�isfilerrr)r*rHr>�
ValueErrorr?r,Z_storage�setr-�get)rrZcounterpartZ	check_funrMr0rNZoption_pathZcounterpart_pathZ
option_keyZcounterpart_keyZ
current_valuer@Zcurrent_counterpart_value�	old_valueZold_counterpart_valuerrrrJ�sJ




zVMPlugin._dirty_optionN)�__name__�
__module__�__qualname__�__doc__�classmethodr�staticmethodrrrr!r#Zcommand_setr4r5Zcommand_getr8r9r;r<rArDrFZcommand_customrOrQrRrSrJrrrrrsF













r)�rZ
decoratorsZ
tuned.logsZtunedrr.�struct�globZtuned.utils.commandsrZlogsrWrr)ZPluginrrrrr�<module>s


Zerion Mini Shell 1.0