Information about available RAM/swap

There is no portable way to figure these out, nor should you generally have to. But GAP currently needs to allocate a cache of fixed size upon startup, and we would like a certain fraction of the swap address space.

EXAMPLES:

sage: from sage.misc.memory_info import MemoryInfo, MemoryInfo_proc
sage: mem = MemoryInfo()
sage: mem.total_ram()          # random output
16708194304
sage: mem.available_ram()      # random output
1690738688
sage: mem.total_swap()         # random output
15728635904
sage: mem.available_swap()     # random output
15340593152
sage.misc.memory_info.MemoryInfo()

Provide information about memory

OUTPUT:

A class that is encapsulates memory information. If no method for the particular host OS is provided, reasonable guesses are given.

EXAMPLES:

sage: from sage.misc.memory_info import MemoryInfo, MemoryInfo_proc
sage: mem = MemoryInfo()
sage: mem.total_ram()       # random output
16708194304
sage: mem.available_ram()   # random output
1690738688
sage: mem.total_swap()      # random output
15728635904
sage: mem.available_swap()  # random output
15340593152
class sage.misc.memory_info.MemoryInfo_OSX

Bases: sage.misc.memory_info.MemoryInfo_base

Memory info on OSX

TESTS:

sage: from sage.misc.memory_info import MemoryInfo_OSX
available_ram()

Return the available (free) RAM size

OUTPUT:

Integer. The free RAM size in bytes.

EXAMPLES:

sage: from sage.misc.memory_info import MemoryInfo
sage: MemoryInfo().available_ram() > 0
True
available_swap()

Return the available (free) swap size

The OSX swap file is growing dynamically, so we just return twice the available ram.

OUTPUT:

Integer. The free swap size in bytes.

EXAMPLES:

sage: from sage.misc.memory_info import MemoryInfo
sage: MemoryInfo().available_swap() in ZZ
True
total_ram()

Return the total RAM size

OUTPUT:

Integer. The RAM size in bytes.

EXAMPLES:

sage: from sage.misc.memory_info import MemoryInfo
sage: MemoryInfo().total_ram() > 0
True
total_swap()

Return the total swap size

The OSX swap file is growing dynamically, so we just return twice the total ram.

OUTPUT:

Integer. The swap size in bytes.

EXAMPLES:

sage: from sage.misc.memory_info import MemoryInfo
sage: MemoryInfo().total_swap() >= 0
True
class sage.misc.memory_info.MemoryInfo_base

Bases: sage.structure.sage_object.SageObject

Base class for memory info objects.

rlimit_address_space()

Return RLIMIT_AS.

OUTPUT:

Integer. The limit in bytes or \(-1\) if no limit is set or cannot be found out.

EXAMPLES:

sage: from sage.misc.memory_info import MemoryInfo
sage: mem = MemoryInfo()
sage: mem.rlimit_address_space() in ZZ
True
virtual_memory_limit()

Return the upper limit for virtual memory usage

This is the value set by ulimit -v at the command line (bounded by sys.maxsize) or a practical limit if no limit is set.

OUTPUT:

Integer. The virtual memory limit in bytes.

EXAMPLES:

sage: from sage.misc.memory_info import MemoryInfo
sage: mem = MemoryInfo()
sage: mem.virtual_memory_limit() > 0
True
sage: mem.virtual_memory_limit() <= sys.maxsize
True
class sage.misc.memory_info.MemoryInfo_guess

Bases: sage.misc.memory_info.MemoryInfo_base

Guess memory as a fallback.

TESTS:

sage: from sage.misc.memory_info import MemoryInfo_guess
sage: mem = MemoryInfo_guess()
sage: mem.total_ram()
4294967296       # 64-bit
4294967296L      # 32-bit
available_ram()

Return the available (free) RAM size

OUTPUT:

Integer. The free RAM size in bytes.

EXAMPLES:

sage: from sage.misc.memory_info import MemoryInfo
sage: MemoryInfo().available_ram() > 0
True
available_swap()

Return the available (free) swap size

OUTPUT:

Integer. The free swap size in bytes.

EXAMPLES:

sage: from sage.misc.memory_info import MemoryInfo
sage: MemoryInfo().available_swap() in ZZ
True
total_ram()

Return the total RAM size

OUTPUT:

Integer. The RAM size in bytes.

EXAMPLES:

sage: from sage.misc.memory_info import MemoryInfo
sage: MemoryInfo().total_ram() > 0
True
total_swap()

Return the total swap size

OUTPUT:

Integer. The swap size in bytes.

EXAMPLES:

sage: from sage.misc.memory_info import MemoryInfo
sage: MemoryInfo().total_swap() >= 0
True
class sage.misc.memory_info.MemoryInfo_proc

Bases: sage.misc.memory_info.MemoryInfo_base

Provide information from /proc/ pseudo-filesystem on most UNIXes

EXAMPLES:

sage: from sage.misc.memory_info import MemoryInfo
sage: mem = MemoryInfo()
sage: mem.total_ram()   # random output
16708194304
available_ram()

Return the available (free) RAM size

OUTPUT:

Integer. The free RAM size in bytes.

EXAMPLES:

sage: from sage.misc.memory_info import MemoryInfo
sage: MemoryInfo().available_ram() > 0
True
available_swap()

Return the available (free) swap size

OUTPUT:

Integer. The free swap size in bytes, excluding reserved swap space. Can be negative if the system is overcommitting memory.

EXAMPLES:

sage: from sage.misc.memory_info import MemoryInfo
sage: MemoryInfo().available_swap() in ZZ
True
total_ram()

Return the total RAM size

OUTPUT:

Integer. The RAM size in bytes.

EXAMPLES:

sage: from sage.misc.memory_info import MemoryInfo
sage: MemoryInfo().total_ram() > 0
True
total_swap()

Return the total swap size

OUTPUT:

Integer. The swap size in bytes.

EXAMPLES:

sage: from sage.misc.memory_info import MemoryInfo
sage: MemoryInfo().total_swap() >= 0
True