Many RHEL 5 sysadmins face this exact frustration - you carefully configure top
to show memory usage in megabytes, only to find it reverts to kilobytes after restarting. The solution involves both runtime configuration and persistent settings.
While in top
interactive view, press these keys sequentially:
E (shift+e for memory scaling) m (for megabytes display)
This will temporarily change the display units, but won't persist between sessions.
For permanent changes, modify or create ~/.toprc
configuration file:
default_memory_units = "m"
After saving, run:
chmod 600 ~/.toprc
For all users on RHEL 5, edit the global configuration:
sudo vi /etc/toprc
Add the same memory unit setting, then set appropriate permissions:
sudo chmod 644 /etc/toprc
After configuration, verify the changes by:
top -n 1 | head -5
Expected output should show memory values in MB. If issues persist, check:
ls -la ~/.toprc cat ~/.toprc | grep memory
For scripting purposes where you need consistent MB output, consider:
top -b -n 1 | awk '/^Mem:/ {printf "Memory: %.1fMB\\n", $3/1024}'
This provides machine-readable output in MB regardless of top's configuration.
Many Red Hat EL5 administrators encounter this situation: after carefully configuring top
to display memory statistics in megabytes, the settings mysteriously revert to kilobytes after terminal sessions. The standard top
implementation in RHEL5 doesn't make this configuration obvious.
Method 1: Runtime Toggle
# While top is running:
Press 'E' (uppercase) to cycle through memory display units
Keep pressing until you see "MiB" in the summary header
Method 2: Persistent Configuration
# Create or modify ~/.toprc
echo "RCfile for \"top with windows\" # shameless braggin
Id:a, Mode_altscr=0, Mode_irixps=1, Delay_time=3.0, Curwin=0
Def fieldscur=AEHIOQTWKNMbcdfgjplrsuvyzX
winflags=32569, sortindx=15, maxtasks=0
summclr=1, msgsclr=1, headclr=3, taskclr=1
Mem scale=1024" > ~/.toprc
The critical line in the configuration is Mem scale=1024
which:
- Divides all memory values by 1024 (converting KB to MB)
- Persists across terminal sessions
- Works with both physical and swap memory displays
# 1. Launch top
top
# 2. Check header line should show:
# "MiB Mem : total used free buff/cache"
# Instead of KiB values
# 3. Check process memory columns show MB values
For system-wide configuration (requires root):
# Copy the config to /etc/toprc
cp ~/.toprc /etc/toprc
# Set appropriate permissions
chmod 644 /etc/toprc
To make the MB display more prominent, consider adding these to your .toprc
:
summarymsize=2 # Makes memory summary more visible
taskmsize=1 # Shows process memory in MB