Commit Graph

934 Commits

Author SHA1 Message Date
Mike Hommey
9741c8e076 Bug 1400096 - Build mozmemory_wrap as C++. r=njn
And since the build system doesn't handle transitions from foo.c to
foo.cpp properly without a clobber, we work around the issue by
switching to unified sources.

--HG--
rename : memory/build/mozmemory_wrap.c => memory/build/mozmemory_wrap.cpp
extra : rebase_source : 3f074b4ccab255bb0eb16841f79582060fafbc86
2017-09-15 10:19:37 +09:00
Mike Hommey
747992864b Bug 1400096 - Annotate mozmemory_wrap.c windows functions as MOZ_MEMORY_API. r=njn
It happens to work because of mozglue.def, but we might as well have the
right annotations (which will also make things correct when building this
file to C++)

--HG--
extra : rebase_source : 61056dc21c9c29bab62ad5d648e94dd56dc53b14
2017-09-15 10:12:24 +09:00
Mike Hommey
57ecf449b4 Bug 1400096 - Remove mozmem_malloc_impl wrapping for operator methods exposed in mozmemory_wrap.c. r=njn
This used to be necessary because those functions might be prefixed with
__wrap_, and linked against with -Wl,--wrap, but that's not been the case
since bug 1077366. Furthermore, mozmem_malloc_impl nowadays only does
something on Windows, and those operators are only exposed on Android.

--HG--
extra : rebase_source : ca34442bfbc5fc8be20ffcfacb9afa0f2f818b82
2017-09-15 09:54:01 +09:00
Phil Ringnalda
eab70d0a07 Backed out changeset 0e349b74bfc6 (bug 1399921) for failure to thrive on Mac
MozReview-Commit-ID: HoBhxzIzn2d
2017-09-14 20:36:41 -07:00
Mike Hommey
c53e695a6e Bug 1399921 - Register zone allocator independently, and delay jemalloc initialization on mac. r=njn
In bug 1361258, we unified the initialization sequence on mac, and
chose to make the zone registration happen after jemalloc
initialization.

The order between jemalloc init and zone registration shouldn't actually
matter, because jemalloc initializes the first time the allocator is
actually used.

On the other hand, in some build setups (e.g. with light optimization),
the initialization of the thread_arena thread local variable can happen
after the forced jemalloc initialization because of the order the
corresponding static initializers run. In some levels of optimization,
the thread_arena initializer resets the value the jemalloc
initialization has set, which subsequently makes choose_arena() return
a bogus value (or hit an assertion in ThreadLocal.h on debug builds).

So instead of initializing jemalloc from a static initializer, which
then registers the zone, we instead register the zone and let jemalloc
initialize itself when used, which increases the chances of the
thread_arena initializer running first.

--HG--
extra : rebase_source : 4d9a5340d097ac8528dc4aaaf0c05bbef40b59bb
2017-09-15 07:34:48 +09:00
Mike Hommey
e4f4d5fc59 Bug 1400063 - Automatically declare jemalloc_* functions in mozmemory.h. r=njn
There is a lot of churn involved in adding new API surface to
mozjemalloc, and mozmemory.h is one. Instead of declaring
everything manually in there, "generate" the declarations through
malloc_decls.h.

--HG--
extra : rebase_source : 1416fa972319c419112c4a8b16759d90692db5b2
2017-09-14 18:28:12 +09:00
Ryan VanderMeulen
277d6a438f Merge m-c to inbound. a=merge 2017-09-14 10:52:18 -04:00
Nathan Froyd
f8fda5a9b5 Bug 1396889 - don't warn about infinite recursion in mozalloc_abort; r=glandium
mozalloc_abort is not marked as a noreturn function on ARM, so clang
complains when abort calls mozalloc_abort, which calls MOZ_CRASH, which
calls abort().  We know this is OK, so just disable the warning.
2017-09-14 09:52:50 -04:00
Mike Hommey
9f3c42a57e Bug 1397101 - Only use a thread local arena for small sizes. r=njn
The bin-unused count in memory reports indicates how much memory is
used by runs of small and sub-page allocations that is not actually
allocated. This is generally thought as an indicator of fragmentation.

While this is generally true, with the use of thread local arenas by
stylo, combined with how stylo allocates memory, it ends up also being
an indicator of wasted memory.

For instance, over the lifetime of an AWSY iteration, there are only a
few allocations that ends up in the bucket for 2048 allocated bytes. In
the "worst" case, there's only one. But the run size for such
allocations is 132KiB. Which means just because we're allocating one
buffer of size between 1024 and 2048 bytes, we end up wasting 130+KiB.
Per thread.

Something similar happens with size classes of 512 and 1024, where the
run size is respectively 32KiB and 64KiB, and where there's at most a
handful of allocations of each class ever happening per thread.

Overall, an allocation log from a full AWSY iteration reveals that there
are only 448 of 860700 allocations happening on the stylo arenas that
involve sizes above (and excluding) 512 bytes, so 0.05%.

While there are improvements that can be done to mozjemalloc so that it
doesn't waste more than one page per sub-page size class, they are
changes that are too low-level to land at this time of the release
cycle. However, considering the numbers above and the fact that the
stylo arenas are only really meant to avoid lock contention during the
heavy parallel work involved, a short term, low risk, strategy is to
just delegate all sub-page (> 512, < 4096) and large (>= 4096) to the
main arena. Technically speaking, only sub-page allocations are causing
this waste, but it's more consistent to just delegate everything above
512 bytes.

This should save 132KiB + 64KiB = 196KiB per stylo thread.

--HG--
extra : rebase_source : c7233d60305365e76aa124045b1c9492068d9415
2017-09-14 07:36:39 +09:00
Mike Hommey
965981b68d Bug 1397101 - Reduce the number of dirty pages we allow to be kept in thread local arenas. r=njn
Until bug 1361258, there was only ever one mozjemalloc arena, and the
number of dirty pages we allow to be kept dirty, fixed to 1MB per arena,
was, in fact, 1MB for an entire process.

With stylo using thread local arenas, we now can have multiple arenas
per process, multiplying that number of dirty pages.

While those dirty pages may be reused later on, when other allocations
end up filling them later on, the fact that a relatively large number of
them is kept around for each stylo thread (in proportion to the amount of
memory ever allocated by stylo), combined with the fact that the memory
use from stylo depends on the workload generated by the pages being
visited, those dirty pages may very well not be used for a rather long
time. This is less of a problem with the main arena, used for most
everything else.

So, for each arena except the main one, we decrease the number of dirty
pages we allow to be kept around to 1/8 of the current value. We do this
by introducing a per-arena configuration of that maximum number.

--HG--
extra : rebase_source : 75eebb175b3746d5ca1c371606cface50ec70f2f
2017-09-14 07:26:30 +09:00
Mike Hommey
f98e560253 Bug 1399031 - Use mozilla/ThreadLocal.h in mozjemalloc. r=njn
--HG--
extra : rebase_source : 46e7abf6f46939cfa0862930feea5f245935b8d4
2017-09-12 16:29:11 +09:00
Mike Hommey
1e26a193e9 Bug 1399031 - Remove the setting of NO_TLS when PIC is not defined in mozjemalloc: it's always defined. r=njn
But it's also useless besides that test, so remove the PIC define.

--HG--
extra : rebase_source : 87b8934c1f8b6ed94e5ba3e2150f92dab9285769
2017-09-12 16:06:56 +09:00
Mike Hommey
05e3823899 Bug 1399350 - Remove jemalloc_*_impl macros. r=njn
Those macros are one more thing that needs to be added when the
mozjemalloc API surface is increased, but after bug 1399350, nothing
actually needs them, so remove them.

--HG--
extra : rebase_source : 2bf62cc6c179540482722a72b0d0c134d2ac2a19
2017-09-13 14:25:21 +09:00
Sebastian Hengst
6af41593df merge mozilla-central to mozilla-inbound. r=merge a=merge 2017-09-12 11:37:58 +02:00
Mike Hommey
6981b76dbc No bug - Remove the TODO item that was implemented in bug 1300948. r=me 2017-09-12 16:34:43 +09:00
Mike Hommey
8cdad036f1 Bug 1398965 - Fold memory/mozjemalloc into memory/build. r=njn
The files relevant to the memory allocator are currently spread between
memory/mozjemalloc and memory/build, and the distinction was
historically from sharing some Mozilla-specific things between
mozjemalloc and jemalloc3. That distinction is not useful anymore, so
we fold everything together.

As we will likely rename the allocator at some point in the future, it
is preferable to move away from the mozjemalloc directory rather than in
its direction.

--HG--
rename : memory/mozjemalloc/Makefile.in => memory/build/Makefile.in
rename : memory/mozjemalloc/mozjemalloc.cpp => memory/build/mozjemalloc.cpp
rename : memory/mozjemalloc/mozjemalloc.h => memory/build/mozjemalloc.h
rename : memory/mozjemalloc/mozjemalloc_types.h => memory/build/mozjemalloc_types.h
rename : memory/mozjemalloc/rb.h => memory/build/rb.h
2017-09-12 13:14:35 +09:00
Mike Hommey
175ddd015f Bug 1398965 - Remove MOZ_JEMALLOC_IMPL in favor of MOZ_MEMORY_IMPL. r=njn
In practice, they mean the same thing, and there's only one place where
MOZ_JEMALLOC_IMPL was used.
2017-09-12 13:06:43 +09:00
Mike Hommey
be1493b6fc Bug 1396723 - Use DoublyLinkedList in mozjemalloc. r=froydnj
Mozjemalloc uses its own doubly linked list, which, being inherited from
C code, doesn't do much type checking, and, in practice, is rather
similar to DoublyLinkedList, so use the latter instead.

--HG--
extra : rebase_source : 9eb7334b6dde05f9af0eaea4184e532c69d0264e
2017-09-02 08:55:42 +09:00
Chris Manchester
fab07bc443 Bug 1386876 - Replace all uses of NO_VISIBILITY_FLAGS with a template and remove NO_VISIBILITY_FLAGS. r=glandium
MozReview-Commit-ID: 194U1WMCAM0

--HG--
extra : rebase_source : 365b68b0a1772d238ae9b84966e53dcd1197fd85
2017-05-01 18:12:35 -07:00
Chris Manchester
c0a229d4c3 Bug 1386876 - Replace all uses of DISABLE_STL_WRAPPING with a template, remove DISABLE_STL_WRAPPING. r=glandium
MozReview-Commit-ID: FMEtb5PY7iP

--HG--
extra : rebase_source : 3cdee7528846462c758e623d6bcd2e6e17dbabff
2017-09-11 11:33:26 -07:00
Nathan Froyd
c88ec30451 Bug 1396892 - turn off -Wtautological-pointer-compare in memory/build/ for Android; r=njn
clang warns about this code in mozmemory_wrap.c in the reimplementation
of vasprintf, complaining that `fmt` cannot be null:

    if (str == NULL || fmt == NULL) {
                       ^~~    ~~~~

clang is apparently exploiting knowledge about the requirements of
vasprintf here, but defensive programming on the part of our
reimplementation seems like the wiser course.  Let's turn off the
warning.
2017-09-07 08:20:12 -04:00
Mike Hommey
938f8a3862 Bug 1396681 - Remove some typedefs in mozjemalloc. r=njn
Previously being a C codebase, mozjemalloc was using typedefs, avoiding
long "struct foo" uses. C++ doesn't need typedefs to achieve that, so we
can remove all that. We however keep a few typedefs in headers that are
still included from other C source files.

--HG--
extra : rebase_source : d0d807bcb76078c0ce36e4554b10803bfb36ddbb
2017-09-02 08:15:39 +09:00
Mike Hommey
acb85e2b41 Bug 1396361 - Avoid crashing when some system library calls malloc_zone_free(zone, NULL). r=njn
Some system libraries call malloc_zone_free directly instead of free,
and sometimes they do that with the wrong zone. When that happens, we
circle back, trying to find the right zone, and call malloc_zone_free
with the right one, but when we can't find one, we crash, which matches
what the system free() would do. Except in one case where the pointer
we're being passed is NULL, in which case we can't trace it back to any
zone, but shouldn't crash (system free() explicitly doesn't crash in
that case).

--HG--
extra : rebase_source : 17efdcd80f1a53be7ab6b7293bfb6060a9aa4a48
2017-09-04 07:32:42 +09:00
Mike Hommey
e8e9ecbd5d Bug 1395776 - Make _recalloc, _expand and _msize go through replace-malloc when enabled. r=njn
--HG--
extra : rebase_source : 454d6dc58681a9bde3564216d013746c0f189add
2017-08-31 14:17:49 +09:00
Mike Hommey
551fcf616e Bug 1395776 - Share the posix_memalign, aligned_alloc and valloc implementations between mozjemalloc and replace-malloc. r=njn
--HG--
extra : rebase_source : ed41b23993cdee89d28b835ee0ee196c15977427
2017-08-31 14:17:19 +09:00
Mike Hommey
e77f51a721 Bug 1395776 - Fold replace-malloc into mozjemalloc. r=njn
Add the MPL 2.0 license header per bug 1395449.

--HG--
extra : rebase_source : c85544a178aba7e77b5b8031851b8e16b22a3848
2017-08-31 12:02:01 +09:00
Mike Hommey
24484e3284 Bug 1395776 - Remove useless goto. r=njn
--HG--
extra : rebase_source : 760898d1521d2c27658e0494677cfecd0375894f
2017-08-31 11:47:22 +09:00
Mike Hommey
89443bb39f Bug 1395776 - Add a level of indirection on top of mozjemalloc. r=njn
Practically speaking, with code inlining, this doesn't change anything,
but will allow, in a subsequent change, to easily divert the exported
allocation functions (malloc, etc.) in order to inject replace-malloc
in the pipeline.

The added macro magic is copied from replace-malloc.c.

At the same time, reformat the functions we're touching.

--HG--
extra : rebase_source : f615909101f832f3cc471e23a3cc44a60886843f
2017-08-31 10:29:11 +09:00
Mike Hommey
dfc6786a68 Bug 1395776 - Move usable_ptr_t definition to mozjemalloc_types.h. r=njn
Because malloc_decls.h is meant to be included multiple times, it
shouldn't actually declare things itself.

--HG--
extra : rebase_source : 9d6f9b2c61407265377845963a19ace2614160f4
2017-08-31 09:51:23 +09:00
Mike Hommey
72d9b36a8c Bug 1395776 - Uniformize valloc implementations in replace-malloc and mozjemalloc. r=njn
valloc is supposed to page-align data, but mozjemalloc's definition of
pagesize is statically compiled in and might not match the actual page
size at runtime (because of MALLOC_STATIC_SIZES). We change valloc in
mozjemalloc to use the runtime page size.

--HG--
extra : rebase_source : c5b1b56e783b311ac1620a87d910e019e3f18b49
2017-08-31 11:36:09 +09:00
Mike Hommey
b0303d9e77 Bug 1395776 - Uniformize posix_memalign implementations in replace-malloc and mozjemalloc. r=njn
--HG--
extra : rebase_source : bbbee18feef2d11b71d5d5a48e98017bfae78722
2017-08-31 11:35:24 +09:00
Sebastian Hengst
43bc951ac7 merge mozilla-inbound to mozilla-central. r=merge a=merge
MozReview-Commit-ID: ES9rKhiQo10
2017-09-01 10:38:51 +02:00
Nicholas Nethercote
c419d5fa48 Bug 1389305 (attempt 2) - Add jemalloc_ptr_info() and moz_malloc_enclosing_size_of(). r=glandium.
--HG--
extra : rebase_source : 93a6cfcc916fb239581c2892f24b24c6fc65ac71
2017-09-01 11:52:23 +10:00
Mike Hommey
01f5dbf93d Bug 1395070 - Replace MOZ_MEMORY_BSD with __FreeBSD_kernel__. r=njn
While MOZ_MEMORY_BSD is set for kFreeBSD, FreeBSD and NetBSD, the only
use of MOZ_MEMORY_BSD is along a check for __GLIBC__ which can only be
true on GNU/kFreeBSD, which doesn't have a XP_ macro, but which we
usually match with __FreeBSD_kernel__.

--HG--
extra : rebase_source : 2f143f8ed641f4e338024a58e20c62b2b30e653a
2017-08-30 16:58:42 +09:00
Mike Hommey
214207b152 Bug 1395070 - Replace MOZ_MEMORY_SOLARIS with XP_SOLARIS. r=njn
--HG--
extra : rebase_source : 5ce65228f7d45da354f6447b3e54781a8553e33b
2017-08-30 16:57:46 +09:00
Mike Hommey
c5dc8a36e4 Bug 1395070 - Replace MOZ_MEMORY_ANDROID with ANDROID. r=njn
For some reason, we don't have a XP_ macro for Android, and we generally use
ANDROID or MOZ_WIDGET_ANDROID. The former is more appropriate.

--HG--
extra : rebase_source : 50576584f194aaf6b090fd530598ce9954e170b3
2017-08-30 16:56:42 +09:00
Mike Hommey
c50122ffb7 Bug 1395070 - Replace MOZ_MEMORY_LINUX with XP_LINUX. r=njn
--HG--
extra : rebase_source : 013c8019777cd87663e60def10a2df549c9308a2
2017-08-30 16:55:30 +09:00
Mike Hommey
2367bdac74 Bug 1395070 - Replace MOZ_MEMORY_DARWIN with XP_DARWIN. r=njn
--HG--
extra : rebase_source : 9e92062072cc45c524d30e9b2e28930687bf45a4
2017-08-30 16:54:17 +09:00
Mike Hommey
e290647690 Bug 1395070 - Replace MOZ_MEMORY_WINDOWS with XP_WIN. r=njn
--HG--
extra : rebase_source : 1c63dca430aa6c81472463d27df41f2acdc2df88
2017-08-30 16:53:10 +09:00
Mike Hommey
57c65279a0 Bug 1395088 - Remove the jemalloc_bool type. r=njn
Back when it was added (for Windows CE, in bug 488608), mozjemalloc was
C and all the supported compilers didn't support C99 bools. Now
mozjemalloc is C++, and all the supported compilers support C99 bools
for the cases where the type is used from C.

--HG--
extra : rebase_source : b9c710a0c48dc36cb473af59e3119131d13523ce
2017-08-30 18:04:47 +09:00
Mike Hommey
0eb2652011 Bug 1395063 - Use MOZ_CRASH directly in mozjemalloc. r=njn
Back when mozjemalloc was considered third-party, and before bug
1365194, mozjemalloc was calling abort() and that was redirectory to
MOZ_CRASH through a moz_abort() function. Bug 1365194 changed that so
that moz_abort is called directly instead of abort, but the indirection
is actually not necessary anymore.

So we just kill moz_abort, which is unused anywhere else, and use
MOZ_CRASH directly.

Note this will (obviously) change crash signatures involving moz_abort.

--HG--
extra : rebase_source : 67698ffd8c5e52e62b9a0b7f28efb0352c8fe8ce
2017-08-30 16:20:08 +09:00
Sylvestre Ledru
64ca35fefe Bug 1387572 - Silent the -Wuninitialized warning r=glandium
MozReview-Commit-ID: DjUumKhNQHz

--HG--
extra : rebase_source : 5bec2af822a54ff2c40b5944d3360b7c889c5ccb
2017-08-04 21:51:18 +02:00
Tom Ritter
1243cb04e0 Bug 1392594 Make variable DebugOnly to address unused variable warning r=glandium
MozReview-Commit-ID: 1qQQGjeWeel

--HG--
extra : rebase_source : f527762cc8d0b572c5315d2a6a11db8e69fbc999
2017-08-24 22:55:35 -05:00
David Major
406287685a Bug 1391420: Set NO_PGO on a bunch of binaries that we don't ship. r=ted 2017-08-23 15:05:40 -04:00
Sebastian Hengst
142b3bf28b Backed out changeset 109e89a7d561 (bug 1391420) for busting Linux pgo builds. r=backout on a CLOSED TREE
--HG--
extra : amend_source : 6a4421254e4de31071785b73abdd1186638e31f2
2017-08-23 18:12:46 +02:00
David Major
8cb2cb650a Bug 1391420: Set NO_PGO on a bunch of binaries that we don't ship. r=ted 2017-08-23 11:10:39 -04:00
Eric Rahm
0938982c90 Bug 1389598 - Part 4: Remove remaining gonk refs. r=froydnj
--HG--
extra : rebase_source : 063c7f95dda063eafabfa1921366bd1957b8fe73
2017-08-11 17:45:18 -07:00
Nicholas Nethercote
57c26c9834 Bug 1387956 - Overhaul ComputedValues measurement, and add style structs measurement. r=bholley.
This patch moves measurement of ComputedValues objects from Rust to C++.
Measurement now happens (a) via DOM elements and (b) remaining elements via
the frame tree. Likewise for the style structs hanging off ComputedValues
objects.

Here is an example of the output.

> ├──27,600,448 B (26.49%) -- active/window(https://en.wikipedia.org/wiki/Barack_Obama)
> │  ├──12,772,544 B (12.26%) -- layout
> │  │  ├───4,483,744 B (04.30%) -- frames
> │  │  │   ├──1,653,552 B (01.59%) ── nsInlineFrame
> │  │  │   ├──1,415,760 B (01.36%) ── nsTextFrame
> │  │  │   ├────431,376 B (00.41%) ── nsBlockFrame
> │  │  │   ├────340,560 B (00.33%) ── nsHTMLScrollFrame
> │  │  │   ├────302,544 B (00.29%) ── nsContinuingTextFrame
> │  │  │   ├────156,408 B (00.15%) ── nsBulletFrame
> │  │  │   ├─────73,024 B (00.07%) ── nsPlaceholderFrame
> │  │  │   ├─────27,656 B (00.03%) ── sundries
> │  │  │   ├─────23,520 B (00.02%) ── nsTableCellFrame
> │  │  │   ├─────16,704 B (00.02%) ── nsImageFrame
> │  │  │   ├─────15,488 B (00.01%) ── nsTableRowFrame
> │  │  │   ├─────13,776 B (00.01%) ── nsTableColFrame
> │  │  │   └─────13,376 B (00.01%) ── nsTableFrame
> │  │  ├───3,412,192 B (03.28%) -- servo-style-structs
> │  │  │   ├──1,288,224 B (01.24%) ── Display
> │  │  │   ├────742,400 B (00.71%) ── Position
> │  │  │   ├────308,736 B (00.30%) ── Font
> │  │  │   ├────226,512 B (00.22%) ── Background
> │  │  │   ├────218,304 B (00.21%) ── TextReset
> │  │  │   ├────214,896 B (00.21%) ── Text
> │  │  │   ├────130,560 B (00.13%) ── Border
> │  │  │   ├─────81,408 B (00.08%) ── UIReset
> │  │  │   ├─────61,440 B (00.06%) ── Padding
> │  │  │   ├─────38,176 B (00.04%) ── UserInterface
> │  │  │   ├─────29,232 B (00.03%) ── Margin
> │  │  │   ├─────21,824 B (00.02%) ── sundries
> │  │  │   ├─────20,080 B (00.02%) ── Color
> │  │  │   ├─────20,080 B (00.02%) ── Column
> │  │  │   └─────10,320 B (00.01%) ── Effects
> │  │  ├───2,227,680 B (02.14%) -- computed-values
> │  │  │   ├──1,182,928 B (01.14%) ── non-dom
> │  │  │   └──1,044,752 B (01.00%) ── dom
> │  │  ├───1,500,016 B (01.44%) ── text-runs
> │  │  ├─────492,640 B (00.47%) ── line-boxes
> │  │  ├─────326,688 B (00.31%) ── frame-properties
> │  │  ├─────301,760 B (00.29%) ── pres-shell
> │  │  ├──────27,648 B (00.03%) ── pres-contexts
> │  │  └─────────176 B (00.00%) ── style-sets

The 'servo-style-structs' and 'computed-values' sub-trees are new. (Prior to
this patch, ComputedValues under DOM elements were tallied under the the
'dom/element-nodes' sub-tree, and ComputedValues not under DOM element were
ignored.) 'servo-style-structs/sundries' aggregates all the style structs that
are smaller than 8 KiB.

Other notable things done by the patch are as follows.

- It significantly changes the signatures of the methods measuring nsINode and
  its subclasses, in order to handle the tallying of style structs separately
  from element-nodes. Likewise for nsIFrame.

- It renames the 'layout/style-structs' sub-tree as
  'layout/gecko-style-structs', to clearly distinguish it from the new
  'layout/servo-style-structs' sub-tree.

- It adds some FFI functions to access various Rust-side data structures from
  C++ code.

- There is a nasty hack used twice to measure Arcs, by stepping backwards from
  an interior pointer to a base pointer. It works, but I want to replace it
  with something better eventually. The "XXX WARNING" comments have details.

- It makes DMD print a line to the console if it sees a pointer it doesn't
  recognise. This is useful for detecting when we are measuring an interior
  pointer instead of a base pointer, which is bad but easy to do when Arcs are
  involved.

- It removes the Rust code for measuring CVs, because it's now all done on the
  C++ side.

MozReview-Commit-ID: BKebACLKtCi

--HG--
extra : rebase_source : 4d9a8c6b198a0ff025b811759a6bfa9f33a260ba
2017-08-11 16:37:33 +10:00
Mike Hommey
fda40761ff Bug 1388935 - Avoid overflowing the chunk recycling limit with very large chunks. r=njn
When recycling chunks, mozjemalloc tries to avoid keeping around more
than 128MB worth of chunks around, but it doesn't actually look at the
size of the chunks that are recycled, so if chunk larger than 128MB is
recycled, it is kept as a whole, going well over the limit.

The chunks are still properly reused, and further recycling doesn't
occur, but that can limit other mmap users from getting enough address
space.

With this change, mozjemalloc now doesn't keep more than 128MB, by
splitting the chunks it recycles if they are too large.

Note this was not a problem on Windows, where chunks larger than 1MB are
never recycled (per CAN_RECYCLE).

--HG--
extra : rebase_source : 6765fd30b78ca5ddc7d55aac861355d960e47828
2017-08-10 09:22:55 +09:00
Mike Hommey
b0f2504373 Bug 1388935 - Inline chunk_dalloc_mmap into chunk_dealloc. r=njn
--HG--
extra : rebase_source : 3348f221f1f577c3af6c1b213a692e58ce347ead
2017-08-10 08:49:51 +09:00
Phil Ringnalda
fe1932364b Backed out 2 changesets (bug 1388935) for gtest crashes
Backed out changeset 208572c7abae (bug 1388935)
Backed out changeset dfb4a15b0c32 (bug 1388935)

MozReview-Commit-ID: HRttV7AIlNT
2017-08-09 22:21:37 -07:00
Mike Hommey
44b527c7d7 Bug 1388935 - Avoid overflowing the chunk recycling limit with very large chunks. r=njn
When recycling chunks, mozjemalloc tries to avoid keeping around more
than 128MB worth of chunks around, but it doesn't actually look at the
size of the chunks that are recycled, so if chunk larger than 128MB is
recycled, it is kept as a whole, going well over the limit.

The chunks are still properly reused, and further recycling doesn't
occur, but that can limit other mmap users from getting enough address
space.

With this change, mozjemalloc now doesn't keep more than 128MB, by
splitting the chunks it recycles if they are too large.

Note this was not a problem on Windows, where chunks larger than 1MB are
never recycled (per CAN_RECYCLE).

--HG--
extra : rebase_source : f81e94c6960ba253037f77de1a39c9ff74651e80
2017-08-10 09:22:55 +09:00
Mike Hommey
b206b3c597 Bug 1388935 - Inline chunk_dalloc_mmap into chunk_dealloc. r=njn
--HG--
extra : rebase_source : f6abde118d26552a681faf7df302b791d39e466a
2017-08-10 08:49:51 +09:00
Nicholas Nethercote
710682624c Bug 1387940 - Make --max-frames=8 the default for dmd.py. r=mccr8.
The current default is 24, which is equal to the maximum number of stack frames
that DMD will record. And that's a terrible value because it splits up too many
related stack traces into separate records. There is no single best value, but
8 is a much better default.

--HG--
extra : rebase_source : c423fc4fe0e490ff6d58fa8f7116bc01c86a366e
2017-08-07 14:56:15 +10:00
Wes Kocher
baf6cddc4c Merge inbound to central, a=merge
MozReview-Commit-ID: 9NFjSEt96iT
2017-08-02 17:11:51 -07:00
Nicholas Nethercote
406a9ed175 Bug 1384819 (part 3) - Remove the return value from the stack walker functions. r=glandium.
Just one caller (in DMD) actually looks at it, and that's in an unimportant way
-- if the return value was false, mLength would be zero anyway.

--HG--
extra : rebase_source : 0463ab3765744742a9e854964342d631095fa55f
2017-07-27 16:46:55 +10:00
Nicholas Nethercote
8a20eb82d2 Bug 1384819 (part 2) - Tweak FramePointerStackWalk() arguments. r=glandium.
This patch does he following.

- Avoids some unnecessary casting.

- Renames the |bp| parameter as |aBp|.

- Makes the no-op FramePointerStackWalk() signature match the real one.
  (Clearly it's dead code in all built configurations!)

--HG--
extra : rebase_source : 3fe606d1ff9b063294f4028ff884c20661ed9e0a
2017-07-27 16:46:33 +10:00
Nicholas Nethercote
08e54b7c13 Bug 1384819 (part 1) - Split MozStackWalk(). r=glandium.
MozStackWalk() is different on Windows to the other platforms. It has two extra
arguments, which can be used to walk the stack of a different thread.

This patch makes those differences clearer. Instead of having a single function
and forbidding those two arguments on non-Windows, it removes those arguments
from MozStackWalk, and splits off MozStackWalkThread() which retains them. This
also allows those arguments to have more appropriate types (HANDLE instead of
uintptr_t; CONTEXT* instead of than void*) and names (aContext instead of
aPlatformData).

The patch also removes unnecessary reinterpret_casts for the aClosure argument
at a couple of MozStackWalk() callsites.

--HG--
extra : rebase_source : 111ab7d6426d7be921facc2264f6db86c501d127
2017-07-27 12:46:47 +10:00
Botond Ballo
b93629ee1d Bug 1383919 - Use |noexcept| instead of an exception-specification in mozalloc.h. r=glandium
MozReview-Commit-ID: DwrE8cmZOQN

--HG--
extra : rebase_source : e45f35dd009a3a8a94f50afc55177976c532f16a
2017-07-24 19:19:07 -04:00
Mike Hommey
4aaef7b18a Bug 1395032 - Remove remainder of the VS CRT allocator mismatch hack. r=gps
Bug 1186064 removed most of it when we started requiring VS 2015u2, but
the "frex" function exported through mozglue.def.in was only used
through the MSVCRT being patched by fixcrt.py, which is not done anymore.
So the "frex" export is not used anymore, and so the "dumb_free_thunk"
function is not used anymore as well.

--HG--
extra : rebase_source : 879c469c317c8b6749410a4a476d6c951c9a1d0f
2017-08-30 14:06:13 +09:00
Nicholas Nethercote
f7a538edd4 Bug 1382076 - Use FramePointerStackWalk() in DMD on Win32. r=erahm.
The patch also uses a better value for skipFrames on Win64.

--HG--
extra : rebase_source : ef3d6d68fbea45e7fd571db2ba78904d97f5e21e
2017-07-20 11:33:31 +10:00
Nicholas Nethercote
7d699f9fa4 Bug 1382099 - Remove MOZ_WIDGET_GONK from memory/. r=glandium.
--HG--
extra : rebase_source : 641de85945cb2f0ccdb9d6f5207bdd22b597b318
2017-07-19 18:39:00 +10:00
Mike Hommey
4956a3cafa Bug 1379897 - Remove opt_abort. r=njn
It causes abort() on errors from munmap/VirtualFree (which in practice
don't happen except maybe in case of memory corruption), and was only
enabled on debug builds.

--HG--
extra : rebase_source : fb0c8c82dc1e2d1f14a588a82144cf82e4f4f773
2017-07-11 14:24:35 +09:00
Carsten "Tomcat" Book
31311070d9 merge mozilla-inbound to mozilla-central a=merge 2017-07-11 12:51:59 +02:00
Mike Hommey
1246710041 Bug 1379890 - Remove unused mozjemalloc stats. r=njn
Since bug 1378258 remove malloc_print_stats, there are a bunch of
allocator stats that are now unused, reducing the memory footprint of
allocator metadata.

--HG--
extra : rebase_source : 337ef3b647c20119334b6576d591006f6bb3dd16
2017-07-11 14:42:57 +09:00
Mike Hommey
1ecc9df3fc Bug 1379878 - Use C++ templates to make _malloc_message calls cleaner. r=njn
--HG--
extra : rebase_source : 695fd9ce6b1f216a8bda29b849e1372601a43fe4
2017-07-11 14:15:04 +09:00
Mike Hommey
26fb8eb7b0 Bug 1379878 - Remove umax2s, its last use was removed in bug 1378258. r=njn
--HG--
extra : rebase_source : d9cb0631662ec0015e9c6d268884adb31c5a38bb
2017-07-11 14:09:09 +09:00
Mike Hommey
860374cbca Bug 1360772 - Allow to initialize non-zeroed arena chunks. r=njn
When initializing a new chunk for use as an arena, we started by zeroing
out the chunk (if that wasn't the case) and then initializing a new
arena chunk in there. It turns out this can have a noticeable overhead,
especially when e.g. the new arena chunk is used for a large allocation
filled out by something that is realloc()ated.

OTOH, the chunk recycle code only ever keeps zeroed or arena chunks
around (there is a "recycled" type too, but in practice, at the moment,
this means they were arena chunks before). Arena chunks that were
recycled were totally emptied, so all the runs they may contain will
contain zeroed-out or poisoned data. They also contain a header, that is
overwritten by the new arena chunk initialization.

This means we can get away with reusing non-zeroed recycled chunks
without zeroing them, as long as the arena chunk header marks the runs
as madvised instead of zeroed.

Code-wise, this would benefit from getting a ChunkType out of
chunk_alloc, but this would require more refactoring than I'm willing to
do at the moment.
2017-07-11 13:55:26 +09:00
Mike Hommey
e6c1516607 Bug 1360772 - Indicate to chunk_recycle callers that pages_commit has zeroed the chunk. r=njn
Before returning a chunk, chunk_recycle calls pages_commit (when
MALLOC_DECOMMIT is enabled), which is guaranteed to zero the chunk.

The code further zeroing the chunk afterwards, which is now moved out to
chunk_alloc callers, never took advantage of that fact, duplicating the
effort of zeroing the chunk on Windows.

By indicating to the callers that the chunk has already been zeroed, we
allow callers to skip zeroing on their own.
2017-07-11 13:44:40 +09:00
Mike Hommey
78a584db8a Bug 1360772 - Make chunk_alloc callers handle zeroing when they need it. r=njn
The current code only allows chunk_calloc() callers to tell whether they
want zeroed memory or not, but some might be okay either way, assuming
they act accordingly afterwards. So move the zeroing out of chunk_alloc.
2017-07-11 13:44:39 +09:00
Mike Hommey
f26f174a0e Bug 1360772 - Store the chunk type in chunk recycling queue. r=njn 2017-07-11 13:44:21 +09:00
Mike Hommey
0380bc7b32 Bug 1360772 - Make pages_purge return whether the pages were purged. r=njn
Many functions in the mozjemalloc codebase like to return the opposite
boolean one would tend to expect. Pages_purge is one of them, and this
reverses the logic to match expectations.

Also make it static.
2017-07-11 13:11:55 +09:00
Mike Hommey
bf7a9e79f6 Bug 1379139 - Instead of not recycling huge chunks, zero them. r=njn
It turns out that not recycling some kinds of chunk can lead to the
recycle queue being starved in some scenarios. When that happens, we end
up mmap()ing new memory, but that turns out to be significantly slower.

So instead of not recycling huge chunks, we force-clean them, before
madvising so that the pages can still be reclaimed in case of memory
pressure.

--HG--
extra : rebase_source : 2dbd028daca92c9cd7c8079eb3dc5a0cfa06495b
2017-07-10 06:41:17 +09:00
Nicholas Nethercote
4325ae218a Bug 1371397 - Use FramePointerStackWalk() in DMD on Mac. r=erahm.
This avoids MozStackWalk(), which has become unusably slow on Mac due to
changes in libunwind, and gets us back to decent speed.

The code for getting the frame pointer and stack end was copied from the Gecko
Profiler, which also uses FramePointerStackWalk() on Mac.

--HG--
extra : rebase_source : 58c32c2df8716c7c8123a4a8fb692182d066caca
2017-07-07 07:08:08 +10:00
Carsten "Tomcat" Book
b5c809a8bc merge mozilla-inbound to mozilla-central a=merge 2017-07-07 10:35:44 +02:00
Mike Hommey
19448fe709 Bug 1356701 - Export unprefixed malloc and duplication functions on OSX. r=njn
Going through the system zone allocator for every call to realloc/free
on OSX is costly, because the zone allocator needs to first verify that
the allocations do belong to the allocator it invokes (which ends up
calling jemalloc's malloc_usable_size), which is unnecessary when we
expect the allocations to belong to jemalloc.

So, we export the malloc/realloc/free/etc. symbols from
libmozglue.dylib, such that libraries and programs linked against it
call directly into jemalloc instead of going through the system zone
allocator, effectively shortcutting the allocator verification.

The risk is that some things in Gecko try to realloc/free pointers it
got from system libraries, if those were allocated with a system zone
that is not jemalloc.

--HG--
extra : rebase_source : ee0b29e1275176f52e64f4648dfa7ce25d61292e
2017-07-04 15:01:50 +09:00
Mike Hommey
ed863255b4 Bug 1378592 - Remove MOZ_REPLACE_MALLOC_LINKAGE. r=froydnj
MOZ_REPLACE_MALLOC_LINKAGE was added back when there were problems with
getting weak references working properly for replace-malloc.

Versions of OSX < 10.6 needed flat namespace, but aren't supported
anymore.

Versions of Xcode < 4.5 required flat namespace + a dummy library in
order to produce proper weak references. There is virtually nobody still
building with such an ancient toolchain.

Keeping those around doesn't /really/ hurt, except recent versions of
Xcode don't expose dyldinfo in /usr/bin, used for the configure test.
Consequently, MOZ_REPLACE_MALLOC_LINKAGE ended up being set to use the
dummy library setup, which, by using flat namespace, now causes harm in
bug 1356701, causing bug 1378332.

--HG--
extra : rebase_source : e3edc1f2cf905943c33fafeb631f2f88fc87167e
2017-07-06 10:26:04 +09:00
Mike Hommey
a02826e8ee Bug 1378278 - Use nullptr in mozjemalloc. r=njn
At the same time:
- replace "(nullptr)" with "nullptr",
- replace "x == nullptr" with "!x",
- replace "x != nullptr" with "x".

--HG--
extra : rebase_source : 5bc5577d0de53244afae9ebadb84962f38306368
2017-07-05 14:02:50 +09:00
Ryan VanderMeulen
5e1e8d2f24 Backed out changeset 261d61f4eeec (bug 1356701) for causing bug 1378339. 2017-07-05 12:58:39 -04:00
Mike Hommey
230dccc3d5 Bug 1378258 - Remove malloc_print_stats. r=njn
malloc_print_stats is designed as a end-of-process dump of malloc stats,
but it has limited value in Firefox itself. It has some usefulness as
something to invoke from a debugger while Firefox is running (after
manually setting opt_print_stats to true), but it also lacks information
about live allocations, which would make it more useful.

All in all, if we want some stats about jemalloc allocations in a more
useful way, we'd be better off augmenting the jemalloc_stats() API and
make the data available to e.g. about:memory, than keeping
malloc_print_stats.

--HG--
extra : rebase_source : f6fbc97dfddd52c8620e37e2e189ae0087a845b0
2017-07-05 10:07:43 +09:00
Mike Hommey
c65bedc1c8 Bug 1356701 - Export unprefixed malloc and duplication functions on OSX. r=njn
Going through the system zone allocator for every call to realloc/free
on OSX is costly, because the zone allocator needs to first verify that
the allocations do belong to the allocator it invokes (which ends up
calling jemalloc's malloc_usable_size), which is unnecessary when we
expect the allocations to belong to jemalloc.

So, we export the malloc/realloc/free/etc. symbols from
libmozglue.dylib, such that libraries and programs linked against it
calls directly into jemalloc instead of going through the system zone
allocator, effectively shortcutting the allocator verification.

The risk is that some things in Gecko try to realloc/free pointers it
got from system libraries, if those were allocated with a system zone
that is not jemalloc.

--HG--
extra : rebase_source : 45b9b98499760a7f946878d41d2fdaadb6dff4d6
2017-07-04 15:01:50 +09:00
Petr Sumbera
a393f2a6cf Bug 1375467 - Redefining abort() in C++ requires extern "C". r=glandium 2017-06-22 05:09:05 -07:00
Jeff Gilbert
58ae26fbc7 Bug 1376057 - Replace MSVC wrappers with std::exception::_Set_raise_handler. - r=froydnj
MozReview-Commit-ID: MG5c4bzDlI
2017-06-27 11:51:34 -07:00
Mike Hommey
7ccc8afe84 Bug 1378658 - When page_purges doesn't zero pages, only record arena chunks or previously recycled chunks for future recycling. r=njn 2017-07-07 09:18:03 +09:00
Mike Hommey
29524a9451 Bug 1369626 - Remove MALLOC_XMALLOC. r=njn
Setting MALLOC_XMALLOC enables a runtime toggle that allows to make
allocations abort() on OOM instead of returning NULL. In other words,
it enables a toggle that allows to turn all allocations into infallible
allocations.

The toggle however still defaults to being disabled, which means even
when MALLOC_XMALLOC is defined when building mozjemalloc, there is no
change in behavior, unless a MALLOC_OPTIONS is set.

Even if this were useful to anyone (MALLOC_XMALLOC is only defined on
debug builds, limiting the usefulness), this is something
replace-malloc, in Firefox, is meant to be used for.

So let's remove this feature, and possibly add an equivalent
replace-malloc later if deemed necessary.

--HG--
extra : rebase_source : 1ccc893e9a8e842c3fa90e91f076a528df2f7dfe
2017-06-02 15:19:20 +09:00
Mike Hommey
1b12c351f2 Bug 1368932 - Add a testcase for a replace-malloc library that doesn't implement all functions. r=njn
--HG--
rename : memory/replace/logalloc/moz.build => memory/replace/logalloc/logalloc.mozbuild
rename : memory/replace/logalloc/replay/replay.log => memory/replace/logalloc/replay/expected_output_minimal.log
extra : rebase_source : 94f8fb4444e2e0ecda61e5ffd283ab560d1e9dfe
2017-05-31 15:04:32 +09:00
Mike Hommey
4ae1509807 Bug 1368932 - Handle missing replace_posix_memalign at the replace-malloc level. r=njn
Replace-malloc libraries, such as DMD, don't really need to care about
the details of implementing all the variants of aligned memory
allocation functions. Currently, by defining MOZ_REPLACE_ONLY_MEMALIGN
before including replace_malloc.h, they get predefined functions.

Instead of making that an opt-in at build time, we make the
replace-malloc initialization just fill the replace-malloc
malloc_table_t with implementations that rely on the replace_memalign
the library provides.

--HG--
extra : rebase_source : 0842a67d9bc27a9a86c33d14d98b9c25f39982fb
2017-05-31 13:47:17 +09:00
Mike Hommey
7fd2c94e79 Bug 1368932 - Move the replace_malloc_init_funcs function around. r=njn
--HG--
extra : rebase_source : 4e3b3bbd18a37a3ee01d6ec30449249be5481b77
2017-05-31 13:47:11 +09:00
Mike Hommey
565f74102e Bug 1368932 - Fill the replace-malloc malloc_table_t with the real allocator as a fallback. r=njn
Until now, the malloc implementation functions would call the
replace-malloc functions if they exist, and fallback to the real
allocator in no such function exists. Instead of doing this, we now
fill the empty slots in the malloc_table_t with the real allocator
functions.

--HG--
extra : rebase_source : b54634f23188906939e4dc01fc5a3007de0f3f2c
2017-05-30 15:57:28 +09:00
Mike Hommey
1a6ac2f8fb Bug 1368932 - Use a malloc_table_t for most replace-malloc function pointers, on all platforms. r=njn
We make replace_malloc_init_funcs called on all platforms and fill out a
malloc_table_t for the replace-malloc functions with what comes from
dlsym/GetProcAddress on Android/Windows, and from the dynamically linked
weak symbols replace_* on other platforms.

replace_malloc.h contains definitions of *_impl_t types for each of the
functions in the malloc_table_t, which is redundant with the
replace_*_impl_t types we were creating, so we remove those typedefs,
except for the two functions (init and get_bridge) that don't have such
a typedef. Those functions don't appear in malloc_table_t.

--HG--
extra : rebase_source : 3705a99ee07f63dbaa66973eef19ddab224e0911
2017-05-30 15:57:28 +09:00
Mike Hommey
409495f283 Bug 1368932 - Refactor such that there is only one definition of replace_malloc_init_funcs. r=njn
We want, in a subsequent patch, to have replace_malloc_init_funcs be
called on all platforms (including those relying on the replace-malloc
library being loaded already) and perform more initialization.

To prepare for that, we move the non-platform-specific pieces out.

--HG--
extra : rebase_source : 239ed363ee168bf4f8a96e0a1ca52981cb941b71
2017-05-30 15:57:28 +09:00
Mike Hommey
37b66db19d Bug 1368932 - Generate all the _impl functions with macros in replace-malloc. r=njn
All the _impl functions in replace-malloc.c are largely identical. This
replaces all of them with macro expansions.

--HG--
extra : rebase_source : 67a1809b0b0fc4645ea5041154fa3a6dcb6cce6b
2017-05-25 16:47:57 +09:00
Mike Hommey
e4fddc104f Bug 1368932 - Add argument names to malloc implementation declarations in replace-malloc. r=njn
This transforms the declarations from e.g.:
    void *realloc(void *, size_t);
into:
    void *realloc(void *arg1, size_t arg2);

--HG--
extra : rebase_source : 627eb833a98d11f044c776f9d29715ccad31174d
2017-05-25 16:04:46 +09:00
Mike Hommey
2357f45d41 Bug 1368932 - Don't rely on the default MALLOC_DECL_VOID for malloc function declarations in replace-malloc. r=njn
In practice, this induces no change in what the expanded code looks
like.

--HG--
extra : rebase_source : 0df6a5dd3ca5161c0969c814e4222eeb51f9f9a2
2017-05-25 15:58:56 +09:00
Mike Hommey
7cd6d8b45d Bug 1368932 - Factor out function declarations for malloc implementation. r=njn
--HG--
extra : rebase_source : a8df78c7ade473eb5d7c71228f0939cce4554f57
2017-05-25 15:54:05 +09:00
Mike Hommey
16215c85f1 Bug 1368932 - Remove void argument from declarations in malloc_decls.h. r=njn
This makes no significant difference in practice in the macro
expansions, but will help down the line.

--HG--
extra : rebase_source : 6d61c1f28c558321478d7e5f26390d27ae8ae3ac
2017-05-25 13:56:40 +09:00
Mike Hommey
f9a4ab0e55 Bug 1367695 - Remove leftovers from jemalloc4. r=njn
MOZ_REPLACE_JEMALLOC was only defined when building jemalloc4 as a
replace-malloc library.

--HG--
extra : rebase_source : fa5c402da07fa96448c170b6db99629469691efe
2017-05-25 16:24:13 +09:00
Mike Hommey
fade48cbe6 Bug 1365206 - Remove Sun Studio compiler optimization flags for mozjemalloc. r=gps
We don't support that compiler anymore.
2017-05-19 08:29:05 +09:00
Mike Hommey
fbbe2d361d Bug 1365460 - Remove function prototypes but keep necessary forward declarations. r=njn
--HG--
extra : rebase_source : 670aecc65cf709f2312a29c80e3c3171ccb2c8c2
2017-05-18 16:27:06 +09:00
Mike Hommey
1dfc7df618 Bug 1365460 - Make umax2s support only base 10. r=njn
Other bases are never used.

--HG--
extra : rebase_source : 6c8edcbde86480995b2d96ac513724e3212457cf
2017-05-18 16:22:10 +09:00