Closed Bug 765244 Opened 14 years ago Closed 14 years ago

add a memory reporter for preferences

Categories

(Core :: Preferences: Backend, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla19
Tracking Status
firefox18 --- fixed
firefox19 --- fixed

People

(Reporter: froydnj, Assigned: froydnj)

Details

Attachments

(1 file, 1 obsolete file)

I see this take up a decent amount with a just-started x86-64/Linux firefox: ==19419== Unreported: 1 block(s) in record 4 of 10929 ==19419== 163,840 bytes (163,840 requested / 0 slop) ==19419== 0.54% of the heap (0.54% cumulative unreported) ==19419== at 0x4C284AF: malloc (vg_replace_malloc.c:267) ==19419== by 0x685312F: moz_malloc (mozalloc.cpp:64) ==19419== by 0x8DAF03C: PL_DHashAllocTable (pldhash.cpp:82) ==19419== by 0x8DAED9B: ChangeTable(PLDHashTable*, int) (pldhash.cpp:525) ==19419== by 0x8DAF3D5: PL_DHashTableOperate (pldhash.cpp:610) ==19419== by 0x8117D21: pref_HashPref(char const*, PrefValue, PrefType, unsigned int) (prefapi.cpp:676) ==19419== by 0x81181DD: PREF_ReaderCallback (prefapi.cpp:938) ==19419== by 0x8118D40: PREF_ParseBuf (prefread.cpp:132) and a number of small allocations that would be worth getting out of the way.
Attached patch patch (obsolete) — — Splinter Review
DMD tested, etc. Flagging Nicholas for about:memory bits, Benjamin for libpref code review. The mildly controversial part of this patch is the marking of the nsIPrefBranch* infrastructure builtinclass. I do this so that the hashtables contained in the branches can be accounted for: ==3328== Unreported: 1 block(s) in record 59 of 10928 ==3328== 32,768 bytes (32,768 requested / 0 slop) ==3328== 0.10% of the heap (10.59% cumulative unreported) ==3328== at 0x4C284AF: malloc (vg_replace_malloc.c:267) ==3328== by 0x685312F: moz_malloc (mozalloc.cpp:64) ==3328== by 0x8DAF03C: PL_DHashAllocTable (pldhash.cpp:82) ==3328== by 0x8DAED9B: ChangeTable(PLDHashTable*, int) (pldhash.cpp:525) ==3328== by 0x8DAF3D5: PL_DHashTableOperate (pldhash.cpp:610) ==3328== by 0x8116600: nsPrefBranch::AddObserver(char const*, nsIObserver*, bool) (nsTHashtable.h:184) ==3328== by 0x811B375: mozilla::Preferences::AddStrongObserver(nsIObserver*, char const*) (Preferences.cpp:1323) ==3328== by 0x811B7EA: mozilla::Preferences::RegisterCallback(int (*)(char const*, void*), char const*, void*) (Preferences.cpp:1406) I figured builtinclass'ing them was more acceptable than adding another method to the interface and possibly screwing up binary interfaces.
Attachment #633547 - Flags: review?(n.nethercote)
Attachment #633547 - Flags: review?(benjamin)
Comment on attachment 633547 [details] [diff] [review] patch Review of attachment 633547 [details] [diff] [review]: ----------------------------------------------------------------- Thanks for doing this; I've seen these stacks numerous times in DMD output but never got up the energy to write reporters for them :) ::: modules/libpref/src/Preferences.cpp @@ +165,5 @@ > +static size_t > +SizeOfObserverEntryExcludingThis(ValueObserverHashKey* aKey, > + const nsRefPtr<ValueObserver>& aData, > + nsMallocSizeOfFun aMallocSizeOf, > + void *) Are nameless params kosher in this part of the code base? Maybe use |dummy| or |unused| as the name? @@ +197,5 @@ > + n += gObserverTable->SizeOfExcludingThis(SizeOfObserverEntryExcludingThis, > + PreferencesMallocSizeOf); > + } > + if (sRootBranch) { > + nsPrefBranch* root = static_cast<nsPrefBranch*>(sRootBranch); I won't pretend to understand this static_cast. Why don't sRootBranch and sDefaultRootBranch just have type |nsPrefBranch*|? ::: modules/libpref/src/prefapi.cpp @@ +744,5 @@ > } > return rv; > } > > +size_t pref_SizeOfPrivateData(nsMallocSizeOfFun aMallocSizeOf) This file annoyingly sometimes puts the return type on a different line, and sometimes doesn't. Since putting it on a separate line is the usual Mozilla convention, I'd do that here.
Attachment #633547 - Flags: review?(n.nethercote) → review+
Attached patch patch — — Splinter Review
(In reply to Nicholas Nethercote [:njn] from comment #2) > ::: modules/libpref/src/Preferences.cpp > @@ +165,5 @@ > > +static size_t > > +SizeOfObserverEntryExcludingThis(ValueObserverHashKey* aKey, > > + const nsRefPtr<ValueObserver>& aData, > > + nsMallocSizeOfFun aMallocSizeOf, > > + void *) > > Are nameless params kosher in this part of the code base? Maybe use |dummy| > or |unused| as the name? I didn't realize we had rules about where and when we used nameless params! I've left this as-is. > @@ +197,5 @@ > > + n += gObserverTable->SizeOfExcludingThis(SizeOfObserverEntryExcludingThis, > > + PreferencesMallocSizeOf); > > + } > > + if (sRootBranch) { > > + nsPrefBranch* root = static_cast<nsPrefBranch*>(sRootBranch); > > I won't pretend to understand this static_cast. Why don't sRootBranch and > sDefaultRootBranch just have type |nsPrefBranch*|? Because I didn't think about just doing that. Fixed, along with not changing the interfaces to be builtinclass. Flagging just Benjamin for review this time.
Attachment #633547 - Attachment is obsolete: true
Attachment #633547 - Flags: review?(benjamin)
Attachment #634083 - Flags: review?(benjamin)
(In reply to Nathan Froyd (:froydnj) from comment #3) > Flagging just Benjamin for review this time. Benjamin, ping?
(In reply to Nathan Froyd (:froydnj) from comment #4) > (In reply to Nathan Froyd (:froydnj) from comment #3) > > Flagging just Benjamin for review this time. > > Benjamin, ping? Ping^2. Now with extra Bugzilla request mojo.
Flags: needinfo?(benjamin)
This is going to have to wait indefinitely. It seems pretty low-value to me and it would require paging in a lot of preferences nuance that I only barely knew to begin with. We don't have a good owner for this code...
Flags: needinfo?(benjamin)
Comment on attachment 634083 [details] [diff] [review] patch Hard to get new owners if the only people who know anything about the code never review patches to said code. ;)
Attachment #634083 - Flags: review?(benjamin)
I don't know the code. I've only reviewed in the past because nobody knows the code and so I read it to see if it makes sense.
Nathan: I suggest you just land it -- you have r+ from me, and this patch only requires a basic understanding of how the relevant data is laid out.
(In reply to Nathan Froyd (:froydnj) from comment #1) > The mildly controversial part of this patch is the marking of the > nsIPrefBranch* infrastructure builtinclass. I do this so that the > hashtables contained in the branches can be accounted for: > > I figured builtinclass'ing them was more acceptable than adding another > method to the interface and possibly screwing up binary interfaces. (In reply to Nathan Froyd (:froydnj) from comment #3) > > @@ +197,5 @@ > > > + n += gObserverTable->SizeOfExcludingThis(SizeOfObserverEntryExcludingThis, > > > + PreferencesMallocSizeOf); > > > + } > > > + if (sRootBranch) { > > > + nsPrefBranch* root = static_cast<nsPrefBranch*>(sRootBranch); > > > > I won't pretend to understand this static_cast. Why don't sRootBranch and > > sDefaultRootBranch just have type |nsPrefBranch*|? > > Because I didn't think about just doing that. Fixed, along with not > changing the interfaces to be builtinclass. I must have forgotten to compile after making this change, because nsPrefBranch is not exposed in Preferences.h. I don't know that exposing it--even via a forward declaration in Preferences.h--is a good idea. I was all ready to commit this, but I feel having to correct this error is enough of a change (not just groveling through data structures, but material changes to how the module works) that choosing builtinclass/forward declaration/something else really needs review from a pref module owner or a reasonable facsimile thereof. And since Benjamin doesn't want to review the patch, I think it's going to have to sit in limbo. Shame, a little less heap-unclassified in B2G would be nice...
A forward declaration seems pretty harmless.
(In reply to Nicholas Nethercote [:njn] from comment #11) > A forward declaration seems pretty harmless. I agree. But since you have things like: http://mxr.mozilla.org/mozilla-central/source/modules/libpref/public/Preferences.h#85 you have to make those non-inline. Is worrying about shuffling all this around just being pedantic? Then again, I don't understand why we're exporting this, because of guards like: http://mxr.mozilla.org/mozilla-central/source/modules/libpref/public/Preferences.h#9 I guess that's just one of the wonders of libpref...
As discussed on IRC: DMD says that gHashTable and gPrefNameArena are the ones taking up all the space. So if you can ignore the root branches and that gets you past the trickiness, by all means do that!
Pushed without measuring the branches, which makes this change much more straightforward. I feel comfortable pushing this without a pref owner review. Nick has argued his r+ is sufficient and in this case I agree. https://hg.mozilla.org/integration/mozilla-inbound/rev/2fe58d68cf8c
Assignee: nobody → nfroyd
Status: NEW → ASSIGNED
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Flags: in-testsuite-
Resolution: --- → FIXED
Target Milestone: --- → mozilla19
Comment on attachment 634083 [details] [diff] [review] patch [Approval Request Comment] Bug caused by (feature/regressing bug #): N/A. User impact if declined: lesser understanding of B2G memory consumption. Testing completed (on m-c, etc.): has been on m-c for 2 days without problem. Risk to taking this patch (and alternatives if risky): minimal; this code only runs when you view about:memory or trigger a memory reporter dump. String or UUID changes made by this patch: none.
Attachment #634083 - Flags: approval-mozilla-aurora?
Attachment #634083 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: