MCPcopy Create free account
hub / github.com/F-Stack/f-stack / swp_pager_getswapspace

Function swp_pager_getswapspace

freebsd/vm/swap_pager.c:788–835  ·  view source on GitHub ↗

* SWP_PAGER_GETSWAPSPACE() - allocate raw swap space * * Allocate swap for up to the requested number of pages. The * starting swap block number (a page index) is returned or * SWAPBLK_NONE if the allocation failed. * * Also has the side effect of advising that somebody made a mistake * when they configured swap and didn't configure enough. * * This routine may not sleep. * * We alloca

Source from the content-addressed store, hash-verified

786 * We allocate in round-robin fashion from the configured devices.
787 */
788static daddr_t
789swp_pager_getswapspace(int *io_npages)
790{
791 daddr_t blk;
792 struct swdevt *sp;
793 int mpages, npages;
794
795 KASSERT(*io_npages >= 1,
796 ("%s: npages not positive", __func__));
797 blk = SWAPBLK_NONE;
798 mpages = *io_npages;
799 npages = imin(BLIST_MAX_ALLOC, mpages);
800 mtx_lock(&sw_dev_mtx);
801 sp = swdevhd;
802 while (!TAILQ_EMPTY(&swtailq)) {
803 if (sp == NULL)
804 sp = TAILQ_FIRST(&swtailq);
805 if ((sp->sw_flags & SW_CLOSING) == 0)
806 blk = blist_alloc(sp->sw_blist, &npages, mpages);
807 if (blk != SWAPBLK_NONE)
808 break;
809 sp = TAILQ_NEXT(sp, sw_list);
810 if (swdevhd == sp) {
811 if (npages == 1)
812 break;
813 mpages = npages - 1;
814 npages >>= 1;
815 }
816 }
817 if (blk != SWAPBLK_NONE) {
818 *io_npages = npages;
819 blk += sp->sw_first;
820 sp->sw_used += npages;
821 swap_pager_avail -= npages;
822 swp_sizecheck();
823 swdevhd = TAILQ_NEXT(sp, sw_list);
824 } else {
825 if (swap_pager_full != 2) {
826 printf("swp_pager_getswapspace(%d): failed\n",
827 *io_npages);
828 swap_pager_full = 2;
829 swap_pager_almost_full = 1;
830 }
831 swdevhd = NULL;
832 }
833 mtx_unlock(&sw_dev_mtx);
834 return (blk);
835}
836
837static bool
838swp_pager_isondev(daddr_t blk, struct swdevt *sp)

Callers 2

swap_pager_reserveFunction · 0.85
swap_pager_putpagesFunction · 0.85

Calls 6

iminFunction · 0.85
blist_allocFunction · 0.85
swp_sizecheckFunction · 0.85
mtx_lockFunction · 0.50
printfFunction · 0.50
mtx_unlockFunction · 0.50

Tested by

no test coverage detected