HEX
Server: Apache
System: Linux nc-ph-4101.simplemoneygoals.com 5.14.0-503.21.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Jan 12 09:45:05 EST 2025 x86_64
User: dailygoldindex (1004)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //lib/python3.9/site-packages/tuned/plugins/__pycache__/plugin_disk.cpython-39.opt-1.pyc
a

,�gC�@slddlZddlmZddlTddlZddlmZddlm	Z	ddl
Z
ddlZej�
�ZGdd�dej�ZdS)�N�)�hotplug)�*)�commandscs�eZdZdZ�fdd�Z�fdd�Zdd�Zdd	�Zed
d��Z	dd
�Z
dd�Z�fdd�Z�fdd�Z
�fdd�Zedd��Zedd��Zdd�Zdd�Z�fdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Z�fd.d/�Zd0d1�Zd\d3d4�Zd5d6�Zed7d8d9�d:d;��Z e!d7�d]d=d>��Z"ed?d8d9�d@dA��Z#e!d?�d^dBdC��Z$edDd8d9�dEdF��Z%e!dD�d_dGdH��Z&dIdJ�Z'dKdL�Z(edMd8d9�dNdO��Z)e!dM�d`dPdQ��Z*e+dRd8d9�dSdT��Z,dUdV�Z-edWd8d9�dXdY��Z.e!dW�dadZd[��Z/�Z0S)b�
DiskPlugina.	
	Plug-in for tuning various block device options. This plug-in can also
	dynamically change the advanced power management and spindown timeout
	setting for a drive according to the current drive utilization. The
	dynamic tuning is controlled by the [option]`dynamic` and the global
	[option]`dynamic_tuning` option in `tuned-main.conf`.

	The disk plug-in operates on all supported block devices unless a
	comma separated list of [option]`devices` is passed to it.

	.Operate only on the `sda` block device
	====
	----
	[disk]
	devices=sda
	----
	====

	The [option]`elevator` option sets the Linux I/O scheduler.

	.Use the bfq I/O scheduler on the `xvda` block device
	====
	----
	[disk]
	device=xvda
	elevator=bfq
	----
	====

	The [option]`scheduler_quantum` option only applies to the CFQ I/O
	scheduler. It defines the number of I/O requests that CFQ sends to
	one device at one time, essentially limiting queue depth. The default
	value is 8 requests. The device being used may support greater queue
	depth, but increasing the value of quantum will also increase latency,
	especially for large sequential write work loads.

	The [option]`apm` option sets the Advanced Power Management feature
	on drives that support it. It corresponds to using the `-B` option of
	the `hdparm` utility. The [option]`spindown` option puts the drive
	into idle (low-power) mode, and also sets the standby (spindown)
	timeout for the drive. It corresponds to using `-S` option of the
	`hdparm` utility.

	.Use a medium-agressive power management with spindown
	====
	----
	[disk]
	apm=128
	spindown=6
	----
	====

	The [option]`readahead` option controls how much extra data the
	operating system reads from disk when performing sequential
	I/O operations. Increasing the `readahead` value might improve
	performance in application environments where sequential reading of
	large files takes place. The default unit for readahead is KiB. This
	can be adjusted to sectors by specifying the suffix 's'. If the
	suffix is specified, there must be at least one space between the
	number and suffix (for example, `readahead=8192 s`).

	.Set the `readahead` to 4MB unless already set to a higher value
	====
	----
	[disk]
	readahead=>4096
	----
	====
	The disk readahead value can be multiplied by the constant
	specified by the [option]`readahead_multiply` option.
	csNtt|�j|i|��gd�|_gd�|_t|j�|_d|_d|_t	�|_
dS)N)��������}�i�U�F�7��)r����������n�Zr�<�g{�G�z�?)�superr�__init__�
_power_levels�_spindown_levels�len�_levels�_level_steps�_load_smallestr�_cmd)�self�args�kwargs��	__class__��=/usr/lib/python3.9/site-packages/tuned/plugins/plugin_disk.pyrUs

zDiskPlugin.__init__cs`tt|���d|_d|_t�|_t�|_|j	�
d�D]}|�|�r6|j�|j
�q6t�|_dS)NT�block)rr�
_init_devicesZ_devices_supported�_use_hdparm�setZ
_free_devices�dict�_hdparm_apm_device_support�_hardware_inventoryZget_devices�_device_is_supported�addZsys_nameZ_assigned_devices�r'�devicer*r,r-r/_s
zDiskPlugin._init_devicescs�fdd�|D�S)Ncsg|]}�j�d|��qS)r.)r4Z
get_device)�.0�x�r'r,r-�
<listcomp>k�z2DiskPlugin._get_device_objects.<locals>.<listcomp>r,)r'Zdevicesr,r;r-�_get_device_objectsjszDiskPlugin._get_device_objectscCs�|js
dS||jvr|j|S|jjddd|gtjgdd�\}}}|tjkrdt�d�d|_dS|r�t�d|�t�	d	||f�d|j|<dSd
|vr�t�d|�d|j|<dSd|j|<dS)NF�hdparm�-C�/dev/%sT)�	no_errorsZ
return_errz4hdparm command not found, ignoring for other devicesz#Device '%s' not supported by hdparmz(rc: %s, msg: '%s')�unknownz3Driver for device '%s' does not support apm command)
r0r3r&�execute�errno�ENOENT�log�warning�info�debug)r'r8�rc�out�err_msgr,r,r-�_is_hdparm_apm_supportedms,

�



z#DiskPlugin._is_hdparm_apm_supportedcCs2|jdko0|j�dd�dko0|jdup0|jjdvS)N�diskZ	removable�0)ZscsiZvirtioZxenZnvme)Zdevice_typeZ
attributes�get�parentZ	subsystem)�clsr8r,r,r-r5�s
�

�zDiskPlugin._device_is_supportedcCs|j�|d|j�dS)Nr.)r4Z	subscribe�_hardware_events_callbackr;r,r,r-�_hardware_events_init�sz DiskPlugin._hardware_events_initcCs|j�|�dS�N)r4Zunsubscriber;r,r,r-�_hardware_events_cleanup�sz#DiskPlugin._hardware_events_cleanupcs(|�|�s|dkr$tt|��||�dS)N�remove)r5rrrT)r'Zeventr8r*r,r-rT�sz$DiskPlugin._hardware_events_callbackcs,|jdur|j�|�tt|��||�dSrV)�
_load_monitorZ
add_devicerr�_added_device_apply_tuning�r'�instance�device_namer*r,r-rZ�s
z%DiskPlugin._added_device_apply_tuningcs,|jdur|j�|�tt|��||�dSrV)rYZ
remove_devicerr�_removed_device_unapply_tuningr[r*r,r-r^�s
z)DiskPlugin._removed_device_unapply_tuningcCsdddddddd�S)NT)�dynamic�elevator�apm�spindown�	readahead�readahead_multiply�scheduler_quantumr,�rSr,r,r-�_get_config_options�s�zDiskPlugin._get_config_optionscCsddgS)Nrarbr,rfr,r,r-�#_get_config_options_used_by_dynamic�s�z.DiskPlugin._get_config_options_used_by_dynamiccCs.d|_d|_d|_d|_|�|jd�|_dS)NTrr_)Z_has_static_tuning�_apm_errcnt�_spindown_errcntrYZ_option_bool�optionsZ_has_dynamic_tuning�r'r\r,r,r-�_instance_init�s
zDiskPlugin._instance_initcCs"|jdur|j�|j�d|_dSrV)rY�_monitors_repository�deleterlr,r,r-�_instance_cleanup�s
zDiskPlugin._instance_cleanupcs>tt|��|�i|_i|_i|_i|_|j�d|j	�|_
dS)NrO)rr�_instance_init_dynamicZ_device_idle�_stats�_idle�_spindown_change_delayedrnZcreateZassigned_devicesrYrlr*r,r-rq�s�z!DiskPlugin._instance_init_dynamiccCs�|rd}|j}n
d}|j}|tjkr(dS|dkr6d}nL|tjkrbtjd|_|_t�d�dS|d7}|tjkr�t�d|�|r�||_n||_dS)NrbrarrzIhdparm command not found, ignoring future set_apm / set_spindown commandsz5disabling set_%s command: too many consecutive errors)	rjri�consts�ERROR_THRESHOLDrErFrGrHrI)r'rKrb�sZcntr,r,r-�_update_errcnt�s&


zDiskPlugin._update_errcntcCsNt�d|�|jjdd|d|gtjgd�\}}|�|d�d|j|<dS)Nzchanging spindown to %dr?z-S%drA�rBTF)rGrJr&rDrErFrxrt)r'r\r8�new_spindown_levelrKrLr,r,r-�_change_spindown�s&zDiskPlugin._change_spindowncCs2|jjddd|gtjgd�\}}d|vo0d|vS)Nr?r@rAryZstandbyZsleeping)r&rDrErF)r'r8rKrLr,r,r-�_drive_spinning�s"zDiskPlugin._drive_spinningcCs&|�|�sdS|j�|�}|dur&dS||jvr<|�||�|�|||�|�||�|j|}|j|}|dd|jkr�|d|j	kr�|d|j	kr�d}n.|ddkr�|ddks�|ddkr�d}nd}|dk�r�|d|7<|j
|d}|j|d}t�
d|d�|jtjk�r`|�|��sR|dk�rRt�
d|�d	|j|<n|�|||�|jtjk�r�t�
d
|�|jjdd|d
|gtjgd�\}	}
|�|	d�n4|j|�r�|�|��r�|j|d}|�|||�t�
d||d|df�t�
d||d|d|df�dS)N�levelr�read�writer���ztuning level changed to %dz;delaying spindown change to %d, drive has already spun downTzchanging APM_level to %dr?z-B%drAryFz %s load: read %0.2f, write %0.2fz$%s idle: read %d, write %d, level %d)rNrYZget_device_loadrr�_init_stats_and_idle�
_update_stats�_update_idlersr#r$r r!rGrJrjrurvr|rtr{rir&rDrErFrx)r'r\r8�loadZstatsZidleZlevel_changeZnew_power_levelrzrKrLr,r,r-�_instance_update_dynamic�sF



.$
&z#DiskPlugin._instance_update_dynamiccCsDddgddgddgd�|j|<dddd�|j|<d|j|<dS)N�rr)�new�old�max)r}r~rF)rrrsrt�r'r\r8r,r,r-r�s$zDiskPlugin._init_stats_and_idlecCs�|j|d|j|d<}||j|d<dd�t||�D�}||j|d<|j|d}dd�t||�D�}||j|d<t|d�t|d�|j|d	<t|d
�t|d
�|j|d<dS)Nr�r�cSsg|]}|d|d�qS)rrr,)r9Znew_oldr,r,r-r<'r=z,DiskPlugin._update_stats.<locals>.<listcomp>�diffr�cSsg|]}t|��qSr,)r�)r9Zpairr,r,r-r<,r=rr~�r)rr�zip�float)r'r\r8Znew_loadZold_loadr�Zold_max_loadZmax_loadr,r,r-r�"s"zDiskPlugin._update_statscCsHdD]>}|j|||jkr4|j||d7<qd|j||<qdS)N)r~rrr)rrr%rs)r'r\r8Z	operationr,r,r-r�3szDiskPlugin._update_idlecs0|�|�st�d|�ntt|��||�dS)Nz<There is no dynamic tuning available for device '%s' at time)rNrGrIrr�_instance_apply_dynamicr�r*r,r-r�;s
z"DiskPlugin._instance_apply_dynamiccCsdSrVr,r�r,r,r-�_instance_unapply_dynamicDsz$DiskPlugin._instance_unapply_dynamic�/sys/block/cCs@d|vr0tj�||�dd�|�}tj�|�r0|Stj�|||�S)N�/�!)�os�path�join�replace�exists)r'r8�suffix�prefix�devr,r,r-�_sysfs_pathGs
zDiskPlugin._sysfs_pathcCs|�|d�S)Nzqueue/scheduler�r�r7r,r,r-�_elevator_fileNszDiskPlugin._elevator_filer`T)Z
per_devicecCs0|�|�}|s,|jj|||r$tjgndd�|S)NF�Zno_error)r�r&�
write_to_filerErF�r'�valuer8r\�simrX�sys_filer,r,r-�
_set_elevatorQs

�zDiskPlugin._set_elevatorFcCs"|�|�}|j�|jj||d��S)Nr�)r�r&Zget_active_option�	read_file)r'r8r\�ignore_missingr�r,r,r-�
_get_elevatorYs
zDiskPlugin._get_elevatorracCs||�|�s(|s t�d|�dSt|�S|jtjkrt|sl|jjddt|�d|gt	j
gd�\}}|�|d�t|�SdSdS)N�+apm option is not supported for device '%s'r?�-B�/dev/ryF)rNrGrI�strrirurvr&rDrErFrx�r'r�r8r\r�rXrKrLr,r,r-�_set_apm`s
(zDiskPlugin._set_apmc	Cs�|�|�s |st�d|�dSd}d}|jjddd|gtjgd�\}}|tjkrZdS|dkrhd}n>t�d	|tj	�}|r�zt
|�d
��}Wnty�d}Yn0|r�t�
d|�|S)Nr�Fr?r�r�ryrTz
.*=\s*(\d+).*rz2could not get current APM settings for device '%s')rNrGrIr&rDrErF�re�match�S�int�group�
ValueError�error)	r'r8r\r�r��errrKrL�mr,r,r-�_get_apmps(
"
zDiskPlugin._get_apmrbcCs||�|�s(|s t�d|�dSt|�S|jtjkrt|sl|jjddt|�d|gt	j
gd�\}}|�|d�t|�SdSdS)N�0spindown option is not supported for device '%s'r?z-Sr�ryT)rNrGrIr�rjrurvr&rDrErFrxr�r,r,r-�
_set_spindown�s
(zDiskPlugin._set_spindowncCs$|�|�s |st�d|�dSdS)Nr��)rNrGrI)r'r8r\r�r,r,r-�
_get_spindown�s

zDiskPlugin._get_spindowncCs|�|d�S)Nzqueue/read_ahead_kbr�r7r,r,r-�_readahead_file�szDiskPlugin._readahead_filecCs^t|��dd�}zt|d�}Wnty4YdS0t|�dkrZ|dddkrZ|d}|S)Nrrrw�)r��splitr�r�r")r'r��val�vr,r,r-�	_parse_ra�szDiskPlugin._parse_rarccCsZ|�|�}|�|�}|dur0t�d||f�n&|sV|jj|d||rNtjgndd�|S)Nz,Invalid readahead value '%s' for device '%s'�%dFr�)r�r�rGr�r&r�rErF)r'r�r8r\r�rXr�r�r,r,r-�_set_readahead�s

�zDiskPlugin._set_readaheadcCs6|�|�}|jj||d���}t|�dkr.dSt|�S)Nr�r)r�r&r��stripr"r��r'r8r\r�r�r�r,r,r-�_get_readahead�s

zDiskPlugin._get_readaheadrdc
Cs�|rdS|jd|d�}|rd|�||�}|dur2dStt|�|�}	|j�||�|�|	||dd�n6|j�|�}|dur|dS|�|||dd�|j�|�dS)Nrd)Zcommand_namer]F)	Z_storage_keyr�r�r�Z_storager1r�rQZunset)
r'ZenablingZ
multiplierr8Zverifyr�r\Zstorage_keyZ
old_readaheadZ
new_readaheadr,r,r-�_multiply_readahead�s$�zDiskPlugin._multiply_readaheadcCs|�|d�S)Nzqueue/iosched/quantumr�r7r,r,r-�_scheduler_quantum_file�sz"DiskPlugin._scheduler_quantum_filerecCs8|�|�}|s4|jj|dt|�|r,tjgndd�|S)Nr�Fr�)r�r&r�r�rErFr�r,r,r-�_set_scheduler_quantum�s
�z!DiskPlugin._set_scheduler_quantumcCsH|�|�}|jj||d���}t|�dkr@|s<t�d|�dSt|�S)Nr�rz>disk_scheduler_quantum option is not supported for device '%s')r�r&r�r�r"rGrIr�r�r,r,r-�_get_scheduler_quantum�s
z!DiskPlugin._get_scheduler_quantum)r�)F)F)F)F)F)1�__name__�
__module__�__qualname__�__doc__rr/r>rN�classmethodr5rUrWrTrZr^rgrhrmrprqrxr{r|r�r�r�r�r�r�r�r�Zcommand_setr�Zcommand_getr�r�r�r�r�r�r�r�r�Zcommand_customr�r�r�r��
__classcell__r,r,r*r-rsnH



		2	












r)rE�rZ
decoratorsZ
tuned.logsZtunedZtuned.constsruZtuned.utils.commandsrr�r�ZlogsrQrGZPluginrr,r,r,r-�<module>s