3 À<×eé ã@snddlmZddlTddlZddlZddlZddlZddlZddl m Z ej j ƒZ e ƒZGdd„dejƒZdS)é)Úbase)Ú*éN)Úcommandsc@s˜eZdZdZedd„ƒZdd„Zdd„Zedd „ƒZe d ƒd d „ƒZ e d ƒdd„ƒZ e d ƒdd„ƒZ e d ƒdd„ƒZe dƒdd„ƒZe dƒdd„ƒZdS)ÚVMPlugina| `vm`:: Enables or disables transparent huge pages depending on 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]. cCs ddddœS)N)Útransparent_hugepagesÚtransparent_hugepageztransparent_hugepage.defrag©)Úselfr r ú/usr/lib/python3.6/plugin_vm.pyÚ_get_config_options%szVMPlugin._get_config_optionscCsd|_d|_dS)NTF)Z_has_static_tuningZ_has_dynamic_tuning)r Úinstancer r r Ú_instance_init-szVMPlugin._instance_initcCsdS)Nr )r r r r r Ú_instance_cleanup1szVMPlugin._instance_cleanupcCsd}tjj|ƒsd}|S)Nz#/sys/kernel/mm/transparent_hugepagez*/sys/kernel/mm/redhat_transparent_hugepage)ÚosÚpathÚexists)r rr r r Ú _thp_path4s zVMPlugin._thp_pathrcCs¨|dkr"|stjdt|ƒƒdStjddd�}|jdƒd krP|sLtjd ƒdStjj |j ƒd ƒ}tjj |ƒr’|sŽtj |||r†t jgnd d�|S|s tjd ƒdSdS)NÚalwaysÚneverÚmadvisez-Incorrect 'transparent_hugepages' value '%s'.z /proc/cmdlineT)Úno_errorztransparent_hugepage=rzWtransparent_hugepage is already set in kernel boot cmdline, ignoring value from profileÚenabledFzDOption 'transparent_hugepages' is not supported on current hardware.)rrr)ÚlogÚwarnÚstrÚcmdÚ read_fileÚfindÚinforrÚjoinrrÚ write_to_fileÚerrnoÚENOENT)r ÚvalueÚsimÚremoveZcmdlineÚsys_filer r r Ú_set_transparent_hugepages<s$   z#VMPlugin._set_transparent_hugepagesrcCs|j|||ƒdS)N)r()r r$r%r&r r r Ú_set_transparent_hugepageUsz"VMPlugin._set_transparent_hugepagecCs6tjj|jƒdƒ}tjj|ƒr.tjtj|ƒƒSdSdS)Nr)rrr rrrÚget_active_optionr)r r'r r r Ú_get_transparent_hugepagesYs z#VMPlugin._get_transparent_hugepagescCs|jƒS)N)r+)r r r r Ú_get_transparent_hugepagebsz"VMPlugin._get_transparent_hugepageztransparent_hugepage.defragcCsXtjj|jƒdƒ}tjj|ƒrB|s>tj|||r6tjgndd�|S|sPt j dƒdSdS)NÚdefragF)rzJOption 'transparent_hugepage.defrag' is not supported on current hardware.) rrr rrrr!r"r#rr)r r$r%r&r'r r r Ú _set_transparent_hugepage_defragfs  z)VMPlugin._set_transparent_hugepage_defragcCs6tjj|jƒdƒ}tjj|ƒr.tjtj|ƒƒSdSdS)Nr-)rrr rrrr*r)r r'r r r Ú _get_transparent_hugepage_defragss z)VMPlugin._get_transparent_hugepage_defragN)Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú classmethodr rrrZ command_setr(r)Z command_getr+r,r.r/r r r r rs    r)ÚrZ decoratorsZ tuned.logsZtunedrr"ÚstructZglobZtuned.utils.commandsrZlogsÚgetrrZPluginrr r r r Ús