mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 03:12:22 +00:00
openvz: determine kb/pages only once
to save some syscalls (as suggested by Eric Blake)
This commit is contained in:
parent
c086af6b9b
commit
80fd8367c9
@ -353,7 +353,8 @@ PHYP_DRIVER_SOURCES = \
|
||||
|
||||
OPENVZ_DRIVER_SOURCES = \
|
||||
openvz/openvz_conf.c openvz/openvz_conf.h \
|
||||
openvz/openvz_driver.c openvz/openvz_driver.h
|
||||
openvz/openvz_driver.c openvz/openvz_driver.h \
|
||||
openvz/openvz_util.c openvz/openvz_util.h
|
||||
|
||||
VMWARE_DRIVER_SOURCES = \
|
||||
vmware/vmware_driver.c vmware/vmware_driver.h \
|
||||
|
@ -45,6 +45,7 @@
|
||||
|
||||
#include "virterror_internal.h"
|
||||
#include "openvz_conf.h"
|
||||
#include "openvz_util.h"
|
||||
#include "uuid.h"
|
||||
#include "buf.h"
|
||||
#include "memory.h"
|
||||
@ -470,16 +471,11 @@ openvzReadMemConf(virDomainDefPtr def, int veid)
|
||||
char *temp = NULL;
|
||||
unsigned long long barrier, limit;
|
||||
const char *param;
|
||||
unsigned long kb_per_pages;
|
||||
long kb_per_pages;
|
||||
|
||||
kb_per_pages = sysconf(_SC_PAGESIZE);
|
||||
if (kb_per_pages > 0) {
|
||||
kb_per_pages /= 1024;
|
||||
} else {
|
||||
openvzError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Can't determine page size"));
|
||||
kb_per_pages = openvzKBPerPages();
|
||||
if (kb_per_pages < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Memory allocation guarantee */
|
||||
param = "VMGUARPAGES";
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include "virterror_internal.h"
|
||||
#include "datatypes.h"
|
||||
#include "openvz_driver.h"
|
||||
#include "openvz_util.h"
|
||||
#include "buf.h"
|
||||
#include "util.h"
|
||||
#include "openvz_conf.h"
|
||||
@ -1683,14 +1684,9 @@ openvzDomainGetMemoryParameters(virDomainPtr domain,
|
||||
|
||||
virCheckFlags(0, -1);
|
||||
|
||||
kb_per_pages = sysconf(_SC_PAGESIZE);
|
||||
if (kb_per_pages > 0) {
|
||||
kb_per_pages /= 1024;
|
||||
} else {
|
||||
openvzError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Can't determine page size"));
|
||||
kb_per_pages = openvzKBPerPages();
|
||||
if (kb_per_pages < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (*nparams == 0) {
|
||||
*nparams = OPENVZ_NB_MEM_PARAM;
|
||||
@ -1754,14 +1750,9 @@ openvzDomainSetMemoryParameters(virDomainPtr domain,
|
||||
int i, result = -1;
|
||||
long kb_per_pages;
|
||||
|
||||
kb_per_pages = sysconf(_SC_PAGESIZE);
|
||||
if (kb_per_pages > 0) {
|
||||
kb_per_pages /= 1024;
|
||||
} else {
|
||||
openvzError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Can't determine page size"));
|
||||
kb_per_pages = openvzKBPerPages();
|
||||
if (kb_per_pages < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
virCheckFlags(0, -1);
|
||||
if (virTypedParameterArrayValidate(params, nparams,
|
||||
|
51
src/openvz/openvz_util.c
Normal file
51
src/openvz/openvz_util.c
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* openvz_driver.c: core driver methods for managing OpenVZ VEs
|
||||
*
|
||||
* Copyright (C) 2012 Guido Günther
|
||||
*
|
||||
* 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#include "virterror_internal.h"
|
||||
|
||||
#include "openvz_conf.h"
|
||||
#include "openvz_util.h"
|
||||
|
||||
|
||||
long
|
||||
openvzKBPerPages(void)
|
||||
{
|
||||
static long kb_per_pages = 0;
|
||||
|
||||
if (kb_per_pages == 0) {
|
||||
kb_per_pages = sysconf(_SC_PAGESIZE);
|
||||
if (kb_per_pages > 0) {
|
||||
kb_per_pages /= 1024;
|
||||
} else {
|
||||
openvzError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Can't determine page size"));
|
||||
kb_per_pages = 0;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return kb_per_pages;
|
||||
}
|
28
src/openvz/openvz_util.h
Normal file
28
src/openvz/openvz_util.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* openvz_driver.h: common util functions for managing openvz VPEs
|
||||
*
|
||||
* Copyright (C) 2012 Guido Günther
|
||||
*
|
||||
* 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OPENVZ_UTIL_H
|
||||
# define OPENVZ_UTIL_H
|
||||
|
||||
long openvzKBPerPages(void);
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user