public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/13328] New: proposal of small optimization in tr_freehook() for mtrace functionality
@ 2011-10-20 19:19 marcukr at op dot pl
2011-12-22 16:39 ` [Bug libc/13328] " drepper.fsp at gmail dot com
2014-06-27 11:50 ` fweimer at redhat dot com
0 siblings, 2 replies; 3+ messages in thread
From: marcukr at op dot pl @ 2011-10-20 19:19 UTC (permalink / raw)
To: glibc-bugs
http://sourceware.org/bugzilla/show_bug.cgi?id=13328
Bug #: 13328
Summary: proposal of small optimization in tr_freehook() for
mtrace functionality
Product: glibc
Version: unspecified
Status: NEW
Severity: minor
Priority: P2
Component: libc
AssignedTo: drepper.fsp@gmail.com
ReportedBy: marcukr@op.pl
Classification: Unclassified
Hi,
I've started to use mtrace functionality to get the summary of
allocations/deallocations done in my system. First I've got into the deadlock
which I found is solved (Bug #6420) in latest libc. Thanks that I had
opportunity to look into libc sources.
Now I would like to propose small optimization in tr_freehook() function.
IMO the hooks should do their job as fast as possible, on the beginning
they block on lock, then call the original malloc/realloc/free...
and unblock the lock when not needed anymore.
I case of tr_freehook() it does the allocation & deallocation twice, but
most of the time they don't need to be called.
The code from latest glibc is like following:
static void tr_freehook (__ptr_t, const __ptr_t) __THROW;
static void
tr_freehook (ptr, caller)
__ptr_t ptr;
const __ptr_t caller;
{
if (ptr == NULL)
return;
Dl_info mem;
Dl_info *info = lock_and_info (caller, &mem);
tr_where (caller, info);
/* Be sure to print it first. */
fprintf (mallstream, "- %p\n", ptr);
__libc_lock_unlock (lock); <==== the unlock
if (ptr == mallwatch) <==== I didn't know about mallwatch till
looking into mtrace.c source, therefore in many cases it is just NULL
tr_break ();
__libc_lock_lock (lock); <==== the lock again
__free_hook = tr_old_free_hook;
if (tr_old_free_hook != NULL)
(*tr_old_free_hook) (ptr, caller);
else
free (ptr);
__free_hook = tr_freehook;
__libc_lock_unlock (lock);
}
My proposal is to do call "internal" __libc_lock_unlock(lock) &
__libc_lock_lock(lock) only inside if (ptr == mallwatch), therefore the code
will look like following:
static void tr_freehook (__ptr_t, const __ptr_t) __THROW;
.....
{
if (ptr == NULL)
return;
Dl_info mem;
Dl_info *info = lock_and_info (caller, &mem);
tr_where (caller, info);
/* Be sure to print it first. */
fprintf (mallstream, "- %p\n", ptr);
if (ptr == mallwatch)
{
__libc_lock_unlock (lock);
tr_break ();
__libc_lock_lock (lock);
}
__free_hook = tr_old_free_hook;
if (tr_old_free_hook != NULL)
(*tr_old_free_hook) (ptr, caller);
.......
The advantages:
if ptr != mallwatch the lock is locked/unlocked only once -> the hook will be
executed faster
if ptr == mallwatch & gdb breakpoint is set on tr_break() debugger will stop
with lock unlocked (as before the potential optimization change)
Regards
Mariusz
--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libc/13328] proposal of small optimization in tr_freehook() for mtrace functionality
2011-10-20 19:19 [Bug libc/13328] New: proposal of small optimization in tr_freehook() for mtrace functionality marcukr at op dot pl
@ 2011-12-22 16:39 ` drepper.fsp at gmail dot com
2014-06-27 11:50 ` fweimer at redhat dot com
1 sibling, 0 replies; 3+ messages in thread
From: drepper.fsp at gmail dot com @ 2011-12-22 16:39 UTC (permalink / raw)
To: glibc-bugs
http://sourceware.org/bugzilla/show_bug.cgi?id=13328
Ulrich Drepper <drepper.fsp at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
--- Comment #1 from Ulrich Drepper <drepper.fsp at gmail dot com> 2011-12-22 16:38:57 UTC ---
I added the change.
--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libc/13328] proposal of small optimization in tr_freehook() for mtrace functionality
2011-10-20 19:19 [Bug libc/13328] New: proposal of small optimization in tr_freehook() for mtrace functionality marcukr at op dot pl
2011-12-22 16:39 ` [Bug libc/13328] " drepper.fsp at gmail dot com
@ 2014-06-27 11:50 ` fweimer at redhat dot com
1 sibling, 0 replies; 3+ messages in thread
From: fweimer at redhat dot com @ 2014-06-27 11:50 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=13328
Florian Weimer <fweimer at redhat dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Flags| |security-
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-06-27 11:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-20 19:19 [Bug libc/13328] New: proposal of small optimization in tr_freehook() for mtrace functionality marcukr at op dot pl
2011-12-22 16:39 ` [Bug libc/13328] " drepper.fsp at gmail dot com
2014-06-27 11:50 ` fweimer at redhat dot com
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).