|
From: <sv...@va...> - 2007-08-23 10:22:46
|
Author: sewardj
Date: 2007-08-23 11:22:44 +0100 (Thu, 23 Aug 2007)
New Revision: 6775
Log:
The drastic increase in the number of per-arena freelists in r6771
exposes a performance problem with doing m_mallocfree.c sanity checks
(at --sanity-level=3, at least), caused by slowness in
listNo_to_pszB_min. This commit fixes the problem by caching the
results of queries to listNo_to_pszB_min.
Modified:
trunk/coregrind/m_mallocfree.c
Modified: trunk/coregrind/m_mallocfree.c
===================================================================
--- trunk/coregrind/m_mallocfree.c 2007-08-22 23:51:33 UTC (rev 6774)
+++ trunk/coregrind/m_mallocfree.c 2007-08-23 10:22:44 UTC (rev 6775)
@@ -737,10 +737,24 @@
static
SizeT listNo_to_pszB_min ( UInt listNo )
{
- SizeT pszB = 0;
+ /* Repeatedly computing this function at every request is
+ expensive. Hence at the first call just cache the result for
+ every possible argument. */
+ static SizeT cache[N_MALLOC_LISTS];
+ static Bool cache_valid = False;
+ if (!cache_valid) {
+ UInt i;
+ for (i = 0; i < N_MALLOC_LISTS; i++) {
+ SizeT pszB = 0;
+ while (pszB_to_listNo(pszB) < i)
+ pszB += VG_MIN_MALLOC_SZB;
+ cache[i] = pszB;
+ }
+ cache_valid = True;
+ }
+ /* Returned cached answer. */
vg_assert(listNo <= N_MALLOC_LISTS);
- while (pszB_to_listNo(pszB) < listNo) pszB += VG_MIN_MALLOC_SZB;
- return pszB;
+ return cache[listNo];
}
// What is the maximum payload size for a given list?
|