1139790Simp/*-
2120294Smarcel * Copyright (c) 2003 The FreeBSD Project
3120294Smarcel * All rights reserved.
4120294Smarcel *
5120294Smarcel * Redistribution and use in source and binary forms, with or without
6120294Smarcel * modification, are permitted provided that the following conditions
7120294Smarcel * are met:
8120294Smarcel *
9120294Smarcel * 1. Redistributions of source code must retain the above copyright
10120294Smarcel *    notice, this list of conditions and the following disclaimer.
11120294Smarcel * 2. Redistributions in binary form must reproduce the above copyright
12120294Smarcel *    notice, this list of conditions and the following disclaimer in the
13120294Smarcel *    documentation and/or other materials provided with the distribution.
14120294Smarcel *
15120294Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16120294Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17120294Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18120294Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19120294Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20120294Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21120294Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22120294Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23120294Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24120294Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25120294Smarcel */
26120294Smarcel
27120294Smarcel#include <sys/cdefs.h>
28120294Smarcel__FBSDID("$FreeBSD$");
29120294Smarcel
30120294Smarcel#include <sys/param.h>
31120294Smarcel#include <sys/lock.h>
32243040Skib#include <sys/malloc.h>
33120294Smarcel#include <sys/mutex.h>
34120294Smarcel#include <sys/systm.h>
35120294Smarcel#include <vm/vm.h>
36120294Smarcel#include <vm/vm_page.h>
37120294Smarcel#include <vm/vm_pageout.h>
38120294Smarcel#include <vm/uma.h>
39120294Smarcel#include <vm/uma_int.h>
40120294Smarcel#include <machine/vmparam.h>
41120294Smarcel
42120294Smarcelvoid *
43287945Srstoneuma_small_alloc(uma_zone_t zone, vm_size_t bytes, u_int8_t *flags, int wait)
44120294Smarcel{
45120294Smarcel	void *va;
46120294Smarcel	vm_page_t m;
47120294Smarcel	int pflags;
48120294Smarcel
49120294Smarcel	*flags = UMA_SLAB_PRIV;
50243040Skib	pflags = malloc2vm_flags(wait) | VM_ALLOC_WIRED;
51120294Smarcel
52120294Smarcel	for (;;) {
53228522Salc		m = vm_page_alloc(NULL, 0, pflags | VM_ALLOC_NOOBJ);
54120294Smarcel		if (m == NULL) {
55120294Smarcel			if (wait & M_NOWAIT)
56120294Smarcel				return (NULL);
57120294Smarcel			VM_WAIT;
58120294Smarcel		} else
59120294Smarcel			break;
60120294Smarcel	}
61120294Smarcel
62120294Smarcel	va = (void *)IA64_PHYS_TO_RR7(VM_PAGE_TO_PHYS(m));
63120294Smarcel	if ((wait & M_ZERO) && (m->flags & PG_ZERO) == 0)
64120294Smarcel		bzero(va, PAGE_SIZE);
65120294Smarcel	return (va);
66120294Smarcel}
67120294Smarcel
68120294Smarcelvoid
69287945Srstoneuma_small_free(void *mem, vm_size_t size, u_int8_t flags)
70120294Smarcel{
71120294Smarcel	vm_page_t m;
72120294Smarcel
73120294Smarcel	m = PHYS_TO_VM_PAGE(IA64_RR_MASK((u_int64_t)mem));
74172189Salc	m->wire_count--;
75120294Smarcel	vm_page_free(m);
76172189Salc	atomic_subtract_int(&cnt.v_wire_count, 1);
77120294Smarcel}
78