CPU/Disk/Memory related task
CPU = brain, executes instruction RAM = short-term memory, Disk = long-term memory, GPU = specialized brain for graphics/math.
CPU
CPU theory and commands
Got it 👍 This is a big topic, so I’ll give you a complete reference on Linux CPU commands + theory. I’ll break it into:
Basics of CPU in Linux
Important files in
/procand/sysCommon commands for CPU info & usage
Performance monitoring tools
Advanced profiling & debugging tools
CPU-related system tuning
1. Basics of CPU in Linux
CPU (Central Processing Unit) executes instructions.
What is a CPU?
CPU stands for Central Processing Unit. It’s often called the “brain of the computer” because it executes instructions/program and controls most operations of the system.
Main Functions of a CPU
Fetch – Gets instructions from memory (RAM).
Decode – Interprets what the instruction means.
Execute – Performs the required action (arithmetic, logic, data movement).
Store – Writes the result back to memory or registers.
This cycle is called the Instruction Cycle.
Modern CPUs have:
Cores → independent processing units.
Threads (logical CPUs) → hardware multithreading (e.g., Intel Hyper-Threading).
Clock speed → cycles per second (GHz).
Caches → L1/L2/L3 memory close to CPU for speed.
Linux sees CPUs as logical processors (
/proc/cpuinfo).CPU usage = time spent in:
user (running user processes)
system (kernel code)
idle (nothing to do)
iowait (waiting for I/O)
steal (time stolen by hypervisor in VMs)
irq/softirq (handling interrupts)
2. Important Files
/proc/cpuinfo→ detailed CPU info (model, cores, flags)./proc/stat→ CPU usage statistics./proc/loadavg→ system load averages./sys/devices/system/cpu/→ CPU topology, governors, scaling, etc./proc/interrupts→ CPU interrupt distribution.
3. Commands for CPU Info & Usage
CPU Information
lscpu # Detailed CPU architecture info
cat /proc/cpuinfo # Per-core info
nproc # Number of available CPUs
getconf _NPROCESSORS_ONLN # Online processors
dmidecode -t processor # BIOS/firmware CPU infoCPU Usage (Snapshot)
top # Realtime processes + CPU usage
htop # Better interactive process viewer
uptime # Load averages
mpstat -P ALL 1 # Per-CPU usage (from sysstat package)
sar -u 1 5 # Historical CPU utilizationProcess CPU Usage
ps -eo pid,ppid,cmd,%cpu,%mem --sort=-%cpu | head # Top CPU hogs
pidstat -u 1 # Per-process CPU stats4. Performance Monitoring Tools
top/htop → live monitoring
atop → advanced system monitor
glances → all-in-one system monitor
dstat → resource usage over time
vmstat 1 → CPU, memory, processes
iostat -c 1 → CPU usage stats
5. Advanced Profiling & Debugging Tools
perf (Linux Performance Counters)
perf stat -a sleep 5 # CPU events for 5s perf top # Live CPU function usagestrace -c -p → syscall profiling per process
perf record / perf report → detailed profiling
ftrace → kernel tracing
bpftrace / eBPF tools → modern tracing, CPU flamegraphs
6. CPU Tuning & Management
CPU Frequency Scaling
cpupower frequency-info # Show CPU frequency
cpupower frequency-set -g performance # Change governorGovernors:
performance→ max speedpowersave→ min speedondemand/schedutil→ dynamic scaling
CPU Affinity (bind processes to cores)
taskset -c 0,2 <command> # Run on CPU 0 and 2
ps -o pid,psr,comm -p <pid> # Show CPU core of processNUMA (Non-Uniform Memory Access)
numactl --hardware # Show NUMA nodes
numactl --cpunodebind=0 command # Bind to NUMA node✅ Summary
Use
lscpuandcat /proc/cpuinfofor CPU details.Use
top/htop/mpstat/sarfor CPU usage.Use
perf/strace/eBPFfor deep analysis.Use
taskset/numactl/cpupowerfor tuning and control.
👉 Pavan, do you want me to also prepare a cheat sheet table with commands + short descriptions (so you can quickly refer during work/interview)?
Memory Theory and commands
Perfect 👍 Let’s do the same structured deep-dive for Linux Memory — just like we did for CPU.
📘 Linux Memory Commands & Theory
1. Basics of Memory in Linux
Memory (RAM) is fast, volatile storage (retaining data only as long as there is a power supply connected) used by CPU to run programs.
Linux uses virtual memory:
RAM (physical memory)
Swap space (disk used when RAM is full)
Memory management includes:
Paging – moving fixed-size pages between RAM & disk.
Swapping – moving entire processes.
Cache & Buffers – Linux caches disk/filesystem data in RAM to speed up performance.
Memory Types (as seen in Linux):
Used memory – actively in use by processes.
Free memory – not used at all.
Buffers – metadata for block devices.
Cache – cached file data (reclaimable if needed).
Swap – disk space used as extra RAM.
2. Important Files
/proc/meminfo→ detailed memory info./proc/swaps→ swap usage./proc/<pid>/status→ memory usage of a process./sys/devices/system/memory/→ memory hotplug info./proc/vmstat→ virtual memory statistics.
3. Commands for Memory Info & Usage
Memory Information
free -h # Human-readable memory usage
cat /proc/meminfo # Detailed memory stats
vmstat -s # Memory statistics
dmidecode -t memory # Hardware memory infoMemory Usage (Snapshot)
top # Shows memory usage per process
htop # Better visualization
glances # All-in-one system monitorPer-Process Memory
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head # Top memory hogs
smem -r # Memory usage with shared/private breakdown
pmap <pid> # Show memory map of a process
cat /proc/<pid>/status | grep VmRSS # Resident Set Size of a process4. Performance Monitoring Tools
vmstat 1 → CPU, memory, paging.
dstat --mem → memory over time.
sar -r 1 5 → memory utilization (sysstat package).
atop → advanced system monitor.
/proc/meminfo +
watch→ live memory stats.
5. Advanced Profiling & Debugging Tools
valgrind / massif → profile memory usage of programs.
memleax → detect memory leaks in running processes.
perf stat -e page-faults → track memory page faults.
bcc/eBPF tools (
memleak,cachestat,oomkill) → advanced memory tracing.numastat → NUMA memory stats.
6. Memory Tuning & Management
Swap Management
swapon -s # Show active swap
swapon /path/to/swapfile # Enable swap
swapoff -a # Disable all swapAdjust Swappiness (tendency to use swap)
cat /proc/sys/vm/swappiness
sysctl -w vm.swappiness=10Clear Cache (careful in production!)
echo 1 > /proc/sys/vm/drop_caches # Clear pagecache
echo 2 > /proc/sys/vm/drop_caches # Clear dentries and inodes
echo 3 > /proc/sys/vm/drop_caches # Clear all cachesMemory Limits (per process)
ulimit -m <bytes> # Limit max memory for a shell/process
cgroups (systemd) # Limit memory usage at container/service level✅ Summary
Use
free -h,cat /proc/meminfofor memory details.Use
top/htop/glancesfor usage.Use
pmap/smemfor per-process analysis.Use
valgrind,bcc/eBPF,perffor deep memory profiling.Tune with swappiness, drop_caches, cgroups.
👉 Pavan, do you want me to also prepare a cheat sheet table (commands + short description) for memory (like a one-page reference for interviews & work)?
Disk Theory and commands
Perfect 👍 Let’s make the Disk Commands & Theory in Linux reference, same structured way like CPU and Memory.
📘 Linux Disk Commands & Theory
1. Basics of Disks in Linux
Disk storage = permanent data storage (HDDs, SSDs, NVMe, SAN).
Linux sees disks as block devices (
/dev/sda,/dev/nvme0n1, etc.).Disks are divided into:
Partitions (
/dev/sda1,/dev/sda2)Filesystems (ext4, xfs, btrfs, etc.)
Disk I/O = Input/Output operations between memory and disk.
Metrics to monitor:
Capacity – total vs. used.
Throughput – MB/s read/write.
IOPS – I/O operations per second.
Latency – time taken per operation.
Utilization – percentage busy.
2. Important Files
/proc/partitions→ partitions info./proc/diskstats→ detailed disk I/O statistics./sys/block/*→ block device attributes (scheduler, queue size)./etc/fstab→ filesystem mount configuration./proc/mounts→ currently mounted filesystems.
3. Commands for Disk Info & Usage
Disk Information
lsblk # Block devices, partitions, mount points
fdisk -l # Partition tables
parted -l # More partition info
blkid # Block device attributes (UUID, type)
ls -l /dev/disk/by-uuid/ # UUID linksDisk Usage (Capacity)
df -h # Human-readable disk usage
du -sh /path # Disk usage of a directory
du -sh * # Disk usage of files/folders in current dir
find / -xdev -type f -size +100M # Find large filesDisk I/O Usage (Snapshot)
iostat -xz 1 # Disk utilization, IOPS, latency (sysstat package)
dstat -d 1 # Disk read/write per second
iotop # Top processes by I/O usage
vmstat -d # Disk statistics4. Performance Monitoring Tools
iostat → throughput, IOPS, latency.
iotop → per-process I/O usage.
dstat --disk → live disk stats.
atop → disk performance + bottlenecks.
collectl → lightweight all-in-one.
sar -d 1 5 → historical disk activity.
5. Advanced Profiling & Debugging Tools
blktrace → trace block layer I/O operations.
bpftrace/eBPF → monitor disk latency, queue depth.
fio → disk benchmarking (IOPS, throughput, latency).
dd → quick read/write performance check.
dd if=/dev/zero of=/tmp/testfile bs=1G count=1 oflag=dsyncsmartctl (from
smartmontools) → check disk health.smartctl -a /dev/sda
6. Disk Tuning & Management
Filesystem Management
mount /dev/sda1 /mnt # Mount a partition
umount /mnt # Unmount
tune2fs -l /dev/sda1 # ext filesystem parameters
xfs_info /mountpoint # xfs filesystem infoI/O Scheduler (for performance tuning)
cat /sys/block/sda/queue/scheduler
echo deadline > /sys/block/sda/queue/schedulerSchedulers:
cfq → default, fair sharing.
deadline → low-latency, predictable.
noop → minimal scheduling (good for SSDs).
Disk Quotas (limit user/group usage)
edquota -u username
repquota -a✅ Summary
Use
lsblk,fdisk,partedfor disk info.Use
df,dufor capacity usage.Use
iostat,iotop,dstatfor I/O performance.Use
fio,blktrace,smartctlfor advanced testing & debugging.Tune with I/O scheduler, quotas, filesystem settings.
👉 Pavan, do you want me to also prepare a single cheat sheet table that combines CPU + Memory + Disk commands (one-page reference for SRE/DevOps interviews)?
Last updated