3 YdN @sfddlmZddlTddlZddlZddlZddlZddlm Z ej j Z e Z GdddejZdS))base)*N)commandsc@seZdZdZeddZddZddZedd Ze d d d Z e d ddZ e d ddZ e d ddZe dddZe dddZdS)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 ddddS)N)transparent_hugepagestransparent_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_cleanup0szVMPlugin._instance_cleanupcCsd}tjj|sd}|S)Nz#/sys/kernel/mm/transparent_hugepagez*/sys/kernel/mm/redhat_transparent_hugepage)ospathexists)r rr r r _thp_path3s zVMPlugin._thp_pathrcCs|d kr"|stjdt|dStjddd}|jdd krP|sLtjd dStjj |j d }tjj |r|s~tj |||S|stjd dSdS)Nalwaysnevermadvisez-Incorrect 'transparent_hugepages' value '%s'.z /proc/cmdlineT)Zno_errorztransparent_hugepage=rzWtransparent_hugepage is already set in kernel boot cmdline, ignoring value from profileenabledzDOption 'transparent_hugepages' is not supported on current hardware.)rrr) logwarnstrcmd read_filefindinforrjoinrr write_to_file)r valuesimZcmdlinesys_filer r r _set_transparent_hugepages;s"    z#VMPlugin._set_transparent_hugepagesrcCs|j||dS)N)r$)r r!r"r r r _set_transparent_hugepageSsz"VMPlugin._set_transparent_hugepagecCs6tjj|jd}tjj|r.tjtj|SdSdS)Nr)rrrrrrget_active_optionr)r r#r r r _get_transparent_hugepagesWs z#VMPlugin._get_transparent_hugepagescCs|jS)N)r')r r r r _get_transparent_hugepage`sz"VMPlugin._get_transparent_hugepageztransparent_hugepage.defragcCsHtjj|jd}tjj|r2|s.tj|||S|s@tjddSdS)NdefragzJOption 'transparent_hugepage.defrag' is not supported on current hardware.) rrrrrrr rr)r r!r"r#r r r _set_transparent_hugepage_defragds   z)VMPlugin._set_transparent_hugepage_defragcCs6tjj|jd}tjj|r.tjtj|SdSdS)Nr))rrrrrrr&r)r r#r r r _get_transparent_hugepage_defragps 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 r s    r)rZ decoratorsZ tuned.logsZtunedrstructZglobZtuned.utils.commandsrZlogsgetrrZPluginrr r r r s