3 d?Z"e d=d\d@dAZ#edBd6d7dCdDZ$e dBd]dEdFZ%dGdHZ&dIdJZ'edKd6d7dLdMZ(e dKd^dNdOZ)e*dPd6d7dQdRZ+dSdTZ,edUd6d7dVdWZ-e dUd_dXdYZ.Z/S)` DiskPlugina `disk`:: 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] # Comma separated list of devices, all devices if commented out. devices=sda ---- ==== + The [option]`elevator` option sets the Linux I/O scheduler. + .Use the bfq I/O scheduler on 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. c srtt|j||ddddddddd d d d g |_d dddddddddd dg |_t|j|_d|_d|_t |_ dS)N}iUF7rnZ<g{Gz?) superr__init__ _power_levels_spindown_levelslen_levels _level_steps_load_smallestr_cmd)selfargskwargs) __class__!/usr/lib/python3.6/plugin_disk.pyrXs zDiskPlugin.__init__cstt|jd|_d|_t|_t|_xL|jj dD]<}|j |r8|jj |j |jr8|j |j r8|jj |j q8Wt|_dS)NTblock)rr _init_devicesZ_devices_supported _use_hdparmsetZ _free_devices_hdparm_apm_devices_hardware_inventoryZ get_devices_device_is_supportedaddZsys_name_is_hdparm_apm_supportedZ_assigned_devices)r'device)r*r+r,r.bs zDiskPlugin._init_devicescsfdd|DS)Ncsg|]}jjd|qS)r-)r2Z get_device).0x)r'r+r, qsz2DiskPlugin._get_device_objects..r+)r'Zdevicesr+)r'r,_get_device_objectspszDiskPlugin._get_device_objectscCs|jjddd|gtjgdd\}}}|tj krFtjdd|_dS|rntjd|tjd ||fdSd |krtjd |dSdS) Nhdparmz-Cz/dev/%sT) no_errorsZ return_errz4hdparm command not found, ignoring for other devicesFz#Device '%s' not supported by hdparmz(rc: %s, msg: '%s')unknownz3Driver for device '%s' does not support apm command) r&executeerrnoENOENTlogwarnr/infodebug)r'r6rcoutZerr_msgr+r+r,r5ss  z#DiskPlugin._is_hdparm_apm_supportedcCs2|jdko0|jjdddko0|jdkp0|jjdkS) NdiskZ removable0scsivirtioxennvme)rIrJrKrL)Z device_typeZ attributesgetparentZ subsystem)clsr6r+r+r,r3s  zDiskPlugin._device_is_supportedcCs|jj|d|jdS)Nr-)r2Z subscribe_hardware_events_callback)r'r+r+r,_hardware_events_initsz DiskPlugin._hardware_events_initcCs|jj|dS)N)r2Z unsubscribe)r'r+r+r,_hardware_events_cleanupsz#DiskPlugin._hardware_events_cleanupcs(|j|s|dkr$tt|j||dS)Nremove)r3rrrP)r'Zeventr6)r*r+r,rPsz$DiskPlugin._hardware_events_callbackcs,|jdk r|jj|tt|j||dS)N) _load_monitorZ add_devicerr_added_device_apply_tuning)r'instance device_name)r*r+r,rUs  z%DiskPlugin._added_device_apply_tuningcs,|jdk r|jj|tt|j||dS)N)rTZ remove_devicerr_removed_device_unapply_tuning)r'rVrW)r*r+r,rXs  z)DiskPlugin._removed_device_unapply_tuningcCsddddddddS)NT)dynamicelevatorapmspindown readaheadreadahead_multiplyscheduler_quantumr+)rOr+r+r,_get_config_optionsszDiskPlugin._get_config_optionscCsddgS)Nr[r\r+)rOr+r+r,#_get_config_options_used_by_dynamicsz.DiskPlugin._get_config_options_used_by_dynamiccCsdd|_d|_d|_|j|jdrTd|_|jjd|j|_ i|_ i|_ i|_ i|_ n d|_d|_ dS)NTrrYrGF)Z_has_static_tuning _apm_errcnt_spindown_errcntZ _option_boolZoptionsZ_has_dynamic_tuning_monitors_repositoryZcreateZassigned_devicesrTZ _device_idle_stats_idle_spindown_change_delayed)r'rVr+r+r,_instance_inits zDiskPlugin._instance_initcCs"|jdk r|jj|jd|_dS)N)rTrddelete)r'rVr+r+r,_instance_cleanups zDiskPlugin._instance_cleanupcCs|rd}|j}n d}|j}|tjkr(dS|dkr6d}nL|tj krbtjd|_|_tjddS|d7}|tjkrtjd||r||_n||_dS)Nr\r[rrzIhdparm command not found, ignoring future set_apm / set_spindown commandsz5disabling set_%s command: too many consecutive errors) rcrbconstsERROR_THRESHOLDr?r@rArBrC)r'rEr\sZcntr+r+r,_update_errcnts&    zDiskPlugin._update_errcntcCsNtjd||jjdd|d|gtjgd\}}|j|dd|j|<dS)Nzchanging spindown to %dr;z-S%dz/dev/%s)r<TF)rArDr&r>r?r@rnrg)r'rVr6new_spindown_levelrErFr+r+r,_change_spindowns& zDiskPlugin._change_spindowncCs2|jjddd|gtjgd\}}d|ko0d|kS)Nr;z-Cz/dev/%s)r<ZstandbyZsleeping)r&r>r?r@)r'r6rErFr+r+r,_drive_spinnings"zDiskPlugin._drive_spinningc Cs(||jkrdS|jj|}|dkr&dS||jkr<|j|||j||||j|||j|}|j|}|dd|jkr|d|j kr|d|j krd}n.|ddkr|ddks|ddkrd}nd}|dkr|d|7<|j |d}|j |d}t j d|d|jtjkrb|j| rT|dkrTt j d|d|j|<n|j||||jtjkrt j d ||jjd d |d |gtjgd \} } |j| dn4|j|r|j|r|j |d}|j|||t j d||d|dft j d||d|d|dfdS)Nlevelrreadwriterztuning level changed to %dz;delaying spindown change to %d, drive has already spun downTzchanging APM_level to %dr;z-B%dz/dev/%s)r<Fz %s load: read %0.2f, write %0.2fz$%s idle: read %d, write %d, level %d)r1rTZget_device_loadre_init_stats_and_idle _update_stats _update_idlerfr#r$r r!rArDrcrkrlrqrgrprbr&r>r?r@rn) r'rVr6loadZstatsZidleZ level_changeZnew_power_levelrorErFr+r+r,_instance_update_dynamicsF       .$  &z#DiskPlugin._instance_update_dynamiccCsDddgddgddgd|j|<dddd|j|<d|j|<dS)N rr)newoldmax)rrrsrtF)rerfrg)r'rVr6r+r+r,rvs$zDiskPlugin._init_stats_and_idlecCs|j|d|j|d<}||j|d<ddt||D}||j|d<|j|d}ddt||D}||j|d<t|dt|d|j|d <t|d t|d |j|d <dS) Nr|r}cSsg|]}|d|dqS)rrr+)r7Znew_oldr+r+r,r9'sz,DiskPlugin._update_stats..diffr~cSsg|] }t|qSr+)r~)r7Zpairr+r+r,r9,srrsrt)rezipfloat)r'rVr6Znew_loadZold_loadrZ old_max_loadZmax_loadr+r+r,rw"s"zDiskPlugin._update_statscCsLxFdD]>}|j|||jkr6|j||d7<qd|j||<qWdS)Nrsrtrr)rsrt)rer%rf)r'rVr6Z operationr+r+r,rx3s zDiskPlugin._update_idlecs0||jkrtjd|ntt|j||dS)Nzr?r@rn)r'rr6rrSrErFr+r+r,_set_apm`s  ( zDiskPlugin._set_apmc Cs||jkr |stjd|dSd}d}|jjddd|gtjgd\}}|tj krZdS|dkrhd}n@tjd |tj }|ryt |j d }Wnt k rd}YnX|rtj d ||S) Nz+apm option is not supported for device '%s'Fr;z-Bz/dev/)r<rTz .*=\s*(\d+).*rz2could not get current APM settings for device '%s')r1rArCr&r>r?r@rematchSintgroup ValueErrorerror)r'r6rrerrrErFmr+r+r,_get_apmps( "  zDiskPlugin._get_apmr\cCs|||jkr(|s tjd|dSt|S|jtjkrt|sl|jjddt|d|gt j gd\}}|j |dt|SdSdS)Nz0spindown option is not supported for device '%s'r;z-Sz/dev/)r<T) r1rArCrrcrkrlr&r>r?r@rn)r'rr6rrSrErFr+r+r, _set_spindowns  ( zDiskPlugin._set_spindowncCs$||jkr |stjd|dSdS)Nz0spindown option is not supported for device '%s')r1rArC)r'r6rr+r+r, _get_spindowns  zDiskPlugin._get_spindowncCs |j|dS)Nzqueue/read_ahead_kb)r)r'r6r+r+r,_readahead_fileszDiskPlugin._readahead_filec Cs^t|jdd}yt|d}Wntk r4dSXt|dkrZ|dddkrZ|d}|S)Nrrrm)rsplitrrr")r'rvalvr+r+r, _parse_raszDiskPlugin._parse_rar]cCsZ|j|}|j|}|dkr0tjd||fn&|sV|jj|d||rNtjgndd|S)Nz,Invalid readahead value '%s' for device '%s'z%dF)r)rrrArr&rr?r@)r'rr6rrSrrr+r+r,_set_readaheads  zDiskPlugin._set_readaheadcCs6|j|}|jj||dj}t|dkr.dSt|S)N)rr)rr&rstripr"r)r'r6rrrr+r+r,_get_readaheads   zDiskPlugin._get_readaheadr^c Cs|rdS|jd|d}|r^|j|}|dkr0dStt||}|jj|||j||dn2|jj|}|dkrvdS|j||d|jj|dS)Nr^)Z command_namerWF) Z _storage_keyrrrZ_storager0rrMZunset) r'ZenablingZ multiplierr6ZverifyrZ storage_keyZ old_readaheadZ new_readaheadr+r+r,_multiply_readaheads"  zDiskPlugin._multiply_readaheadcCs |j|dS)Nzqueue/iosched/quantum)r)r'r6r+r+r,_scheduler_quantum_filesz"DiskPlugin._scheduler_quantum_filer_cCs8|j|}|s4|jj|dt||r,tjgndd|S)Nz%dF)r)rr&rrr?r@)r'rr6rrSrr+r+r,_set_scheduler_quantums  z!DiskPlugin._set_scheduler_quantumcCsH|j|}|jj||dj}t|dkr@|sdisk_scheduler_quantum option is not supported for device '%s')rr&rrr"rArCr)r'r6rrrr+r+r,_get_scheduler_quantums  z!DiskPlugin._get_scheduler_quantum)r)F)F)F)F)F)0__name__ __module__ __qualname____doc__rr.r:r5 classmethodr3rQrRrPrUrXr`rarhrjrnrprqrzrvrwrxrrrrZ command_setrZ command_getrrrrrrrrrZcommand_customrrrr __classcell__r+r+)r*r,r sZJ      2        r)r?rZ decoratorsZ tuned.logsZtunedZ tuned.constsrkZtuned.utils.commandsrrrZlogsrMrAZPluginrr+r+r+r,s