* [PATCH] malloc: Use C11 atomics rather than atomic_exchange_and_add
@ 2022-09-05 16:14 Wilco Dijkstra
2022-09-06 12:03 ` Florian Weimer
0 siblings, 1 reply; 2+ messages in thread
From: Wilco Dijkstra @ 2022-09-05 16:14 UTC (permalink / raw)
To: 'GNU C Library'; +Cc: Adhemerval Zanella
Replace a few counters using atomic_exchange_and_add with atomic_fetch_add_relaxed.
Passes regress on AArch64.
---
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 29fa71b3b2a3d0a671149eaf619e4d518c56aef5..ecec901b14f602e3c93da1a847f043ffee41a1f4 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -2460,11 +2460,11 @@ sysmalloc_mmap (INTERNAL_SIZE_T nb, size_t pagesize, int extra_flags, mstate av)
}
/* update statistics */
- int new = atomic_exchange_and_add (&mp_.n_mmaps, 1) + 1;
+ int new = atomic_fetch_add_relaxed (&mp_.n_mmaps, 1) + 1;
atomic_max (&mp_.max_n_mmaps, new);
unsigned long sum;
- sum = atomic_exchange_and_add (&mp_.mmapped_mem, size) + size;
+ sum = atomic_fetch_add_relaxed (&mp_.mmapped_mem, size) + size;
atomic_max (&mp_.max_mmapped_mem, sum);
check_chunk (av, p);
@@ -3084,7 +3084,7 @@ mremap_chunk (mchunkptr p, size_t new_size)
set_head (p, (new_size - offset) | IS_MMAPPED);
INTERNAL_SIZE_T new;
- new = atomic_exchange_and_add (&mp_.mmapped_mem, new_size - size - offset)
+ new = atomic_fetch_add_relaxed (&mp_.mmapped_mem, new_size - size - offset)
+ new_size - size - offset;
atomic_max (&mp_.max_mmapped_mem, new);
return p;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] malloc: Use C11 atomics rather than atomic_exchange_and_add
2022-09-05 16:14 [PATCH] malloc: Use C11 atomics rather than atomic_exchange_and_add Wilco Dijkstra
@ 2022-09-06 12:03 ` Florian Weimer
0 siblings, 0 replies; 2+ messages in thread
From: Florian Weimer @ 2022-09-06 12:03 UTC (permalink / raw)
To: Wilco Dijkstra via Libc-alpha; +Cc: Wilco Dijkstra
* Wilco Dijkstra via Libc-alpha:
> Replace a few counters using atomic_exchange_and_add with atomic_fetch_add_relaxed.
Line is overly long.
Patch looks okay to me (relative to what we had before).
Reviewed-by: Florian Weimer <fweimer@redhat.com>
Thanks,
Florian
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-09-06 12:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-05 16:14 [PATCH] malloc: Use C11 atomics rather than atomic_exchange_and_add Wilco Dijkstra
2022-09-06 12:03 ` Florian Weimer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).