Deleted Added
sdiff udiff text old ( 323537 ) new ( 323638 )
full compact
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * The Mach Operating System project at Carnegie-Mellon University.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 49 unchanged lines hidden (view full) ---

58 * rights to redistribute these changes.
59 */
60
61/*
62 * Virtual memory object module.
63 */
64
65#include <sys/cdefs.h>
66__FBSDID("$FreeBSD: stable/11/sys/vm/vm_object.c 323537 2017-09-13 11:19:04Z kib $");
67
68#include "opt_vm.h"
69
70#include <sys/param.h>
71#include <sys/systm.h>
72#include <sys/lock.h>
73#include <sys/mman.h>
74#include <sys/mount.h>

--- 1830 unchanged lines hidden (view full) ---

1905 *
1906 * The object must be locked.
1907 */
1908void
1909vm_object_page_remove(vm_object_t object, vm_pindex_t start, vm_pindex_t end,
1910 int options)
1911{
1912 vm_page_t p, next;
1913
1914 VM_OBJECT_ASSERT_WLOCKED(object);
1915 KASSERT((object->flags & OBJ_UNMANAGED) == 0 ||
1916 (options & (OBJPR_CLEANONLY | OBJPR_NOTMAPPED)) == OBJPR_NOTMAPPED,
1917 ("vm_object_page_remove: illegal options for object %p", object));
1918 if (object->resident_page_count == 0)
1919 return;
1920 vm_object_pip_add(object, 1);
1921again:
1922 p = vm_page_find_least(object, start);
1923
1924 /*
1925 * Here, the variable "p" is either (1) the page with the least pindex
1926 * greater than or equal to the parameter "start" or (2) NULL.
1927 */
1928 for (; p != NULL && (p->pindex < end || end == 0); p = next) {
1929 next = TAILQ_NEXT(p, listq);
1930
1931 /*
1932 * If the page is wired for any reason besides the existence
1933 * of managed, wired mappings, then it cannot be freed. For
1934 * example, fictitious pages, which represent device memory,
1935 * are inherently wired and cannot be freed. They can,
1936 * however, be invalidated if the option OBJPR_CLEANONLY is
1937 * not specified.
1938 */
1939 vm_page_lock(p);
1940 if (vm_page_xbusied(p)) {
1941 VM_OBJECT_WUNLOCK(object);
1942 vm_page_busy_sleep(p, "vmopax", true);
1943 VM_OBJECT_WLOCK(object);
1944 goto again;
1945 }
1946 if (p->wire_count != 0) {
1947 if ((options & OBJPR_NOTMAPPED) == 0)
1948 pmap_remove_all(p);
1949 if ((options & OBJPR_CLEANONLY) == 0) {
1950 p->valid = 0;
1951 vm_page_undirty(p);
1952 }
1953 goto next;
1954 }
1955 if (vm_page_busied(p)) {
1956 VM_OBJECT_WUNLOCK(object);
1957 vm_page_busy_sleep(p, "vmopar", false);
1958 VM_OBJECT_WLOCK(object);
1959 goto again;
1960 }
1961 KASSERT((p->flags & PG_FICTITIOUS) == 0,
1962 ("vm_object_page_remove: page %p is fictitious", p));
1963 if ((options & OBJPR_CLEANONLY) != 0 && p->valid != 0) {
1964 if ((options & OBJPR_NOTMAPPED) == 0)
1965 pmap_remove_write(p);
1966 if (p->dirty)
1967 goto next;
1968 }
1969 if ((options & OBJPR_NOTMAPPED) == 0)
1970 pmap_remove_all(p);
1971 vm_page_free(p);
1972next:
1973 vm_page_unlock(p);
1974 }
1975 vm_object_pip_wakeup(object);
1976}
1977
1978/*
1979 * vm_object_page_noreuse:
1980 *
1981 * For the given object, attempt to move the specified pages to
1982 * the head of the inactive queue. This bypasses regular LRU

--- 6 unchanged lines hidden (view full) ---

1989 * This operation should only be performed on objects that
1990 * contain non-fictitious, managed pages.
1991 *
1992 * The object must be locked.
1993 */
1994void
1995vm_object_page_noreuse(vm_object_t object, vm_pindex_t start, vm_pindex_t end)
1996{
1997 struct mtx *mtx, *new_mtx;
1998 vm_page_t p, next;
1999
2000 VM_OBJECT_ASSERT_LOCKED(object);
2001 KASSERT((object->flags & (OBJ_FICTITIOUS | OBJ_UNMANAGED)) == 0,
2002 ("vm_object_page_noreuse: illegal object %p", object));
2003 if (object->resident_page_count == 0)
2004 return;
2005 p = vm_page_find_least(object, start);
2006
2007 /*
2008 * Here, the variable "p" is either (1) the page with the least pindex
2009 * greater than or equal to the parameter "start" or (2) NULL.
2010 */
2011 mtx = NULL;
2012 for (; p != NULL && (p->pindex < end || end == 0); p = next) {
2013 next = TAILQ_NEXT(p, listq);
2014
2015 /*
2016 * Avoid releasing and reacquiring the same page lock.
2017 */
2018 new_mtx = vm_page_lockptr(p);
2019 if (mtx != new_mtx) {
2020 if (mtx != NULL)
2021 mtx_unlock(mtx);
2022 mtx = new_mtx;
2023 mtx_lock(mtx);
2024 }
2025 vm_page_deactivate_noreuse(p);
2026 }
2027 if (mtx != NULL)
2028 mtx_unlock(mtx);
2029}
2030
2031/*
2032 * Populate the specified range of the object with valid pages. Returns

--- 633 unchanged lines hidden ---