| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: uvm_physseg.c,v 1.9 2018/01/21 17:58:43 christos Exp $ */ | | 1 | /* $NetBSD: uvm_physseg.c,v 1.10 2019/09/20 11:09:43 maxv Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1997 Charles D. Cranor and Washington University. | | 4 | * Copyright (c) 1997 Charles D. Cranor and Washington University. |
5 | * Copyright (c) 1991, 1993, The Regents of the University of California. | | 5 | * Copyright (c) 1991, 1993, The Regents of the University of California. |
6 | * | | 6 | * |
7 | * All rights reserved. | | 7 | * All rights reserved. |
8 | * | | 8 | * |
9 | * This code is derived from software contributed to Berkeley by | | 9 | * This code is derived from software contributed to Berkeley by |
10 | * The Mach Operating System project at Carnegie-Mellon University. | | 10 | * The Mach Operating System project at Carnegie-Mellon University. |
11 | * | | 11 | * |
12 | * Redistribution and use in source and binary forms, with or without | | 12 | * Redistribution and use in source and binary forms, with or without |
13 | * modification, are permitted provided that the following conditions | | 13 | * modification, are permitted provided that the following conditions |
14 | * are met: | | 14 | * are met: |
| @@ -461,27 +461,26 @@ uvm_physseg_get_highest_frame(void) | | | @@ -461,27 +461,26 @@ uvm_physseg_get_highest_frame(void) |
461 | * caller. | | 461 | * caller. |
462 | */ | | 462 | */ |
463 | bool | | 463 | bool |
464 | uvm_page_physunload(uvm_physseg_t upm, int freelist, paddr_t *paddrp) | | 464 | uvm_page_physunload(uvm_physseg_t upm, int freelist, paddr_t *paddrp) |
465 | { | | 465 | { |
466 | struct uvm_physseg *seg; | | 466 | struct uvm_physseg *seg; |
467 | | | 467 | |
468 | if (__predict_true(uvm.page_init_done == true)) | | 468 | if (__predict_true(uvm.page_init_done == true)) |
469 | panic("%s: unload attempted after uvm_page_init()\n", __func__); | | 469 | panic("%s: unload attempted after uvm_page_init()\n", __func__); |
470 | | | 470 | |
471 | seg = HANDLE_TO_PHYSSEG_NODE(upm); | | 471 | seg = HANDLE_TO_PHYSSEG_NODE(upm); |
472 | | | 472 | |
473 | if (seg->free_list != freelist) { | | 473 | if (seg->free_list != freelist) { |
474 | paddrp = NULL; | | | |
475 | return false; | | 474 | return false; |
476 | } | | 475 | } |
477 | | | 476 | |
478 | /* | | 477 | /* |
479 | * During cold boot, what we're about to unplug hasn't been | | 478 | * During cold boot, what we're about to unplug hasn't been |
480 | * put on the uvm freelist, nor has uvmexp.npages been | | 479 | * put on the uvm freelist, nor has uvmexp.npages been |
481 | * updated. (This happens in uvm_page.c:uvm_page_init()) | | 480 | * updated. (This happens in uvm_page.c:uvm_page_init()) |
482 | * | | 481 | * |
483 | * For hotplug, we assume here that the pages being unloaded | | 482 | * For hotplug, we assume here that the pages being unloaded |
484 | * here are completely out of sight of uvm (ie; not on any uvm | | 483 | * here are completely out of sight of uvm (ie; not on any uvm |
485 | * lists), and that uvmexp.npages has been suitably | | 484 | * lists), and that uvmexp.npages has been suitably |
486 | * decremented before we're called. | | 485 | * decremented before we're called. |
487 | * | | 486 | * |
| @@ -506,27 +505,26 @@ uvm_page_physunload(uvm_physseg_t upm, i | | | @@ -506,27 +505,26 @@ uvm_page_physunload(uvm_physseg_t upm, i |
506 | } | | 505 | } |
507 | | | 506 | |
508 | bool | | 507 | bool |
509 | uvm_page_physunload_force(uvm_physseg_t upm, int freelist, paddr_t *paddrp) | | 508 | uvm_page_physunload_force(uvm_physseg_t upm, int freelist, paddr_t *paddrp) |
510 | { | | 509 | { |
511 | struct uvm_physseg *seg; | | 510 | struct uvm_physseg *seg; |
512 | | | 511 | |
513 | seg = HANDLE_TO_PHYSSEG_NODE(upm); | | 512 | seg = HANDLE_TO_PHYSSEG_NODE(upm); |
514 | | | 513 | |
515 | if (__predict_true(uvm.page_init_done == true)) | | 514 | if (__predict_true(uvm.page_init_done == true)) |
516 | panic("%s: unload attempted after uvm_page_init()\n", __func__); | | 515 | panic("%s: unload attempted after uvm_page_init()\n", __func__); |
517 | /* any room in this bank? */ | | 516 | /* any room in this bank? */ |
518 | if (seg->avail_start >= seg->avail_end) { | | 517 | if (seg->avail_start >= seg->avail_end) { |
519 | paddrp = NULL; | | | |
520 | return false; /* nope */ | | 518 | return false; /* nope */ |
521 | } | | 519 | } |
522 | | | 520 | |
523 | *paddrp = ctob(seg->avail_start); | | 521 | *paddrp = ctob(seg->avail_start); |
524 | | | 522 | |
525 | /* Always unplug from front */ | | 523 | /* Always unplug from front */ |
526 | return uvm_physseg_unplug(seg->avail_start, 1); | | 524 | return uvm_physseg_unplug(seg->avail_start, 1); |
527 | } | | 525 | } |
528 | | | 526 | |
529 | | | 527 | |
530 | /* | | 528 | /* |
531 | * vm_physseg_find: find vm_physseg structure that belongs to a PA | | 529 | * vm_physseg_find: find vm_physseg structure that belongs to a PA |
532 | */ | | 530 | */ |
| @@ -652,27 +650,26 @@ uvm_post_preload_check(void) | | | @@ -652,27 +650,26 @@ uvm_post_preload_check(void) |
652 | * caller. | | 650 | * caller. |
653 | */ | | 651 | */ |
654 | bool | | 652 | bool |
655 | uvm_page_physunload(uvm_physseg_t psi, int freelist, paddr_t *paddrp) | | 653 | uvm_page_physunload(uvm_physseg_t psi, int freelist, paddr_t *paddrp) |
656 | { | | 654 | { |
657 | int x; | | 655 | int x; |
658 | struct uvm_physseg *seg; | | 656 | struct uvm_physseg *seg; |
659 | | | 657 | |
660 | uvm_post_preload_check(); | | 658 | uvm_post_preload_check(); |
661 | | | 659 | |
662 | seg = VM_PHYSMEM_PTR(psi); | | 660 | seg = VM_PHYSMEM_PTR(psi); |
663 | | | 661 | |
664 | if (seg->free_list != freelist) { | | 662 | if (seg->free_list != freelist) { |
665 | paddrp = NULL; | | | |
666 | return false; | | 663 | return false; |
667 | } | | 664 | } |
668 | | | 665 | |
669 | /* try from front */ | | 666 | /* try from front */ |
670 | if (seg->avail_start == seg->start && | | 667 | if (seg->avail_start == seg->start && |
671 | seg->avail_start < seg->avail_end) { | | 668 | seg->avail_start < seg->avail_end) { |
672 | *paddrp = ctob(seg->avail_start); | | 669 | *paddrp = ctob(seg->avail_start); |
673 | seg->avail_start++; | | 670 | seg->avail_start++; |
674 | seg->start++; | | 671 | seg->start++; |
675 | /* nothing left? nuke it */ | | 672 | /* nothing left? nuke it */ |
676 | if (seg->avail_start == seg->end) { | | 673 | if (seg->avail_start == seg->end) { |
677 | if (vm_nphysmem == 1) | | 674 | if (vm_nphysmem == 1) |
678 | panic("uvm_page_physget: out of memory!"); | | 675 | panic("uvm_page_physget: out of memory!"); |
| @@ -707,27 +704,26 @@ uvm_page_physunload(uvm_physseg_t psi, i | | | @@ -707,27 +704,26 @@ uvm_page_physunload(uvm_physseg_t psi, i |
707 | | | 704 | |
708 | bool | | 705 | bool |
709 | uvm_page_physunload_force(uvm_physseg_t psi, int freelist, paddr_t *paddrp) | | 706 | uvm_page_physunload_force(uvm_physseg_t psi, int freelist, paddr_t *paddrp) |
710 | { | | 707 | { |
711 | int x; | | 708 | int x; |
712 | struct uvm_physseg *seg; | | 709 | struct uvm_physseg *seg; |
713 | | | 710 | |
714 | uvm_post_preload_check(); | | 711 | uvm_post_preload_check(); |
715 | | | 712 | |
716 | seg = VM_PHYSMEM_PTR(psi); | | 713 | seg = VM_PHYSMEM_PTR(psi); |
717 | | | 714 | |
718 | /* any room in this bank? */ | | 715 | /* any room in this bank? */ |
719 | if (seg->avail_start >= seg->avail_end) { | | 716 | if (seg->avail_start >= seg->avail_end) { |
720 | paddrp = NULL; | | | |
721 | return false; /* nope */ | | 717 | return false; /* nope */ |
722 | } | | 718 | } |
723 | | | 719 | |
724 | *paddrp = ctob(seg->avail_start); | | 720 | *paddrp = ctob(seg->avail_start); |
725 | seg->avail_start++; | | 721 | seg->avail_start++; |
726 | /* truncate! */ | | 722 | /* truncate! */ |
727 | seg->start = seg->avail_start; | | 723 | seg->start = seg->avail_start; |
728 | | | 724 | |
729 | /* nothing left? nuke it */ | | 725 | /* nothing left? nuke it */ |
730 | if (seg->avail_start == seg->end) { | | 726 | if (seg->avail_start == seg->end) { |
731 | if (vm_nphysmem == 1) | | 727 | if (vm_nphysmem == 1) |
732 | panic("uvm_page_physget: out of memory!"); | | 728 | panic("uvm_page_physget: out of memory!"); |
733 | vm_nphysmem--; | | 729 | vm_nphysmem--; |