Граф коммитов

200 Коммитов

Автор SHA1 Сообщение Дата
Mike Hommey 00433d9cf4 Bug 1401099 - Move arena_ralloc_large_grow to a method of arena_t. r=njn
--HG--
extra : rebase_source : 0a1863785b2c3a22946ee735c73afa5ac764f076
2017-09-15 20:50:42 +09:00
Mike Hommey 3c2c85e407 Bug 1401099 - Move arena_ralloc_large_shrink to a method of arena_t. r=njn
--HG--
extra : rebase_source : 3b9aede58b3c9163b8a28a4371120d471533f8eb
2017-09-15 20:44:34 +09:00
Mike Hommey 24adb9a7a8 Bug 1401099 - Move arena_dalloc_large to a method of arena_t. r=njn
--HG--
extra : rebase_source : dbc79744f42ed99709ed9857ec5d91ceaea83b0d
2017-09-15 20:40:36 +09:00
Mike Hommey eea012c8aa Bug 1401099 - Move arena_dalloc_small to a method of arena_t. r=njn
--HG--
extra : rebase_source : 9cc4efbbcd0da012be9fa4e5dd3262d89bdab161
2017-09-15 20:37:47 +09:00
Mike Hommey 05188caf59 Bug 1401099 - Move arena_palloc to a method of arena_t. r=njn
--HG--
extra : rebase_source : 0c64ea5c0681704a85e15977a8803403d06d0962
2017-09-15 20:28:23 +09:00
Mike Hommey 91f0d70f6f Bug 1401099 - Move arena_malloc to a method of arena_t. r=njn
--HG--
extra : rebase_source : c06e3c5a63a12ba48f7f4bc52390ba9c8670f722
2017-09-15 19:20:09 +09:00
Mike Hommey cd573d5abc Bug 1401099 - Move arena_malloc_large to a method of arena_t. r=njn
--HG--
extra : rebase_source : 837d0d67556097140ff6141f2876fdbbb70d4e08
2017-09-15 19:14:00 +09:00
Mike Hommey 3576cd2578 Bug 1401099 - Move arena_malloc_small to a method of arena_t. r=njn
--HG--
extra : rebase_source : 7df0043060caf4cd14fc48428296428acf1771c7
2017-09-15 19:11:52 +09:00
Mike Hommey 2c4099f29f Bug 1401099 - Move arena_bin_nonfull_run_get to a method of arena_t. r=njn
--HG--
extra : rebase_source : 808f7ba52a4fc4f99a283ae894296cafac5166da
2017-09-15 18:23:33 +09:00
Mike Hommey 003004a71a Bug 1401099 - Move arena_bin_malloc_hard to a method of arena_t. r=njn
--HG--
extra : rebase_source : 2bed3221e38714d00ab95937d20ac5faafc89e9e
2017-09-15 18:20:11 +09:00
Mike Hommey 577b65d3c1 Bug 1401099 - Move arena_bin_malloc_easy to a method of arena_t. r=njn
--HG--
extra : rebase_source : 8675de21e7c79e3c458367f3f10b1331efe55094
2017-09-15 18:18:11 +09:00
Mike Hommey 0ec33d017f Bug 1401099 - Move arena_run_trim_tail to a method of arena_t. r=njn
--HG--
extra : rebase_source : e105fa4b8aae6b41c12e2f72293cdf68489a939d
2017-09-15 18:14:33 +09:00
Mike Hommey 3cc5f23c76 Bug 1401099 - Move arena_run_trim_head to a method of arena_t. r=njn
--HG--
extra : rebase_source : 2a2d2b9d454d69d0d1924f60d4771b39a1dddfb2
2017-09-15 18:11:12 +09:00
Mike Hommey b6e66b7b02 Bug 1401099 - Move arena_run_split to a method of arena_t. r=njn
--HG--
extra : rebase_source : 919dc2b9980ae59340553bcbfa029ba9c1bf9479
2017-09-15 18:08:23 +09:00
Mike Hommey 99d28b4355 Bug 1401099 - Move arena_run_dalloc to a method of arena_t. r=njn
--HG--
extra : rebase_source : 5cf37d39b6d8bdb591352051b3f37a2e3982dc69
2017-09-15 18:01:27 +09:00
Mike Hommey 7cb9914a15 Bug 1401099 - Move arena_run_alloc to a method of arena_t. r=njn
--HG--
extra : rebase_source : 6a683f4d0cf5ad68c670dbe8ea9d3a34acf11549
2017-09-15 17:57:11 +09:00
Mike Hommey d2ba03c881 Bug 1401099 - Move arena_chunk_dealloc to a method of arena_t. r=njn
--HG--
extra : rebase_source : 973b8764903f4e9c65aaaa053bb394a8a9ff2acb
2017-09-15 17:50:48 +09:00
Mike Hommey d6d578553d Bug 1401099 - Move arena_chunk_init to a method of arena_t. r=njn
--HG--
extra : rebase_source : d30e062f7117743a0c88fdf0325b0a395bff5658
2017-09-15 17:43:36 +09:00
Mike Hommey 11cfd193d1 Bug 1401099 - Move arena_new to a method of arena_t. r=njn
--HG--
extra : rebase_source : d0a9a0cebb4e8a1a74c5a48e42fb952310798604
2017-09-15 17:38:58 +09:00
Mike Hommey beb406f1a7 Bug 1401099 - Move hard_purge_arena to a method of arena_t. r=njn
--HG--
extra : rebase_source : af20d24ba0dd8ce6c9e42703688c1bca98594b4d
2017-09-15 17:34:53 +09:00
Mike Hommey a980219f16 Bug 1401099 - Move arena_purge to a method of arena_t. r=njn
--HG--
extra : rebase_source : d48623ce7ea7be5489c89a575bc1409de34e834a
2017-09-15 17:32:21 +09:00
Mike Hommey cb3efd88ef Bug 1401099 - Use Gecko style names for arena_t members. r=njn
--HG--
extra : rebase_source : cefcbc29323145557faed6c676867500c21c6ba4
2017-09-15 17:20:01 +09:00
Mike Hommey 707bc83a01 Bug 1401875 - Replace MALLOC_DECL_VOID with a clever use of templates. r=njn
This effectively means malloc_hook_table_t is now C++ only, which is not
a big problem.

This also makes some functions use a return construct with functions
that don't return a value (such as free). While that is not allowed in
ISO C, it's allowed in C++, so the simplification is welcome (although,
retrospectively, it turns out C compilers don't complain about it
without -pedantic).

--HG--
extra : rebase_source : defd88ca3f6d478e61a4b970393dba60fb6ca81d
2017-09-21 15:27:12 +09:00
Mike Hommey 4a2740def4 Bug 1401453 - Don't keep libmemory.a separate anymore. r=gps
This was done in bug 736564 for the xulrunner SDK, which later became
the firefox SDK, which is now gone. So we don't actually need to keep it
separate anymore (except for logalloc/replay, which still needs to link
it directly, so we keep the library definition intact so it can be
referenced ; we just don't DIST_INSTALL it anymore, and always make it
linked into mozglue)

--HG--
extra : rebase_source : e4d0627ec907fe0139df5c0b2b9f7d04b43c7c78
2017-09-20 14:23:57 +09:00
Mike Hommey 7bbdb00059 No bug - Remove a comment that has no significance after bug 1395776. r=me 2017-09-20 11:53:00 +09:00
Mike Hommey 078c8d1896 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 50182c9f53 Bug 1400146 - Gracefully handle the allocator not being initialized in isalloc_validate. r=njn
isalloc_validate is the function behind malloc_usable_size. If for some
reason malloc_usable_size is called before mozjemalloc is initialized,
this can lead to an unexpected crash.

The chance of this actually happening is rather slim on Linux
and Windows (although still possible), and impossible on Mac, due to the
fact the earlier something can end up calling it is after the
mozjemalloc zone is registered, which happens after initialization.

... except with bug 1399921, which reorders that initialization, and
puts the zone registration first. There's then a slim chance for the
zone allocator to call into zone_size, which calls malloc_usable_size,
to determine whether a pointer allocated by some other zone belongs to
mozjemalloc's.

And it turns out that does happen, during the startup of the
plugin-container process on OSX 10.10 (but not more recent versions).

--HG--
extra : rebase_source : 331d093b03add7b2c2ce440593f5aeccaaf4dd1f
2017-09-15 15:13:52 +09:00
Mike Hommey f3bff41d59 Bug 1400096 - Don't define the operator new/delete functions as mangled in mozmem_wrap.cpp. r=njn
Now that this is a C++ file, and that the function names are not
mangled, we can just use the actual C++ names.

We do however need to replace MOZ_MEMORY_API, which implies extern "C",
with MFBT_API.

Also use the correct type for the size given to operator new. It
happened to work before because the generated code would just jump to
malloc without touching any register, but on aarch64, unsigned int was
the wrong type.

--HG--
extra : rebase_source : 8045f30e9c609dd7d922c77d85ac017638df6961
2017-09-15 10:28:33 +09:00
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
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
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
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 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 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 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 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
Sebastian Hengst 4310ea4600 Backed out changeset f232b5b1a0c7 (bug 1389305) for frequently failing GTest Jemalloc.PtrInfo on Linux opt. r=backout 2017-08-31 13:52:48 +02:00
Nicholas Nethercote 365285b831 Bug 1389305 - Add jemalloc_ptr_info() and moz_malloc_enclosing_size_of(). r=glandium.
jemalloc_ptr_info() gives info about any pointer, such as whether it's within a
live or free allocation, and if so, info about that allocation. It's useful for
debugging.

moz_malloc_enclosing_size_of() uses jemalloc_ptr_info() to measure the size of
an allocation from an interior pointer. It's useful for memory reporting,
especially for Rust code.

--HG--
extra : rebase_source : caa19cccf8c2d1f79cf004fe6a408775de5a7b22
2017-08-24 19:37:27 +10:00