Skip to content

Commit fa086d0

Browse files
author
Prasanna Santhanam
committed
CLOUDSTACK-2554: Ensuring that we honor hypervisor xen's memory constraints
When setting memory constraints on Xen guests we should honor: static-min <= dynamic-min <= dynamic-max <= static-max Our VmSpec while allows the guests to like between dynamic-min and dynamic-max the memory set by the resource set the static min to be equal to the dynamic max. This restricts the hypervisor from ensuring optimized memory handling of guests. see: http://wiki.xen.org/wiki/XCP_FAQ_Dynamic_Memory_Control#How_does_XCP_choose_targets_for_guests_in_dynamic_range_mode.3F Another fix was related the restrict_dmc option. when enabled (true) this option disallows scaling a vm. The logic was reverse handled allowing scaling when restrict_dmc was on. This control flow is now fixed. Signed-off-by: Prasanna Santhanam <tsp@apache.org>
1 parent ac48c38 commit fa086d0

3 files changed

Lines changed: 98 additions & 36 deletions

File tree

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
335335
long _xs_memory_used = 128 * 1024 * 1024L; // xen hypervisor used 128 M
336336
double _xs_virtualization_factor = 63.0/64.0; // 1 - virtualization overhead
337337

338+
//static min values for guests on xen
339+
private static final long mem_128m = 134217728L;
340+
338341
protected boolean _canBridgeFirewall = false;
339342
protected boolean _isOvs = false;
340343
protected List<VIF> _tmpDom0Vif = new ArrayList<VIF>();
@@ -1208,8 +1211,11 @@ protected VM createVmFromTemplate(Connection conn, VirtualMachineTO vmSpec, Host
12081211
}
12091212
Set<VM> templates = VM.getByNameLabel(conn, guestOsTypeName);
12101213
assert templates.size() == 1 : "Should only have 1 template but found " + templates.size();
1214+
if (!templates.iterator().hasNext()) {
1215+
throw new CloudRuntimeException("No matching OS type found for starting a [" + vmSpec.getOs()
1216+
+ "] VM on host " + host.getHostname(conn));
1217+
}
12111218
VM template = templates.iterator().next();
1212-
12131219
VM vm = template.createClone(conn, vmSpec.getName());
12141220
VM.Record vmr = vm.getRecord(conn);
12151221
if (s_logger.isDebugEnabled()) {
@@ -3503,8 +3509,21 @@ protected void startvmfailhandle(Connection conn, VM vm, List<Ternary<SR, VDI, V
35033509
}
35043510
}
35053511

3512+
/**
3513+
* WARN: static-min <= dynamic-min <= dynamic-max <= static-max
3514+
* @see XcpServerResource#setMemory(com.xensource.xenapi.Connection, com.xensource.xenapi.VM, long, long)
3515+
* @param conn
3516+
* @param vm
3517+
* @param minMemsize
3518+
* @param maxMemsize
3519+
* @throws XmlRpcException
3520+
* @throws XenAPIException
3521+
*/
35063522
protected void setMemory(Connection conn, VM vm, long minMemsize, long maxMemsize) throws XmlRpcException, XenAPIException {
3507-
vm.setMemoryLimits(conn, maxMemsize, maxMemsize, minMemsize, maxMemsize);
3523+
vm.setMemoryStaticMin(conn, mem_128m);
3524+
vm.setMemoryDynamicMin(conn, minMemsize);
3525+
vm.setMemoryDynamicMax(conn, maxMemsize);
3526+
vm.setMemoryStaticMax(conn, maxMemsize);
35083527
}
35093528

35103529
protected void waitForTask(Connection c, Task task, long pollInterval, long timeout) throws XenAPIException, XmlRpcException {
@@ -4299,7 +4318,7 @@ protected VDI mount(Connection conn, StoragePoolType pooltype, String volumeFold
42994318
* @throws XenAPIException
43004319
* @throws XmlRpcException
43014320
*
4302-
* @see enableVlanNetwork
4321+
* @see CitrixResourceBase#enableVlanNetwork
43034322
*/
43044323
protected XsLocalNetwork getNetworkByName(Connection conn, String name) throws XenAPIException, XmlRpcException {
43054324
Set<Network> networks = Network.getByNameLabel(conn, name);

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XcpServerResource.java‎

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
@Local(value=ServerResource.class)
3838
public class XcpServerResource extends CitrixResourceBase {
3939
private final static Logger s_logger = Logger.getLogger(XcpServerResource.class);
40+
private static final long mem_32m = 33554432L;
41+
4042
private String version;
4143

4244
public XcpServerResource() {
@@ -70,20 +72,6 @@ protected String getGuestOsType(String stdType, boolean bootFromCD) {
7072
return CitrixHelper.getXcpGuestOsType(stdType);
7173
}
7274

73-
@Override
74-
protected void setMemory(Connection conn, VM vm, long minMemsize, long maxMemsize) throws XmlRpcException, XenAPIException {
75-
76-
vm.setMemoryStaticMin(conn, 33554432L);
77-
//vm.setMemoryDynamicMin(conn, 33554432L);
78-
//vm.setMemoryDynamicMax(conn, 33554432L);
79-
vm.setMemoryStaticMax(conn, 33554432L);
80-
81-
//vm.setMemoryStaticMax(conn, maxMemsize );
82-
vm.setMemoryDynamicMax(conn, maxMemsize );
83-
vm.setMemoryDynamicMin(conn, minMemsize );
84-
//vm.setMemoryStaticMin(conn, maxMemsize );
85-
}
86-
8775
protected NetworkUsageAnswer execute(NetworkUsageCommand cmd) {
8876
try {
8977
Connection conn = getConnection();
@@ -100,4 +88,61 @@ protected NetworkUsageAnswer execute(NetworkUsageCommand cmd) {
10088
return new NetworkUsageAnswer(cmd, ex);
10189
}
10290
}
91+
92+
/**
93+
XCP provides four memory configuration fields through which
94+
administrators can control this behaviour:
95+
96+
* static-min
97+
* dynamic-min
98+
* dynamic-max
99+
* static-max
100+
101+
The fields static-{min,max} act as *hard* lower and upper
102+
bounds for a guest's memory. For a running guest:
103+
* it's not possible to assign the guest more memory than
104+
static-max without first shutting down the guest.
105+
* it's not possible to assign the guest less memory than
106+
static-min without first shutting down the guest.
107+
108+
The fields dynamic-{min,max} act as *soft* lower and upper
109+
bounds for a guest's memory. It's possible to change these
110+
fields even when a guest is running.
111+
112+
The dynamic range must lie wholly within the static range. To
113+
put it another way, XCP at all times ensures that:
114+
115+
static-min <= dynamic-min <= dynamic-max <= static-max
116+
117+
At all times, XCP will attempt to keep a guest's memory usage
118+
between dynamic-min and dynamic-max.
119+
120+
If dynamic-min = dynamic-max, then XCP will attempt to keep
121+
a guest's memory allocation at a constant size.
122+
123+
If dynamic-min < dynamic-max, then XCP will attempt to give
124+
the guest as much memory as possible, while keeping the guest
125+
within dynamic-min and dynamic-max.
126+
127+
If there is enough memory on a given host to give all resident
128+
guests dynamic-max, then XCP will attempt do so.
129+
130+
If there is not enough memory to give all guests dynamic-max,
131+
then XCP will ask each of the guests (on that host) to use
132+
an amount of memory that is the same *proportional* distance
133+
between dynamic-min and dynamic-max.
134+
135+
XCP will refuse to start guests if starting those guests would
136+
cause the sum of all the dynamic-min values to exceed the total
137+
host memory (taking into account various memory overheads).
138+
139+
cf: http://wiki.xen.org/wiki/XCP_FAQ_Dynamic_Memory_Control
140+
*/
141+
@Override
142+
protected void setMemory(Connection conn, VM vm, long minMemsize, long maxMemsize) throws XmlRpcException, XenAPIException {
143+
vm.setMemoryStaticMin(conn, mem_32m);
144+
vm.setMemoryDynamicMin(conn, minMemsize);
145+
vm.setMemoryDynamicMax(conn, maxMemsize);
146+
vm.setMemoryStaticMax(conn, maxMemsize);
147+
}
103148
}

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer56FP1Resource.java‎

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,6 @@
1717
package com.cloud.hypervisor.xen.resource;
1818

1919

20-
import java.io.File;
21-
import java.util.ArrayList;
22-
import java.util.HashMap;
23-
import java.util.HashSet;
24-
import java.util.List;
25-
import java.util.Map;
26-
import java.util.Set;
27-
28-
import javax.ejb.Local;
29-
import org.apache.log4j.Logger;
30-
import org.apache.xmlrpc.XmlRpcException;
31-
3220
import com.cloud.agent.api.FenceAnswer;
3321
import com.cloud.agent.api.FenceCommand;
3422
import com.cloud.agent.api.to.VirtualMachineTO;
@@ -39,13 +27,23 @@
3927
import com.cloud.utils.exception.CloudRuntimeException;
4028
import com.cloud.utils.script.Script;
4129
import com.xensource.xenapi.Connection;
42-
import com.xensource.xenapi.Console;
4330
import com.xensource.xenapi.Host;
4431
import com.xensource.xenapi.Types;
32+
import com.xensource.xenapi.Types.XenAPIException;
4533
import com.xensource.xenapi.VBD;
4634
import com.xensource.xenapi.VDI;
4735
import com.xensource.xenapi.VM;
48-
import com.xensource.xenapi.Types.XenAPIException;
36+
import org.apache.log4j.Logger;
37+
import org.apache.xmlrpc.XmlRpcException;
38+
39+
import javax.ejb.Local;
40+
import java.io.File;
41+
import java.util.ArrayList;
42+
import java.util.HashMap;
43+
import java.util.HashSet;
44+
import java.util.List;
45+
import java.util.Map;
46+
import java.util.Set;
4947

5048
@Local(value=ServerResource.class)
5149
public class XenServer56FP1Resource extends XenServer56Resource {
@@ -137,17 +135,17 @@ protected VM createVmFromTemplate(Connection conn, VirtualMachineTO vmSpec, Host
137135
record.nameLabel = vmSpec.getName();
138136
record.actionsAfterCrash = Types.OnCrashBehaviour.DESTROY;
139137
record.actionsAfterShutdown = Types.OnNormalExit.DESTROY;
140-
record.memoryDynamicMax = vmSpec.getMaxRam();
141138
record.memoryDynamicMin = vmSpec.getMinRam();
139+
record.memoryDynamicMax = vmSpec.getMaxRam();
142140
Map<String, String> hostParams = new HashMap<String, String>();
143141
hostParams = host.getLicenseParams(conn);
144142
if (hostParams.get("restrict_dmc").equalsIgnoreCase("false")) {
145-
record.memoryStaticMax = 8589934592L; //8GB
146-
record.memoryStaticMin = 134217728L; //128MB
143+
record.memoryStaticMin = vmSpec.getMinRam();
144+
record.memoryStaticMax = vmSpec.getMaxRam();
147145
} else {
148146
s_logger.warn("Host "+ _host.uuid + " does not support Dynamic Memory Control, so we cannot scale up the vm");
149-
record.memoryStaticMax = vmSpec.getMaxRam();
150-
record.memoryStaticMin = vmSpec.getMinRam();
147+
record.memoryStaticMin = 134217728L; //128MB
148+
record.memoryStaticMax = 8589934592L; //8GB
151149
}
152150

153151
if (guestOsTypeName.toLowerCase().contains("windows")) {

0 commit comments

Comments
 (0)