[Python-Dev] tracemalloc: add an optional memory limit

Serhiy Storchaka storchaka at gmail.com
Mon Dec 9 10:07:38 CET 2013

09.12.13 03:56, Victor Stinner написав(ла):
> On Linux, it's possible to limit globally the "address space" of a
> process, but this value is not convinient. For example, the address
> space includes shared memory and read-only memory mappings of files,
> whereas this memory should not reduce the memory available for other
> applications. tracemalloc only counts memory directly allocated by
> Python and so private memory which reduces directly the memory
> available for other applications.

But tracemalloc doesn't count memory allocated besides Python allocators 
(e.g. memory for executable, static variables and stack, memory 
allocated by extensions and C lib, unallocated but not returned to OS 
dynamical memory). When you want investigate how your program works on 
low memory, e.g. 500 MB, ulimit -v 500000 is much closer to real life 
than tracemalloc.

Limiting memory in tracemalloc can be used only for testing obscure 
corner cases in Python interpreter itself. It will be very rarely used 
since all bugs will be fixed first time (and thank you for your current 
work). So there is more sense implemented it as auxiliary utility than 
as feature of the stdlib module.

More information about the Python-Dev mailing list