View | Details | Raw Unified | Return to bug 223059
Collapse All | Expand All

(-)sys/vm/swap_pager.c (-6 / +14 lines)
Lines 131-136 Link Here
131
#define	SWAP_META_PAGES		PCTRIE_COUNT
130
#define	SWAP_META_PAGES		PCTRIE_COUNT
132
131
133
/*
132
/*
133
 * SWAP_DEVICE_START_OFFSET is to skip first two blocks in order to avoid
134
 * overwriting any bsd label at the front of the partition.
135
 */
136
#define	SWAP_DEVICE_START_OFFSET	2
137
138
/*
134
 * A swblk structure maps each page index within a
139
 * A swblk structure maps each page index within a
135
 * SWAP_META_PAGES-aligned and sized range to the address of an
140
 * SWAP_META_PAGES-aligned and sized range to the address of an
136
 * on-disk swap block (or SWAPBLK_NONE). The collection of these
141
 * on-disk swap block (or SWAPBLK_NONE). The collection of these
Lines 693-699 Link Here
693
	for (i = 0; i < nswapdev; i++) {
753
	for (i = 0; i < nswapdev; i++) {
694
		if (sp == NULL)
754
		if (sp == NULL)
695
			sp = TAILQ_FIRST(&swtailq);
755
			sp = TAILQ_FIRST(&swtailq);
696
		if (!(sp->sw_flags & SW_CLOSING)) {
756
		if (!(sp->sw_flags & SW_CLOSING) && (sp->sw_nblks - sp->sw_used >= npages)) {
697
			blk = blist_alloc(sp->sw_blist, npages);
757
			blk = blist_alloc(sp->sw_blist, npages);
698
			if (blk != SWAPBLK_NONE) {
758
			if (blk != SWAPBLK_NONE) {
699
				blk += sp->sw_first;
759
				blk += sp->sw_first;
Lines 2169-2179 Link Here
2169
	}
2257
	}
2170
2258
2171
	sp = malloc(sizeof *sp, M_VMPGDATA, M_WAITOK | M_ZERO);
2259
	sp = malloc(sizeof *sp, M_VMPGDATA, M_WAITOK | M_ZERO);
2260
	/* Can this fail?  */
2172
	sp->sw_vp = vp;
2261
	sp->sw_vp = vp;
2173
	sp->sw_id = id;
2262
	sp->sw_id = id;
2174
	sp->sw_dev = dev;
2263
	sp->sw_dev = dev;
2175
	sp->sw_flags = 0;
2264
	sp->sw_flags = 0;
2176
	sp->sw_nblks = nblks;
2265
	sp->sw_nblks = nblks - SWAP_DEVICE_START_OFFSET;
2177
	sp->sw_used = 0;
2266
	sp->sw_used = 0;
2178
	sp->sw_strategy = strategy;
2267
	sp->sw_strategy = strategy;
2179
	sp->sw_close = close;
2268
	sp->sw_close = close;
Lines 2180-2190 Link Here
2180
	sp->sw_flags = flags;
2269
	sp->sw_flags = flags;
2181
2270
2182
	sp->sw_blist = blist_create(nblks, M_WAITOK);
2271
	sp->sw_blist = blist_create(nblks, M_WAITOK);
2272
	/* Can thsi fail? */
2183
	/*
2273
	/*
2184
	 * Do not free the first two block in order to avoid overwriting
2274
	 * Do not free the first two block in order to avoid overwriting
2185
	 * any bsd label at the front of the partition
2275
	 * any bsd label at the front of the partition
2186
	 */
2276
	 */
2187
	blist_free(sp->sw_blist, 2, nblks - 2);
2277
	blist_free(sp->sw_blist, SWAP_DEVICE_START_OFFSET, sp->sw_nblks);
2188
2278
2189
	dvbase = 0;
2279
	dvbase = 0;
2190
	mtx_lock(&sw_dev_mtx);
2280
	mtx_lock(&sw_dev_mtx);
Lines 2202-2209 Link Here
2202
	sp->sw_end = dvbase + nblks;
2296
	sp->sw_end = dvbase + nblks;
2203
	TAILQ_INSERT_TAIL(&swtailq, sp, sw_list);
2297
	TAILQ_INSERT_TAIL(&swtailq, sp, sw_list);
2204
	nswapdev++;
2298
	nswapdev++;
2205
	swap_pager_avail += nblks - 2;
2299
	swap_pager_avail += sp->sw_nblks;
2206
	swap_total += (vm_ooffset_t)nblks * PAGE_SIZE;
2300
	swap_total += (vm_ooffset_t)(sp->sw_nblks) * PAGE_SIZE;
2207
	swapon_check_swzone();
2301
	swapon_check_swzone();
2208
	swp_sizecheck();
2302
	swp_sizecheck();
2209
	mtx_unlock(&sw_dev_mtx);
2303
	mtx_unlock(&sw_dev_mtx);
Lines 2298-2304 Link Here
2298
	 */
2393
	 */
2299
	mtx_lock(&sw_dev_mtx);
2394
	mtx_lock(&sw_dev_mtx);
2300
	sp->sw_flags |= SW_CLOSING;
2395
	sp->sw_flags |= SW_CLOSING;
2301
	swap_pager_avail -= blist_fill(sp->sw_blist, 0, nblks);
2396
	swap_pager_avail -= blist_fill(sp->sw_blist, SWAP_DEVICE_START_OFFSET, nblks);
2302
	swap_total -= (vm_ooffset_t)nblks * PAGE_SIZE;
2397
	swap_total -= (vm_ooffset_t)nblks * PAGE_SIZE;
2303
	mtx_unlock(&sw_dev_mtx);
2398
	mtx_unlock(&sw_dev_mtx);
2304
2399

Return to bug 223059