Skip to content

Commit 6402e2b

Browse files
committed
reduce probability hint for is_memtag_enabled
1 parent e86192e commit 6402e2b

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

h_malloc.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ static void write_after_free_check(const char *p, size_t size) {
470470
}
471471

472472
#ifdef HAS_ARM_MTE
473-
if (likely(is_memtag_enabled())) {
473+
if (likely51(is_memtag_enabled())) {
474474
return;
475475
}
476476
#endif
@@ -505,7 +505,7 @@ static void set_slab_canary_value(UNUSED struct slab_metadata *metadata, UNUSED
505505
static void set_canary(UNUSED const struct slab_metadata *metadata, UNUSED void *p, UNUSED size_t size) {
506506
#if SLAB_CANARY
507507
#ifdef HAS_ARM_MTE
508-
if (likely(is_memtag_enabled())) {
508+
if (likely51(is_memtag_enabled())) {
509509
return;
510510
}
511511
#endif
@@ -517,7 +517,7 @@ static void set_canary(UNUSED const struct slab_metadata *metadata, UNUSED void
517517
static void check_canary(UNUSED const struct slab_metadata *metadata, UNUSED const void *p, UNUSED size_t size) {
518518
#if SLAB_CANARY
519519
#ifdef HAS_ARM_MTE
520-
if (likely(is_memtag_enabled())) {
520+
if (likely51(is_memtag_enabled())) {
521521
return;
522522
}
523523
#endif
@@ -624,7 +624,7 @@ static inline void *allocate_small(unsigned arena, size_t requested_size) {
624624
write_after_free_check(p, size - canary_size);
625625
set_canary(metadata, p, size);
626626
#ifdef HAS_ARM_MTE
627-
if (likely(is_memtag_enabled())) {
627+
if (likely51(is_memtag_enabled())) {
628628
p = tag_and_clear_slab_slot(metadata, p, slot, size);
629629
}
630630
#endif
@@ -661,7 +661,7 @@ static inline void *allocate_small(unsigned arena, size_t requested_size) {
661661
if (requested_size) {
662662
set_canary(metadata, p, size);
663663
#ifdef HAS_ARM_MTE
664-
if (likely(is_memtag_enabled())) {
664+
if (likely51(is_memtag_enabled())) {
665665
p = tag_and_clear_slab_slot(metadata, p, slot, size);
666666
}
667667
#endif
@@ -688,7 +688,7 @@ static inline void *allocate_small(unsigned arena, size_t requested_size) {
688688
if (requested_size) {
689689
set_canary(metadata, p, size);
690690
#ifdef HAS_ARM_MTE
691-
if (likely(is_memtag_enabled())) {
691+
if (likely51(is_memtag_enabled())) {
692692
p = tag_and_clear_slab_slot(metadata, p, slot, size);
693693
}
694694
#endif
@@ -717,7 +717,7 @@ static inline void *allocate_small(unsigned arena, size_t requested_size) {
717717
write_after_free_check(p, size - canary_size);
718718
set_canary(metadata, p, size);
719719
#ifdef HAS_ARM_MTE
720-
if (likely(is_memtag_enabled())) {
720+
if (likely51(is_memtag_enabled())) {
721721
p = tag_and_clear_slab_slot(metadata, p, slot, size);
722722
}
723723
#endif
@@ -805,7 +805,7 @@ static inline void deallocate_small(void *p, const size_t *expected_size) {
805805

806806
bool skip_zero = false;
807807
#ifdef HAS_ARM_MTE
808-
if (likely(is_memtag_enabled())) {
808+
if (likely51(is_memtag_enabled())) {
809809
arm_mte_tag_and_clear_mem(set_pointer_tag(p, RESERVED_TAG), size);
810810
// metadata->arm_mte_tags is intentionally not updated, see tag_and_clear_slab_slot()
811811
skip_zero = true;
@@ -1243,7 +1243,7 @@ COLD static void init_slow_path(void) {
12431243
fatal_error("failed to unprotect memory for regions table");
12441244
}
12451245
#ifdef HAS_ARM_MTE
1246-
if (likely(is_memtag_enabled())) {
1246+
if (likely51(is_memtag_enabled())) {
12471247
ro.slab_region_start = memory_map_mte(slab_region_size);
12481248
} else {
12491249
ro.slab_region_start = memory_map(slab_region_size);

util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#define noreturn __attribute__((noreturn))
1010

1111
#define likely(x) __builtin_expect(!!(x), 1)
12+
#define likely51(x) __builtin_expect_with_probability(!!(x), 1, 0.51)
1213
#define unlikely(x) __builtin_expect(!!(x), 0)
14+
#define unlikely51(x) __builtin_expect_with_probability(!!(x), 0, 0.51)
1315

1416
#define min(x, y) ({ \
1517
__typeof__(x) _x = (x); \

0 commit comments

Comments
 (0)