MALLOC_OPTIONS

  看nginx源代码ngx_debug_init函数,本意是打开FreeBSD内存调试的功能:

void
ngx_debug_init()
{
#if (NGX_DEBUG_MALLOC)

#if __FreeBSD_version >= 500014
    _malloc_options = "J";
#else
    malloc_options = "J";
#endif

    ngx_freebsd_debug_malloc = 1;

#else
    char  *mo;

    mo = getenv("MALLOC_OPTIONS");

    if (mo && ngx_strchr(mo, 'J')) {
        ngx_freebsd_debug_malloc = 1;
    }
#endif

  对'J'有些不解,上网查一下资料,查看环境变量MALLOC_OPTIONS:


TUNING
     Once, when the first call is made to one of these memory allocation rou-
     tines, various flags will be set or reset, which affect the workings of
     this allocator implementation.

     The ``name'' of the file referenced by the symbolic link named
     /etc/malloc.conf, the value of the environment variable MALLOC_OPTIONS,
     and the string pointed to by the global variable _malloc_options will be
     interpreted, in that order, character by character as flags.

     Most flags are single letters, where uppercase indicates that the behav-
     ior is set, or on, and lowercase means that the behavior is not set, or
     off.

     A       All warnings (except for the warning about unknown flags being
             set) become fatal.  The process will call abort(3) in these
             cases.

     H       Use madvise(2) when pages within a chunk are no longer in use,
             but the chunk as a whole cannot yet be deallocated.  This is pri-
             marily of use when swapping is a real possibility, due to the
             high overhead of the madvise() system call.

     J       Each byte of new memory allocated by malloc(), realloc() will be
             initialized to 0xa5.  All memory returned by free(), realloc()
             will be initialized to 0x5a.  This is intended for debugging and
             will impact performance negatively.

     K       Increase/decrease the virtual memory chunk size by a factor of
             two.  The default chunk size is 1 MB.  This option can be speci-
             fied multiple times.

     N       Increase/decrease the number of arenas by a factor of two.  The
             default number of arenas is four times the number of CPUs, or one
             if there is a single CPU.  This option can be specified multiple
             times.

     P       Various statistics are printed at program exit via an atexit(3)
             function.  This has the potential to cause deadlock for a multi-
             threaded process that exits while one or more threads are execut-
             ing in the memory allocation functions.  Therefore, this option
             should only be used with care; it is primarily intended as a per-
             formance tuning aid during application development.

     Q       Increase/decrease the size of the allocation quantum by a factor
             of two.  The default quantum is the minimum allowed by the archi-
             tecture (typically 8 or 16 bytes).  This option can be specified
             multiple times.

     S       Increase/decrease the size of the maximum size class that is a
             multiple of the quantum by a factor of two.  Above this size,
             power-of-two spacing is used for size classes.  The default value
             is 512 bytes.  This option can be specified multiple times.

     U       Generate ``utrace'' entries for ktrace(1), for all operations.
             Consult the source for details on this option.

     V       Attempting to allocate zero bytes will return a NULL pointer
             instead of a valid pointer.  (The default behavior is to make a
             minimal allocation and return a pointer to it.)  This option is
             provided for System V compatibility.  This option is incompatible
             with the ``X'' option.

     X       Rather than return failure for any allocation function, display a
             diagnostic message on stderr and cause the program to drop core
             (using abort(3)).  This option should be set at compile time by
             including the following in the source code:

                   _malloc_options = "X";

     Z       Each byte of new memory allocated by malloc(), realloc() will be
             initialized to 0.  Note that this initialization only happens
             once for each byte, so realloc() call do not zero memory that was
             previously allocated.  This is intended for debugging and will
             impact performance negatively.

     The ``J'' and ``Z'' options are intended for testing and debugging.  An
     application which changes its behavior when these options are used is
     flawed.

 

哪位路过的大侠详细解释一下

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值