2007-12-29 19:53:04 +00:00
|
|
|
/*-
|
2017-11-27 15:23:17 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2007-12-29 19:53:04 +00:00
|
|
|
* Copyright (c) 2002-2006 Rice University
|
2013-12-28 04:28:35 +00:00
|
|
|
* Copyright (c) 2007-2011 Alan L. Cox <alc@cs.rice.edu>
|
2007-12-29 19:53:04 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed for the FreeBSD Project by Alan L. Cox,
|
|
|
|
* Olivier Crameri, Peter Druschel, Sitaram Iyer, and Juan Navarro.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
|
|
|
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Superpage reservation management module
|
2011-12-05 18:29:25 +00:00
|
|
|
*
|
|
|
|
* Any external functions defined by this module are only to be used by the
|
|
|
|
* virtual memory system.
|
2007-12-29 19:53:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include "opt_vm.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/queue.h>
|
2013-03-09 02:32:23 +00:00
|
|
|
#include <sys/rwlock.h>
|
2007-12-29 19:53:04 +00:00
|
|
|
#include <sys/sbuf.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/systm.h>
|
2018-03-23 03:22:30 +00:00
|
|
|
#include <sys/counter.h>
|
|
|
|
#include <sys/ktr.h>
|
2017-04-17 17:07:00 +00:00
|
|
|
#include <sys/vmmeter.h>
|
2018-03-22 19:21:11 +00:00
|
|
|
#include <sys/smp.h>
|
2007-12-29 19:53:04 +00:00
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_param.h>
|
|
|
|
#include <vm/vm_object.h>
|
|
|
|
#include <vm/vm_page.h>
|
2018-02-06 22:10:07 +00:00
|
|
|
#include <vm/vm_pageout.h>
|
2007-12-29 19:53:04 +00:00
|
|
|
#include <vm/vm_phys.h>
|
2018-02-06 22:10:07 +00:00
|
|
|
#include <vm/vm_pagequeue.h>
|
Sync back vmcontention branch into HEAD:
Replace the per-object resident and cached pages splay tree with a
path-compressed multi-digit radix trie.
Along with this, switch also the x86-specific handling of idle page
tables to using the radix trie.
This change is supposed to do the following:
- Allowing the acquisition of read locking for lookup operations of the
resident/cached pages collections as the per-vm_page_t splay iterators
are now removed.
- Increase the scalability of the operations on the page collections.
The radix trie does rely on the consumers locking to ensure atomicity of
its operations. In order to avoid deadlocks the bisection nodes are
pre-allocated in the UMA zone. This can be done safely because the
algorithm needs at maximum one new node per insert which means the
maximum number of the desired nodes is the number of available physical
frames themselves. However, not all the times a new bisection node is
really needed.
The radix trie implements path-compression because UFS indirect blocks
can lead to several objects with a very sparse trie, increasing the number
of levels to usually scan. It also helps in the nodes pre-fetching by
introducing the single node per-insert property.
This code is not generalized (yet) because of the possible loss of
performance by having much of the sizes in play configurable.
However, efforts to make this code more general and then reusable in
further different consumers might be really done.
The only KPI change is the removal of the function vm_page_splay() which
is now reaped.
The only KBI change, instead, is the removal of the left/right iterators
from struct vm_page, which are now reaped.
Further technical notes broken into mealpieces can be retrieved from the
svn branch:
http://svn.freebsd.org/base/user/attilio/vmcontention/
Sponsored by: EMC / Isilon storage division
In collaboration with: alc, jeff
Tested by: flo, pho, jhb, davide
Tested by: ian (arm)
Tested by: andreast (powerpc)
2013-03-18 00:25:02 +00:00
|
|
|
#include <vm/vm_radix.h>
|
2007-12-29 19:53:04 +00:00
|
|
|
#include <vm/vm_reserv.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The reservation system supports the speculative allocation of large physical
|
2016-12-12 17:47:09 +00:00
|
|
|
* pages ("superpages"). Speculative allocation enables the fully automatic
|
2007-12-29 19:53:04 +00:00
|
|
|
* utilization of superpages by the virtual memory system. In other words, no
|
|
|
|
* programmatic directives are required to use superpages.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if VM_NRESERVLEVEL > 0
|
|
|
|
|
2019-01-18 13:35:06 +00:00
|
|
|
#ifndef VM_LEVEL_0_ORDER_MAX
|
|
|
|
#define VM_LEVEL_0_ORDER_MAX VM_LEVEL_0_ORDER
|
|
|
|
#endif
|
|
|
|
|
2007-12-29 19:53:04 +00:00
|
|
|
/*
|
|
|
|
* The number of small pages that are contained in a level 0 reservation
|
|
|
|
*/
|
|
|
|
#define VM_LEVEL_0_NPAGES (1 << VM_LEVEL_0_ORDER)
|
2019-01-18 13:35:06 +00:00
|
|
|
#define VM_LEVEL_0_NPAGES_MAX (1 << VM_LEVEL_0_ORDER_MAX)
|
2007-12-29 19:53:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The number of bits by which a physical address is shifted to obtain the
|
|
|
|
* reservation number
|
|
|
|
*/
|
|
|
|
#define VM_LEVEL_0_SHIFT (VM_LEVEL_0_ORDER + PAGE_SHIFT)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The size of a level 0 reservation in bytes
|
|
|
|
*/
|
|
|
|
#define VM_LEVEL_0_SIZE (1 << VM_LEVEL_0_SHIFT)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Computes the index of the small page underlying the given (object, pindex)
|
|
|
|
* within the reservation's array of small pages.
|
|
|
|
*/
|
|
|
|
#define VM_RESERV_INDEX(object, pindex) \
|
|
|
|
(((object)->pg_color + (pindex)) & (VM_LEVEL_0_NPAGES - 1))
|
|
|
|
|
2013-12-28 04:28:35 +00:00
|
|
|
/*
|
|
|
|
* The size of a population map entry
|
|
|
|
*/
|
|
|
|
typedef u_long popmap_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The number of bits in a population map entry
|
|
|
|
*/
|
|
|
|
#define NBPOPMAP (NBBY * sizeof(popmap_t))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The number of population map entries in a reservation
|
|
|
|
*/
|
|
|
|
#define NPOPMAP howmany(VM_LEVEL_0_NPAGES, NBPOPMAP)
|
2019-01-18 13:35:06 +00:00
|
|
|
#define NPOPMAP_MAX howmany(VM_LEVEL_0_NPAGES_MAX, NBPOPMAP)
|
2013-12-28 04:28:35 +00:00
|
|
|
|
2018-07-07 01:54:45 +00:00
|
|
|
/*
|
|
|
|
* Number of elapsed ticks before we update the LRU queue position. Used
|
|
|
|
* to reduce contention and churn on the list.
|
|
|
|
*/
|
|
|
|
#define PARTPOPSLOP 1
|
|
|
|
|
2014-06-11 16:11:12 +00:00
|
|
|
/*
|
|
|
|
* Clear a bit in the population map.
|
|
|
|
*/
|
|
|
|
static __inline void
|
|
|
|
popmap_clear(popmap_t popmap[], int i)
|
|
|
|
{
|
|
|
|
|
|
|
|
popmap[i / NBPOPMAP] &= ~(1UL << (i % NBPOPMAP));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set a bit in the population map.
|
|
|
|
*/
|
|
|
|
static __inline void
|
|
|
|
popmap_set(popmap_t popmap[], int i)
|
|
|
|
{
|
|
|
|
|
|
|
|
popmap[i / NBPOPMAP] |= 1UL << (i % NBPOPMAP);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is a bit in the population map clear?
|
|
|
|
*/
|
|
|
|
static __inline boolean_t
|
|
|
|
popmap_is_clear(popmap_t popmap[], int i)
|
|
|
|
{
|
|
|
|
|
|
|
|
return ((popmap[i / NBPOPMAP] & (1UL << (i % NBPOPMAP))) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is a bit in the population map set?
|
|
|
|
*/
|
|
|
|
static __inline boolean_t
|
|
|
|
popmap_is_set(popmap_t popmap[], int i)
|
|
|
|
{
|
|
|
|
|
|
|
|
return ((popmap[i / NBPOPMAP] & (1UL << (i % NBPOPMAP))) != 0);
|
|
|
|
}
|
|
|
|
|
2007-12-29 19:53:04 +00:00
|
|
|
/*
|
|
|
|
* The reservation structure
|
|
|
|
*
|
|
|
|
* A reservation structure is constructed whenever a large physical page is
|
|
|
|
* speculatively allocated to an object. The reservation provides the small
|
|
|
|
* physical pages for the range [pindex, pindex + VM_LEVEL_0_NPAGES) of offsets
|
|
|
|
* within that object. The reservation's "popcnt" tracks the number of these
|
|
|
|
* small physical pages that are in use at any given time. When and if the
|
2016-12-12 17:47:09 +00:00
|
|
|
* reservation is not fully utilized, it appears in the queue of partially
|
2007-12-29 19:53:04 +00:00
|
|
|
* populated reservations. The reservation always appears on the containing
|
|
|
|
* object's list of reservations.
|
|
|
|
*
|
2016-12-12 17:47:09 +00:00
|
|
|
* A partially populated reservation can be broken and reclaimed at any time.
|
2018-02-06 22:10:07 +00:00
|
|
|
*
|
2019-11-22 16:28:52 +00:00
|
|
|
* c - constant after boot
|
2018-03-22 19:21:11 +00:00
|
|
|
* d - vm_reserv_domain_lock
|
2018-02-06 22:10:07 +00:00
|
|
|
* o - vm_reserv_object_lock
|
2019-11-22 16:28:52 +00:00
|
|
|
* r - vm_reserv_lock
|
|
|
|
* s - vm_reserv_domain_scan_lock
|
2007-12-29 19:53:04 +00:00
|
|
|
*/
|
|
|
|
struct vm_reserv {
|
2018-03-22 19:21:11 +00:00
|
|
|
struct mtx lock; /* reservation lock. */
|
2019-11-18 18:25:51 +00:00
|
|
|
TAILQ_ENTRY(vm_reserv) partpopq; /* (d, r) per-domain queue. */
|
2018-03-22 19:21:11 +00:00
|
|
|
LIST_ENTRY(vm_reserv) objq; /* (o, r) object queue */
|
|
|
|
vm_object_t object; /* (o, r) containing object */
|
|
|
|
vm_pindex_t pindex; /* (o, r) offset in object */
|
2018-02-06 22:10:07 +00:00
|
|
|
vm_page_t pages; /* (c) first page */
|
2018-03-22 19:21:11 +00:00
|
|
|
uint16_t popcnt; /* (r) # of pages in use */
|
2019-11-18 18:25:51 +00:00
|
|
|
uint8_t domain; /* (c) NUMA domain. */
|
|
|
|
char inpartpopq; /* (d, r) */
|
2018-07-07 01:54:45 +00:00
|
|
|
int lasttick; /* (r) last pop update tick. */
|
2019-01-18 13:35:06 +00:00
|
|
|
popmap_t popmap[NPOPMAP_MAX]; /* (r) bit vector, used pages */
|
2007-12-29 19:53:04 +00:00
|
|
|
};
|
|
|
|
|
2019-11-22 16:28:52 +00:00
|
|
|
TAILQ_HEAD(vm_reserv_queue, vm_reserv);
|
|
|
|
|
2018-03-22 19:21:11 +00:00
|
|
|
#define vm_reserv_lockptr(rv) (&(rv)->lock)
|
|
|
|
#define vm_reserv_assert_locked(rv) \
|
|
|
|
mtx_assert(vm_reserv_lockptr(rv), MA_OWNED)
|
|
|
|
#define vm_reserv_lock(rv) mtx_lock(vm_reserv_lockptr(rv))
|
|
|
|
#define vm_reserv_trylock(rv) mtx_trylock(vm_reserv_lockptr(rv))
|
|
|
|
#define vm_reserv_unlock(rv) mtx_unlock(vm_reserv_lockptr(rv))
|
|
|
|
|
2007-12-29 19:53:04 +00:00
|
|
|
/*
|
|
|
|
* The reservation array
|
|
|
|
*
|
|
|
|
* This array is analoguous in function to vm_page_array. It differs in the
|
|
|
|
* respect that it may contain a greater number of useful reservation
|
|
|
|
* structures than there are (physical) superpages. These "invalid"
|
|
|
|
* reservation structures exist to trade-off space for time in the
|
|
|
|
* implementation of vm_reserv_from_page(). Invalid reservation structures are
|
|
|
|
* distinguishable from "valid" reservation structures by inspecting the
|
|
|
|
* reservation's "pages" field. Invalid reservation structures have a NULL
|
|
|
|
* "pages" field.
|
|
|
|
*
|
|
|
|
* vm_reserv_from_page() maps a small (physical) page to an element of this
|
|
|
|
* array by computing a physical reservation number from the page's physical
|
|
|
|
* address. The physical reservation number is used as the array index.
|
|
|
|
*
|
|
|
|
* An "active" reservation is a valid reservation structure that has a non-NULL
|
|
|
|
* "object" field and a non-zero "popcnt" field. In other words, every active
|
|
|
|
* reservation belongs to a particular object. Moreover, every active
|
|
|
|
* reservation has an entry in the containing object's list of reservations.
|
|
|
|
*/
|
|
|
|
static vm_reserv_t vm_reserv_array;
|
|
|
|
|
|
|
|
/*
|
2019-11-18 18:25:51 +00:00
|
|
|
* The per-domain partially populated reservation queues
|
2007-12-29 19:53:04 +00:00
|
|
|
*
|
2019-11-18 18:25:51 +00:00
|
|
|
* These queues enable the fast recovery of an unused free small page from a
|
|
|
|
* partially populated reservation. The reservation at the head of a queue
|
2016-12-12 17:47:09 +00:00
|
|
|
* is the least recently changed, partially populated reservation.
|
2007-12-29 19:53:04 +00:00
|
|
|
*
|
2019-11-18 18:25:51 +00:00
|
|
|
* Access to this queue is synchronized by the per-domain reservation lock.
|
2019-11-22 16:28:52 +00:00
|
|
|
* Threads reclaiming free pages from the queue must hold the per-domain scan
|
|
|
|
* lock.
|
2007-12-29 19:53:04 +00:00
|
|
|
*/
|
2019-11-18 18:25:51 +00:00
|
|
|
struct vm_reserv_domain {
|
2019-11-22 16:28:52 +00:00
|
|
|
struct mtx lock;
|
|
|
|
struct vm_reserv_queue partpop; /* (d) */
|
|
|
|
struct vm_reserv marker; /* (d, s) scan marker/lock */
|
2019-11-18 18:25:51 +00:00
|
|
|
} __aligned(CACHE_LINE_SIZE);
|
|
|
|
|
|
|
|
static struct vm_reserv_domain vm_rvd[MAXMEMDOM];
|
|
|
|
|
|
|
|
#define vm_reserv_domain_lockptr(d) (&vm_rvd[(d)].lock)
|
2019-11-22 16:28:52 +00:00
|
|
|
#define vm_reserv_domain_assert_locked(d) \
|
|
|
|
mtx_assert(vm_reserv_domain_lockptr(d), MA_OWNED)
|
2019-11-18 18:25:51 +00:00
|
|
|
#define vm_reserv_domain_lock(d) mtx_lock(vm_reserv_domain_lockptr(d))
|
|
|
|
#define vm_reserv_domain_unlock(d) mtx_unlock(vm_reserv_domain_lockptr(d))
|
2007-12-29 19:53:04 +00:00
|
|
|
|
2019-11-22 16:28:52 +00:00
|
|
|
#define vm_reserv_domain_scan_lock(d) mtx_lock(&vm_rvd[(d)].marker.lock)
|
|
|
|
#define vm_reserv_domain_scan_unlock(d) mtx_unlock(&vm_rvd[(d)].marker.lock)
|
|
|
|
|
2020-02-26 14:26:36 +00:00
|
|
|
static SYSCTL_NODE(_vm, OID_AUTO, reserv, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
|
|
|
|
"Reservation Info");
|
2007-12-29 19:53:04 +00:00
|
|
|
|
2020-03-06 19:10:00 +00:00
|
|
|
static COUNTER_U64_DEFINE_EARLY(vm_reserv_broken);
|
2018-03-22 19:21:11 +00:00
|
|
|
SYSCTL_COUNTER_U64(_vm_reserv, OID_AUTO, broken, CTLFLAG_RD,
|
|
|
|
&vm_reserv_broken, "Cumulative number of broken reservations");
|
2007-12-29 19:53:04 +00:00
|
|
|
|
2020-03-06 19:10:00 +00:00
|
|
|
static COUNTER_U64_DEFINE_EARLY(vm_reserv_freed);
|
2018-03-22 19:21:11 +00:00
|
|
|
SYSCTL_COUNTER_U64(_vm_reserv, OID_AUTO, freed, CTLFLAG_RD,
|
|
|
|
&vm_reserv_freed, "Cumulative number of freed reservations");
|
2007-12-29 19:53:04 +00:00
|
|
|
|
2015-08-06 21:27:50 +00:00
|
|
|
static int sysctl_vm_reserv_fullpop(SYSCTL_HANDLER_ARGS);
|
|
|
|
|
2020-01-12 05:08:57 +00:00
|
|
|
SYSCTL_PROC(_vm_reserv, OID_AUTO, fullpop, CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD,
|
|
|
|
NULL, 0, sysctl_vm_reserv_fullpop, "I", "Current number of full reservations");
|
2015-08-06 21:27:50 +00:00
|
|
|
|
2007-12-29 19:53:04 +00:00
|
|
|
static int sysctl_vm_reserv_partpopq(SYSCTL_HANDLER_ARGS);
|
|
|
|
|
2020-02-26 14:26:36 +00:00
|
|
|
SYSCTL_OID(_vm_reserv, OID_AUTO, partpopq,
|
|
|
|
CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_NEEDGIANT, NULL, 0,
|
|
|
|
sysctl_vm_reserv_partpopq, "A",
|
|
|
|
"Partially populated reservation queues");
|
2007-12-29 19:53:04 +00:00
|
|
|
|
2020-03-06 19:10:00 +00:00
|
|
|
static COUNTER_U64_DEFINE_EARLY(vm_reserv_reclaimed);
|
2018-03-22 19:21:11 +00:00
|
|
|
SYSCTL_COUNTER_U64(_vm_reserv, OID_AUTO, reclaimed, CTLFLAG_RD,
|
|
|
|
&vm_reserv_reclaimed, "Cumulative number of reclaimed reservations");
|
2007-12-29 19:53:04 +00:00
|
|
|
|
2018-02-06 22:10:07 +00:00
|
|
|
/*
|
|
|
|
* The object lock pool is used to synchronize the rvq. We can not use a
|
|
|
|
* pool mutex because it is required before malloc works.
|
|
|
|
*
|
|
|
|
* The "hash" function could be made faster without divide and modulo.
|
|
|
|
*/
|
|
|
|
#define VM_RESERV_OBJ_LOCK_COUNT MAXCPU
|
|
|
|
|
|
|
|
struct mtx_padalign vm_reserv_object_mtx[VM_RESERV_OBJ_LOCK_COUNT];
|
|
|
|
|
|
|
|
#define vm_reserv_object_lock_idx(object) \
|
|
|
|
(((uintptr_t)object / sizeof(*object)) % VM_RESERV_OBJ_LOCK_COUNT)
|
|
|
|
#define vm_reserv_object_lock_ptr(object) \
|
|
|
|
&vm_reserv_object_mtx[vm_reserv_object_lock_idx((object))]
|
|
|
|
#define vm_reserv_object_lock(object) \
|
|
|
|
mtx_lock(vm_reserv_object_lock_ptr((object)))
|
|
|
|
#define vm_reserv_object_unlock(object) \
|
|
|
|
mtx_unlock(vm_reserv_object_lock_ptr((object)))
|
|
|
|
|
2018-02-14 00:34:02 +00:00
|
|
|
static void vm_reserv_break(vm_reserv_t rv);
|
2013-12-28 04:28:35 +00:00
|
|
|
static void vm_reserv_depopulate(vm_reserv_t rv, int index);
|
2007-12-29 19:53:04 +00:00
|
|
|
static vm_reserv_t vm_reserv_from_page(vm_page_t m);
|
|
|
|
static boolean_t vm_reserv_has_pindex(vm_reserv_t rv,
|
|
|
|
vm_pindex_t pindex);
|
2013-12-28 04:28:35 +00:00
|
|
|
static void vm_reserv_populate(vm_reserv_t rv, int index);
|
2008-04-06 18:09:28 +00:00
|
|
|
static void vm_reserv_reclaim(vm_reserv_t rv);
|
2007-12-29 19:53:04 +00:00
|
|
|
|
2015-08-06 21:27:50 +00:00
|
|
|
/*
|
|
|
|
* Returns the current number of full reservations.
|
|
|
|
*
|
2019-11-18 18:25:51 +00:00
|
|
|
* Since the number of full reservations is computed without acquiring any
|
|
|
|
* locks, the returned value is inexact.
|
2015-08-06 21:27:50 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
sysctl_vm_reserv_fullpop(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
vm_paddr_t paddr;
|
|
|
|
struct vm_phys_seg *seg;
|
|
|
|
vm_reserv_t rv;
|
|
|
|
int fullpop, segind;
|
|
|
|
|
|
|
|
fullpop = 0;
|
|
|
|
for (segind = 0; segind < vm_phys_nsegs; segind++) {
|
|
|
|
seg = &vm_phys_segs[segind];
|
|
|
|
paddr = roundup2(seg->start, VM_LEVEL_0_SIZE);
|
2019-08-16 19:27:05 +00:00
|
|
|
while (paddr + VM_LEVEL_0_SIZE > paddr && paddr +
|
|
|
|
VM_LEVEL_0_SIZE <= seg->end) {
|
2015-08-06 21:27:50 +00:00
|
|
|
rv = &vm_reserv_array[paddr >> VM_LEVEL_0_SHIFT];
|
|
|
|
fullpop += rv->popcnt == VM_LEVEL_0_NPAGES;
|
|
|
|
paddr += VM_LEVEL_0_SIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (sysctl_handle_int(oidp, &fullpop, 0, req));
|
|
|
|
}
|
|
|
|
|
2007-12-29 19:53:04 +00:00
|
|
|
/*
|
2016-12-12 17:47:09 +00:00
|
|
|
* Describes the current state of the partially populated reservation queue.
|
2007-12-29 19:53:04 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
sysctl_vm_reserv_partpopq(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct sbuf sbuf;
|
|
|
|
vm_reserv_t rv;
|
2017-11-28 23:18:35 +00:00
|
|
|
int counter, error, domain, level, unused_pages;
|
2007-12-29 19:53:04 +00:00
|
|
|
|
2011-01-27 00:34:12 +00:00
|
|
|
error = sysctl_wire_old_buffer(req, 0);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
2010-09-16 16:13:12 +00:00
|
|
|
sbuf_new_for_sysctl(&sbuf, NULL, 128, req);
|
2017-11-28 23:18:35 +00:00
|
|
|
sbuf_printf(&sbuf, "\nDOMAIN LEVEL SIZE NUMBER\n\n");
|
|
|
|
for (domain = 0; domain < vm_ndomains; domain++) {
|
|
|
|
for (level = -1; level <= VM_NRESERVLEVEL - 2; level++) {
|
|
|
|
counter = 0;
|
|
|
|
unused_pages = 0;
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_domain_lock(domain);
|
2019-11-18 18:25:51 +00:00
|
|
|
TAILQ_FOREACH(rv, &vm_rvd[domain].partpop, partpopq) {
|
2019-11-22 16:28:52 +00:00
|
|
|
if (rv == &vm_rvd[domain].marker)
|
|
|
|
continue;
|
2017-11-28 23:18:35 +00:00
|
|
|
counter++;
|
|
|
|
unused_pages += VM_LEVEL_0_NPAGES - rv->popcnt;
|
|
|
|
}
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_domain_unlock(domain);
|
2017-11-28 23:18:35 +00:00
|
|
|
sbuf_printf(&sbuf, "%6d, %7d, %6dK, %6d\n",
|
|
|
|
domain, level,
|
|
|
|
unused_pages * ((int)PAGE_SIZE / 1024), counter);
|
2007-12-29 19:53:04 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-16 16:13:12 +00:00
|
|
|
error = sbuf_finish(&sbuf);
|
2007-12-29 19:53:04 +00:00
|
|
|
sbuf_delete(&sbuf);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2018-02-06 22:10:07 +00:00
|
|
|
/*
|
|
|
|
* Remove a reservation from the object's objq.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
vm_reserv_remove(vm_reserv_t rv)
|
|
|
|
{
|
|
|
|
vm_object_t object;
|
|
|
|
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_assert_locked(rv);
|
|
|
|
CTR5(KTR_VM, "%s: rv %p object %p popcnt %d inpartpop %d",
|
|
|
|
__FUNCTION__, rv, rv->object, rv->popcnt, rv->inpartpopq);
|
2018-02-06 22:10:07 +00:00
|
|
|
KASSERT(rv->object != NULL,
|
|
|
|
("vm_reserv_remove: reserv %p is free", rv));
|
|
|
|
KASSERT(!rv->inpartpopq,
|
|
|
|
("vm_reserv_remove: reserv %p's inpartpopq is TRUE", rv));
|
|
|
|
object = rv->object;
|
|
|
|
vm_reserv_object_lock(object);
|
|
|
|
LIST_REMOVE(rv, objq);
|
|
|
|
rv->object = NULL;
|
|
|
|
vm_reserv_object_unlock(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Insert a new reservation into the object's objq.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
vm_reserv_insert(vm_reserv_t rv, vm_object_t object, vm_pindex_t pindex)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_assert_locked(rv);
|
|
|
|
CTR6(KTR_VM,
|
|
|
|
"%s: rv %p(%p) object %p new %p popcnt %d",
|
|
|
|
__FUNCTION__, rv, rv->pages, rv->object, object,
|
|
|
|
rv->popcnt);
|
2018-02-06 22:10:07 +00:00
|
|
|
KASSERT(rv->object == NULL,
|
|
|
|
("vm_reserv_insert: reserv %p isn't free", rv));
|
|
|
|
KASSERT(rv->popcnt == 0,
|
|
|
|
("vm_reserv_insert: reserv %p's popcnt is corrupted", rv));
|
|
|
|
KASSERT(!rv->inpartpopq,
|
|
|
|
("vm_reserv_insert: reserv %p's inpartpopq is TRUE", rv));
|
|
|
|
for (i = 0; i < NPOPMAP; i++)
|
|
|
|
KASSERT(rv->popmap[i] == 0,
|
|
|
|
("vm_reserv_insert: reserv %p's popmap is corrupted", rv));
|
|
|
|
vm_reserv_object_lock(object);
|
|
|
|
rv->pindex = pindex;
|
|
|
|
rv->object = object;
|
2018-07-07 01:54:45 +00:00
|
|
|
rv->lasttick = ticks;
|
2018-02-06 22:10:07 +00:00
|
|
|
LIST_INSERT_HEAD(&object->rvq, rv, objq);
|
|
|
|
vm_reserv_object_unlock(object);
|
|
|
|
}
|
|
|
|
|
2007-12-29 19:53:04 +00:00
|
|
|
/*
|
|
|
|
* Reduces the given reservation's population count. If the population count
|
|
|
|
* becomes zero, the reservation is destroyed. Additionally, moves the
|
2016-12-12 17:47:09 +00:00
|
|
|
* reservation to the tail of the partially populated reservation queue if the
|
2007-12-29 19:53:04 +00:00
|
|
|
* population count is non-zero.
|
|
|
|
*/
|
|
|
|
static void
|
2013-12-28 04:28:35 +00:00
|
|
|
vm_reserv_depopulate(vm_reserv_t rv, int index)
|
2007-12-29 19:53:04 +00:00
|
|
|
{
|
2018-03-22 19:21:11 +00:00
|
|
|
struct vm_domain *vmd;
|
2007-12-29 19:53:04 +00:00
|
|
|
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_assert_locked(rv);
|
|
|
|
CTR5(KTR_VM, "%s: rv %p object %p popcnt %d inpartpop %d",
|
|
|
|
__FUNCTION__, rv, rv->object, rv->popcnt, rv->inpartpopq);
|
2007-12-29 19:53:04 +00:00
|
|
|
KASSERT(rv->object != NULL,
|
|
|
|
("vm_reserv_depopulate: reserv %p is free", rv));
|
2014-06-11 16:11:12 +00:00
|
|
|
KASSERT(popmap_is_set(rv->popmap, index),
|
2013-12-29 04:54:52 +00:00
|
|
|
("vm_reserv_depopulate: reserv %p's popmap[%d] is clear", rv,
|
|
|
|
index));
|
2007-12-29 19:53:04 +00:00
|
|
|
KASSERT(rv->popcnt > 0,
|
|
|
|
("vm_reserv_depopulate: reserv %p's popcnt is corrupted", rv));
|
2018-03-23 18:24:02 +00:00
|
|
|
KASSERT(rv->domain < vm_ndomains,
|
2017-11-28 23:18:35 +00:00
|
|
|
("vm_reserv_depopulate: reserv %p's domain is corrupted %d",
|
|
|
|
rv, rv->domain));
|
2018-03-22 19:21:11 +00:00
|
|
|
if (rv->popcnt == VM_LEVEL_0_NPAGES) {
|
Add a page size field to struct vm_page. Increase the page size field when
a partially populated reservation becomes fully populated, and decrease this
field when a fully populated reservation becomes partially populated.
Use this field to simplify the implementation of pmap_enter_object() on
amd64, arm, and i386.
On all architectures where we support superpages, the cost of creating a
superpage mapping is roughly the same as creating a base page mapping. For
example, both kinds of mappings entail the creation of a single PTE and PV
entry. With this in mind, use the page size field to make the
implementation of vm_map_pmap_enter(..., MAP_PREFAULT_PARTIAL) a little
smarter. Previously, if MAP_PREFAULT_PARTIAL was specified to
vm_map_pmap_enter(), that function would only map base pages. Now, it will
create up to 96 base page or superpage mappings.
Reviewed by: kib
Sponsored by: EMC / Isilon Storage Division
2014-06-07 17:12:26 +00:00
|
|
|
KASSERT(rv->pages->psind == 1,
|
|
|
|
("vm_reserv_depopulate: reserv %p is already demoted",
|
|
|
|
rv));
|
|
|
|
rv->pages->psind = 0;
|
2007-12-29 19:53:04 +00:00
|
|
|
}
|
2014-06-11 16:11:12 +00:00
|
|
|
popmap_clear(rv->popmap, index);
|
2007-12-29 19:53:04 +00:00
|
|
|
rv->popcnt--;
|
2018-07-07 01:54:45 +00:00
|
|
|
if ((unsigned)(ticks - rv->lasttick) >= PARTPOPSLOP ||
|
|
|
|
rv->popcnt == 0) {
|
|
|
|
vm_reserv_domain_lock(rv->domain);
|
|
|
|
if (rv->inpartpopq) {
|
2019-11-18 18:25:51 +00:00
|
|
|
TAILQ_REMOVE(&vm_rvd[rv->domain].partpop, rv, partpopq);
|
2018-07-07 01:54:45 +00:00
|
|
|
rv->inpartpopq = FALSE;
|
|
|
|
}
|
|
|
|
if (rv->popcnt != 0) {
|
|
|
|
rv->inpartpopq = TRUE;
|
2019-11-18 18:25:51 +00:00
|
|
|
TAILQ_INSERT_TAIL(&vm_rvd[rv->domain].partpop, rv,
|
|
|
|
partpopq);
|
2018-07-07 01:54:45 +00:00
|
|
|
}
|
|
|
|
vm_reserv_domain_unlock(rv->domain);
|
|
|
|
rv->lasttick = ticks;
|
2018-03-22 19:21:11 +00:00
|
|
|
}
|
|
|
|
vmd = VM_DOMAIN(rv->domain);
|
2007-12-29 19:53:04 +00:00
|
|
|
if (rv->popcnt == 0) {
|
2018-02-06 22:10:07 +00:00
|
|
|
vm_reserv_remove(rv);
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_domain_free_lock(vmd);
|
2007-12-29 19:53:04 +00:00
|
|
|
vm_phys_free_pages(rv->pages, VM_LEVEL_0_ORDER);
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_domain_free_unlock(vmd);
|
|
|
|
counter_u64_add(vm_reserv_freed, 1);
|
2007-12-29 19:53:04 +00:00
|
|
|
}
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_domain_freecnt_inc(vmd, 1);
|
2007-12-29 19:53:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns the reservation to which the given page might belong.
|
|
|
|
*/
|
|
|
|
static __inline vm_reserv_t
|
|
|
|
vm_reserv_from_page(vm_page_t m)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (&vm_reserv_array[VM_PAGE_TO_PHYS(m) >> VM_LEVEL_0_SHIFT]);
|
|
|
|
}
|
|
|
|
|
2018-02-06 22:10:07 +00:00
|
|
|
/*
|
|
|
|
* Returns an existing reservation or NULL and initialized successor pointer.
|
|
|
|
*/
|
|
|
|
static vm_reserv_t
|
|
|
|
vm_reserv_from_object(vm_object_t object, vm_pindex_t pindex,
|
|
|
|
vm_page_t mpred, vm_page_t *msuccp)
|
|
|
|
{
|
|
|
|
vm_reserv_t rv;
|
|
|
|
vm_page_t msucc;
|
|
|
|
|
|
|
|
msucc = NULL;
|
|
|
|
if (mpred != NULL) {
|
|
|
|
KASSERT(mpred->object == object,
|
|
|
|
("vm_reserv_from_object: object doesn't contain mpred"));
|
|
|
|
KASSERT(mpred->pindex < pindex,
|
|
|
|
("vm_reserv_from_object: mpred doesn't precede pindex"));
|
|
|
|
rv = vm_reserv_from_page(mpred);
|
|
|
|
if (rv->object == object && vm_reserv_has_pindex(rv, pindex))
|
|
|
|
goto found;
|
|
|
|
msucc = TAILQ_NEXT(mpred, listq);
|
|
|
|
} else
|
|
|
|
msucc = TAILQ_FIRST(&object->memq);
|
|
|
|
if (msucc != NULL) {
|
|
|
|
KASSERT(msucc->pindex > pindex,
|
|
|
|
("vm_reserv_from_object: msucc doesn't succeed pindex"));
|
|
|
|
rv = vm_reserv_from_page(msucc);
|
|
|
|
if (rv->object == object && vm_reserv_has_pindex(rv, pindex))
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
rv = NULL;
|
|
|
|
|
|
|
|
found:
|
|
|
|
*msuccp = msucc;
|
|
|
|
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
2007-12-29 19:53:04 +00:00
|
|
|
/*
|
|
|
|
* Returns TRUE if the given reservation contains the given page index and
|
|
|
|
* FALSE otherwise.
|
|
|
|
*/
|
|
|
|
static __inline boolean_t
|
|
|
|
vm_reserv_has_pindex(vm_reserv_t rv, vm_pindex_t pindex)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (((pindex - rv->pindex) & ~(VM_LEVEL_0_NPAGES - 1)) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Increases the given reservation's population count. Moves the reservation
|
2016-12-12 17:47:09 +00:00
|
|
|
* to the tail of the partially populated reservation queue.
|
2007-12-29 19:53:04 +00:00
|
|
|
*/
|
|
|
|
static void
|
2013-12-28 04:28:35 +00:00
|
|
|
vm_reserv_populate(vm_reserv_t rv, int index)
|
2007-12-29 19:53:04 +00:00
|
|
|
{
|
|
|
|
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_assert_locked(rv);
|
|
|
|
CTR5(KTR_VM, "%s: rv %p object %p popcnt %d inpartpop %d",
|
|
|
|
__FUNCTION__, rv, rv->object, rv->popcnt, rv->inpartpopq);
|
2007-12-29 19:53:04 +00:00
|
|
|
KASSERT(rv->object != NULL,
|
|
|
|
("vm_reserv_populate: reserv %p is free", rv));
|
2014-06-11 16:11:12 +00:00
|
|
|
KASSERT(popmap_is_clear(rv->popmap, index),
|
2013-12-29 04:54:52 +00:00
|
|
|
("vm_reserv_populate: reserv %p's popmap[%d] is set", rv,
|
|
|
|
index));
|
2007-12-29 19:53:04 +00:00
|
|
|
KASSERT(rv->popcnt < VM_LEVEL_0_NPAGES,
|
|
|
|
("vm_reserv_populate: reserv %p is already full", rv));
|
Add a page size field to struct vm_page. Increase the page size field when
a partially populated reservation becomes fully populated, and decrease this
field when a fully populated reservation becomes partially populated.
Use this field to simplify the implementation of pmap_enter_object() on
amd64, arm, and i386.
On all architectures where we support superpages, the cost of creating a
superpage mapping is roughly the same as creating a base page mapping. For
example, both kinds of mappings entail the creation of a single PTE and PV
entry. With this in mind, use the page size field to make the
implementation of vm_map_pmap_enter(..., MAP_PREFAULT_PARTIAL) a little
smarter. Previously, if MAP_PREFAULT_PARTIAL was specified to
vm_map_pmap_enter(), that function would only map base pages. Now, it will
create up to 96 base page or superpage mappings.
Reviewed by: kib
Sponsored by: EMC / Isilon Storage Division
2014-06-07 17:12:26 +00:00
|
|
|
KASSERT(rv->pages->psind == 0,
|
|
|
|
("vm_reserv_populate: reserv %p is already promoted", rv));
|
2018-03-23 18:24:02 +00:00
|
|
|
KASSERT(rv->domain < vm_ndomains,
|
2017-11-28 23:18:35 +00:00
|
|
|
("vm_reserv_populate: reserv %p's domain is corrupted %d",
|
|
|
|
rv, rv->domain));
|
2018-03-22 19:21:11 +00:00
|
|
|
popmap_set(rv->popmap, index);
|
|
|
|
rv->popcnt++;
|
2018-07-07 01:54:45 +00:00
|
|
|
if ((unsigned)(ticks - rv->lasttick) < PARTPOPSLOP &&
|
|
|
|
rv->inpartpopq && rv->popcnt != VM_LEVEL_0_NPAGES)
|
|
|
|
return;
|
|
|
|
rv->lasttick = ticks;
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_domain_lock(rv->domain);
|
2007-12-29 19:53:04 +00:00
|
|
|
if (rv->inpartpopq) {
|
2019-11-18 18:25:51 +00:00
|
|
|
TAILQ_REMOVE(&vm_rvd[rv->domain].partpop, rv, partpopq);
|
2007-12-29 19:53:04 +00:00
|
|
|
rv->inpartpopq = FALSE;
|
|
|
|
}
|
|
|
|
if (rv->popcnt < VM_LEVEL_0_NPAGES) {
|
|
|
|
rv->inpartpopq = TRUE;
|
2019-11-18 18:25:51 +00:00
|
|
|
TAILQ_INSERT_TAIL(&vm_rvd[rv->domain].partpop, rv, partpopq);
|
2018-03-22 19:21:11 +00:00
|
|
|
} else {
|
|
|
|
KASSERT(rv->pages->psind == 0,
|
|
|
|
("vm_reserv_populate: reserv %p is already promoted",
|
|
|
|
rv));
|
Add a page size field to struct vm_page. Increase the page size field when
a partially populated reservation becomes fully populated, and decrease this
field when a fully populated reservation becomes partially populated.
Use this field to simplify the implementation of pmap_enter_object() on
amd64, arm, and i386.
On all architectures where we support superpages, the cost of creating a
superpage mapping is roughly the same as creating a base page mapping. For
example, both kinds of mappings entail the creation of a single PTE and PV
entry. With this in mind, use the page size field to make the
implementation of vm_map_pmap_enter(..., MAP_PREFAULT_PARTIAL) a little
smarter. Previously, if MAP_PREFAULT_PARTIAL was specified to
vm_map_pmap_enter(), that function would only map base pages. Now, it will
create up to 96 base page or superpage mappings.
Reviewed by: kib
Sponsored by: EMC / Isilon Storage Division
2014-06-07 17:12:26 +00:00
|
|
|
rv->pages->psind = 1;
|
2018-03-22 19:21:11 +00:00
|
|
|
}
|
|
|
|
vm_reserv_domain_unlock(rv->domain);
|
2007-12-29 19:53:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-12-05 18:29:25 +00:00
|
|
|
* Allocates a contiguous set of physical pages of the given size "npages"
|
2019-06-03 05:15:36 +00:00
|
|
|
* from existing or newly created reservations. All of the physical pages
|
2011-12-05 18:29:25 +00:00
|
|
|
* must be at or above the given physical address "low" and below the given
|
|
|
|
* physical address "high". The given value "alignment" determines the
|
|
|
|
* alignment of the first physical page in the set. If the given value
|
|
|
|
* "boundary" is non-zero, then the set of physical pages cannot cross any
|
|
|
|
* physical address boundary that is a multiple of that value. Both
|
|
|
|
* "alignment" and "boundary" must be a power of two.
|
2007-12-29 19:53:04 +00:00
|
|
|
*
|
2016-12-28 18:32:13 +00:00
|
|
|
* The page "mpred" must immediately precede the offset "pindex" within the
|
|
|
|
* specified object.
|
|
|
|
*
|
2019-06-03 05:15:36 +00:00
|
|
|
* The object must be locked.
|
2007-12-29 19:53:04 +00:00
|
|
|
*/
|
|
|
|
vm_page_t
|
2019-06-03 05:15:36 +00:00
|
|
|
vm_reserv_alloc_contig(vm_object_t object, vm_pindex_t pindex, int domain,
|
|
|
|
int req, vm_page_t mpred, u_long npages, vm_paddr_t low, vm_paddr_t high,
|
|
|
|
u_long alignment, vm_paddr_t boundary)
|
2007-12-29 19:53:04 +00:00
|
|
|
{
|
2018-03-22 19:21:11 +00:00
|
|
|
struct vm_domain *vmd;
|
2011-12-05 18:29:25 +00:00
|
|
|
vm_paddr_t pa, size;
|
2016-12-28 18:32:13 +00:00
|
|
|
vm_page_t m, m_ret, msucc;
|
2007-12-29 19:53:04 +00:00
|
|
|
vm_pindex_t first, leftcap, rightcap;
|
|
|
|
vm_reserv_t rv;
|
2011-12-05 18:29:25 +00:00
|
|
|
u_long allocpages, maxpages, minpages;
|
|
|
|
int i, index, n;
|
2007-12-29 19:53:04 +00:00
|
|
|
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_ASSERT_WLOCKED(object);
|
2011-12-05 18:29:25 +00:00
|
|
|
KASSERT(npages != 0, ("vm_reserv_alloc_contig: npages is 0"));
|
2007-12-29 19:53:04 +00:00
|
|
|
|
|
|
|
/*
|
2011-12-05 18:29:25 +00:00
|
|
|
* Is a reservation fundamentally impossible?
|
2007-12-29 19:53:04 +00:00
|
|
|
*/
|
|
|
|
if (pindex < VM_RESERV_INDEX(object, pindex) ||
|
2011-12-05 18:29:25 +00:00
|
|
|
pindex + npages > object->size)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All reservations of a particular size have the same alignment.
|
|
|
|
* Assuming that the first page is allocated from a reservation, the
|
|
|
|
* least significant bits of its physical address can be determined
|
|
|
|
* from its offset from the beginning of the reservation and the size
|
|
|
|
* of the reservation.
|
|
|
|
*
|
|
|
|
* Could the specified index within a reservation of the smallest
|
|
|
|
* possible size satisfy the alignment and boundary requirements?
|
|
|
|
*/
|
|
|
|
pa = VM_RESERV_INDEX(object, pindex) << PAGE_SHIFT;
|
|
|
|
if ((pa & (alignment - 1)) != 0)
|
|
|
|
return (NULL);
|
|
|
|
size = npages << PAGE_SHIFT;
|
|
|
|
if (((pa ^ (pa + size - 1)) & ~(boundary - 1)) != 0)
|
2007-12-29 19:53:04 +00:00
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
/*
|
2019-06-03 05:15:36 +00:00
|
|
|
* Look for an existing reservation.
|
2007-12-29 19:53:04 +00:00
|
|
|
*/
|
2018-02-06 22:10:07 +00:00
|
|
|
rv = vm_reserv_from_object(object, pindex, mpred, &msucc);
|
2019-06-03 05:15:36 +00:00
|
|
|
if (rv != NULL) {
|
|
|
|
KASSERT(object != kernel_object || rv->domain == domain,
|
|
|
|
("vm_reserv_alloc_contig: domain mismatch"));
|
|
|
|
index = VM_RESERV_INDEX(object, pindex);
|
|
|
|
/* Does the allocation fit within the reservation? */
|
|
|
|
if (index + npages > VM_LEVEL_0_NPAGES)
|
|
|
|
return (NULL);
|
|
|
|
domain = rv->domain;
|
|
|
|
vmd = VM_DOMAIN(domain);
|
|
|
|
vm_reserv_lock(rv);
|
|
|
|
/* Handle reclaim race. */
|
|
|
|
if (rv->object != object)
|
|
|
|
goto out;
|
|
|
|
m = &rv->pages[index];
|
|
|
|
pa = VM_PAGE_TO_PHYS(m);
|
|
|
|
if (pa < low || pa + size > high ||
|
|
|
|
(pa & (alignment - 1)) != 0 ||
|
|
|
|
((pa ^ (pa + size - 1)) & ~(boundary - 1)) != 0)
|
|
|
|
goto out;
|
|
|
|
/* Handle vm_page_rename(m, new_object, ...). */
|
|
|
|
for (i = 0; i < npages; i++)
|
|
|
|
if (popmap_is_set(rv->popmap, index + i))
|
|
|
|
goto out;
|
|
|
|
if (!vm_domain_allocate(vmd, req, npages))
|
|
|
|
goto out;
|
|
|
|
for (i = 0; i < npages; i++)
|
|
|
|
vm_reserv_populate(rv, index + i);
|
|
|
|
vm_reserv_unlock(rv);
|
|
|
|
return (m);
|
|
|
|
out:
|
|
|
|
vm_reserv_unlock(rv);
|
2018-02-06 22:10:07 +00:00
|
|
|
return (NULL);
|
2019-06-03 05:15:36 +00:00
|
|
|
}
|
2007-12-29 19:53:04 +00:00
|
|
|
|
|
|
|
/*
|
2011-12-05 18:29:25 +00:00
|
|
|
* Could at least one reservation fit between the first index to the
|
2014-09-10 05:52:30 +00:00
|
|
|
* left that can be used ("leftcap") and the first index to the right
|
|
|
|
* that cannot be used ("rightcap")?
|
2018-02-06 22:10:07 +00:00
|
|
|
*
|
|
|
|
* We must synchronize with the reserv object lock to protect the
|
|
|
|
* pindex/object of the resulting reservations against rename while
|
|
|
|
* we are inspecting.
|
2007-12-29 19:53:04 +00:00
|
|
|
*/
|
|
|
|
first = pindex - VM_RESERV_INDEX(object, pindex);
|
2018-02-06 22:10:07 +00:00
|
|
|
minpages = VM_RESERV_INDEX(object, pindex) + npages;
|
|
|
|
maxpages = roundup2(minpages, VM_LEVEL_0_NPAGES);
|
|
|
|
allocpages = maxpages;
|
|
|
|
vm_reserv_object_lock(object);
|
2011-12-05 18:29:25 +00:00
|
|
|
if (mpred != NULL) {
|
|
|
|
if ((rv = vm_reserv_from_page(mpred))->object != object)
|
|
|
|
leftcap = mpred->pindex + 1;
|
|
|
|
else
|
|
|
|
leftcap = rv->pindex + VM_LEVEL_0_NPAGES;
|
2018-02-06 22:10:07 +00:00
|
|
|
if (leftcap > first) {
|
|
|
|
vm_reserv_object_unlock(object);
|
2011-12-05 18:29:25 +00:00
|
|
|
return (NULL);
|
2018-02-06 22:10:07 +00:00
|
|
|
}
|
2011-12-05 18:29:25 +00:00
|
|
|
}
|
|
|
|
if (msucc != NULL) {
|
|
|
|
if ((rv = vm_reserv_from_page(msucc))->object != object)
|
|
|
|
rightcap = msucc->pindex;
|
|
|
|
else
|
|
|
|
rightcap = rv->pindex;
|
|
|
|
if (first + maxpages > rightcap) {
|
2018-02-06 22:10:07 +00:00
|
|
|
if (maxpages == VM_LEVEL_0_NPAGES) {
|
|
|
|
vm_reserv_object_unlock(object);
|
2011-12-05 18:29:25 +00:00
|
|
|
return (NULL);
|
2018-02-06 22:10:07 +00:00
|
|
|
}
|
2014-09-10 05:52:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* At least one reservation will fit between "leftcap"
|
|
|
|
* and "rightcap". However, a reservation for the
|
|
|
|
* last of the requested pages will not fit. Reduce
|
|
|
|
* the size of the upcoming allocation accordingly.
|
|
|
|
*/
|
2011-12-05 18:29:25 +00:00
|
|
|
allocpages = minpages;
|
|
|
|
}
|
|
|
|
}
|
2018-02-06 22:10:07 +00:00
|
|
|
vm_reserv_object_unlock(object);
|
2007-12-29 19:53:04 +00:00
|
|
|
|
|
|
|
/*
|
2011-12-05 18:29:25 +00:00
|
|
|
* Would the last new reservation extend past the end of the object?
|
2019-11-19 23:19:43 +00:00
|
|
|
*
|
|
|
|
* If the object is unlikely to grow don't allocate a reservation for
|
|
|
|
* the tail.
|
2007-12-29 19:53:04 +00:00
|
|
|
*/
|
2019-11-19 23:19:43 +00:00
|
|
|
if ((object->flags & OBJ_ANON) == 0 &&
|
|
|
|
first + maxpages > object->size) {
|
|
|
|
if (maxpages == VM_LEVEL_0_NPAGES)
|
|
|
|
return (NULL);
|
|
|
|
allocpages = minpages;
|
2007-12-29 19:53:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-09-10 05:52:30 +00:00
|
|
|
* Allocate the physical pages. The alignment and boundary specified
|
|
|
|
* for this allocation may be different from the alignment and
|
|
|
|
* boundary specified for the requested pages. For instance, the
|
|
|
|
* specified index may not be the first page within the first new
|
|
|
|
* reservation.
|
2007-12-29 19:53:04 +00:00
|
|
|
*/
|
2018-03-22 19:21:11 +00:00
|
|
|
m = NULL;
|
|
|
|
vmd = VM_DOMAIN(domain);
|
|
|
|
if (vm_domain_allocate(vmd, req, npages)) {
|
|
|
|
vm_domain_free_lock(vmd);
|
|
|
|
m = vm_phys_alloc_contig(domain, allocpages, low, high,
|
|
|
|
ulmax(alignment, VM_LEVEL_0_SIZE),
|
|
|
|
boundary > VM_LEVEL_0_SIZE ? boundary : 0);
|
|
|
|
vm_domain_free_unlock(vmd);
|
|
|
|
if (m == NULL) {
|
|
|
|
vm_domain_freecnt_inc(vmd, npages);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
} else
|
2011-12-05 18:29:25 +00:00
|
|
|
return (NULL);
|
2018-02-06 22:10:07 +00:00
|
|
|
KASSERT(vm_phys_domain(m) == domain,
|
2018-01-12 23:13:55 +00:00
|
|
|
("vm_reserv_alloc_contig: Page domain does not match requested."));
|
2014-09-10 05:52:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The allocated physical pages always begin at a reservation
|
|
|
|
* boundary, but they do not always end at a reservation boundary.
|
|
|
|
* Initialize every reservation that is completely covered by the
|
|
|
|
* allocated physical pages.
|
|
|
|
*/
|
2011-12-05 18:29:25 +00:00
|
|
|
m_ret = NULL;
|
|
|
|
index = VM_RESERV_INDEX(object, pindex);
|
|
|
|
do {
|
2007-12-29 19:53:04 +00:00
|
|
|
rv = vm_reserv_from_page(m);
|
|
|
|
KASSERT(rv->pages == m,
|
2011-12-05 18:29:25 +00:00
|
|
|
("vm_reserv_alloc_contig: reserv %p's pages is corrupted",
|
2007-12-29 19:53:04 +00:00
|
|
|
rv));
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_lock(rv);
|
2018-02-06 22:10:07 +00:00
|
|
|
vm_reserv_insert(rv, object, first);
|
2011-12-05 18:29:25 +00:00
|
|
|
n = ulmin(VM_LEVEL_0_NPAGES - index, npages);
|
|
|
|
for (i = 0; i < n; i++)
|
2013-12-28 04:28:35 +00:00
|
|
|
vm_reserv_populate(rv, index + i);
|
2011-12-05 18:29:25 +00:00
|
|
|
npages -= n;
|
|
|
|
if (m_ret == NULL) {
|
|
|
|
m_ret = &rv->pages[index];
|
|
|
|
index = 0;
|
|
|
|
}
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_unlock(rv);
|
2011-12-05 18:29:25 +00:00
|
|
|
m += VM_LEVEL_0_NPAGES;
|
|
|
|
first += VM_LEVEL_0_NPAGES;
|
|
|
|
allocpages -= VM_LEVEL_0_NPAGES;
|
2014-09-10 05:52:30 +00:00
|
|
|
} while (allocpages >= VM_LEVEL_0_NPAGES);
|
2011-12-05 18:29:25 +00:00
|
|
|
return (m_ret);
|
2018-02-06 22:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2019-06-03 05:15:36 +00:00
|
|
|
* Allocate a physical page from an existing or newly created reservation.
|
2018-02-06 22:10:07 +00:00
|
|
|
*
|
|
|
|
* The page "mpred" must immediately precede the offset "pindex" within the
|
|
|
|
* specified object.
|
|
|
|
*
|
|
|
|
* The object must be locked.
|
|
|
|
*/
|
|
|
|
vm_page_t
|
2019-06-03 05:15:36 +00:00
|
|
|
vm_reserv_alloc_page(vm_object_t object, vm_pindex_t pindex, int domain,
|
|
|
|
int req, vm_page_t mpred)
|
2011-12-05 18:29:25 +00:00
|
|
|
{
|
2018-03-22 19:21:11 +00:00
|
|
|
struct vm_domain *vmd;
|
2013-05-12 16:50:18 +00:00
|
|
|
vm_page_t m, msucc;
|
2011-12-05 18:29:25 +00:00
|
|
|
vm_pindex_t first, leftcap, rightcap;
|
|
|
|
vm_reserv_t rv;
|
2018-02-06 22:10:07 +00:00
|
|
|
int index;
|
2011-12-05 18:29:25 +00:00
|
|
|
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_ASSERT_WLOCKED(object);
|
2011-12-05 18:29:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Is a reservation fundamentally impossible?
|
|
|
|
*/
|
|
|
|
if (pindex < VM_RESERV_INDEX(object, pindex) ||
|
|
|
|
pindex >= object->size)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
/*
|
2019-06-03 05:15:36 +00:00
|
|
|
* Look for an existing reservation.
|
2011-12-05 18:29:25 +00:00
|
|
|
*/
|
2018-02-06 22:10:07 +00:00
|
|
|
rv = vm_reserv_from_object(object, pindex, mpred, &msucc);
|
2019-06-03 05:15:36 +00:00
|
|
|
if (rv != NULL) {
|
|
|
|
KASSERT(object != kernel_object || rv->domain == domain,
|
|
|
|
("vm_reserv_alloc_page: domain mismatch"));
|
|
|
|
domain = rv->domain;
|
|
|
|
vmd = VM_DOMAIN(domain);
|
|
|
|
index = VM_RESERV_INDEX(object, pindex);
|
|
|
|
m = &rv->pages[index];
|
|
|
|
vm_reserv_lock(rv);
|
|
|
|
/* Handle reclaim race. */
|
|
|
|
if (rv->object != object ||
|
|
|
|
/* Handle vm_page_rename(m, new_object, ...). */
|
|
|
|
popmap_is_set(rv->popmap, index)) {
|
|
|
|
m = NULL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (vm_domain_allocate(vmd, req, 1) == 0)
|
|
|
|
m = NULL;
|
|
|
|
else
|
|
|
|
vm_reserv_populate(rv, index);
|
|
|
|
out:
|
|
|
|
vm_reserv_unlock(rv);
|
|
|
|
return (m);
|
|
|
|
}
|
2011-12-05 18:29:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Could a reservation fit between the first index to the left that
|
|
|
|
* can be used and the first index to the right that cannot be used?
|
2018-02-06 22:10:07 +00:00
|
|
|
*
|
|
|
|
* We must synchronize with the reserv object lock to protect the
|
|
|
|
* pindex/object of the resulting reservations against rename while
|
|
|
|
* we are inspecting.
|
2011-12-05 18:29:25 +00:00
|
|
|
*/
|
|
|
|
first = pindex - VM_RESERV_INDEX(object, pindex);
|
2018-02-06 22:10:07 +00:00
|
|
|
vm_reserv_object_lock(object);
|
2011-12-05 18:29:25 +00:00
|
|
|
if (mpred != NULL) {
|
|
|
|
if ((rv = vm_reserv_from_page(mpred))->object != object)
|
|
|
|
leftcap = mpred->pindex + 1;
|
|
|
|
else
|
|
|
|
leftcap = rv->pindex + VM_LEVEL_0_NPAGES;
|
2018-02-06 22:10:07 +00:00
|
|
|
if (leftcap > first) {
|
|
|
|
vm_reserv_object_unlock(object);
|
2011-12-05 18:29:25 +00:00
|
|
|
return (NULL);
|
2018-02-06 22:10:07 +00:00
|
|
|
}
|
2011-12-05 18:29:25 +00:00
|
|
|
}
|
|
|
|
if (msucc != NULL) {
|
|
|
|
if ((rv = vm_reserv_from_page(msucc))->object != object)
|
|
|
|
rightcap = msucc->pindex;
|
|
|
|
else
|
|
|
|
rightcap = rv->pindex;
|
2018-02-06 22:10:07 +00:00
|
|
|
if (first + VM_LEVEL_0_NPAGES > rightcap) {
|
|
|
|
vm_reserv_object_unlock(object);
|
2011-12-05 18:29:25 +00:00
|
|
|
return (NULL);
|
2018-02-06 22:10:07 +00:00
|
|
|
}
|
2011-12-05 18:29:25 +00:00
|
|
|
}
|
2018-02-06 22:10:07 +00:00
|
|
|
vm_reserv_object_unlock(object);
|
2011-12-05 18:29:25 +00:00
|
|
|
|
|
|
|
/*
|
2019-11-19 23:19:43 +00:00
|
|
|
* Would the last new reservation extend past the end of the object?
|
|
|
|
*
|
|
|
|
* If the object is unlikely to grow don't allocate a reservation for
|
|
|
|
* the tail.
|
2011-12-05 18:29:25 +00:00
|
|
|
*/
|
2019-11-19 23:19:43 +00:00
|
|
|
if ((object->flags & OBJ_ANON) == 0 &&
|
|
|
|
first + VM_LEVEL_0_NPAGES > object->size)
|
|
|
|
return (NULL);
|
2011-12-05 18:29:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate and populate the new reservation.
|
|
|
|
*/
|
2018-03-22 19:21:11 +00:00
|
|
|
m = NULL;
|
|
|
|
vmd = VM_DOMAIN(domain);
|
|
|
|
if (vm_domain_allocate(vmd, req, 1)) {
|
|
|
|
vm_domain_free_lock(vmd);
|
|
|
|
m = vm_phys_alloc_pages(domain, VM_FREEPOOL_DEFAULT,
|
|
|
|
VM_LEVEL_0_ORDER);
|
|
|
|
vm_domain_free_unlock(vmd);
|
|
|
|
if (m == NULL) {
|
|
|
|
vm_domain_freecnt_inc(vmd, 1);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
} else
|
2011-12-05 18:29:25 +00:00
|
|
|
return (NULL);
|
|
|
|
rv = vm_reserv_from_page(m);
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_lock(rv);
|
2011-12-05 18:29:25 +00:00
|
|
|
KASSERT(rv->pages == m,
|
|
|
|
("vm_reserv_alloc_page: reserv %p's pages is corrupted", rv));
|
2018-02-06 22:10:07 +00:00
|
|
|
vm_reserv_insert(rv, object, first);
|
2013-12-28 04:28:35 +00:00
|
|
|
index = VM_RESERV_INDEX(object, pindex);
|
|
|
|
vm_reserv_populate(rv, index);
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_unlock(rv);
|
|
|
|
|
2013-12-28 04:28:35 +00:00
|
|
|
return (&rv->pages[index]);
|
2007-12-29 19:53:04 +00:00
|
|
|
}
|
|
|
|
|
2013-12-28 04:28:35 +00:00
|
|
|
/*
|
2018-02-14 00:34:02 +00:00
|
|
|
* Breaks the given reservation. All free pages in the reservation
|
|
|
|
* are returned to the physical memory allocator. The reservation's
|
|
|
|
* population count and map are reset to their initial state.
|
2013-12-28 04:28:35 +00:00
|
|
|
*
|
2016-12-12 17:47:09 +00:00
|
|
|
* The given reservation must not be in the partially populated reservation
|
2019-11-18 18:25:51 +00:00
|
|
|
* queue.
|
2013-12-28 04:28:35 +00:00
|
|
|
*/
|
|
|
|
static void
|
2018-02-14 00:34:02 +00:00
|
|
|
vm_reserv_break(vm_reserv_t rv)
|
2013-12-28 04:28:35 +00:00
|
|
|
{
|
2019-05-28 00:51:23 +00:00
|
|
|
u_long changes;
|
|
|
|
int bitpos, hi, i, lo;
|
2013-12-28 04:28:35 +00:00
|
|
|
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_assert_locked(rv);
|
|
|
|
CTR5(KTR_VM, "%s: rv %p object %p popcnt %d inpartpop %d",
|
|
|
|
__FUNCTION__, rv, rv->object, rv->popcnt, rv->inpartpopq);
|
2018-02-06 22:10:07 +00:00
|
|
|
vm_reserv_remove(rv);
|
2018-02-13 15:36:28 +00:00
|
|
|
rv->pages->psind = 0;
|
2019-05-28 00:51:23 +00:00
|
|
|
hi = lo = -1;
|
|
|
|
for (i = 0; i <= NPOPMAP; i++) {
|
|
|
|
/*
|
|
|
|
* "changes" is a bitmask that marks where a new sequence of
|
|
|
|
* 0s or 1s begins in popmap[i], with last bit in popmap[i-1]
|
|
|
|
* considered to be 1 if and only if lo == hi. The bits of
|
|
|
|
* popmap[-1] and popmap[NPOPMAP] are considered all 1s.
|
|
|
|
*/
|
|
|
|
if (i == NPOPMAP)
|
|
|
|
changes = lo != hi;
|
|
|
|
else {
|
|
|
|
changes = rv->popmap[i];
|
|
|
|
changes ^= (changes << 1) | (lo == hi);
|
2013-12-28 04:28:35 +00:00
|
|
|
rv->popmap[i] = 0;
|
|
|
|
}
|
2019-05-28 00:51:23 +00:00
|
|
|
while (changes != 0) {
|
|
|
|
/*
|
|
|
|
* If the next change marked begins a run of 0s, set
|
|
|
|
* lo to mark that position. Otherwise set hi and
|
|
|
|
* free pages from lo up to hi.
|
|
|
|
*/
|
|
|
|
bitpos = ffsl(changes) - 1;
|
|
|
|
changes ^= 1UL << bitpos;
|
|
|
|
if (lo == hi)
|
|
|
|
lo = NBPOPMAP * i + bitpos;
|
|
|
|
else {
|
|
|
|
hi = NBPOPMAP * i + bitpos;
|
|
|
|
vm_domain_free_lock(VM_DOMAIN(rv->domain));
|
2019-05-31 21:02:42 +00:00
|
|
|
vm_phys_enqueue_contig(&rv->pages[lo], hi - lo);
|
2019-05-28 00:51:23 +00:00
|
|
|
vm_domain_free_unlock(VM_DOMAIN(rv->domain));
|
|
|
|
lo = hi;
|
|
|
|
}
|
2013-12-28 04:28:35 +00:00
|
|
|
}
|
2019-05-28 00:51:23 +00:00
|
|
|
}
|
|
|
|
rv->popcnt = 0;
|
2018-03-22 19:21:11 +00:00
|
|
|
counter_u64_add(vm_reserv_broken, 1);
|
2013-12-28 04:28:35 +00:00
|
|
|
}
|
|
|
|
|
2007-12-29 19:53:04 +00:00
|
|
|
/*
|
|
|
|
* Breaks all reservations belonging to the given object.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
vm_reserv_break_all(vm_object_t object)
|
|
|
|
{
|
|
|
|
vm_reserv_t rv;
|
|
|
|
|
2018-02-06 22:10:07 +00:00
|
|
|
/*
|
|
|
|
* This access of object->rvq is unsynchronized so that the
|
|
|
|
* object rvq lock can nest after the domain_free lock. We
|
|
|
|
* must check for races in the results. However, the object
|
|
|
|
* lock prevents new additions, so we are guaranteed that when
|
|
|
|
* it returns NULL the object is properly empty.
|
|
|
|
*/
|
2007-12-29 19:53:04 +00:00
|
|
|
while ((rv = LIST_FIRST(&object->rvq)) != NULL) {
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_lock(rv);
|
2018-02-06 22:10:07 +00:00
|
|
|
/* Reclaim race. */
|
2018-03-22 19:21:11 +00:00
|
|
|
if (rv->object != object) {
|
|
|
|
vm_reserv_unlock(rv);
|
2018-02-06 22:10:07 +00:00
|
|
|
continue;
|
2018-03-22 19:21:11 +00:00
|
|
|
}
|
|
|
|
vm_reserv_domain_lock(rv->domain);
|
2007-12-29 19:53:04 +00:00
|
|
|
if (rv->inpartpopq) {
|
2019-11-18 18:25:51 +00:00
|
|
|
TAILQ_REMOVE(&vm_rvd[rv->domain].partpop, rv, partpopq);
|
2007-12-29 19:53:04 +00:00
|
|
|
rv->inpartpopq = FALSE;
|
|
|
|
}
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_domain_unlock(rv->domain);
|
2018-02-14 00:34:02 +00:00
|
|
|
vm_reserv_break(rv);
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_unlock(rv);
|
2007-12-29 19:53:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Frees the given page if it belongs to a reservation. Returns TRUE if the
|
|
|
|
* page is freed and FALSE otherwise.
|
|
|
|
*/
|
|
|
|
boolean_t
|
|
|
|
vm_reserv_free_page(vm_page_t m)
|
|
|
|
{
|
|
|
|
vm_reserv_t rv;
|
2018-03-22 19:21:11 +00:00
|
|
|
boolean_t ret;
|
2007-12-29 19:53:04 +00:00
|
|
|
|
|
|
|
rv = vm_reserv_from_page(m);
|
2012-04-08 17:00:46 +00:00
|
|
|
if (rv->object == NULL)
|
|
|
|
return (FALSE);
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_lock(rv);
|
|
|
|
/* Re-validate after lock. */
|
|
|
|
if (rv->object != NULL) {
|
|
|
|
vm_reserv_depopulate(rv, m - rv->pages);
|
|
|
|
ret = TRUE;
|
|
|
|
} else
|
|
|
|
ret = FALSE;
|
|
|
|
vm_reserv_unlock(rv);
|
|
|
|
|
|
|
|
return (ret);
|
2007-12-29 19:53:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initializes the reservation management system. Specifically, initializes
|
|
|
|
* the reservation array.
|
|
|
|
*
|
|
|
|
* Requires that vm_page_array and first_page are initialized!
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
vm_reserv_init(void)
|
|
|
|
{
|
|
|
|
vm_paddr_t paddr;
|
2014-11-22 17:46:30 +00:00
|
|
|
struct vm_phys_seg *seg;
|
2018-03-22 19:21:11 +00:00
|
|
|
struct vm_reserv *rv;
|
2019-11-22 16:28:52 +00:00
|
|
|
struct vm_reserv_domain *rvd;
|
|
|
|
int i, j, segind;
|
2007-12-29 19:53:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the reservation array. Specifically, initialize the
|
|
|
|
* "pages" field for every element that has an underlying superpage.
|
|
|
|
*/
|
2014-11-22 17:46:30 +00:00
|
|
|
for (segind = 0; segind < vm_phys_nsegs; segind++) {
|
|
|
|
seg = &vm_phys_segs[segind];
|
|
|
|
paddr = roundup2(seg->start, VM_LEVEL_0_SIZE);
|
2019-08-16 19:27:05 +00:00
|
|
|
while (paddr + VM_LEVEL_0_SIZE > paddr && paddr +
|
|
|
|
VM_LEVEL_0_SIZE <= seg->end) {
|
2018-03-22 19:21:11 +00:00
|
|
|
rv = &vm_reserv_array[paddr >> VM_LEVEL_0_SHIFT];
|
|
|
|
rv->pages = PHYS_TO_VM_PAGE(paddr);
|
|
|
|
rv->domain = seg->domain;
|
|
|
|
mtx_init(&rv->lock, "vm reserv", NULL, MTX_DEF);
|
2007-12-29 19:53:04 +00:00
|
|
|
paddr += VM_LEVEL_0_SIZE;
|
|
|
|
}
|
|
|
|
}
|
2018-03-22 19:21:11 +00:00
|
|
|
for (i = 0; i < MAXMEMDOM; i++) {
|
2019-11-22 16:28:52 +00:00
|
|
|
rvd = &vm_rvd[i];
|
|
|
|
mtx_init(&rvd->lock, "vm reserv domain", NULL, MTX_DEF);
|
|
|
|
TAILQ_INIT(&rvd->partpop);
|
|
|
|
mtx_init(&rvd->marker.lock, "vm reserv marker", NULL, MTX_DEF);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fully populated reservations should never be present in the
|
|
|
|
* partially populated reservation queues.
|
|
|
|
*/
|
|
|
|
rvd->marker.popcnt = VM_LEVEL_0_NPAGES;
|
|
|
|
for (j = 0; j < NBPOPMAP; j++)
|
|
|
|
popmap_set(rvd->marker.popmap, j);
|
2018-03-22 19:21:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < VM_RESERV_OBJ_LOCK_COUNT; i++)
|
|
|
|
mtx_init(&vm_reserv_object_mtx[i], "resv obj lock", NULL,
|
|
|
|
MTX_DEF);
|
2007-12-29 19:53:04 +00:00
|
|
|
}
|
|
|
|
|
2015-12-19 18:42:50 +00:00
|
|
|
/*
|
|
|
|
* Returns true if the given page belongs to a reservation and that page is
|
|
|
|
* free. Otherwise, returns false.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
vm_reserv_is_page_free(vm_page_t m)
|
|
|
|
{
|
|
|
|
vm_reserv_t rv;
|
|
|
|
|
|
|
|
rv = vm_reserv_from_page(m);
|
|
|
|
if (rv->object == NULL)
|
|
|
|
return (false);
|
|
|
|
return (popmap_is_clear(rv->popmap, m - rv->pages));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the given page belongs to a reservation, returns the level of that
|
|
|
|
* reservation. Otherwise, returns -1.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
vm_reserv_level(vm_page_t m)
|
|
|
|
{
|
|
|
|
vm_reserv_t rv;
|
|
|
|
|
|
|
|
rv = vm_reserv_from_page(m);
|
|
|
|
return (rv->object != NULL ? 0 : -1);
|
|
|
|
}
|
|
|
|
|
2007-12-29 19:53:04 +00:00
|
|
|
/*
|
2016-12-12 17:47:09 +00:00
|
|
|
* Returns a reservation level if the given page belongs to a fully populated
|
2007-12-29 19:53:04 +00:00
|
|
|
* reservation and -1 otherwise.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
vm_reserv_level_iffullpop(vm_page_t m)
|
|
|
|
{
|
|
|
|
vm_reserv_t rv;
|
|
|
|
|
|
|
|
rv = vm_reserv_from_page(m);
|
|
|
|
return (rv->popcnt == VM_LEVEL_0_NPAGES ? 0 : -1);
|
|
|
|
}
|
|
|
|
|
2008-04-06 18:09:28 +00:00
|
|
|
/*
|
2019-11-22 16:28:52 +00:00
|
|
|
* Remove a partially populated reservation from the queue.
|
2008-04-06 18:09:28 +00:00
|
|
|
*/
|
|
|
|
static void
|
2019-11-22 16:28:52 +00:00
|
|
|
vm_reserv_dequeue(vm_reserv_t rv)
|
2008-04-06 18:09:28 +00:00
|
|
|
{
|
|
|
|
|
2019-11-22 16:28:52 +00:00
|
|
|
vm_reserv_domain_assert_locked(rv->domain);
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_assert_locked(rv);
|
|
|
|
CTR5(KTR_VM, "%s: rv %p object %p popcnt %d inpartpop %d",
|
|
|
|
__FUNCTION__, rv, rv->object, rv->popcnt, rv->inpartpopq);
|
2008-04-06 18:09:28 +00:00
|
|
|
KASSERT(rv->inpartpopq,
|
2013-12-28 04:28:35 +00:00
|
|
|
("vm_reserv_reclaim: reserv %p's inpartpopq is FALSE", rv));
|
2019-11-22 16:28:52 +00:00
|
|
|
|
2019-11-18 18:25:51 +00:00
|
|
|
TAILQ_REMOVE(&vm_rvd[rv->domain].partpop, rv, partpopq);
|
2008-04-06 18:09:28 +00:00
|
|
|
rv->inpartpopq = FALSE;
|
2019-11-22 16:28:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Breaks the given partially populated reservation, releasing its free pages
|
|
|
|
* to the physical memory allocator.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
vm_reserv_reclaim(vm_reserv_t rv)
|
|
|
|
{
|
|
|
|
|
|
|
|
vm_reserv_assert_locked(rv);
|
|
|
|
CTR5(KTR_VM, "%s: rv %p object %p popcnt %d inpartpop %d",
|
|
|
|
__FUNCTION__, rv, rv->object, rv->popcnt, rv->inpartpopq);
|
|
|
|
if (rv->inpartpopq) {
|
|
|
|
vm_reserv_domain_lock(rv->domain);
|
|
|
|
vm_reserv_dequeue(rv);
|
|
|
|
vm_reserv_domain_unlock(rv->domain);
|
|
|
|
}
|
2018-02-14 00:34:02 +00:00
|
|
|
vm_reserv_break(rv);
|
2018-03-22 19:21:11 +00:00
|
|
|
counter_u64_add(vm_reserv_reclaimed, 1);
|
2008-04-06 18:09:28 +00:00
|
|
|
}
|
|
|
|
|
2007-12-29 19:53:04 +00:00
|
|
|
/*
|
2019-11-22 16:28:52 +00:00
|
|
|
* Breaks a reservation near the head of the partially populated reservation
|
2016-12-12 17:47:09 +00:00
|
|
|
* queue, releasing its free pages to the physical memory allocator. Returns
|
|
|
|
* TRUE if a reservation is broken and FALSE otherwise.
|
2007-12-29 19:53:04 +00:00
|
|
|
*/
|
2019-11-22 16:28:52 +00:00
|
|
|
bool
|
2017-11-28 23:18:35 +00:00
|
|
|
vm_reserv_reclaim_inactive(int domain)
|
2007-12-29 19:53:04 +00:00
|
|
|
{
|
|
|
|
vm_reserv_t rv;
|
|
|
|
|
2019-11-22 16:28:52 +00:00
|
|
|
vm_reserv_domain_lock(domain);
|
|
|
|
TAILQ_FOREACH(rv, &vm_rvd[domain].partpop, partpopq) {
|
|
|
|
/*
|
|
|
|
* A locked reservation is likely being updated or reclaimed,
|
|
|
|
* so just skip ahead.
|
|
|
|
*/
|
|
|
|
if (rv != &vm_rvd[domain].marker && vm_reserv_trylock(rv)) {
|
|
|
|
vm_reserv_dequeue(rv);
|
|
|
|
break;
|
2018-03-22 19:21:11 +00:00
|
|
|
}
|
2019-11-22 16:28:52 +00:00
|
|
|
}
|
|
|
|
vm_reserv_domain_unlock(domain);
|
|
|
|
if (rv != NULL) {
|
2008-04-06 18:09:28 +00:00
|
|
|
vm_reserv_reclaim(rv);
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_unlock(rv);
|
2019-11-22 16:28:52 +00:00
|
|
|
return (true);
|
2007-12-29 19:53:04 +00:00
|
|
|
}
|
2019-11-22 16:28:52 +00:00
|
|
|
return (false);
|
2007-12-29 19:53:04 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 16:28:34 +00:00
|
|
|
/*
|
|
|
|
* Determine whether this reservation has free pages that satisfy the given
|
|
|
|
* request for contiguous physical memory. Start searching from the lower
|
|
|
|
* bound, defined by low_index.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
vm_reserv_test_contig(vm_reserv_t rv, u_long npages, vm_paddr_t low,
|
|
|
|
vm_paddr_t high, u_long alignment, vm_paddr_t boundary)
|
|
|
|
{
|
|
|
|
vm_paddr_t pa, size;
|
|
|
|
u_long changes;
|
|
|
|
int bitpos, bits_left, i, hi, lo, n;
|
|
|
|
|
|
|
|
vm_reserv_assert_locked(rv);
|
|
|
|
size = npages << PAGE_SHIFT;
|
|
|
|
pa = VM_PAGE_TO_PHYS(&rv->pages[0]);
|
|
|
|
lo = (pa < low) ?
|
|
|
|
((low + PAGE_MASK - pa) >> PAGE_SHIFT) : 0;
|
|
|
|
i = lo / NBPOPMAP;
|
|
|
|
changes = rv->popmap[i] | ((1UL << (lo % NBPOPMAP)) - 1);
|
|
|
|
hi = (pa + VM_LEVEL_0_SIZE > high) ?
|
|
|
|
((high + PAGE_MASK - pa) >> PAGE_SHIFT) : VM_LEVEL_0_NPAGES;
|
|
|
|
n = hi / NBPOPMAP;
|
|
|
|
bits_left = hi % NBPOPMAP;
|
|
|
|
hi = lo = -1;
|
|
|
|
for (;;) {
|
|
|
|
/*
|
|
|
|
* "changes" is a bitmask that marks where a new sequence of
|
|
|
|
* 0s or 1s begins in popmap[i], with last bit in popmap[i-1]
|
|
|
|
* considered to be 1 if and only if lo == hi. The bits of
|
|
|
|
* popmap[-1] and popmap[NPOPMAP] are considered all 1s.
|
|
|
|
*/
|
|
|
|
changes ^= (changes << 1) | (lo == hi);
|
|
|
|
while (changes != 0) {
|
|
|
|
/*
|
|
|
|
* If the next change marked begins a run of 0s, set
|
|
|
|
* lo to mark that position. Otherwise set hi and
|
|
|
|
* look for a satisfactory first page from lo up to hi.
|
|
|
|
*/
|
|
|
|
bitpos = ffsl(changes) - 1;
|
|
|
|
changes ^= 1UL << bitpos;
|
|
|
|
if (lo == hi) {
|
|
|
|
lo = NBPOPMAP * i + bitpos;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
hi = NBPOPMAP * i + bitpos;
|
|
|
|
pa = VM_PAGE_TO_PHYS(&rv->pages[lo]);
|
|
|
|
if ((pa & (alignment - 1)) != 0) {
|
|
|
|
/* Skip to next aligned page. */
|
|
|
|
lo += (((pa - 1) | (alignment - 1)) + 1) >>
|
|
|
|
PAGE_SHIFT;
|
|
|
|
if (lo >= VM_LEVEL_0_NPAGES)
|
|
|
|
return (false);
|
|
|
|
pa = VM_PAGE_TO_PHYS(&rv->pages[lo]);
|
|
|
|
}
|
|
|
|
if (((pa ^ (pa + size - 1)) & ~(boundary - 1)) != 0) {
|
|
|
|
/* Skip to next boundary-matching page. */
|
|
|
|
lo += (((pa - 1) | (boundary - 1)) + 1) >>
|
|
|
|
PAGE_SHIFT;
|
|
|
|
if (lo >= VM_LEVEL_0_NPAGES)
|
|
|
|
return (false);
|
|
|
|
pa = VM_PAGE_TO_PHYS(&rv->pages[lo]);
|
|
|
|
}
|
|
|
|
if (lo * PAGE_SIZE + size <= hi * PAGE_SIZE)
|
|
|
|
return (true);
|
|
|
|
lo = hi;
|
|
|
|
}
|
|
|
|
if (++i < n)
|
|
|
|
changes = rv->popmap[i];
|
|
|
|
else if (i == n)
|
|
|
|
changes = bits_left == 0 ? -1UL :
|
|
|
|
(rv->popmap[n] | (-1UL << bits_left));
|
|
|
|
else
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-06 18:09:28 +00:00
|
|
|
/*
|
2016-12-12 17:47:09 +00:00
|
|
|
* Searches the partially populated reservation queue for the least recently
|
|
|
|
* changed reservation with free pages that satisfy the given request for
|
|
|
|
* contiguous physical memory. If a satisfactory reservation is found, it is
|
2019-06-06 16:28:34 +00:00
|
|
|
* broken. Returns true if a reservation is broken and false otherwise.
|
2008-04-06 18:09:28 +00:00
|
|
|
*/
|
2019-11-22 16:28:52 +00:00
|
|
|
bool
|
2017-11-28 23:18:35 +00:00
|
|
|
vm_reserv_reclaim_contig(int domain, u_long npages, vm_paddr_t low,
|
|
|
|
vm_paddr_t high, u_long alignment, vm_paddr_t boundary)
|
2008-04-06 18:09:28 +00:00
|
|
|
{
|
2019-11-22 16:28:52 +00:00
|
|
|
struct vm_reserv_queue *queue;
|
2013-12-28 04:28:35 +00:00
|
|
|
vm_paddr_t pa, size;
|
2019-11-22 16:28:52 +00:00
|
|
|
vm_reserv_t marker, rv, rvn;
|
2008-04-06 18:09:28 +00:00
|
|
|
|
2011-12-05 18:29:25 +00:00
|
|
|
if (npages > VM_LEVEL_0_NPAGES - 1)
|
2019-06-06 16:28:34 +00:00
|
|
|
return (false);
|
2019-11-22 16:28:52 +00:00
|
|
|
marker = &vm_rvd[domain].marker;
|
|
|
|
queue = &vm_rvd[domain].partpop;
|
2011-12-05 18:29:25 +00:00
|
|
|
size = npages << PAGE_SHIFT;
|
2019-11-22 16:28:52 +00:00
|
|
|
|
|
|
|
vm_reserv_domain_scan_lock(domain);
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_domain_lock(domain);
|
2019-11-22 16:28:52 +00:00
|
|
|
TAILQ_FOREACH_SAFE(rv, queue, partpopq, rvn) {
|
2019-06-06 16:28:34 +00:00
|
|
|
pa = VM_PAGE_TO_PHYS(&rv->pages[0]);
|
|
|
|
if (pa + VM_LEVEL_0_SIZE - size < low) {
|
2013-12-28 04:28:35 +00:00
|
|
|
/* This entire reservation is too low; go to next. */
|
2008-04-06 18:09:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-12-28 04:28:35 +00:00
|
|
|
if (pa + size > high) {
|
|
|
|
/* This entire reservation is too high; go to next. */
|
|
|
|
continue;
|
|
|
|
}
|
2019-11-22 16:28:52 +00:00
|
|
|
|
2018-03-22 19:21:11 +00:00
|
|
|
if (vm_reserv_trylock(rv) == 0) {
|
2019-11-22 16:28:52 +00:00
|
|
|
TAILQ_INSERT_AFTER(queue, rv, marker, partpopq);
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_domain_unlock(domain);
|
|
|
|
vm_reserv_lock(rv);
|
2019-11-22 16:28:52 +00:00
|
|
|
if (!rv->inpartpopq ||
|
|
|
|
TAILQ_NEXT(rv, partpopq) != marker) {
|
|
|
|
vm_reserv_unlock(rv);
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_domain_lock(domain);
|
2019-11-22 16:28:52 +00:00
|
|
|
rvn = TAILQ_NEXT(marker, partpopq);
|
|
|
|
TAILQ_REMOVE(queue, marker, partpopq);
|
2018-03-22 19:21:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-11-22 16:28:52 +00:00
|
|
|
vm_reserv_domain_lock(domain);
|
|
|
|
TAILQ_REMOVE(queue, marker, partpopq);
|
|
|
|
}
|
|
|
|
vm_reserv_domain_unlock(domain);
|
2019-06-06 16:28:34 +00:00
|
|
|
if (vm_reserv_test_contig(rv, npages, low, high,
|
|
|
|
alignment, boundary)) {
|
2019-11-22 16:28:52 +00:00
|
|
|
vm_reserv_domain_scan_unlock(domain);
|
2019-06-06 16:28:34 +00:00
|
|
|
vm_reserv_reclaim(rv);
|
|
|
|
vm_reserv_unlock(rv);
|
|
|
|
return (true);
|
|
|
|
}
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_unlock(rv);
|
|
|
|
vm_reserv_domain_lock(domain);
|
2008-04-06 18:09:28 +00:00
|
|
|
}
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_domain_unlock(domain);
|
2019-11-22 16:28:52 +00:00
|
|
|
vm_reserv_domain_scan_unlock(domain);
|
2019-06-06 16:28:34 +00:00
|
|
|
return (false);
|
2008-04-06 18:09:28 +00:00
|
|
|
}
|
|
|
|
|
2007-12-29 19:53:04 +00:00
|
|
|
/*
|
|
|
|
* Transfers the reservation underlying the given page to a new object.
|
|
|
|
*
|
|
|
|
* The object must be locked.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
vm_reserv_rename(vm_page_t m, vm_object_t new_object, vm_object_t old_object,
|
|
|
|
vm_pindex_t old_object_offset)
|
|
|
|
{
|
|
|
|
vm_reserv_t rv;
|
|
|
|
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_ASSERT_WLOCKED(new_object);
|
2007-12-29 19:53:04 +00:00
|
|
|
rv = vm_reserv_from_page(m);
|
|
|
|
if (rv->object == old_object) {
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_lock(rv);
|
|
|
|
CTR6(KTR_VM,
|
|
|
|
"%s: rv %p object %p new %p popcnt %d inpartpop %d",
|
|
|
|
__FUNCTION__, rv, rv->object, new_object, rv->popcnt,
|
|
|
|
rv->inpartpopq);
|
2007-12-29 19:53:04 +00:00
|
|
|
if (rv->object == old_object) {
|
2018-02-06 22:10:07 +00:00
|
|
|
vm_reserv_object_lock(old_object);
|
|
|
|
rv->object = NULL;
|
2007-12-29 19:53:04 +00:00
|
|
|
LIST_REMOVE(rv, objq);
|
2018-02-06 22:10:07 +00:00
|
|
|
vm_reserv_object_unlock(old_object);
|
|
|
|
vm_reserv_object_lock(new_object);
|
2007-12-29 19:53:04 +00:00
|
|
|
rv->object = new_object;
|
|
|
|
rv->pindex -= old_object_offset;
|
2018-02-06 22:10:07 +00:00
|
|
|
LIST_INSERT_HEAD(&new_object->rvq, rv, objq);
|
|
|
|
vm_reserv_object_unlock(new_object);
|
2007-12-29 19:53:04 +00:00
|
|
|
}
|
2018-03-22 19:21:11 +00:00
|
|
|
vm_reserv_unlock(rv);
|
2007-12-29 19:53:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-19 18:42:50 +00:00
|
|
|
/*
|
|
|
|
* Returns the size (in bytes) of a reservation of the specified level.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
vm_reserv_size(int level)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (level) {
|
|
|
|
case 0:
|
|
|
|
return (VM_LEVEL_0_SIZE);
|
|
|
|
case -1:
|
|
|
|
return (PAGE_SIZE);
|
|
|
|
default:
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-29 19:53:04 +00:00
|
|
|
/*
|
|
|
|
* Allocates the virtual and physical memory required by the reservation
|
|
|
|
* management system's data structures, in particular, the reservation array.
|
|
|
|
*/
|
|
|
|
vm_paddr_t
|
2019-08-18 23:07:56 +00:00
|
|
|
vm_reserv_startup(vm_offset_t *vaddr, vm_paddr_t end)
|
2007-12-29 19:53:04 +00:00
|
|
|
{
|
2019-08-18 23:07:56 +00:00
|
|
|
vm_paddr_t new_end, high_water;
|
2007-12-29 19:53:04 +00:00
|
|
|
size_t size;
|
2019-08-18 23:07:56 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
high_water = phys_avail[1];
|
|
|
|
for (i = 0; i < vm_phys_nsegs; i++) {
|
|
|
|
if (vm_phys_segs[i].end > high_water)
|
|
|
|
high_water = vm_phys_segs[i].end;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip the first chunk. It is already accounted for. */
|
|
|
|
for (i = 2; phys_avail[i + 1] != 0; i += 2) {
|
|
|
|
if (phys_avail[i + 1] > high_water)
|
|
|
|
high_water = phys_avail[i + 1];
|
|
|
|
}
|
2007-12-29 19:53:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate the size (in bytes) of the reservation array. Round up
|
|
|
|
* from "high_water" because every small page is mapped to an element
|
|
|
|
* in the reservation array based on its physical address. Thus, the
|
|
|
|
* number of elements in the reservation array can be greater than the
|
|
|
|
* number of superpages.
|
|
|
|
*/
|
|
|
|
size = howmany(high_water, VM_LEVEL_0_SIZE) * sizeof(struct vm_reserv);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate and map the physical memory for the reservation array. The
|
|
|
|
* next available virtual address is returned by reference.
|
|
|
|
*/
|
|
|
|
new_end = end - round_page(size);
|
|
|
|
vm_reserv_array = (void *)(uintptr_t)pmap_map(vaddr, new_end, end,
|
|
|
|
VM_PROT_READ | VM_PROT_WRITE);
|
|
|
|
bzero(vm_reserv_array, size);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the next available physical address.
|
|
|
|
*/
|
|
|
|
return (new_end);
|
|
|
|
}
|
|
|
|
|
2017-07-23 16:28:13 +00:00
|
|
|
/*
|
|
|
|
* Returns the superpage containing the given page.
|
|
|
|
*/
|
|
|
|
vm_page_t
|
|
|
|
vm_reserv_to_superpage(vm_page_t m)
|
|
|
|
{
|
|
|
|
vm_reserv_t rv;
|
|
|
|
|
|
|
|
VM_OBJECT_ASSERT_LOCKED(m->object);
|
|
|
|
rv = vm_reserv_from_page(m);
|
2018-03-22 19:21:11 +00:00
|
|
|
if (rv->object == m->object && rv->popcnt == VM_LEVEL_0_NPAGES)
|
|
|
|
m = rv->pages;
|
|
|
|
else
|
|
|
|
m = NULL;
|
|
|
|
|
|
|
|
return (m);
|
2017-07-23 16:28:13 +00:00
|
|
|
}
|
|
|
|
|
2007-12-29 19:53:04 +00:00
|
|
|
#endif /* VM_NRESERVLEVEL > 0 */
|