Tech News
← Back to articles

Memstop: Use LD_PRELOAD to delay process execution when low on memory

read original related products more articles

Memstop

A lightweight LD_PRELOAD shared object that delays process execution when system memory is critically low. Memstop monitors available memory and waits until a configurable percentage of memory becomes available before allowing the application to start.

Purpose

Memstop is designed to prevent crashes caused by memory exhaustion in parallel processing systems. It can be particularly useful in:

Parallel build systems (like make -j ) where you want to prevent the build from failing due to the OOM (out-of-memory) killer

) where you want to prevent the build from failing due to the OOM (out-of-memory) killer Batch processing systems where you want to ensure adequate memory before starting jobs

High-memory applications that might crash the system if started when memory is low

How It Works

When loaded as a shared object (via LD_PRELOAD ), memstop automatically runs before your application's and all subprocesses' main() functions. It:

Reads system memory information from /proc/meminfo Calculates the required available memory percentage (default: 10%) Waits until the specified percentage of memory is available Releases control to your application once memory requirements are met

... continue reading