[PATCH v2 01/13] virhostmem: Introduce virHostMemGetTHPSize()
Peter Krempa
pkrempa at redhat.com
Thu Feb 18 14:02:07 UTC 2021
On Thu, Feb 18, 2021 at 14:30:56 +0100, Michal Privoznik wrote:
> New virHostMemGetTHPSize() is introduced which allows caller to
> obtain THP PMD (Page Middle Directory) size, which is equal to
> the minimal size that THP can use, taken from kernel doc
> (Documentation/admin-guide/mm/transhuge.rst):
>
> Some userspace (such as a test program, or an optimized memory allocation
> library) may want to know the size (in bytes) of a transparent hugepage::
>
> cat /sys/kernel/mm/transparent_hugepage/hpage_pmd_size
>
> Since this size depends on the host architecture and the kernel
> it won't change whilst libvirtd is running. Therefore, we can use
> virOnce() and cache the value. Of course, we can be running under
> kernel that has THP disabled or has no notion of THP at all. In
> that case a negative value is returned to signal error.
>
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
> src/libvirt_private.syms | 1 +
> src/util/virhostmem.c | 63 ++++++++++++++++++++++++++++++++++++++++
> src/util/virhostmem.h | 3 ++
> tests/domaincapsmock.c | 9 ++++++
> 4 files changed, 76 insertions(+)
[...]
> diff --git a/src/util/virhostmem.c b/src/util/virhostmem.c
> index ae42978ed2..ef7b97806f 100644
> --- a/src/util/virhostmem.c
> +++ b/src/util/virhostmem.c
> @@ -45,11 +45,14 @@
> #include "virstring.h"
> #include "virnuma.h"
> #include "virlog.h"
> +#include "virthread.h"
>
> #define VIR_FROM_THIS VIR_FROM_NONE
>
> VIR_LOG_INIT("util.hostmem");
>
> +static unsigned long long virHostTHPPMDSize;
Please add a comment that it's in kiB.
> +static virOnceControl virHostMemGetTHPSizeOnce = VIR_ONCE_CONTROL_INITIALIZER;
More information about the libvir-list
mailing list