2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#ifndef _MTMALLOC_IMPL_H
2N/A#define _MTMALLOC_IMPL_H
2N/A
2N/A
2N/A/*
2N/A * Various data structures that define the guts of the mt malloc
2N/A * library.
2N/A */
2N/A
2N/A#include <sys/types.h>
2N/A#include <synch.h>
2N/A
2N/A#ifdef __cplusplus
2N/Aextern "C" {
2N/A#endif
2N/A
2N/A
2N/Atypedef struct cache {
2N/A /* volatile needed to support atomic operations */
2N/A volatile ulong_t *mt_freemask; /* free block bit mask */
2N/A volatile ulong_t *mt_efreemask; /* end of free block bit mask */
2N/A caddr_t mt_arena; /* addr of arena for dblks */
2N/A size_t mt_size; /* size of this cache */
2N/A volatile uint_t *mt_nfreeptr; /* pointer to free space */
2N/A size_t mt_length; /* size of the arena in bytes */
2N/A volatile size_t mt_lastoffset; /* last freemask allocated frm */
2N/A int mt_hunks; /* at creation time what chunk size */
2N/A} cache_t;
2N/A
2N/Atypedef struct oversize {
2N/A struct oversize *next_bysize;
2N/A struct oversize *prev_bysize;
2N/A struct oversize *next_byaddr;
2N/A struct oversize *prev_byaddr;
2N/A struct oversize *hash_next;
2N/A caddr_t addr;
2N/A size_t size;
2N/A} oversize_t;
2N/A
2N/A#define CACHESPACES 512
2N/A
2N/Atypedef struct cachespaceblock {
2N/A volatile uint_t mt_nfree[CACHESPACES]; /* free space in cache */
2N/A cache_t *mt_cache[CACHESPACES]; /* Pointer to cache */
2N/A struct cachespaceblock *mt_nextblock; /* Ptr to next block */
2N/A} cachespaceblock_t;
2N/A
2N/Atypedef struct cache_head {
2N/A ulong_t mt_hint;
2N/A cachespaceblock_t *mt_cachespaceblock; /* caches w space */
2N/A cachespaceblock_t *mt_cachespaceblockhint; /* last blk w space */
2N/A} cache_head_t;
2N/A
2N/A/* used to avoid false sharing, should be power-of-2 >= cache coherency size */
2N/A#define CACHE_COHERENCY_UNIT 64
2N/A
2N/A#define PERCPU_SIZE CACHE_COHERENCY_UNIT
2N/A#define PERCPU_PAD (PERCPU_SIZE - sizeof (mutex_t) - \
2N/A sizeof (cache_head_t *))
2N/A
2N/Atypedef struct percpu {
2N/A mutex_t mt_parent_lock; /* used for hooking in new caches */
2N/A cache_head_t *mt_caches;
2N/A char mt_pad[PERCPU_PAD];
2N/A} percpu_t;
2N/A
2N/Atypedef uint_t (*curcpu_func)(void);
2N/A
2N/A#define DATA_SHIFT 1
2N/A#define TAIL_SHIFT 2
2N/A
2N/A/*
2N/A * Oversize bit definitions: 3 bits to represent the oversize for
2N/A * head fragment, data itself, and tail fragment.
2N/A * If the head fragment is oversize, the first bit is on.
2N/A * If the data itself is oversize, the second bit is on.
2N/A * If the tail fragment is oversize, then the third bit is on.
2N/A */
2N/A#define NONE_OVERSIZE 0x0
2N/A#define HEAD_OVERSIZE 0x1
2N/A#define DATA_OVERSIZE 0x2
2N/A#define HEAD_AND_DATA_OVERSIZE 0x3
2N/A#define TAIL_OVERSIZE 0x4
2N/A#define HEAD_AND_TAIL_OVERSIZE 0x5
2N/A#define DATA_AND_TAIL_OVERSIZE 0x6
2N/A#define ALL_OVERSIZE 0x7
2N/A
2N/A#ifdef __cplusplus
2N/A}
2N/A#endif
2N/A
2N/A#endif /* _MTMALLOC_IMPL_H */