/* $Id$ * * shared memory, multi-process safe, pool based, mostly lockless version of * f_malloc * * Copyright (C) 2007 iptelorg GmbH * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* * History: * -------- * 2003-05-21 on sparc64 roundto 8 even in debugging mode (so malloc'ed * long longs will be 64 bit aligned) (andrei) * 2004-07-19 support for 64 bit (2^64 mem. block) and more info * for the future de-fragmentation support (andrei) * 2004-11-10 support for > 4Gb mem., switched to long (andrei) * 2007-06-11 forked from the sf_malloc code (andrei) */ #if !defined(ll_malloc_h) #define ll_malloc_h #include "meminfo.h" #include "../lock_ops.h" #include "../atomic_ops.h" #include "../compiler_opt.h" /* defs*/ #ifdef GEN_LOCK_T_UNLIMITED #define SFM_LOCK_PER_BUCKET #else #define SFM_ONE_LOCK #endif #ifdef DBG_SF_MALLOC #if defined(__CPU_sparc64) || defined(__CPU_sparc) /* tricky, on sun in 32 bits mode long long must be 64 bits aligned * but long can be 32 bits aligned => malloc should return long long * aligned memory */ #define SF_ROUNDTO sizeof(long long) #else #define SF_ROUNDTO sizeof(void*) /* size we round to, must be = 2^n, and sizeof(sfm_frag) must be multiple of SF_ROUNDTO !*/ #endif #else /* DBG_SF_MALLOC */ #define SF_ROUNDTO 8UL #endif #define SF_MIN_FRAG_SIZE SF_ROUNDTO #define SFM_POOLS_NO 4U /* the more the better, but higher initial mem. consumption */ #define SF_MALLOC_OPTIMIZE_FACTOR 14UL /*used below */ #define SF_MALLOC_OPTIMIZE (1UL<