a ”ˆ«h­"ã@snddlmZddlTddlZddlZddlZddlZddlZddl m Z ej   ¡Z e ƒZGdd„dejƒZdS)é)Úbase)Ú*éN)Úcommandsc@seZdZdZedd„ƒZedd„ƒZedd„ƒZdd „Z d d „Z ed d „ƒZ e 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 r r 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Ú ValueErrorr?r,Z_storageÚsetr-Úget)rrZ counterpartZ check_funrMr0rNZ option_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#Z command_setr4r5Z command_getr8r9r;r<rArDrFZcommand_customrOrQrRrSrJrrrrrsF              r)ÚrZ decoratorsZ tuned.logsZtunedrr.ÚstructÚglobZtuned.utils.commandsrZlogsrWrr)ZPluginrrrrrÚs