Removing memory

7.1 LPAR mode z/VM guest

You can remove memory from your Linux® instance by setting memory blocks offline.

About this task

Avoid removing core memory. The Linux kernel requires core memory to allocate its data structures.

Procedure

  • Use the chmem command with the -d parameter to set memory offline and the -b parameter to specify the target memory block.
    # chmem -d -b <blockno>
    You can specify the amount of memory you want to remove with the command without specifying particular memory blocks. The tool finds eligible memory blocks for you and sets the most suitable blocks offline.
    The memory block must be online before it can be set offline. This operation:
    • Sets the memory block offline.
    • Implicitly deconfigures it, if supported by the architecture.
    Typically, no separate deconfiguration step is required after chmem -d.

    Alternatively, if a memory block is configured but not online, deconfigure it directly:

    # chmem -g -b <blockno> 

    This applies to memory blocks that were previously configured, for example, with: # chmem -c -b <blockno> Such blocks are already offline, so they cannot be offlined using -d. They must be deconfigured explicitly using -g.

    For example, to implicitly deconfigure memory block 16 and set it offline:
    # chmem -d -b 16 -v
    Memory Block 16 (0x0000000080000000-0x0000000087ffffff) disabled
    Memory Block 16 (0x0000000080000000-0x0000000087ffffff) deconfigured
    
    # lsmem -o RANGE,SIZE,STATE,BLOCK,CONFIGURED,MEMMAP-ON-MEMORY
    RANGE                  SIZE   STATE BLOCK CONFIGURED MEMMAP-ON-MEMORY
    0x00000000-0x7fffffff    2G  online  0-15        yes               no
    0x80000000-0x87ffffff  128M offline    16         no              yes
    0x88000000-0xbfffffff  896M offline 17-23         no              yes
    
    Memory block size:                128M
    Total online memory:                2G
    Total offline memory:               1G
    Memmap on memory parameter:        yes
  • Alternatively, you can write offline to the sysfs state attribute of an unused memory block to set it offline.
    Issue a command of the form:
    # echo offline > /sys/devices/system/memory/memory<n>/state
    where <n> is an integer that identifies the memory unit. This operation only sets the memory block offline. The memory block remains configured, and deconfiguration must be performed separately if supported by the architecture.
    To completely remove the memory block, it must also be deconfigured explicitly, if supported by the architecture:
    # echo 0 > /sys/firmware/memory/memory<n>/config
    The memory block must be offline before it can be deconfigured.

Results

The hotplug memory functions first relocate memory pages to free the memory block and then remove it. The state attribute changes to offline when the memory block has been removed successfully. If supported, the memory block is automatically deconfigured during offlining with chmem -d.

The memory block is not removed if it cannot be freed completely.