Deleted Added
full compact
vm_glue.c (289059) vm_glue.c (292373)
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

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

52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
54 *
55 * any improvements or extensions that they make and grant Carnegie the
56 * rights to redistribute these changes.
57 */
58
59#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

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

52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
54 *
55 * any improvements or extensions that they make and grant Carnegie the
56 * rights to redistribute these changes.
57 */
58
59#include <sys/cdefs.h>
60__FBSDID("$FreeBSD: head/sys/vm/vm_glue.c 289059 2015-10-09 03:38:58Z alc $");
60__FBSDID("$FreeBSD: head/sys/vm/vm_glue.c 292373 2015-12-16 21:30:45Z glebius $");
61
62#include "opt_vm.h"
63#include "opt_kstack_pages.h"
64#include "opt_kstack_max_pages.h"
65#include "opt_kstack_usage_prof.h"
66
67#include <sys/param.h>
68#include <sys/systm.h>

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

233 vm_page_t m;
234 vm_pindex_t pindex;
235 int rv;
236
237 VM_OBJECT_WLOCK(object);
238 pindex = OFF_TO_IDX(offset);
239 m = vm_page_grab(object, pindex, VM_ALLOC_NORMAL);
240 if (m->valid != VM_PAGE_BITS_ALL) {
61
62#include "opt_vm.h"
63#include "opt_kstack_pages.h"
64#include "opt_kstack_max_pages.h"
65#include "opt_kstack_usage_prof.h"
66
67#include <sys/param.h>
68#include <sys/systm.h>

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

233 vm_page_t m;
234 vm_pindex_t pindex;
235 int rv;
236
237 VM_OBJECT_WLOCK(object);
238 pindex = OFF_TO_IDX(offset);
239 m = vm_page_grab(object, pindex, VM_ALLOC_NORMAL);
240 if (m->valid != VM_PAGE_BITS_ALL) {
241 rv = vm_pager_get_pages(object, &m, 1, 0);
241 rv = vm_pager_get_pages(object, &m, 1, NULL, NULL);
242 if (rv != VM_PAGER_OK) {
243 vm_page_lock(m);
244 vm_page_free(m);
245 vm_page_unlock(m);
246 m = NULL;
247 goto out;
248 }
249 }

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

562/*
563 * Bring the kernel stack for a specified thread back in.
564 */
565static void
566vm_thread_swapin(struct thread *td)
567{
568 vm_object_t ksobj;
569 vm_page_t ma[KSTACK_MAX_PAGES];
242 if (rv != VM_PAGER_OK) {
243 vm_page_lock(m);
244 vm_page_free(m);
245 vm_page_unlock(m);
246 m = NULL;
247 goto out;
248 }
249 }

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

562/*
563 * Bring the kernel stack for a specified thread back in.
564 */
565static void
566vm_thread_swapin(struct thread *td)
567{
568 vm_object_t ksobj;
569 vm_page_t ma[KSTACK_MAX_PAGES];
570 int i, j, pages, rv;
570 int pages;
571
572 pages = td->td_kstack_pages;
573 ksobj = td->td_kstack_obj;
574 VM_OBJECT_WLOCK(ksobj);
571
572 pages = td->td_kstack_pages;
573 ksobj = td->td_kstack_obj;
574 VM_OBJECT_WLOCK(ksobj);
575 for (i = 0; i < pages; i++)
575 for (int i = 0; i < pages; i++)
576 ma[i] = vm_page_grab(ksobj, i, VM_ALLOC_NORMAL |
577 VM_ALLOC_WIRED);
576 ma[i] = vm_page_grab(ksobj, i, VM_ALLOC_NORMAL |
577 VM_ALLOC_WIRED);
578 for (i = 0; i < pages; i++) {
579 if (ma[i]->valid != VM_PAGE_BITS_ALL) {
580 vm_page_assert_xbusied(ma[i]);
581 vm_object_pip_add(ksobj, 1);
582 for (j = i + 1; j < pages; j++) {
583 if (ma[j]->valid != VM_PAGE_BITS_ALL)
584 vm_page_assert_xbusied(ma[j]);
585 if (ma[j]->valid == VM_PAGE_BITS_ALL)
586 break;
587 }
588 rv = vm_pager_get_pages(ksobj, ma + i, j - i, 0);
589 if (rv != VM_PAGER_OK)
590 panic("vm_thread_swapin: cannot get kstack for proc: %d",
591 td->td_proc->p_pid);
592 /*
593 * All pages in the array are in place, due to the
594 * pager is always the swap pager, which doesn't
595 * free or remove wired non-req pages from object.
596 */
597 vm_object_pip_wakeup(ksobj);
578 for (int i = 0; i < pages;) {
579 int j, a, count, rv;
580
581 vm_page_assert_xbusied(ma[i]);
582 if (ma[i]->valid == VM_PAGE_BITS_ALL) {
598 vm_page_xunbusy(ma[i]);
583 vm_page_xunbusy(ma[i]);
599 } else if (vm_page_xbusied(ma[i]))
600 vm_page_xunbusy(ma[i]);
584 i++;
585 continue;
586 }
587 vm_object_pip_add(ksobj, 1);
588 for (j = i + 1; j < pages; j++)
589 if (ma[j]->valid == VM_PAGE_BITS_ALL)
590 break;
591 rv = vm_pager_has_page(ksobj, ma[i]->pindex, NULL, &a);
592 KASSERT(rv == 1, ("%s: missing page %p", __func__, ma[i]));
593 count = min(a + 1, j - i);
594 rv = vm_pager_get_pages(ksobj, ma + i, count, NULL, NULL);
595 KASSERT(rv == VM_PAGER_OK, ("%s: cannot get kstack for proc %d",
596 __func__, td->td_proc->p_pid));
597 vm_object_pip_wakeup(ksobj);
598 for (j = i; j < i + count; j++)
599 vm_page_xunbusy(ma[j]);
600 i += count;
601 }
602 VM_OBJECT_WUNLOCK(ksobj);
603 pmap_qenter(td->td_kstack, ma, pages);
604 cpu_thread_swapin(td);
605}
606#endif /* !NO_SWAPPING */
607
608/*

--- 485 unchanged lines hidden ---
601 }
602 VM_OBJECT_WUNLOCK(ksobj);
603 pmap_qenter(td->td_kstack, ma, pages);
604 cpu_thread_swapin(td);
605}
606#endif /* !NO_SWAPPING */
607
608/*

--- 485 unchanged lines hidden ---