Deleted Added
full compact
vm_object.c (254138) vm_object.c (254141)
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: head/sys/vm/vm_object.c 254138 2013-08-09 11:11:11Z attilio $");
66__FBSDID("$FreeBSD: head/sys/vm/vm_object.c 254141 2013-08-09 11:28:55Z attilio $");
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>

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

196 vm_object_t object;
197
198 object = (vm_object_t)mem;
199 bzero(&object->lock, sizeof(object->lock));
200 rw_init_flags(&object->lock, "vm object", RW_DUPOK);
201
202 /* These are true for any object that has been freed */
203 object->rtree.rt_root = 0;
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>

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

196 vm_object_t object;
197
198 object = (vm_object_t)mem;
199 bzero(&object->lock, sizeof(object->lock));
200 rw_init_flags(&object->lock, "vm object", RW_DUPOK);
201
202 /* These are true for any object that has been freed */
203 object->rtree.rt_root = 0;
204 object->rtree.rt_flags = 0;
204 object->paging_in_progress = 0;
205 object->resident_page_count = 0;
206 object->shadow_count = 0;
207 object->cache.rt_root = 0;
205 object->paging_in_progress = 0;
206 object->resident_page_count = 0;
207 object->shadow_count = 0;
208 object->cache.rt_root = 0;
209 object->cache.rt_flags = 0;
208 return (0);
209}
210
211static void
212_vm_object_allocate(objtype_t type, vm_pindex_t size, vm_object_t object)
213{
214
215 TAILQ_INIT(&object->memq);

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

1346 VM_OBJECT_WUNLOCK(new_object);
1347 vm_page_lock(m);
1348 VM_OBJECT_WUNLOCK(orig_object);
1349 vm_page_busy_sleep(m, "spltwt");
1350 VM_OBJECT_WLOCK(orig_object);
1351 VM_OBJECT_WLOCK(new_object);
1352 goto retry;
1353 }
210 return (0);
211}
212
213static void
214_vm_object_allocate(objtype_t type, vm_pindex_t size, vm_object_t object)
215{
216
217 TAILQ_INIT(&object->memq);

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

1348 VM_OBJECT_WUNLOCK(new_object);
1349 vm_page_lock(m);
1350 VM_OBJECT_WUNLOCK(orig_object);
1351 vm_page_busy_sleep(m, "spltwt");
1352 VM_OBJECT_WLOCK(orig_object);
1353 VM_OBJECT_WLOCK(new_object);
1354 goto retry;
1355 }
1356
1357 /* vm_page_rename() will handle dirty and cache. */
1358 if (vm_page_rename(m, new_object, idx)) {
1359 VM_OBJECT_WUNLOCK(new_object);
1360 VM_OBJECT_WUNLOCK(orig_object);
1361 VM_WAIT;
1362 VM_OBJECT_WLOCK(orig_object);
1363 VM_OBJECT_WLOCK(new_object);
1364 goto retry;
1365 }
1354#if VM_NRESERVLEVEL > 0
1355 /*
1356 * If some of the reservation's allocated pages remain with
1357 * the original object, then transferring the reservation to
1358 * the new object is neither particularly beneficial nor
1359 * particularly harmful as compared to leaving the reservation
1360 * with the original object. If, however, all of the
1361 * reservation's allocated pages are transferred to the new
1362 * object, then transferring the reservation is typically
1363 * beneficial. Determining which of these two cases applies
1364 * would be more costly than unconditionally renaming the
1365 * reservation.
1366 */
1367 vm_reserv_rename(m, new_object, orig_object, offidxstart);
1368#endif
1366#if VM_NRESERVLEVEL > 0
1367 /*
1368 * If some of the reservation's allocated pages remain with
1369 * the original object, then transferring the reservation to
1370 * the new object is neither particularly beneficial nor
1371 * particularly harmful as compared to leaving the reservation
1372 * with the original object. If, however, all of the
1373 * reservation's allocated pages are transferred to the new
1374 * object, then transferring the reservation is typically
1375 * beneficial. Determining which of these two cases applies
1376 * would be more costly than unconditionally renaming the
1377 * reservation.
1378 */
1379 vm_reserv_rename(m, new_object, orig_object, offidxstart);
1380#endif
1369 vm_page_lock(m);
1370 vm_page_rename(m, new_object, idx);
1371 vm_page_unlock(m);
1372 /* page automatically made dirty by rename and cache handled */
1373 if (orig_object->type == OBJT_SWAP)
1374 vm_page_xbusy(m);
1375 }
1376 if (orig_object->type == OBJT_SWAP) {
1377 /*
1378 * swap_pager_copy() can sleep, in which case the orig_object's
1379 * and new_object's locks are released and reacquired.
1380 */

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

1520 }
1521 }
1522
1523 KASSERT(
1524 p->object == backing_object,
1525 ("vm_object_backing_scan: object mismatch")
1526 );
1527
1381 if (orig_object->type == OBJT_SWAP)
1382 vm_page_xbusy(m);
1383 }
1384 if (orig_object->type == OBJT_SWAP) {
1385 /*
1386 * swap_pager_copy() can sleep, in which case the orig_object's
1387 * and new_object's locks are released and reacquired.
1388 */

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

1528 }
1529 }
1530
1531 KASSERT(
1532 p->object == backing_object,
1533 ("vm_object_backing_scan: object mismatch")
1534 );
1535
1528 /*
1529 * Destroy any associated swap
1530 */
1531 if (backing_object->type == OBJT_SWAP) {
1532 swap_pager_freespace(
1533 backing_object,
1534 p->pindex,
1535 1
1536 );
1537 }
1538
1539 if (
1540 p->pindex < backing_offset_index ||
1541 new_pindex >= object->size
1542 ) {
1536 if (
1537 p->pindex < backing_offset_index ||
1538 new_pindex >= object->size
1539 ) {
1540 if (backing_object->type == OBJT_SWAP)
1541 swap_pager_freespace(backing_object,
1542 p->pindex, 1);
1543
1543 /*
1544 * Page is out of the parent object's range, we
1545 * can simply destroy it.
1546 */
1547 vm_page_lock(p);
1548 KASSERT(!pmap_page_is_mapped(p),
1549 ("freeing mapped page %p", p));
1550 if (p->wire_count == 0)

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

1556 continue;
1557 }
1558
1559 pp = vm_page_lookup(object, new_pindex);
1560 if (
1561 (op & OBSC_COLLAPSE_NOWAIT) != 0 &&
1562 (pp != NULL && pp->valid == 0)
1563 ) {
1544 /*
1545 * Page is out of the parent object's range, we
1546 * can simply destroy it.
1547 */
1548 vm_page_lock(p);
1549 KASSERT(!pmap_page_is_mapped(p),
1550 ("freeing mapped page %p", p));
1551 if (p->wire_count == 0)

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

1557 continue;
1558 }
1559
1560 pp = vm_page_lookup(object, new_pindex);
1561 if (
1562 (op & OBSC_COLLAPSE_NOWAIT) != 0 &&
1563 (pp != NULL && pp->valid == 0)
1564 ) {
1565 if (backing_object->type == OBJT_SWAP)
1566 swap_pager_freespace(backing_object,
1567 p->pindex, 1);
1568
1564 /*
1565 * The page in the parent is not (yet) valid.
1566 * We don't know anything about the state of
1567 * the original page. It might be mapped,
1568 * so we must avoid the next if here.
1569 *
1570 * This is due to a race in vm_fault() where
1571 * we must unbusy the original (backing_obj)
1572 * page before we can (re)lock the parent.
1573 * Hence we can get here.
1574 */
1575 p = next;
1576 continue;
1577 }
1578 if (
1579 pp != NULL ||
1580 vm_pager_has_page(object, new_pindex, NULL, NULL)
1581 ) {
1569 /*
1570 * The page in the parent is not (yet) valid.
1571 * We don't know anything about the state of
1572 * the original page. It might be mapped,
1573 * so we must avoid the next if here.
1574 *
1575 * This is due to a race in vm_fault() where
1576 * we must unbusy the original (backing_obj)
1577 * page before we can (re)lock the parent.
1578 * Hence we can get here.
1579 */
1580 p = next;
1581 continue;
1582 }
1583 if (
1584 pp != NULL ||
1585 vm_pager_has_page(object, new_pindex, NULL, NULL)
1586 ) {
1587 if (backing_object->type == OBJT_SWAP)
1588 swap_pager_freespace(backing_object,
1589 p->pindex, 1);
1590
1582 /*
1583 * page already exists in parent OR swap exists
1584 * for this location in the parent. Destroy
1585 * the original page from the backing object.
1586 *
1587 * Leave the parent's page alone
1588 */
1589 vm_page_lock(p);
1590 KASSERT(!pmap_page_is_mapped(p),
1591 ("freeing mapped page %p", p));
1592 if (p->wire_count == 0)
1593 vm_page_free(p);
1594 else
1595 vm_page_remove(p);
1596 vm_page_unlock(p);
1597 p = next;
1598 continue;
1599 }
1600
1591 /*
1592 * page already exists in parent OR swap exists
1593 * for this location in the parent. Destroy
1594 * the original page from the backing object.
1595 *
1596 * Leave the parent's page alone
1597 */
1598 vm_page_lock(p);
1599 KASSERT(!pmap_page_is_mapped(p),
1600 ("freeing mapped page %p", p));
1601 if (p->wire_count == 0)
1602 vm_page_free(p);
1603 else
1604 vm_page_remove(p);
1605 vm_page_unlock(p);
1606 p = next;
1607 continue;
1608 }
1609
1601#if VM_NRESERVLEVEL > 0
1602 /*
1610 /*
1603 * Rename the reservation.
1604 */
1605 vm_reserv_rename(p, object, backing_object,
1606 backing_offset_index);
1607#endif
1608
1609 /*
1610 * Page does not exist in parent, rename the
1611 * page from the backing object to the main object.
1612 *
1613 * If the page was mapped to a process, it can remain
1614 * mapped through the rename.
1611 * Page does not exist in parent, rename the
1612 * page from the backing object to the main object.
1613 *
1614 * If the page was mapped to a process, it can remain
1615 * mapped through the rename.
1616 * vm_page_rename() will handle dirty and cache.
1615 */
1617 */
1616 vm_page_lock(p);
1617 vm_page_rename(p, object, new_pindex);
1618 vm_page_unlock(p);
1619 /* page automatically made dirty by rename */
1618 if (vm_page_rename(p, object, new_pindex)) {
1619 if (op & OBSC_COLLAPSE_NOWAIT) {
1620 p = next;
1621 continue;
1622 }
1623 VM_OBJECT_WLOCK(backing_object);
1624 VM_OBJECT_WUNLOCK(object);
1625 VM_WAIT;
1626 VM_OBJECT_WLOCK(object);
1627 VM_OBJECT_WLOCK(backing_object);
1628 p = TAILQ_FIRST(&backing_object->memq);
1629 continue;
1630 }
1631 if (backing_object->type == OBJT_SWAP)
1632 swap_pager_freespace(backing_object, p->pindex,
1633 1);
1634
1635#if VM_NRESERVLEVEL > 0
1636 /*
1637 * Rename the reservation.
1638 */
1639 vm_reserv_rename(p, object, backing_object,
1640 backing_offset_index);
1641#endif
1620 }
1621 p = next;
1622 }
1623 return (r);
1624}
1625
1626
1627/*

--- 779 unchanged lines hidden ---
1642 }
1643 p = next;
1644 }
1645 return (r);
1646}
1647
1648
1649/*

--- 779 unchanged lines hidden ---