libvirt/src/util/virhostmem.h
Michal Privoznik 45aa4c1d2a virhostmem: Introduce virHostMemGetTHPSize()
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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-01 10:58:27 +02:00

61 lines
2.2 KiB
C

/*
* virhostmem.h: helper APIs for host memory info
*
* Copyright (C) 2006-2016 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "internal.h"
int virHostMemGetStats(int cellNum,
virNodeMemoryStatsPtr params,
int *nparams,
unsigned int flags);
int virHostMemGetCellsFree(unsigned long long *freeMems,
int startCell,
int maxCells);
int virHostMemGetInfo(unsigned long long *mem,
unsigned long long *freeMem);
int virHostMemGetParameters(virTypedParameterPtr params,
int *nparams,
unsigned int flags);
int virHostMemSetParameters(virTypedParameterPtr params,
int nparams,
unsigned int flags);
int virHostMemGetFreePages(unsigned int npages,
unsigned int *pages,
int startCell,
unsigned int cellCount,
int lastCell,
unsigned long long *counts);
int virHostMemAllocPages(unsigned int npages,
unsigned int *pageSizes,
unsigned long long *pageCounts,
int startCell,
unsigned int cellCount,
int lastCell,
bool add);
int virHostMemGetTHPSize(unsigned long long *size)
G_GNUC_NO_INLINE;