-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib: qmem show changes (header and max) #2859
lib: qmem show changes (header and max) #2859
Conversation
louberger
commented
Aug 17, 2018
💚 Basic BGPD CI results: SUCCESS, 0 tests failedResults table
For details, please contact louberger |
Continuous Integration Result: SUCCESSFULCongratulations, this patch passed basic tests Tested-by: NetDEF / OpenSourceRouting.org CI System CI System Testrun URL: https://ci1.netdef.org/browse/FRR-FRRPULLREQ-4890/ This is a comment from an EXPERIMENTAL automated CI system. Warnings Generated during build:Checkout code: Successful with additional warnings:
CLANG Static Analyzer Summary
No Changes in Static Analysis warnings compared to base4 Static Analyzer issues remaining.See details at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work correctly under MT scenarios.
lib/memory.c
Outdated
oldsize = 1 + atomic_fetch_add_explicit(&mt->n_alloc, 1, | ||
memory_order_relaxed); | ||
|
||
if (oldsize > atomic_load_explicit(&mt->n_max, memory_order_relaxed)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not how atomics work.
lib/memory.c
Outdated
oldsize = mallocsz + | ||
atomic_fetch_add_explicit(&mt->total, mallocsz, | ||
memory_order_relaxed); | ||
if (oldsize > atomic_load_explicit(&mt->max_size, memory_order_relaxed)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, this won't work correctly in MT.
Yes but it's a close enough approximation. Do you really want to lock this
code?
…----------
On August 18, 2018 1:25:04 PM David Lamparter ***@***.***> wrote:
eqvinox requested changes on this pull request.
This won't work correctly under MT scenarios.
> @@ -38,7 +38,12 @@ static inline void mt_count_alloc(struct memtype *mt,
> size_t size, void *ptr)
{
size_t oldsize;
- atomic_fetch_add_explicit(&mt->n_alloc, 1, memory_order_relaxed);
+ oldsize = 1 + atomic_fetch_add_explicit(&mt->n_alloc, 1,
+ memory_order_relaxed);
+
+ if (oldsize > atomic_load_explicit(&mt->n_max, memory_order_relaxed))
This is not how atomics work.
> @@ -51,7 +56,12 @@ static inline void mt_count_alloc(struct memtype *mt,
> size_t size, void *ptr)
#ifdef HAVE_MALLOC_USABLE_SIZE
size_t mallocsz = malloc_usable_size(ptr);
- atomic_fetch_add_explicit(&mt->total, mallocsz, memory_order_relaxed);
+ oldsize = mallocsz +
+ atomic_fetch_add_explicit(&mt->total, mallocsz,
+ memory_order_relaxed);
+ if (oldsize > atomic_load_explicit(&mt->max_size, memory_order_relaxed))
Same here, this won't work correctly in MT.
--
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#2859 (review)
|
Point of the atomics is to not lock ;) ... We can track the max, but I would actually prefer tracking the total lifetime numbers (i.e. separately count allocations and frees, instead of having frees decrement the allocs.) Do you specifically want the max? (max can be done in atomics too, albeit slightly more complicated) |
----------
On August 20, 2018 11:23:40 AM David Lamparter ***@***.***> wrote:
> Yes but it's a close enough approximation. Do you really want to lock this
> code?
Point of the atomics is not to lock ;) ...
We can track the max, but I would actually prefer tracking the total
lifetime numbers (i.e. separately count allocations and frees, instead of
having frees decrement the allocs.)
I agree. I thought about changing it and decided I didn't care enough to
make the change.
Do you specifically want the max?
Yes. Thanks the sole purpose of the change.
(max can be done in atomics too, albeit slightly more complicated)
I think an approximate value is good enough. I'd even be fine without using
atomics on the max fields, but expected some would object. Please propose
your preferred solution....
Thanks
… --
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#2859 (comment)
|
@louberger alright gimme a bit to find my goat for the atomics gods. |
I'm gonna close this for the moment, I'm working on it and will have a new PR up in a few days probably. We've lived without the numbers for years, we can survive a few days 😄 |
Closing someone else's PR is generally considered bad form...
…----------
On August 23, 2018 11:03:06 AM David Lamparter ***@***.***> wrote:
I'm gonna close this for the moment, I'm working on it and will have a new
PR up in a few days probably. We've lived without the numbers for years, we
can survive a few days :smile:
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#2859 (comment)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a reference to lib/thread.c where a different atomic pattern is being used for something similar
lib/memory.c
Outdated
oldsize = 1 + atomic_fetch_add_explicit(&mt->n_alloc, 1, | ||
memory_order_relaxed); | ||
|
||
if (oldsize > atomic_load_explicit(&mt->n_max, memory_order_relaxed)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we've got some code in lib/thread.c that's using atomic_compare_exchange_weak_explicit()
in a loop to accomplish this sort of thing - maybe that pattern could be reused?
Yeah, that's what I was trying to avoid as it locks the critical code:
…__sync_synchronize(); \
typeof(*atom) rval = \
__sync_val_compare_and_swap(_atom, *_expect, _desire); \
__sync_synchronize();
Sort of like your volatile argument -- the current approach balances
precision and cost.
Thanks for the thought!
On 8/28/2018 11:58 AM, Mark Stapp wrote:
***@***.**** commented on this pull request.
Added a reference to lib/thread.c where a different atomic pattern is
being used for something similar
------------------------------------------------------------------------
In lib/memory.c
<#2859 (comment)>:
> @@ -38,7 +38,12 @@ static inline void mt_count_alloc(struct memtype *mt, size_t size, void *ptr)
{
size_t oldsize;
- atomic_fetch_add_explicit(&mt->n_alloc, 1, memory_order_relaxed);
+ oldsize = 1 + atomic_fetch_add_explicit(&mt->n_alloc, 1,
+ memory_order_relaxed);
+
+ if (oldsize > atomic_load_explicit(&mt->n_max, memory_order_relaxed))
we've got some code in lib/thread.c that's using
|atomic_compare_exchange_weak_explicit()| in a loop to accomplish this
sort of thing - maybe that pattern could be reused?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#2859 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGRWyNUgiFey3K7v7Dv4Eaogmhf1GNdnks5uVWiqgaJpZM4WB7fd>.
|
hmm - that's only for older compilers, isn't it - and ... it's not really a lock - it's just a barrier? I mean, in order to support MT we have to take some precautions, even though there's sometimes a cost involved. |
43227f2
to
6497310
Compare
@eqvinox @mjstapp okay revised with suggested changes and additions. @donaldsharp Note that the result is an approximation in the MT case -- I'm intentionally not testing the result of atomic_compare_exchange_weak_explicit which would fully cover the MT case, but the while loop required is overly expensive IMO. I'll fully cover the MT case if others think this is critical. |
This comment has been minimized.
This comment has been minimized.
💚 Basic BGPD CI results: SUCCESS, 0 tests failedResults table
For details, please contact louberger |
add header to show qmem, align table with headers add tracking of max # allocs and max bytes alloc'ed Signed-off-by: Lou Berger <lberger@labn.net>
Signed-off-by: Lou Berger <lberger@labn.net>
6497310
to
7a15333
Compare
💚 Basic BGPD CI results: SUCCESS, 0 tests failedResults table
For details, please contact louberger |
Continuous Integration Result: SUCCESSFULCongratulations, this patch passed basic tests Tested-by: NetDEF / OpenSourceRouting.org CI System CI System Testrun URL: https://ci1.netdef.org/browse/FRR-FRRPULLREQ-5078/ This is a comment from an EXPERIMENTAL automated CI system. CLANG Static Analyzer Summary
No Changes in Static Analysis warnings compared to base4 Static Analyzer issues remaining.See details at |