Skip to content

Commit 130a7ed

Browse files
committed
Rename preprocessor flag, make easy to override.
1 parent 509a5c7 commit 130a7ed

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
Add a radix tree to track used obmalloc arenas. Use to replace the old
2-
implementation of address_in_range(). The radix tree approach makes it easy
3-
to increase pool sizes beyond the OS page size. Boosting the pool and arena
4-
size allows obmalloc to handle a significantly higher percentage of requests
5-
from its ultra-fast paths.
1+
Add a radix tree based memory map to track in-use obmalloc arenas. Use to
2+
replace the old implementation of address_in_range(). The radix tree
3+
approach makes it easy to increase pool sizes beyond the OS page size.
4+
Boosting the pool and arena size allows obmalloc to handle a significantly
5+
higher percentage of requests from its ultra-fast paths.
66

77
It also has the advantage of eliminating the memory unsanitary behavior of
88
the previous address_in_range(). The old address_in_range() was marked with
99
the annotations _Py_NO_SANITIZE_ADDRESS, _Py_NO_SANITIZE_THREAD, and
1010
_Py_NO_SANITIZE_MEMORY. Those annotations are no longer needed.
1111

12+
To disable the radix tree map, set a preprocessor flag as follows:
13+
`-DWITH_PYMALLOC_RADIX_TREE=0`.
14+
1215
Co-authored-by: Tim Peters <[email protected]>

Objects/obmalloc.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -894,13 +894,17 @@ static int running_on_valgrind = -1;
894894
#endif
895895
#endif
896896

897-
/* use radix-tree to track arena memory regions, for address_in_range() */
898-
#define USE_RADIX_TREE
897+
#if !defined(WITH_PYMALLOC_RADIX_TREE)
898+
/* Use radix-tree to track arena memory regions, for address_in_range().
899+
* Enable by default since it allows larger pool sizes. Can be disabled
900+
* using -DWITH_PYMALLOC_RADIX_TREE=0 */
901+
#define WITH_PYMALLOC_RADIX_TREE 1
902+
#endif
899903

900904
#if SIZEOF_VOID_P > 4
901905
/* on 64-bit platforms use larger pools and arenas if we can */
902906
#define USE_LARGE_ARENAS
903-
#ifdef USE_RADIX_TREE
907+
#if WITH_PYMALLOC_RADIX_TREE
904908
/* large pools only supported if radix-tree is enabled */
905909
#define USE_LARGE_POOLS
906910
#endif
@@ -942,9 +946,9 @@ static int running_on_valgrind = -1;
942946
#define POOL_SIZE (1 << POOL_BITS)
943947
#define POOL_SIZE_MASK (POOL_SIZE - 1)
944948

945-
#ifndef USE_RADIX_TREE
949+
#if !WITH_PYMALLOC_RADIX_TREE
946950
#if POOL_SIZE != SYSTEM_PAGE_SIZE
947-
# error "pool size must be system page size"
951+
# error "pool size must be equal to system page size"
948952
#endif
949953
#endif
950954

@@ -1261,7 +1265,7 @@ _Py_GetAllocatedBlocks(void)
12611265
return n;
12621266
}
12631267

1264-
#ifdef USE_RADIX_TREE
1268+
#if WITH_PYMALLOC_RADIX_TREE
12651269
/*==========================================================================*/
12661270
/* radix tree for tracking arena usage
12671271
@@ -1514,7 +1518,7 @@ arena_map_is_used(block *p)
15141518

15151519
/* end of radix tree logic */
15161520
/*==========================================================================*/
1517-
#endif /* USE_RADIX_TREE */
1521+
#endif /* WITH_PYMALLOC_RADIX_TREE */
15181522

15191523

15201524
/* Allocate a new arena. If we run out of memory, return NULL. Else
@@ -1585,7 +1589,7 @@ new_arena(void)
15851589
unused_arena_objects = arenaobj->nextarena;
15861590
assert(arenaobj->address == 0);
15871591
address = _PyObject_Arena.alloc(_PyObject_Arena.ctx, ARENA_SIZE);
1588-
#ifdef USE_RADIX_TREE
1592+
#if WITH_PYMALLOC_RADIX_TREE
15891593
if (address != NULL) {
15901594
if (!arena_map_mark_used((uintptr_t)address, 1)) {
15911595
/* marking arena in radix tree failed, abort */
@@ -1625,7 +1629,7 @@ new_arena(void)
16251629

16261630

16271631

1628-
#ifdef USE_RADIX_TREE
1632+
#if WITH_PYMALLOC_RADIX_TREE
16291633
/* Return true if and only if P is an address that was allocated by
16301634
pymalloc. When the radix tree is used, 'poolp' is unused.
16311635
*/
@@ -1726,7 +1730,7 @@ address_in_range(void *p, poolp pool)
17261730
arenas[arenaindex].address != 0;
17271731
}
17281732

1729-
#endif /* !USE_RADIX_TREE */
1733+
#endif /* !WITH_PYMALLOC_RADIX_TREE */
17301734

17311735
/*==========================================================================*/
17321736

@@ -2072,7 +2076,7 @@ insert_to_freepool(poolp pool)
20722076
ao->nextarena = unused_arena_objects;
20732077
unused_arena_objects = ao;
20742078

2075-
#ifdef USE_RADIX_TREE
2079+
#if WITH_PYMALLOC_RADIX_TREE
20762080
/* mark arena region as not under control of obmalloc */
20772081
arena_map_mark_used(ao->address, 0);
20782082
#endif

0 commit comments

Comments
 (0)