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

Function swaponsomething

freebsd/vm/swap_pager.c:2367–2423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2365}
2366
2367static void
2368swaponsomething(struct vnode *vp, void *id, u_long nblks,
2369 sw_strategy_t *strategy, sw_close_t *close, dev_t dev, int flags)
2370{
2371 struct swdevt *sp, *tsp;
2372 daddr_t dvbase;
2373
2374 /*
2375 * nblks is in DEV_BSIZE'd chunks, convert to PAGE_SIZE'd chunks.
2376 * First chop nblks off to page-align it, then convert.
2377 *
2378 * sw->sw_nblks is in page-sized chunks now too.
2379 */
2380 nblks &= ~(ctodb(1) - 1);
2381 nblks = dbtoc(nblks);
2382
2383 sp = malloc(sizeof *sp, M_VMPGDATA, M_WAITOK | M_ZERO);
2384 sp->sw_blist = blist_create(nblks, M_WAITOK);
2385 sp->sw_vp = vp;
2386 sp->sw_id = id;
2387 sp->sw_dev = dev;
2388 sp->sw_nblks = nblks;
2389 sp->sw_used = 0;
2390 sp->sw_strategy = strategy;
2391 sp->sw_close = close;
2392 sp->sw_flags = flags;
2393
2394 /*
2395 * Do not free the first blocks in order to avoid overwriting
2396 * any bsd label at the front of the partition
2397 */
2398 blist_free(sp->sw_blist, howmany(BBSIZE, PAGE_SIZE),
2399 nblks - howmany(BBSIZE, PAGE_SIZE));
2400
2401 dvbase = 0;
2402 mtx_lock(&sw_dev_mtx);
2403 TAILQ_FOREACH(tsp, &swtailq, sw_list) {
2404 if (tsp->sw_end >= dvbase) {
2405 /*
2406 * We put one uncovered page between the devices
2407 * in order to definitively prevent any cross-device
2408 * I/O requests
2409 */
2410 dvbase = tsp->sw_end + 1;
2411 }
2412 }
2413 sp->sw_first = dvbase;
2414 sp->sw_end = dvbase + nblks;
2415 TAILQ_INSERT_TAIL(&swtailq, sp, sw_list);
2416 nswapdev++;
2417 swap_pager_avail += nblks - howmany(BBSIZE, PAGE_SIZE);
2418 swap_total += nblks;
2419 swapon_check_swzone();
2420 swp_sizecheck();
2421 mtx_unlock(&sw_dev_mtx);
2422 EVENTHANDLER_INVOKE(swapon, sp);
2423}
2424

Callers 2

swapongeom_lockedFunction · 0.85
swaponvpFunction · 0.85

Calls 7

mallocFunction · 0.85
blist_createFunction · 0.85
blist_freeFunction · 0.85
swapon_check_swzoneFunction · 0.85
swp_sizecheckFunction · 0.85
mtx_lockFunction · 0.50
mtx_unlockFunction · 0.50

Tested by

no test coverage detected