From owner-freebsd-current@FreeBSD.ORG Fri Mar 20 14:07:24 2015 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7FD081E5; Fri, 20 Mar 2015 14:07:24 +0000 (UTC) Received: from ivan-labs.com (ivan-labs.com [162.243.251.239]) by mx1.freebsd.org (Postfix) with ESMTP id 3D226B8; Fri, 20 Mar 2015 14:07:24 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by ivan-labs.com (Postfix) with ESMTP id 20213121108; Fri, 20 Mar 2015 17:00:01 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at Received: from ivan-labs.com ([127.0.0.1]) by localhost (ivan-labs.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PuxQ27PWPNXZ; Fri, 20 Mar 2015 17:00:00 +0300 (MSK) Received: from [192.168.43.253] (unknown [149.62.201.153]) by ivan-labs.com (Postfix) with ESMTPSA id 1EFD81206B7; Fri, 20 Mar 2015 16:59:59 +0300 (MSK) Message-ID: <550C27D8.2010105@ivan-labs.com> Date: Fri, 20 Mar 2015 15:59:52 +0200 From: "Ivan A. Kosarev" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: freebsd-current@freebsd.org Subject: Use of chunksize before initialization Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Cc: Ed Maste X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Mar 2015 14:07:24 -0000 Hello everybody, The malloc_init_hard() function defined in jemalloc_jemalloc.c, FreeBSD 11 r277486 reads: static bool malloc_init_hard(void) { ... if (base_boot()) { malloc_mutex_unlock(&init_lock); eturn (true); } if (chunk_boot()) { malloc_mutex_unlock(&init_lock); return (true); } ... The second call initializes the 'chunksize' global variable defined in jemalloc_chunk.c: bool chunk_boot(void) { /* Set variables according to the value of opt_lg_chunk. */ chunksize = (ZU(1) << opt_lg_chunk); assert(chunksize >= PAGE); ... However, it seems the first call to base_boot() depends on that variable already: (gdb) bt #0 thr_kill () at thr_kill.S:3 #1 0x0000000801241408 in __raise (s=6) at /usr/src/lib/libc/gen/raise.c:51 #2 0x000000000041d817 in __interceptor_raise () at /usr/home/ik/llvm/llvm.current/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:2097 #3 0x000000080123f969 in abort () at /usr/src/lib/libc/stdlib/abort.c:65 #4 0x000000000041c5d9 in __interceptor_abort () at /usr/home/ik/llvm/llvm.current/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:1851 #5 0x00000008011a8d64 in __je_chunk_alloc (size=, alignment=, base=, zero=, dss_prec=dss_prec_disabled) at jemalloc_chunk.c:150 #6 0x00000008011a9bfc in base_pages_alloc (minsize=128) at jemalloc_base.c:35 #7 __je_base_alloc (size=) at jemalloc_base.c:57 #8 0x00000008011a9c96 in __je_base_calloc (number=, size=6) at jemalloc_base.c:74 #9 0x00000008008ae548 in mutex_init (calloc_cb=0x0, mutex=, mutex_attr=) at /usr/src/lib/libthr/thread/thr_mutex.c:145 #10 _pthread_mutex_init_calloc_cb (mutex=0x801487c90, calloc_cb=0x0) at /usr/src/lib/libthr/thread/thr_mutex.c:229 #11 0x00000008011a18da in __je_malloc_mutex_init (mutex=0x18744) at jemalloc_mutex.c:97 #12 0x00000008011b428d in malloc_init_hard () at jemalloc_jemalloc.c:698 #13 malloc_init () at jemalloc_jemalloc.c:296 #14 0x0000000801243ea2 in ?? () from /lib/libc.so.7 #15 0x00000008006a5400 in ?? () #16 0x000000080089e5b0 in ?? () from /libexec/ld-elf.so.1 #17 0x00007fffffffe0b0 in ?? () #18 0x0000000801139d06 in _init () from /lib/libc.so.7 #19 0x00007fffffffe0b0 in ?? () Note that base_pages() calls chunk_alloc() with chucksize used as the alignment value: static bool base_pages_alloc(size_t minsize) { ... base_pages = chunk_alloc(csize, chunksize, true, &zero, chunk_dss_prec_get()); ... and the latter tests it against zero: void * chunk_alloc(size_t size, size_t alignment, bool base, bool *zero, dss_prec_t dss_prec) { ... assert(alignment != 0); .... so we sometimes we end up with: : jemalloc_chunk.c:152: Failed assertion: "alignment != 0" Here's more of failures of this kind around: http://lab.llvm.org:8011/builders/sanitizer_x86_64-freebsd/builds/4758/steps/make-check-tsan/logs/stdio Can you please let me know if the analysis is correct and there's something to fix about initialization of the variable? Thanks. --