//+++2004-08-31
// Copyright (C) 2004 Mike Rieker, Beverly, MA USA
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//---2004-08-31
/************************************************************************/
/* */
/* General heap memory allocation routines */
/* */
/* The list is composed of an array of varying sized blocks, the */
/* size of which can be found in .size. The size and state at the */
/* beginning of the block should match the size and state at the */
/* end of the block. */
/* */
/* At the very beginning of the list is a block of type END and */
/* with .size = 1. This is used to eliminate a special case when */
/* allocating or freeing the following block. Since it is of type */
/* END, it will not merge with either a FREE or ALLOC block. */
/* */
/* At the very end is a block of type END with .size 0. */
/* */
/* The size includes the ends and the guards and is in units of */
/* sizeof (Block). */
/* */
/************************************************************************/
#define _OZ_KNL_MALLOC_C
#include "ozone.h"
#include "oz_knl_hw.h"
#include "oz_knl_malloc.h"
#include "oz_knl_printk.h"
#include "oz_knl_sdata.h"
#define PAGESIZE (1 << OZ_HW_L2PAGESIZE)
typedef enum { STATE_FREE, STATE_BIN, STATE_ALLOC, STATE_END } State;
typedef struct Block Block;
struct Block { OZ_Memsize size; /* size of this subblock */
State state; /* state of the block */
int physcontig; /* it is from a phys contig alloc */
uLong pad1; /* pad to 16-byte boundary */
};
#define L2BS 4 /* log2 (sizeof (Block)) */
/* sizeof Block is the alignment, also */
#define NGUARD 2 /* 0, 1, 2 */ /* number of blocks to use in each guard band */
#define POISON 1 /* 0, 1, 2 */ /* 0: no poison; 1: poison but don't check; 2: poison and check */
#define FULLCHECK 0 /* 0, 1 */ /* full checking every step (very slow) */
#if FULLCHECK /* if full checking, make sure poison is turned all the way on */
#undef POISON
#define POISON 2
#endif
/* 1600 bytes because ethernet packets are a little over 1500 */
#define NBINS (1600 >> L2BS) /* number of bins to have for lookaside list */
/* bin[0] = blocks of data size 1<