🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

Linux Memory Profiling with Python: Per-Process RSS, Swap, and Application Memory Analysis (Free CLI Tool)

Linux Memory Profiling with Python: Per-Process RSS, Swap, and Application Memory Analysis (Free CLI Tool)

Memory management is one of the most challenging aspects of Linux system administration. Understanding which processes are consuming the most memory, how much is shared between processes, and whether swap is being used excessively requires systematic profiling.

dargslan-memory-profiler is a free Python CLI tool that gives you a complete memory profile of your Linux system. It reads directly from the /proc filesystem — zero dependencies, instant results.

Quick Start

pip install dargslan-memory-profiler

dargslan-memprof report        # Full memory profile report
dargslan-memprof system        # System memory overview
dargslan-memprof top -n 30     # Top 30 processes by RSS
dargslan-memprof grouped       # Memory grouped by application
dargslan-memprof shm           # Shared memory segments
dargslan-memprof issues        # Memory issues audit

Understanding Linux Memory Metrics

Linux memory metrics can be confusing. Here is what matters:

  • RSS (Resident Set Size): Physical memory actually used by a process. This includes shared libraries, so summing RSS across all processes overestimates total usage.
  • PSS (Proportional Set Size): RSS divided proportionally for shared pages. Summing PSS gives accurate total memory usage.
  • VSize: Virtual memory allocated. Much larger than RSS because it includes unmapped and swapped pages.
  • Swap: Memory that has been moved to disk. High swap usage means the system needs more RAM.

Grouping Memory by Application

The grouped command aggregates memory by process name. This is invaluable for understanding which applications (not just individual processes) are consuming the most memory. For example, you might see 50 Apache worker processes totaling 2 GB of RSS.

Python API

from dargslan_memory_profiler import MemoryProfiler

mp = MemoryProfiler()
sys_mem = mp.get_system_memory()
print(f"Used: {sys_mem['used_human']} ({sys_mem['used_percent']}%)")

for proc in mp.get_all_processes(limit=10):
    print(f"PID {proc['pid']} {proc.get('name','?')}: {proc.get('rss_human','N/A')}")

for group in mp.get_memory_by_name()[:5]:
    print(f"{group['name']}: {group['total_rss_human']} ({group['count']} procs)")

Detecting Memory Issues

The audit feature checks for critical memory conditions: overall usage above 80% (warning) or 90% (critical), high swap usage, and individual processes consuming more than 25% of total system memory.

Best Practices

  1. Monitor PSS rather than RSS for accurate per-process accounting
  2. Watch swap usage trends — increasing swap indicates a memory shortage
  3. Set up alerts when overall memory usage exceeds 80%
  4. Use the grouped view to identify memory-hungry applications
  5. Check shared memory segments for orphaned allocations

Conclusion

Memory profiling is essential for capacity planning and troubleshooting performance issues. dargslan-memory-profiler gives you instant, detailed memory visibility across your entire system. Install it and make memory profiling part of your monitoring routine.

For more Linux tools, visit dargslan.com.

Share this article:
Dargslan Editorial Team (Dargslan)
About the Author

Dargslan Editorial Team (Dargslan)

Collective of Software Developers, System Administrators, DevOps Engineers, and IT Authors

Dargslan is an independent technology publishing collective formed by experienced software developers, system administrators, and IT specialists.

The Dargslan editorial team works collaboratively to create practical, hands-on technology books focused on real-world use cases. Each publication is developed, reviewed, and...

Programming Languages Linux Administration Web Development Cybersecurity Networking

Stay Updated

Subscribe to our newsletter for the latest tutorials, tips, and exclusive offers.