Deleted Added
full compact
vm_object.c (323537) vm_object.c (323638)
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>
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 $");
66__FBSDID("$FreeBSD: stable/11/sys/vm/vm_object.c 323638 2017-09-16 13:49:26Z 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;
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 struct mtx *mtx;
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);
1914
1915 VM_OBJECT_ASSERT_WLOCKED(object);
1916 KASSERT((object->flags & OBJ_UNMANAGED) == 0 ||
1917 (options & (OBJPR_CLEANONLY | OBJPR_NOTMAPPED)) == OBJPR_NOTMAPPED,
1918 ("vm_object_page_remove: illegal options for object %p", object));
1919 if (object->resident_page_count == 0)
1920 return;
1921 vm_object_pip_add(object, 1);
1922again:
1923 p = vm_page_find_least(object, start);
1924 mtx = NULL;
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 */
1925
1926 /*
1927 * Here, the variable "p" is either (1) the page with the least pindex
1928 * greater than or equal to the parameter "start" or (2) NULL.
1929 */
1930 for (; p != NULL && (p->pindex < end || end == 0); p = next) {
1931 next = TAILQ_NEXT(p, listq);
1932
1933 /*
1934 * If the page is wired for any reason besides the existence
1935 * of managed, wired mappings, then it cannot be freed. For
1936 * example, fictitious pages, which represent device memory,
1937 * are inherently wired and cannot be freed. They can,
1938 * however, be invalidated if the option OBJPR_CLEANONLY is
1939 * not specified.
1940 */
1939 vm_page_lock(p);
1941 vm_page_change_lock(p, &mtx);
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 }
1942 if (vm_page_xbusied(p)) {
1943 VM_OBJECT_WUNLOCK(object);
1944 vm_page_busy_sleep(p, "vmopax", true);
1945 VM_OBJECT_WLOCK(object);
1946 goto again;
1947 }
1948 if (p->wire_count != 0) {
1949 if ((options & OBJPR_NOTMAPPED) == 0)
1950 pmap_remove_all(p);
1951 if ((options & OBJPR_CLEANONLY) == 0) {
1952 p->valid = 0;
1953 vm_page_undirty(p);
1954 }
1953 goto next;
1955 continue;
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)
1956 }
1957 if (vm_page_busied(p)) {
1958 VM_OBJECT_WUNLOCK(object);
1959 vm_page_busy_sleep(p, "vmopar", false);
1960 VM_OBJECT_WLOCK(object);
1961 goto again;
1962 }
1963 KASSERT((p->flags & PG_FICTITIOUS) == 0,
1964 ("vm_object_page_remove: page %p is fictitious", p));
1965 if ((options & OBJPR_CLEANONLY) != 0 && p->valid != 0) {
1966 if ((options & OBJPR_NOTMAPPED) == 0)
1967 pmap_remove_write(p);
1968 if (p->dirty)
1967 goto next;
1969 continue;
1968 }
1969 if ((options & OBJPR_NOTMAPPED) == 0)
1970 pmap_remove_all(p);
1971 vm_page_free(p);
1970 }
1971 if ((options & OBJPR_NOTMAPPED) == 0)
1972 pmap_remove_all(p);
1973 vm_page_free(p);
1972next:
1973 vm_page_unlock(p);
1974 }
1974 }
1975 if (mtx != NULL)
1976 mtx_unlock(mtx);
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{
1977 vm_object_pip_wakeup(object);
1978}
1979
1980/*
1981 * vm_object_page_noreuse:
1982 *
1983 * For the given object, attempt to move the specified pages to
1984 * the head of the inactive queue. This bypasses regular LRU

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

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

--- 633 unchanged lines hidden ---