Revision f078c799

b/lib/hypervisor/hv_lxc.py
43 43
  TODO:
44 44
    - move hardcoded parameters into hypervisor parameters, once we
45 45
      have the container-parameter support
46
    - implement memory limits, but only optionally, depending on host
47
      kernel support
48 46

  
49 47
  Problems/issues:
50 48
    - LXC is very temperamental; in daemon mode, it succeeds or fails
......
143 141

  
144 142
    return utils.ParseCpuMask(cpus)
145 143

  
144
  @classmethod
145
  def _GetCgroupMemoryLimit(cls, instance_name):
146
    """Return the memory limit for an instance
147

  
148
    """
149
    cgroup = cls._GetCgroupMountPoint()
150
    try:
151
      memory = int(utils.ReadFile(utils.PathJoin(cgroup, 'lxc',
152
                                           instance_name,
153
                                           "memory.limit_in_bytes")))
154
    except EnvironmentError:
155
      # memory resource controller may be disabled, ignore
156
      memory = 0
157

  
158
    return memory
159

  
146 160
  def ListInstances(self):
147 161
    """Get the list of running instances.
148 162

  
......
154 168

  
155 169
    @type instance_name: string
156 170
    @param instance_name: the instance name
157

  
171
    @rtype: tuple of strings
158 172
    @return: (name, id, memory, vcpus, stat, times)
159 173

  
160 174
    """
......
172 186
      return None
173 187

  
174 188
    cpu_list = self._GetCgroupCpuList(instance_name)
175
    return (instance_name, 0, 0, len(cpu_list), 0, 0)
189
    memory = self._GetCgroupMemoryLimit(instance_name) / (1024 ** 2)
190
    return (instance_name, 0, memory, len(cpu_list), 0, 0)
176 191

  
177 192
  def GetAllInstancesInfo(self):
178 193
    """Get properties of all instances.
......
230 245
      out.append("lxc.cgroup.cpuset.cpus = %s" %
231 246
                 instance.hvparams[constants.HV_CPU_MASK])
232 247

  
248
    # Memory
249
    # Conditionally enable, memory resource controller might be disabled
250
    cgroup = self._GetCgroupMountPoint()
251
    if os.path.exists(utils.PathJoin(cgroup, 'memory.limit_in_bytes')):
252
        out.append("lxc.cgroup.memory.limit_in_bytes = %dM" %
253
                    instance.beparams[constants.BE_MAXMEM])
254

  
255
    if os.path.exists(utils.PathJoin(cgroup, 'memory.memsw.limit_in_bytes')):
256
        out.append("lxc.cgroup.memory.memsw.limit_in_bytes = %dM" %
257
                    instance.beparams[constants.BE_MAXMEM])
258

  
233 259
    # Device control
234 260
    # deny direct device access
235 261
    out.append("lxc.cgroup.devices.deny = a")

Also available in: Unified diff