Differences between revisions 1 and 2
Revision 1 as of 2006-10-10 06:12:12
Size: 1264
Comment:
Revision 2 as of 2006-10-10 22:46:40
Size: 2059
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
This page describes possible malloc (or PyMem_Malloc) replacements to be used for memory management in SAGE which is not directly controlled by Python as manual malloc calls, the GMP library etc. This page describes possible malloc replacements to be used for memory management in SAGE which is not directly controlled by Python such as manual malloc/realloc calls, the GMP library etc..

== PyMem_Malloc ==
The Python memory manager does keep track of some previous allocated, unused, but not yet freed blocks so it should be faster than malloc itself. It is currently used in GMP and Pyrex code in SAGE.
Line 15: Line 18:
== default libCF Memory Manager ==
 * GPL
 * seems to be faster for Integer addition than Python's manager
{{{#!python
sage: from sage.memory import * #only in my (malb) working copy
Line 16: Line 24:
== libCF old Memory Manager ==
 * GPL
 * default memory manager for libCF
 * ZZ(3) + ZZ(5) with PyMem_Malloc: 8.21 microseconds, with the old libCF memory manager: 7.5 microseconds
# PyMem_Malloc
sage: x = 5; y = 3
sage: %timeit _ = x+y
100000 loops, best of 3: 8.15 microseconds per loop
Line 21: Line 29:
# default libCF memory manager
sage: memman_malloc()
sage: %timeit _ = x+y
100000 loops, best of 3: 7.36 microseconds per loop
}}}
 
Line 27: Line 41:
 *  {{{Short description of the Givaro memory mechanism:
each request of sz bytes returns the smallest bloc that contains
at least sz bytes. Each bloc begins by a private data used to store
size information or a pointer. All free blocs are linked in list.
The allocation algorithm search in the corresponding list a free bloc,
before call the system "malloc" routine.
512 different sizes of bloc are predefined.
The maximum bloc size is 8054880 bytes.
 * Short description of the Givaro memory mechanism: each request of sz bytes returns the smallest bloc that contains at least sz bytes. Each bloc begins by a private data used to store size information or a pointer. All free blocs are linked in list. The allocation algorithm search in the corresponding list a free bloc, before call the system "malloc" routine. 512 different sizes of bloc are predefined. The maximum bloc size is 8054880 bytes.
Line 36: Line 43:
 * Seems to be slower than PyMem_Malloc for Integer addition
{{{#!python
sage: from sage.memory import *
sage: x = 5; y = 3

# PyMem_Malloc
sage: %timeit _ = x+y
100000 loops, best of 3: 8.15 microseconds per loop

# GivaroMM
sage: givaro_malloc()
sage: %timeit _ = x+y
100000 loops, best of 3: 8.36 microseconds per loop

Malloc Replacements

This page describes possible malloc replacements to be used for memory management in SAGE which is not directly controlled by Python such as manual malloc/realloc calls, the GMP library etc..

PyMem_Malloc

The Python memory manager does keep track of some previous allocated, unused, but not yet freed blocks so it should be faster than malloc itself. It is currently used in GMP and Pyrex code in SAGE.

OMalloc

  • currently non-free
  • supposed to be very fast
  • drop-in ?

DLMalloc

  • LGPL
  • used by OMalloc
  • unsure what it does

default libCF Memory Manager

  • GPL
  • seems to be faster for Integer addition than Python's manager

   1 sage: from sage.memory import * #only in my (malb) working copy
   2 
   3 # PyMem_Malloc
   4 sage: x = 5; y = 3
   5 sage: %timeit _ = x+y
   6 100000 loops, best of 3: 8.15 microseconds per loop
   7 
   8 # default libCF memory manager
   9 sage: memman_malloc()
  10 sage: %timeit _ = x+y
  11 100000 loops, best of 3: 7.36 microseconds per loop

libCF new Memory Manager

  • GPL
  • crashed on me ([:MartinAlbrecht:malb]) when trying to use it from withing SAGE

GivMM

  • GPL
  • Short description of the Givaro memory mechanism: each request of sz bytes returns the smallest bloc that contains at least sz bytes. Each bloc begins by a private data used to store size information or a pointer. All free blocs are linked in list. The allocation algorithm search in the corresponding list a free bloc, before call the system "malloc" routine. 512 different sizes of bloc are predefined. The maximum bloc size is 8054880 bytes.

For higher bloc, the manager directly call malloc/free of the underlaying system.

  • Seems to be slower than PyMem_Malloc for Integer addition

   1 sage: from sage.memory import *
   2 sage: x = 5; y = 3
   3 
   4 # PyMem_Malloc
   5 sage: %timeit _ = x+y
   6 100000 loops, best of 3: 8.15 microseconds per loop
   7 
   8 # GivaroMM
   9 sage: givaro_malloc()
  10 sage: %timeit _ = x+y
  11 100000 loops, best of 3: 8.36 microseconds per loop