Closed Bug 1252639 Opened 9 years ago Closed 9 years ago

Remove the shared PLArena freelist

Categories

(NSPR :: NSPR, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: n.nethercote, Assigned: n.nethercote)

Details

Attachments

(2 files, 4 obsolete files)

plarena.c has a shared freelist for arenas. When an arena is freed via PL_ArenaRelease() or PL_FreeArenaPool() (but *not* via PL_FinishArenaPool()) it gets put on the freelist, which requires getting a lock. Subsequent arena allocations are obtained from the freelist when possible. This adds complexity. It makes things confusing when investigating pool usage, because pools can end up with arenas larger or smaller than they're "supposed" to get. (This has tripped me up more than once.) The freelist almost certainly doesn't help performance, but it may increase memory usage, because it's making decisions that the heap allocator is likely to do a better job at, given that heap allocator has a global view of things.
glandium: I'm not expecting you to review this until you are feeling better :)
Attachment #8725431 - Flags: review?(mh+mozilla)
Assignee: nobody → n.nethercote
Status: NEW → ASSIGNED
Because the plarenas.h/plarena.h is strange and confusing. But the patch keeps plarenas.h around in a way that the API doesn't change -- any code that included plarena.h or plarenas.h should not need changing.
Attachment #8725433 - Flags: review?(mh+mozilla)
Note to self: there are some tweaks in NSS that can be made as a result of this, such as removing NSS_DISABLE_ARENA_FREE_LIST.
Comment on attachment 8725433 [details] [diff] [review] (part 2) - Move contents of plarenas.h into plarena.h Review of attachment 8725433 [details] [diff] [review]: ----------------------------------------------------------------- ::: nsprpub/lib/ds/plarenas.h @@ +5,5 @@ > > +// PLArena-related declarations used to be split between plarenas.h and > +// plarena.h. That split wasn't useful, so now all the declarations are in > +// plarena.h. However, this file still exists so that any old code that > +// includes it will still work. You probably want to use /* */ here, we've had complaints about // comments.
Now with C-style comments only.
Attachment #8726461 - Flags: review?(mh+mozilla)
Attachment #8725433 - Attachment is obsolete: true
Attachment #8725433 - Flags: review?(mh+mozilla)
Comment on attachment 8725431 [details] [diff] [review] (part 1) - Remove the shared PLArena freelist Review of attachment 8725431 [details] [diff] [review]: ----------------------------------------------------------------- ::: nsprpub/lib/ds/plarena.c @@ -280,5 @@ > -#endif > - > - if (reallyFree) { > - do { > - *ap = a->next; On the first iteration, this would do: head->next = a->next; effectively removing a from the linked list. Combined with the loop, all in all this means we do: head->next = NULL; Although the loop kinda sorta makes things a little bit safer while the loop is still running. I don't see you doing this in the new code, effectively opening the door for use-after-free.
Attachment #8725431 - Flags: review?(mh+mozilla) → review-
Attachment #8726461 - Flags: review?(mh+mozilla) → review+
> I don't see you doing this in the new code, effectively opening the door for > use-after-free. Ugh, good catch. New patch coming shortly.
This version explicitly nulls head->next before the loop in FreeArenaList().
Attachment #8727198 - Flags: review?(mh+mozilla)
Attachment #8725431 - Attachment is obsolete: true
Attachment #8727198 - Flags: review?(mh+mozilla) → review+
(In reply to Nicholas Nethercote [:njn] from comment #9) > https://hg.mozilla.org/integration/mozilla-inbound/rev/ > c661f2c5cd878c26e25abc0256b4893d8a249b49 > Bug 1252639 (part 1) - Remove the shared PLArena freelist. r=glandium. > > https://hg.mozilla.org/integration/mozilla-inbound/rev/ > bf22fcece06e85cd195d61e37382ffc0084e4d05 > Bug 1252639 (part 2) - Move contents of plarenas.h into plarena.h. > r=glandium. Shouldn't this have landed upstream at https://hg.mozilla.org/projects/nspr first?
Flags: needinfo?(n.nethercote)
https://hg.mozilla.org/integration/mozilla-inbound/rev/ce12c108f9c4294c51ccb9df1a1b6b124e1ce003 Backout c661f2c5cd87 and bf22fcece06e (from bug 1252639) because NSPR changes aren't supposed to land on mozilla-inbound.
> Shouldn't this have landed upstream at https://hg.mozilla.org/projects/nspr > first? Sorry, yes. My mistake. I've backed it out and I will land to the NSPR repo instead.
Flags: needinfo?(n.nethercote)
> I will land to the NSPR repo instead. Except I don't have permission to push to the NSPR repo! Argh.
Attachment #8726461 - Attachment is obsolete: true
Attachment #8727198 - Attachment is obsolete: true
Attachment #8728801 - Flags: review+
Attachment #8728802 - Flags: review+
ted: I've updated the patches so they apply cleanly to the NSPR repo, and carried over glandium's r+s. I don't have permission to push patches to NSPR. Could you please do it for me?
Flags: needinfo?(ted)
FYI, I am amenable to simultaneous landing of patches to mozilla-central and NSPR, as long as you've done something to ensure someone will land them in the NSPR repo (your needinfo? here was perfect). Also I should find out if glandium has the right bits set to push to the nspr repo, what with him being a peer. :)
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Flags: needinfo?(ted)
Resolution: --- → FIXED
I'm happy to wait for the next NSPR merge. Thank you for landing the patches.
Target Milestone: --- → 4.13
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: