Eliminate duplication of the fake page code and zone by the device and sg
pagers. Reviewed by: jhb
This commit is contained in:
parent
d268e58dd4
commit
9e6c312311
@ -67,13 +67,6 @@ static struct pagerlst dev_pager_object_list;
|
||||
/* protect list manipulation */
|
||||
static struct mtx dev_pager_mtx;
|
||||
|
||||
|
||||
static uma_zone_t fakepg_zone;
|
||||
|
||||
static vm_page_t dev_pager_getfake(vm_paddr_t, vm_memattr_t);
|
||||
static void dev_pager_putfake(vm_page_t);
|
||||
static void dev_pager_updatefake(vm_page_t, vm_paddr_t, vm_memattr_t);
|
||||
|
||||
struct pagerops devicepagerops = {
|
||||
.pgo_init = dev_pager_init,
|
||||
.pgo_alloc = dev_pager_alloc,
|
||||
@ -88,9 +81,6 @@ dev_pager_init()
|
||||
{
|
||||
TAILQ_INIT(&dev_pager_object_list);
|
||||
mtx_init(&dev_pager_mtx, "dev_pager list", NULL, MTX_DEF);
|
||||
fakepg_zone = uma_zcreate("DP fakepg", sizeof(struct vm_page),
|
||||
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR,
|
||||
UMA_ZONE_NOFREE|UMA_ZONE_VM);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -199,7 +189,7 @@ dev_pager_dealloc(object)
|
||||
*/
|
||||
while ((m = TAILQ_FIRST(&object->un_pager.devp.devp_pglist)) != NULL) {
|
||||
TAILQ_REMOVE(&object->un_pager.devp.devp_pglist, m, pageq);
|
||||
dev_pager_putfake(m);
|
||||
vm_page_putfake(m);
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,7 +240,7 @@ dev_pager_getpages(object, m, count, reqpage)
|
||||
* the new physical address.
|
||||
*/
|
||||
VM_OBJECT_LOCK(object);
|
||||
dev_pager_updatefake(page, paddr, memattr);
|
||||
vm_page_updatefake(page, paddr, memattr);
|
||||
if (count > 1) {
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
@ -266,7 +256,7 @@ dev_pager_getpages(object, m, count, reqpage)
|
||||
* Replace the passed in reqpage page with our own fake page and
|
||||
* free up the all of the original pages.
|
||||
*/
|
||||
page = dev_pager_getfake(paddr, memattr);
|
||||
page = vm_page_getfake(paddr, memattr);
|
||||
VM_OBJECT_LOCK(object);
|
||||
TAILQ_INSERT_TAIL(&object->un_pager.devp.devp_pglist, page, pageq);
|
||||
for (i = 0; i < count; i++) {
|
||||
@ -305,51 +295,3 @@ dev_pager_haspage(object, pindex, before, after)
|
||||
*after = 0;
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a fictitious page with the specified physical address and memory
|
||||
* attribute. The memory attribute is the only the machine-dependent aspect
|
||||
* of a fictitious page that must be initialized.
|
||||
*/
|
||||
static vm_page_t
|
||||
dev_pager_getfake(vm_paddr_t paddr, vm_memattr_t memattr)
|
||||
{
|
||||
vm_page_t m;
|
||||
|
||||
m = uma_zalloc(fakepg_zone, M_WAITOK | M_ZERO);
|
||||
m->phys_addr = paddr;
|
||||
m->queue = PQ_NONE;
|
||||
/* Fictitious pages don't use "segind". */
|
||||
m->flags = PG_FICTITIOUS;
|
||||
/* Fictitious pages don't use "order" or "pool". */
|
||||
m->oflags = VPO_BUSY;
|
||||
m->wire_count = 1;
|
||||
pmap_page_set_memattr(m, memattr);
|
||||
return (m);
|
||||
}
|
||||
|
||||
/*
|
||||
* Release a fictitious page.
|
||||
*/
|
||||
static void
|
||||
dev_pager_putfake(vm_page_t m)
|
||||
{
|
||||
|
||||
if (!(m->flags & PG_FICTITIOUS))
|
||||
panic("dev_pager_putfake: bad page");
|
||||
uma_zfree(fakepg_zone, m);
|
||||
}
|
||||
|
||||
/*
|
||||
* Update the given fictitious page to the specified physical address and
|
||||
* memory attribute.
|
||||
*/
|
||||
static void
|
||||
dev_pager_updatefake(vm_page_t m, vm_paddr_t paddr, vm_memattr_t memattr)
|
||||
{
|
||||
|
||||
if (!(m->flags & PG_FICTITIOUS))
|
||||
panic("dev_pager_updatefake: bad page");
|
||||
m->phys_addr = paddr;
|
||||
pmap_page_set_memattr(m, memattr);
|
||||
}
|
||||
|
@ -43,7 +43,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <vm/vm_pager.h>
|
||||
#include <vm/uma.h>
|
||||
|
||||
static void sg_pager_init(void);
|
||||
static vm_object_t sg_pager_alloc(void *, vm_ooffset_t, vm_prot_t,
|
||||
vm_ooffset_t, struct ucred *);
|
||||
static void sg_pager_dealloc(vm_object_t);
|
||||
@ -53,13 +52,7 @@ static void sg_pager_putpages(vm_object_t, vm_page_t *, int,
|
||||
static boolean_t sg_pager_haspage(vm_object_t, vm_pindex_t, int *,
|
||||
int *);
|
||||
|
||||
static uma_zone_t fakepg_zone;
|
||||
|
||||
static vm_page_t sg_pager_getfake(vm_paddr_t, vm_memattr_t);
|
||||
static void sg_pager_putfake(vm_page_t);
|
||||
|
||||
struct pagerops sgpagerops = {
|
||||
.pgo_init = sg_pager_init,
|
||||
.pgo_alloc = sg_pager_alloc,
|
||||
.pgo_dealloc = sg_pager_dealloc,
|
||||
.pgo_getpages = sg_pager_getpages,
|
||||
@ -67,15 +60,6 @@ struct pagerops sgpagerops = {
|
||||
.pgo_haspage = sg_pager_haspage,
|
||||
};
|
||||
|
||||
static void
|
||||
sg_pager_init(void)
|
||||
{
|
||||
|
||||
fakepg_zone = uma_zcreate("SG fakepg", sizeof(struct vm_page),
|
||||
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR,
|
||||
UMA_ZONE_NOFREE|UMA_ZONE_VM);
|
||||
}
|
||||
|
||||
static vm_object_t
|
||||
sg_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot,
|
||||
vm_ooffset_t foff, struct ucred *cred)
|
||||
@ -138,7 +122,7 @@ sg_pager_dealloc(vm_object_t object)
|
||||
*/
|
||||
while ((m = TAILQ_FIRST(&object->un_pager.sgp.sgp_pglist)) != 0) {
|
||||
TAILQ_REMOVE(&object->un_pager.sgp.sgp_pglist, m, pageq);
|
||||
sg_pager_putfake(m);
|
||||
vm_page_putfake(m);
|
||||
}
|
||||
|
||||
sg = object->handle;
|
||||
@ -193,7 +177,7 @@ sg_pager_getpages(vm_object_t object, vm_page_t *m, int count, int reqpage)
|
||||
("backing page for SG is fake"));
|
||||
|
||||
/* Construct a new fake page. */
|
||||
page = sg_pager_getfake(paddr, memattr);
|
||||
page = vm_page_getfake(paddr, memattr);
|
||||
VM_OBJECT_LOCK(object);
|
||||
TAILQ_INSERT_TAIL(&object->un_pager.sgp.sgp_pglist, page, pageq);
|
||||
|
||||
@ -229,34 +213,3 @@ sg_pager_haspage(vm_object_t object, vm_pindex_t pindex, int *before,
|
||||
*after = 0;
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a fictitious page with the specified physical address and memory
|
||||
* attribute. The memory attribute is the only the machine-dependent aspect
|
||||
* of a fictitious page that must be initialized.
|
||||
*/
|
||||
static vm_page_t
|
||||
sg_pager_getfake(vm_paddr_t paddr, vm_memattr_t memattr)
|
||||
{
|
||||
vm_page_t m;
|
||||
|
||||
m = uma_zalloc(fakepg_zone, M_WAITOK | M_ZERO);
|
||||
m->phys_addr = paddr;
|
||||
m->queue = PQ_NONE;
|
||||
/* Fictitious pages don't use "segind". */
|
||||
m->flags = PG_FICTITIOUS;
|
||||
/* Fictitious pages don't use "order" or "pool". */
|
||||
m->oflags = VPO_BUSY;
|
||||
m->wire_count = 1;
|
||||
pmap_page_set_memattr(m, memattr);
|
||||
return (m);
|
||||
}
|
||||
|
||||
static void
|
||||
sg_pager_putfake(vm_page_t m)
|
||||
{
|
||||
|
||||
if (!(m->flags & PG_FICTITIOUS))
|
||||
panic("sg_pager_putfake: bad page");
|
||||
uma_zfree(fakepg_zone, m);
|
||||
}
|
||||
|
@ -156,9 +156,22 @@ static int pa_tryrelock_restart;
|
||||
SYSCTL_INT(_vm, OID_AUTO, tryrelock_restart, CTLFLAG_RD,
|
||||
&pa_tryrelock_restart, 0, "Number of tryrelock restarts");
|
||||
|
||||
static uma_zone_t fakepg_zone;
|
||||
|
||||
static void vm_page_clear_dirty_mask(vm_page_t m, int pagebits);
|
||||
static void vm_page_queue_remove(int queue, vm_page_t m);
|
||||
static void vm_page_enqueue(int queue, vm_page_t m);
|
||||
static void vm_page_init_fakepg(void *dummy);
|
||||
|
||||
SYSINIT(vm_page, SI_SUB_VM, SI_ORDER_SECOND, vm_page_init_fakepg, NULL);
|
||||
|
||||
static void
|
||||
vm_page_init_fakepg(void *dummy)
|
||||
{
|
||||
|
||||
fakepg_zone = uma_zcreate("fakepg", sizeof(struct vm_page), NULL, NULL,
|
||||
NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE | UMA_ZONE_VM);
|
||||
}
|
||||
|
||||
/* Make sure that u_long is at least 64 bits when PAGE_SIZE is 32K. */
|
||||
#if PAGE_SIZE == 32768
|
||||
@ -605,6 +618,60 @@ vm_page_unhold_pages(vm_page_t *ma, int count)
|
||||
mtx_unlock(mtx);
|
||||
}
|
||||
|
||||
/*
|
||||
* vm_page_getfake:
|
||||
*
|
||||
* Create a fictitious page with the specified physical address and
|
||||
* memory attribute. The memory attribute is the only the machine-
|
||||
* dependent aspect of a fictitious page that must be initialized.
|
||||
*/
|
||||
vm_page_t
|
||||
vm_page_getfake(vm_paddr_t paddr, vm_memattr_t memattr)
|
||||
{
|
||||
vm_page_t m;
|
||||
|
||||
m = uma_zalloc(fakepg_zone, M_WAITOK | M_ZERO);
|
||||
m->phys_addr = paddr;
|
||||
m->queue = PQ_NONE;
|
||||
/* Fictitious pages don't use "segind". */
|
||||
m->flags = PG_FICTITIOUS;
|
||||
/* Fictitious pages don't use "order" or "pool". */
|
||||
m->oflags = VPO_BUSY;
|
||||
m->wire_count = 1;
|
||||
pmap_page_set_memattr(m, memattr);
|
||||
return (m);
|
||||
}
|
||||
|
||||
/*
|
||||
* vm_page_putfake:
|
||||
*
|
||||
* Release a fictitious page.
|
||||
*/
|
||||
void
|
||||
vm_page_putfake(vm_page_t m)
|
||||
{
|
||||
|
||||
KASSERT((m->flags & PG_FICTITIOUS) != 0,
|
||||
("vm_page_putfake: bad page %p", m));
|
||||
uma_zfree(fakepg_zone, m);
|
||||
}
|
||||
|
||||
/*
|
||||
* vm_page_updatefake:
|
||||
*
|
||||
* Update the given fictitious page to the specified physical address and
|
||||
* memory attribute.
|
||||
*/
|
||||
void
|
||||
vm_page_updatefake(vm_page_t m, vm_paddr_t paddr, vm_memattr_t memattr)
|
||||
{
|
||||
|
||||
KASSERT((m->flags & PG_FICTITIOUS) != 0,
|
||||
("vm_page_updatefake: bad page %p", m));
|
||||
m->phys_addr = paddr;
|
||||
pmap_page_set_memattr(m, memattr);
|
||||
}
|
||||
|
||||
/*
|
||||
* vm_page_free:
|
||||
*
|
||||
|
@ -352,11 +352,13 @@ int vm_page_try_to_free (vm_page_t);
|
||||
void vm_page_dontneed(vm_page_t);
|
||||
void vm_page_deactivate (vm_page_t);
|
||||
vm_page_t vm_page_find_least(vm_object_t, vm_pindex_t);
|
||||
vm_page_t vm_page_getfake(vm_paddr_t paddr, vm_memattr_t memattr);
|
||||
void vm_page_insert (vm_page_t, vm_object_t, vm_pindex_t);
|
||||
vm_page_t vm_page_lookup (vm_object_t, vm_pindex_t);
|
||||
vm_page_t vm_page_next(vm_page_t m);
|
||||
int vm_page_pa_tryrelock(pmap_t, vm_paddr_t, vm_paddr_t *);
|
||||
vm_page_t vm_page_prev(vm_page_t m);
|
||||
void vm_page_putfake(vm_page_t m);
|
||||
void vm_page_remove (vm_page_t);
|
||||
void vm_page_rename (vm_page_t, vm_object_t, vm_pindex_t);
|
||||
void vm_page_requeue(vm_page_t m);
|
||||
@ -366,6 +368,7 @@ vm_page_t vm_page_splay(vm_pindex_t, vm_page_t);
|
||||
vm_offset_t vm_page_startup(vm_offset_t vaddr);
|
||||
void vm_page_unhold_pages(vm_page_t *ma, int count);
|
||||
void vm_page_unwire (vm_page_t, int);
|
||||
void vm_page_updatefake(vm_page_t m, vm_paddr_t paddr, vm_memattr_t memattr);
|
||||
void vm_page_wire (vm_page_t);
|
||||
void vm_page_set_validclean (vm_page_t, int, int);
|
||||
void vm_page_clear_dirty (vm_page_t, int, int);
|
||||
|
Loading…
Reference in New Issue
Block a user