Home | History | Annotate | Download | only in jemalloc
      1 //
      2 // Copyright (C) 2014 The Android Open Source Project
      3 //
      4 // Licensed under the Apache License, Version 2.0 (the "License");
      5 // you may not use this file except in compliance with the License.
      6 // You may obtain a copy of the License at
      7 //
      8 //      http://www.apache.org/licenses/LICENSE-2.0
      9 //
     10 // Unless required by applicable law or agreed to in writing, software
     11 // distributed under the License is distributed on an "AS IS" BASIS,
     12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 // See the License for the specific language governing permissions and
     14 // limitations under the License.
     15 //
     16 
     17 common_cflags = [
     18     "-std=gnu99",
     19     "-D_REENTRANT",
     20     "-fvisibility=hidden",
     21     "-Wno-unused-parameter",
     22     "-Wno-type-limits",
     23 ]
     24 
     25 // These parameters change the way jemalloc works.
     26 //   ANDROID_ALWAYS_PURGE
     27 //     If defined, always purge immediately when a page is purgeable.
     28 //   ANDROID_MAX_ARENAS=XX
     29 //     The total number of arenas will be less than or equal to this number.
     30 //     The number of arenas will be calculated as 2 * the number of cpus
     31 //     but no larger than XX.
     32 //   ANDROID_TCACHE_NSLOTS_SMALL_MAX=XX
     33 //     The number of small slots held in the tcache. The higher this number
     34 //     is, the higher amount of PSS consumed. If this number is set too low
     35 //     then small allocations will take longer to complete.
     36 //   ANDROID_TCACHE_NSLOTS_LARGE=XX
     37 //     The number of large slots held in the tcache. The higher this number
     38 //     is, the higher amount of PSS consumed. If this number is set too low
     39 //     then large allocations will take longer to complete.
     40 //   ANDROID_LG_TCACHE_MAXCLASS_DEFAULT=XX
     41 //     1 << XX is the maximum sized allocation that will be in the tcache.
     42 //   ANDROID_LG_CHUNK_DEFAULT=XX
     43 //     1 << XX is the default chunk size used by the system. Decreasing this
     44 //     usually decreases the amount of PSS used, but can increase
     45 //     fragmentation.
     46 common_cflags += [
     47     "-DANDROID_ALWAYS_PURGE",
     48     "-DANDROID_MAX_ARENAS=2",
     49     "-DANDROID_TCACHE_NSLOTS_SMALL_MAX=8",
     50     "-DANDROID_TCACHE_NSLOTS_LARGE=16",
     51     "-DANDROID_LG_TCACHE_MAXCLASS_DEFAULT=16",
     52 ]
     53 
     54 common_c_local_includes = [
     55     "src",
     56     "include",
     57 ]
     58 
     59 common_product_variables = {
     60     // Only enable the tcache on non-svelte configurations, to save PSS.
     61     malloc_not_svelte: {
     62         cflags: ["-DJEMALLOC_TCACHE"],
     63     },
     64 }
     65 
     66 cc_defaults {
     67     name: "jemalloc_defaults",
     68     cflags: common_cflags,
     69 
     70     product_variables: common_product_variables,
     71 
     72     multilib: {
     73         lib32: {
     74             // Use a 512K chunk size on 32 bit systems.
     75             // This keeps the total amount of virtual address space consumed
     76             // by jemalloc lower.
     77             cflags: [
     78                 "-DANDROID_LG_CHUNK_DEFAULT=19",
     79             ],
     80         },
     81         lib64: {
     82             // Use a 2MB chunk size on 64 bit systems.
     83             // This is the default currently used by 4.0.0
     84             cflags: [
     85                 "-DANDROID_LG_CHUNK_DEFAULT=21",
     86             ],
     87         },
     88     },
     89 
     90     local_include_dirs: common_c_local_includes,
     91 }
     92 
     93 lib_src_files = [
     94     "src/arena.c",
     95     "src/atomic.c",
     96     "src/base.c",
     97     "src/bitmap.c",
     98     "src/chunk.c",
     99     "src/chunk_dss.c",
    100     "src/chunk_mmap.c",
    101     "src/ckh.c",
    102     "src/ctl.c",
    103     "src/extent.c",
    104     "src/hash.c",
    105     "src/huge.c",
    106     "src/jemalloc.c",
    107     "src/mb.c",
    108     "src/mutex.c",
    109     "src/nstime.c",
    110     "src/pages.c",
    111     "src/prng.c",
    112     "src/prof.c",
    113     "src/quarantine.c",
    114     "src/rtree.c",
    115     "src/stats.c",
    116     "src/tcache.c",
    117     "src/ticker.c",
    118     "src/tsd.c",
    119     "src/util.c",
    120 ]
    121 
    122 //-----------------------------------------------------------------------
    123 // jemalloc static library
    124 //-----------------------------------------------------------------------
    125 cc_library_static {
    126     name: "libjemalloc",
    127 
    128     defaults: ["jemalloc_defaults"],
    129 
    130     include_files: ["bionic/libc/private/libc_logging.h"],
    131 
    132     srcs: lib_src_files,
    133 
    134     sanitize: ["never"],
    135 }
    136 
    137 //-----------------------------------------------------------------------
    138 // jemalloc static jet library
    139 //-----------------------------------------------------------------------
    140 cc_library_static {
    141     name: "libjemalloc_jet",
    142 
    143     defaults: ["jemalloc_defaults"],
    144 
    145     cflags: ["-DJEMALLOC_JET"],
    146 
    147     local_include_files: ["android/include/libc_logging.h"],
    148 
    149     srcs: lib_src_files,
    150 
    151 }
    152 
    153 jemalloc_testlib_srcs = [
    154     "test/src/btalloc.c",
    155     "test/src/btalloc_0.c",
    156     "test/src/btalloc_1.c",
    157     "test/src/math.c",
    158     "test/src/mq.c",
    159     "test/src/mtx.c",
    160     "test/src/SFMT.c",
    161     "test/src/test.c",
    162     "test/src/thd.c",
    163     "test/src/timer.c",
    164 ]
    165 
    166 //-----------------------------------------------------------------------
    167 // jemalloc unit test library
    168 //-----------------------------------------------------------------------
    169 cc_library_static {
    170     name: "libjemalloc_unittest",
    171 
    172     defaults: ["jemalloc_defaults"],
    173 
    174     cflags: ["-DJEMALLOC_UNIT_TEST"],
    175 
    176     local_include_files: ["android/include/libc_logging.h"],
    177 
    178     local_include_dirs: [
    179         "test/src",
    180         "test/include",
    181     ],
    182 
    183     srcs: jemalloc_testlib_srcs,
    184 
    185     whole_static_libs: ["libjemalloc_jet"],
    186 
    187 }
    188 
    189 //-----------------------------------------------------------------------
    190 // jemalloc unit tests
    191 //-----------------------------------------------------------------------
    192 unit_tests = [
    193     "test/unit/atomic.c",
    194     "test/unit/bitmap.c",
    195     "test/unit/ckh.c",
    196     "test/unit/decay.c",
    197     "test/unit/hash.c",
    198     "test/unit/junk.c",
    199     "test/unit/junk_alloc.c",
    200     "test/unit/junk_free.c",
    201     "test/unit/lg_chunk.c",
    202     "test/unit/mallctl.c",
    203     "test/unit/math.c",
    204     "test/unit/mq.c",
    205     "test/unit/mtx.c",
    206     "test/unit/nstime.c",
    207     "test/unit/prng.c",
    208     "test/unit/prof_accum.c",
    209     "test/unit/prof_active.c",
    210     "test/unit/prof_gdump.c",
    211     "test/unit/prof_idump.c",
    212     "test/unit/prof_reset.c",
    213     "test/unit/prof_thread_name.c",
    214     "test/unit/ql.c",
    215     "test/unit/qr.c",
    216     "test/unit/quarantine.c",
    217     "test/unit/rb.c",
    218     "test/unit/rtree.c",
    219     "test/unit/run_quantize.c",
    220     "test/unit/SFMT.c",
    221     "test/unit/size_classes.c",
    222     "test/unit/smoothstep.c",
    223     "test/unit/stats.c",
    224     "test/unit/ticker.c",
    225     "test/unit/tsd.c",
    226     "test/unit/util.c",
    227     "test/unit/zero.c",
    228 ]
    229 
    230 cc_test {
    231     name: "jemalloc_unittests",
    232 
    233     gtest: false,
    234 
    235     product_variables: common_product_variables,
    236 
    237     cflags: common_cflags + ["-DJEMALLOC_UNIT_TEST"],
    238 
    239     local_include_files: ["android/include/libc_logging.h"],
    240 
    241     local_include_dirs: common_c_local_includes + [
    242         "test/src",
    243         "test/include",
    244     ],
    245 
    246     srcs: unit_tests,
    247 
    248     static_libs: ["libjemalloc_unittest"],
    249 
    250     shared_libs: ["liblog"],
    251 
    252     test_per_src: true,
    253 }
    254 
    255 //-----------------------------------------------------------------------
    256 // jemalloc integration test library
    257 //-----------------------------------------------------------------------
    258 cc_library_static {
    259     name: "libjemalloc_integrationtest",
    260 
    261     defaults: ["jemalloc_defaults"],
    262 
    263     cflags: ["-DJEMALLOC_INTEGRATION_TEST"],
    264 
    265     local_include_files: ["android/include/libc_logging.h"],
    266 
    267     local_include_dirs: [
    268         "test/src",
    269         "test/include",
    270     ],
    271 
    272     srcs: jemalloc_testlib_srcs + lib_src_files,
    273 
    274 }
    275 
    276 //-----------------------------------------------------------------------
    277 // jemalloc integration tests
    278 //-----------------------------------------------------------------------
    279 integration_tests = [
    280     "test/integration/aligned_alloc.c",
    281     "test/integration/allocated.c",
    282     "test/integration/chunk.c",
    283     "test/integration/iterate.c",
    284     "test/integration/MALLOCX_ARENA.c",
    285     "test/integration/mallocx.c",
    286     "test/integration/overflow.c",
    287     "test/integration/posix_memalign.c",
    288     "test/integration/rallocx.c",
    289     "test/integration/sdallocx.c",
    290     "test/integration/thread_arena.c",
    291     "test/integration/thread_tcache_enabled.c",
    292     "test/integration/xallocx.c",
    293 ]
    294 
    295 cc_test {
    296 
    297     name: "jemalloc_integrationtests",
    298 
    299     gtest: false,
    300 
    301     product_variables: common_product_variables,
    302 
    303     cflags: common_cflags + ["-DJEMALLOC_INTEGRATION_TEST"],
    304 
    305     local_include_files: ["android/include/libc_logging.h"],
    306 
    307     local_include_dirs: common_c_local_includes + [
    308         "test/src",
    309         "test/include",
    310     ],
    311 
    312     srcs: integration_tests,
    313 
    314     static_libs: ["libjemalloc_integrationtest"],
    315 
    316     shared_libs: ["liblog"],
    317 
    318     test_per_src: true,
    319 }
    320