- Chainsaw the storage pool code. This was being used by a bunch of code
within the HARP atm stack and the hea and hfa device drivers, but since all of these systems were changed to use UMA zones, there is no use for the api any longer.
This commit is contained in:
parent
1d7cf06c8c
commit
fe1c49fbba
@ -69,7 +69,6 @@ __RCSID("@(#) $FreeBSD$");
|
||||
struct atm_pif *atm_interface_head = NULL;
|
||||
struct atm_ncm *atm_netconv_head = NULL;
|
||||
Atm_endpoint *atm_endpoints[ENDPT_MAX+1] = {NULL};
|
||||
struct sp_info *atm_pool_head = NULL;
|
||||
struct stackq_entry *atm_stackq_head = NULL, *atm_stackq_tail;
|
||||
struct atm_sock_stat atm_sock_stat = { { 0 } };
|
||||
int atm_init = 0;
|
||||
@ -84,15 +83,12 @@ uma_zone_t atm_attributes_zone;
|
||||
/*
|
||||
* Local functions
|
||||
*/
|
||||
static void atm_compact(struct atm_time *);
|
||||
static KTimeout_ret atm_timexp(void *);
|
||||
|
||||
/*
|
||||
* Local variables
|
||||
*/
|
||||
static struct atm_time *atm_timeq = NULL;
|
||||
static struct atm_time atm_compactimer = {0, 0};
|
||||
|
||||
static uma_zone_t atm_stackq_zone;
|
||||
|
||||
/*
|
||||
@ -148,350 +144,10 @@ atm_initialize()
|
||||
/*
|
||||
* Prime the timer
|
||||
*/
|
||||
(void) timeout(atm_timexp, (void *)0, hz/ATM_HZ);
|
||||
|
||||
/*
|
||||
* Start the compaction timer
|
||||
*/
|
||||
atm_timeout(&atm_compactimer, SPOOL_COMPACT, atm_compact);
|
||||
(void)timeout(atm_timexp, (void *)0, hz/ATM_HZ);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Allocate a Control Block
|
||||
*
|
||||
* Gets a new control block allocated from the specified storage pool,
|
||||
* acquiring memory for new pool chunks if required. The returned control
|
||||
* block's contents will be cleared.
|
||||
*
|
||||
* Arguments:
|
||||
* sip pointer to sp_info for storage pool
|
||||
*
|
||||
* Returns:
|
||||
* addr pointer to allocated control block
|
||||
* 0 allocation failed
|
||||
*
|
||||
*/
|
||||
void *
|
||||
atm_allocate(sip)
|
||||
struct sp_info *sip;
|
||||
{
|
||||
void *bp;
|
||||
struct sp_chunk *scp;
|
||||
struct sp_link *slp;
|
||||
int s = splnet();
|
||||
|
||||
/*
|
||||
* Count calls
|
||||
*/
|
||||
sip->si_allocs++;
|
||||
|
||||
/*
|
||||
* Are there any free in the pool?
|
||||
*/
|
||||
if (sip->si_free) {
|
||||
|
||||
/*
|
||||
* Find first chunk with a free block
|
||||
*/
|
||||
for (scp = sip->si_poolh; scp; scp = scp->sc_next) {
|
||||
if (scp->sc_freeh != NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
/*
|
||||
* No free blocks - have to allocate a new
|
||||
* chunk (but put a limit to this)
|
||||
*/
|
||||
struct sp_link *slp_next;
|
||||
int i;
|
||||
|
||||
/*
|
||||
* First time for this pool??
|
||||
*/
|
||||
if (sip->si_chunksiz == 0) {
|
||||
size_t n;
|
||||
|
||||
/*
|
||||
* Initialize pool information
|
||||
*/
|
||||
n = sizeof(struct sp_chunk) +
|
||||
sip->si_blkcnt *
|
||||
(sip->si_blksiz + sizeof(struct sp_link));
|
||||
sip->si_chunksiz = roundup(n, SPOOL_ROUNDUP);
|
||||
|
||||
/*
|
||||
* Place pool on kernel chain
|
||||
*/
|
||||
LINK2TAIL(sip, struct sp_info, atm_pool_head, si_next);
|
||||
}
|
||||
|
||||
if (sip->si_chunks >= sip->si_maxallow) {
|
||||
sip->si_fails++;
|
||||
(void) splx(s);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
scp = malloc(sip->si_chunksiz, M_DEVBUF, M_NOWAIT | M_ZERO);
|
||||
if (scp == NULL) {
|
||||
sip->si_fails++;
|
||||
(void) splx(s);
|
||||
return (NULL);
|
||||
}
|
||||
scp->sc_info = sip;
|
||||
scp->sc_magic = SPOOL_MAGIC;
|
||||
|
||||
/*
|
||||
* Divy up chunk into free blocks
|
||||
*/
|
||||
slp = (struct sp_link *)(scp + 1);
|
||||
scp->sc_freeh = slp;
|
||||
|
||||
for (i = sip->si_blkcnt; i > 1; i--) {
|
||||
slp_next = (struct sp_link *)((caddr_t)(slp + 1) +
|
||||
sip->si_blksiz);
|
||||
slp->sl_u.slu_next = slp_next;
|
||||
slp = slp_next;
|
||||
}
|
||||
slp->sl_u.slu_next = NULL;
|
||||
scp->sc_freet = slp;
|
||||
|
||||
/*
|
||||
* Add new chunk to end of pool
|
||||
*/
|
||||
if (sip->si_poolh)
|
||||
sip->si_poolt->sc_next = scp;
|
||||
else
|
||||
sip->si_poolh = scp;
|
||||
sip->si_poolt = scp;
|
||||
|
||||
sip->si_chunks++;
|
||||
sip->si_total += sip->si_blkcnt;
|
||||
sip->si_free += sip->si_blkcnt;
|
||||
if (sip->si_chunks > sip->si_maxused)
|
||||
sip->si_maxused = sip->si_chunks;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate the first free block in chunk
|
||||
*/
|
||||
slp = scp->sc_freeh;
|
||||
scp->sc_freeh = slp->sl_u.slu_next;
|
||||
scp->sc_used++;
|
||||
sip->si_free--;
|
||||
bp = (slp + 1);
|
||||
|
||||
/*
|
||||
* Save link back to pool chunk
|
||||
*/
|
||||
slp->sl_u.slu_chunk = scp;
|
||||
|
||||
/*
|
||||
* Clear out block
|
||||
*/
|
||||
bzero(bp, sip->si_blksiz);
|
||||
|
||||
(void) splx(s);
|
||||
return (bp);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Free a Control Block
|
||||
*
|
||||
* Returns a previously allocated control block back to the owners
|
||||
* storage pool.
|
||||
*
|
||||
* Arguments:
|
||||
* bp pointer to block to be freed
|
||||
*
|
||||
* Returns:
|
||||
* none
|
||||
*
|
||||
*/
|
||||
void
|
||||
atm_free(bp)
|
||||
void *bp;
|
||||
{
|
||||
struct sp_info *sip;
|
||||
struct sp_chunk *scp;
|
||||
struct sp_link *slp;
|
||||
int s = splnet();
|
||||
|
||||
/*
|
||||
* Get containing chunk and pool info
|
||||
*/
|
||||
slp = (struct sp_link *)bp;
|
||||
slp--;
|
||||
scp = slp->sl_u.slu_chunk;
|
||||
if (scp->sc_magic != SPOOL_MAGIC)
|
||||
panic("atm_free: chunk magic missing");
|
||||
sip = scp->sc_info;
|
||||
|
||||
/*
|
||||
* Add block to free chain
|
||||
*/
|
||||
if (scp->sc_freeh) {
|
||||
scp->sc_freet->sl_u.slu_next = slp;
|
||||
scp->sc_freet = slp;
|
||||
} else
|
||||
scp->sc_freeh = scp->sc_freet = slp;
|
||||
slp->sl_u.slu_next = NULL;
|
||||
sip->si_free++;
|
||||
scp->sc_used--;
|
||||
|
||||
(void) splx(s);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Storage Pool Compaction
|
||||
*
|
||||
* Called periodically in order to perform compaction of the
|
||||
* storage pools. Each pool will be checked to see if any chunks
|
||||
* can be freed, taking some care to avoid freeing too many chunks
|
||||
* in order to avoid memory thrashing.
|
||||
*
|
||||
* Called at splnet.
|
||||
*
|
||||
* Arguments:
|
||||
* tip pointer to timer control block (atm_compactimer)
|
||||
*
|
||||
* Returns:
|
||||
* none
|
||||
*
|
||||
*/
|
||||
static void
|
||||
atm_compact(tip)
|
||||
struct atm_time *tip;
|
||||
{
|
||||
struct sp_info *sip;
|
||||
struct sp_chunk *scp;
|
||||
int i;
|
||||
struct sp_chunk *scp_prev;
|
||||
|
||||
/*
|
||||
* Check out all storage pools
|
||||
*/
|
||||
for (sip = atm_pool_head; sip; sip = sip->si_next) {
|
||||
|
||||
/*
|
||||
* Always keep a minimum number of chunks around
|
||||
*/
|
||||
if (sip->si_chunks <= SPOOL_MIN_CHUNK)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* Maximum chunks to free at one time will leave
|
||||
* pool with at least 50% utilization, but never
|
||||
* go below minimum chunk count.
|
||||
*/
|
||||
i = ((sip->si_free * 2) - sip->si_total) / sip->si_blkcnt;
|
||||
i = MIN(i, sip->si_chunks - SPOOL_MIN_CHUNK);
|
||||
|
||||
/*
|
||||
* Look for chunks to free
|
||||
*/
|
||||
scp_prev = NULL;
|
||||
for (scp = sip->si_poolh; scp && i > 0; ) {
|
||||
|
||||
if (scp->sc_used == 0) {
|
||||
|
||||
/*
|
||||
* Found a chunk to free, so do it
|
||||
*/
|
||||
if (scp_prev) {
|
||||
scp_prev->sc_next = scp->sc_next;
|
||||
if (sip->si_poolt == scp)
|
||||
sip->si_poolt = scp_prev;
|
||||
} else
|
||||
sip->si_poolh = scp->sc_next;
|
||||
|
||||
free((caddr_t)scp, M_DEVBUF);
|
||||
|
||||
/*
|
||||
* Update pool controls
|
||||
*/
|
||||
sip->si_chunks--;
|
||||
sip->si_total -= sip->si_blkcnt;
|
||||
sip->si_free -= sip->si_blkcnt;
|
||||
i--;
|
||||
if (scp_prev)
|
||||
scp = scp_prev->sc_next;
|
||||
else
|
||||
scp = sip->si_poolh;
|
||||
} else {
|
||||
scp_prev = scp;
|
||||
scp = scp->sc_next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Restart the compaction timer
|
||||
*/
|
||||
atm_timeout(&atm_compactimer, SPOOL_COMPACT, atm_compact);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Release a Storage Pool
|
||||
*
|
||||
* Frees all dynamic storage acquired for a storage pool.
|
||||
* This function is normally called just prior to a module's unloading.
|
||||
*
|
||||
* Arguments:
|
||||
* sip pointer to sp_info for storage pool
|
||||
*
|
||||
* Returns:
|
||||
* none
|
||||
*
|
||||
*/
|
||||
void
|
||||
atm_release_pool(sip)
|
||||
struct sp_info *sip;
|
||||
{
|
||||
struct sp_chunk *scp, *scp_next;
|
||||
int s = splnet();
|
||||
|
||||
/*
|
||||
* Free each chunk in pool
|
||||
*/
|
||||
for (scp = sip->si_poolh; scp; scp = scp_next) {
|
||||
|
||||
/*
|
||||
* Check for memory leaks
|
||||
*/
|
||||
if (scp->sc_used)
|
||||
panic("atm_release_pool: unfreed blocks");
|
||||
|
||||
scp_next = scp->sc_next;
|
||||
free((caddr_t)scp, M_DEVBUF);
|
||||
}
|
||||
|
||||
/*
|
||||
* Update pool controls
|
||||
*/
|
||||
sip->si_poolh = NULL;
|
||||
sip->si_chunks = 0;
|
||||
sip->si_total = 0;
|
||||
sip->si_free = 0;
|
||||
|
||||
/*
|
||||
* Unlink pool from active chain
|
||||
*/
|
||||
sip->si_chunksiz = 0;
|
||||
UNLINK(sip, struct sp_info, atm_pool_head, si_next);
|
||||
|
||||
(void) splx(s);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle timer tick expiration
|
||||
*
|
||||
|
@ -172,61 +172,6 @@ struct atm_time {
|
||||
|
||||
#define ATM_HZ 2 /* Time ticks per second */
|
||||
|
||||
|
||||
/*
|
||||
* To avoid heavy use of kmem_alloc, memory for protocol control blocks may
|
||||
* be allocated from storage pools. Each control block type will have
|
||||
* its own pool. Each storage pool will consist of individually allocated
|
||||
* memory chunks, which will then be sub-divided into the separate control
|
||||
* blocks. Each chunk will contain a header (sp_chunk) and 'n' blocks of the
|
||||
* same type, plus a link field for each block. Each chunk will also contain
|
||||
* a list of all free control blocks in the chunk.
|
||||
*
|
||||
* Each protocol must define an sp_info structure for each of its storage
|
||||
* pools. This structure serves as the "root" for its particular pool.
|
||||
* Protocols must not modify this structure after its first use.
|
||||
*/
|
||||
struct sp_info {
|
||||
/* Values supplied by pool owner */
|
||||
char *si_name; /* Name of pool */
|
||||
size_t si_blksiz; /* Size of each block */
|
||||
int si_blkcnt; /* Blocks per chunk */
|
||||
int si_maxallow; /* Maximum allowable chunks */
|
||||
|
||||
/* Used by allocate/free functions - do not touch */
|
||||
struct sp_info *si_next; /* Next active storage pool */
|
||||
struct sp_chunk *si_poolh; /* Storage pool chunk head */
|
||||
struct sp_chunk *si_poolt; /* Storage pool chunk tail */
|
||||
size_t si_chunksiz; /* Size of chunk */
|
||||
int si_chunks; /* Current allocated chunks */
|
||||
int si_total; /* Total number of blocks */
|
||||
int si_free; /* Free blocks */
|
||||
int si_maxused; /* Maximum allocated chunks */
|
||||
int si_allocs; /* Total allocate calls */
|
||||
int si_fails; /* Allocate failures */
|
||||
};
|
||||
|
||||
struct sp_chunk {
|
||||
struct sp_chunk *sc_next; /* Next chunk in pool */
|
||||
struct sp_info *sc_info; /* Storage pool info */
|
||||
u_int sc_magic; /* Chunk magic number */
|
||||
int sc_used; /* Allocated blocks in chunk */
|
||||
struct sp_link *sc_freeh; /* Head of free blocks in chunk */
|
||||
struct sp_link *sc_freet; /* Tail of free blocks in chunk */
|
||||
};
|
||||
|
||||
struct sp_link {
|
||||
union {
|
||||
struct sp_link *slu_next; /* Next block in free list */
|
||||
struct sp_chunk *slu_chunk; /* Link back to our chunk */
|
||||
} sl_u;
|
||||
};
|
||||
|
||||
#define SPOOL_MAGIC 0x73d4b69c /* Storage pool magic number */
|
||||
#define SPOOL_MIN_CHUNK 2 /* Minimum number of chunks */
|
||||
#define SPOOL_ROUNDUP 16 /* Roundup for allocated chunks */
|
||||
#define SPOOL_COMPACT (300 * ATM_HZ) /* Compaction timeout value */
|
||||
|
||||
/*
|
||||
* Debugging
|
||||
*/
|
||||
|
@ -57,7 +57,6 @@ extern struct domain atmdomain;
|
||||
extern struct atm_pif *atm_interface_head;
|
||||
extern struct atm_ncm *atm_netconv_head;
|
||||
extern Atm_endpoint *atm_endpoints[];
|
||||
extern struct sp_info *atm_pool_head;
|
||||
extern struct stackq_entry *atm_stackq_head;
|
||||
extern struct stackq_entry *atm_stackq_tail;
|
||||
extern struct ifqueue atm_intrq;
|
||||
@ -168,9 +167,6 @@ void atm_sock_cleared(void *, struct t_atm_cause *);
|
||||
|
||||
/* atm_subr.c */
|
||||
void atm_initialize(void);
|
||||
void * atm_allocate(struct sp_info *);
|
||||
void atm_free(void *);
|
||||
void atm_release_pool(struct sp_info *);
|
||||
void atm_timeout(struct atm_time *, int,
|
||||
void (*)(struct atm_time *) );
|
||||
int atm_untimeout(struct atm_time *);
|
||||
|
Loading…
Reference in New Issue
Block a user