@@ -2825,17 +2825,24 @@ _PyObject_DebugMallocStats(FILE *out)
2825
2825
# error "arena size must be < 2^32"
2826
2826
#endif
2827
2827
2828
+ /* Current 64-bit processors are limited to 48-bit physical addresses. For
2829
+ * now, the top 17 bits of addresses will all be equal to bit 2**47. If that
2830
+ * changes in the future, this must be adjusted upwards.
2831
+ */
2832
+ #define PHYSICAL_BITS 48
2833
+
2828
2834
/* bits used for MAP1 and MAP2 nodes */
2829
- #define INTERIOR_BITS ((BITS - ARENA_BITS + 2) / 3)
2835
+ #define INTERIOR_BITS ((PHYSICAL_BITS - ARENA_BITS + 2) / 3)
2830
2836
2831
2837
#define MAP1_BITS INTERIOR_BITS
2832
2838
#define MAP1_LENGTH (1 << MAP1_BITS)
2839
+ #define MAP1_MASK (MAP3_LENGTH - 1)
2833
2840
2834
2841
#define MAP2_BITS INTERIOR_BITS
2835
2842
#define MAP2_LENGTH (1 << MAP2_BITS)
2836
2843
#define MAP2_MASK (MAP2_LENGTH - 1)
2837
2844
2838
- #define MAP3_BITS (BITS - ARENA_BITS - 2*INTERIOR_BITS)
2845
+ #define MAP3_BITS (PHYSICAL_BITS - ARENA_BITS - 2*INTERIOR_BITS)
2839
2846
#define MAP3_LENGTH (1 << MAP3_BITS)
2840
2847
#define MAP3_MASK (MAP3_LENGTH - 1)
2841
2848
@@ -2846,7 +2853,8 @@ _PyObject_DebugMallocStats(FILE *out)
2846
2853
#define AS_UINT (p ) ((uintptr_t)(p))
2847
2854
#define MAP3_INDEX (p ) ((AS_UINT(p) >> MAP3_SHIFT) & MAP3_MASK)
2848
2855
#define MAP2_INDEX (p ) ((AS_UINT(p) >> MAP2_SHIFT) & MAP2_MASK)
2849
- #define MAP1_INDEX (p ) (AS_UINT(p) >> MAP1_SHIFT)
2856
+ #define MAP1_INDEX (p ) ((AS_UINT(p) >> MAP1_SHIFT) & MAP1_MASK)
2857
+ #define HIGH_BITS (p ) (AS_UINT(p) >> PHYSICAL_BITS)
2850
2858
2851
2859
/* See arena_map_mark_used() for the meaning of these members. */
2852
2860
typedef struct {
@@ -2882,6 +2890,8 @@ static arena_map1_t arena_map_root;
2882
2890
static arena_map3_t *
2883
2891
arena_map_get (block * p , int create )
2884
2892
{
2893
+ /* sanity check that PHYSICAL_BITS is correct */
2894
+ assert (HIGH_BITS (p ) == HIGH_BITS (& arena_map_root ));
2885
2895
int i1 = MAP1_INDEX (p );
2886
2896
if (arena_map_root .ptrs [i1 ] == NULL ) {
2887
2897
if (!create ) {
@@ -2936,6 +2946,8 @@ arena_map_get(block *p, int create)
2936
2946
static int
2937
2947
arena_map_mark_used (uintptr_t arena_base , int is_used )
2938
2948
{
2949
+ /* sanity check that PHYSICAL_BITS is correct */
2950
+ assert (HIGH_BITS (arena_base ) == HIGH_BITS (& arena_map_root ));
2939
2951
arena_map3_t * n_hi = arena_map_get ((block * )arena_base , is_used );
2940
2952
if (n_hi == NULL ) {
2941
2953
assert (is_used ); /* otherwise node should already exist */
0 commit comments