@@ -2831,17 +2831,24 @@ _PyObject_DebugMallocStats(FILE *out)
2831
2831
# error "arena size must be < 2^32"
2832
2832
#endif
2833
2833
2834
+ /* Current 64-bit processors are limited to 48-bit physical addresses. For
2835
+ * now, the top 17 bits of addresses will all be equal to bit 2**47. If that
2836
+ * changes in the future, this must be adjusted upwards.
2837
+ */
2838
+ #define PHYSICAL_BITS 48
2839
+
2834
2840
/* bits used for MAP1 and MAP2 nodes */
2835
- #define INTERIOR_BITS ((BITS - ARENA_BITS + 2) / 3)
2841
+ #define INTERIOR_BITS ((PHYSICAL_BITS - ARENA_BITS + 2) / 3)
2836
2842
2837
2843
#define MAP1_BITS INTERIOR_BITS
2838
2844
#define MAP1_LENGTH (1 << MAP1_BITS)
2845
+ #define MAP1_MASK (MAP3_LENGTH - 1)
2839
2846
2840
2847
#define MAP2_BITS INTERIOR_BITS
2841
2848
#define MAP2_LENGTH (1 << MAP2_BITS)
2842
2849
#define MAP2_MASK (MAP2_LENGTH - 1)
2843
2850
2844
- #define MAP3_BITS (BITS - ARENA_BITS - 2*INTERIOR_BITS)
2851
+ #define MAP3_BITS (PHYSICAL_BITS - ARENA_BITS - 2*INTERIOR_BITS)
2845
2852
#define MAP3_LENGTH (1 << MAP3_BITS)
2846
2853
#define MAP3_MASK (MAP3_LENGTH - 1)
2847
2854
@@ -2852,7 +2859,8 @@ _PyObject_DebugMallocStats(FILE *out)
2852
2859
#define AS_UINT (p ) ((uintptr_t)(p))
2853
2860
#define MAP3_INDEX (p ) ((AS_UINT(p) >> MAP3_SHIFT) & MAP3_MASK)
2854
2861
#define MAP2_INDEX (p ) ((AS_UINT(p) >> MAP2_SHIFT) & MAP2_MASK)
2855
- #define MAP1_INDEX (p ) (AS_UINT(p) >> MAP1_SHIFT)
2862
+ #define MAP1_INDEX (p ) ((AS_UINT(p) >> MAP1_SHIFT) & MAP1_MASK)
2863
+ #define HIGH_BITS (p ) (AS_UINT(p) >> PHYSICAL_BITS)
2856
2864
2857
2865
/* See arena_map_mark_used() for the meaning of these members. */
2858
2866
typedef struct {
@@ -2888,6 +2896,8 @@ static arena_map1_t arena_map_root;
2888
2896
static arena_map3_t *
2889
2897
arena_map_get (block * p , int create )
2890
2898
{
2899
+ /* sanity check that PHYSICAL_BITS is correct */
2900
+ assert (HIGH_BITS (p ) == HIGH_BITS (& arena_map_root ));
2891
2901
int i1 = MAP1_INDEX (p );
2892
2902
if (arena_map_root .ptrs [i1 ] == NULL ) {
2893
2903
if (!create ) {
@@ -2942,6 +2952,8 @@ arena_map_get(block *p, int create)
2942
2952
static int
2943
2953
arena_map_mark_used (uintptr_t arena_base , int is_used )
2944
2954
{
2955
+ /* sanity check that PHYSICAL_BITS is correct */
2956
+ assert (HIGH_BITS (arena_base ) == HIGH_BITS (& arena_map_root ));
2945
2957
arena_map3_t * n_hi = arena_map_get ((block * )arena_base , is_used );
2946
2958
if (n_hi == NULL ) {
2947
2959
assert (is_used ); /* otherwise node should already exist */
0 commit comments