lsmem
Overview
The lsmem
command displays information about memory ranges and their online/offline status. It’s particularly useful for systems with memory hotplug capabilities and NUMA architectures.
Syntax
lsmem [options]
Common Options
Option | Description |
---|---|
-a |
List all memory ranges |
-b |
Show output in bytes |
-h |
Human-readable sizes |
-o columns |
Specify output columns |
-r |
Raw output format |
-S |
Split by node |
-s |
Show summary only |
--sysroot=dir |
Use alternative sysfs root |
Output Columns
Column | Description |
---|---|
RANGE | Memory address range |
SIZE | Size of memory range |
STATE | Online/Offline status |
REMOVABLE | Whether memory can be removed |
BLOCK | Memory block number |
NODE | NUMA node number |
ZONES | Memory zones |
Key Use Cases
- Memory inventory
- NUMA topology analysis
- Memory hotplug management
- System capacity planning
- Memory troubleshooting
Examples with Explanations
Example 1: Basic Memory Information
lsmem
Shows memory ranges and their status
Example 2: Human-Readable Sizes
lsmem -h
Displays memory sizes in human-readable format (KB, MB, GB)
Example 3: Summary Only
lsmem -s
Shows only summary information
Understanding Memory States
State | Description |
---|---|
online | Memory is available for use |
offline | Memory is not available |
going-offline | Memory is being taken offline |
going-online | Memory is being brought online |
Memory Block Management
Memory is managed in blocks: - Block size typically 128MB or 256MB - Blocks can be individually onlined/offlined - Useful for memory hotplug operations
Common Usage Patterns
Check total memory:
lsmem -s | grep "Total online memory"
List offline memory:
lsmem | grep offline
Show NUMA distribution:
lsmem -S
NUMA Memory Information
For NUMA systems: - Shows memory distribution across nodes - Helps with memory locality optimization - Useful for performance tuning
Memory Hotplug Operations
Check removable memory:
lsmem | grep "yes" | grep "REMOVABLE"
Find offline blocks:
lsmem -a | awk '$3=="offline" {print $4}'
Performance Analysis
Memory information useful for: - Memory bandwidth optimization - NUMA-aware application tuning - Memory pressure analysis - Capacity planning
Additional Resources
Best Practices
- Monitor memory hotplug status
- Understand NUMA topology
- Check removable memory before maintenance
- Use with other memory analysis tools
- Consider memory block alignment
Scripting Examples
Count online memory blocks:
lsmem | grep -c "online"
Get total memory size:
lsmem -s | grep "Total online memory" | awk '{print $4}'
Check NUMA nodes:
lsmem -o NODE | grep -v NODE | sort -u
Memory Zones
Common memory zones: - DMA: Direct Memory Access zone - DMA32: 32-bit DMA zone - Normal: Regular memory zone - HighMem: High memory zone (32-bit systems) - Movable: Memory that can be migrated
System Integration
Memory monitoring:
watch -n 5 'lsmem -s'
NUMA optimization:
lsmem -S | grep "node 0"
Capacity reporting:
echo "Total Memory: $(lsmem -s | grep 'Total online' | awk '{print $4}')"
Troubleshooting
- Memory not showing up
- Offline memory blocks
- NUMA node misalignment
- Memory hotplug failures
- Inconsistent memory reporting
Advanced Usage
Custom column output:
lsmem -o RANGE,SIZE,STATE,NODE
Raw format for parsing:
lsmem -r
Alternative sysfs root:
lsmem --sysroot=/alternative/path
Memory Block Operations
To manage memory blocks (requires root):
# Online a memory block
echo online > /sys/devices/system/memory/memory64/state
# Offline a memory block
echo offline > /sys/devices/system/memory/memory64/state
Integration Examples
With NUMA tools:
lsmem -S && numactl --hardware
Memory pressure monitoring:
lsmem -s && free -h
System inventory:
echo "Memory Layout:" && lsmem -h
Output Formatting
Specific columns:
lsmem -o SIZE,STATE | column -t
Summary with details:
lsmem -s && echo "---" && lsmem
Node-specific information:
lsmem | awk '$6==0 {print}' # Node 0 only