View | Details | Raw Unified | Return to bug 54690 | Differences between
and this patch

Collapse All | Expand All

(-)/usr/src/sys/vm/swap_pager.c (-2 / +33 lines)
Lines 113-120 Link Here
113
static int nsw_cluster_max;	/* maximum VOP I/O allowed		*/
113
static int nsw_cluster_max;	/* maximum VOP I/O allowed		*/
114
114
115
struct blist *swapblist;
115
struct blist *swapblist;
116
117
static struct mtx swhash_mtx;	/* protect hash table */
116
static struct swblock **swhash;
118
static struct swblock **swhash;
117
static int swhash_mask;
119
static int swhash_mask;
120
118
static int swap_async_max = 4;	/* maximum in-progress async I/O's	*/
121
static int swap_async_max = 4;	/* maximum in-progress async I/O's	*/
119
static struct sx sw_alloc_sx;
122
static struct sx sw_alloc_sx;
120
123
Lines 256-261 Link Here
256
	 */
259
	 */
257
	dmmax = SWB_NPAGES * 2;
260
	dmmax = SWB_NPAGES * 2;
258
	dmmax_mask = ~(dmmax - 1);
261
	dmmax_mask = ~(dmmax - 1);
262
263
	mtx_init(&swhash_mtx, "swap_pager swhash mutex", NULL, MTX_DEF);
259
}
264
}
260
265
261
/*
266
/*
Lines 1648-1653 Link Here
1648
	int i;
1653
	int i;
1649
1654
1650
	VM_OBJECT_LOCK_ASSERT(object, MA_OWNED);
1655
	VM_OBJECT_LOCK_ASSERT(object, MA_OWNED);
1656
	mtx_lock(&swhash_mtx);
1651
	for (bcount = 0; bcount < object->un_pager.swp.swp_bcount; bcount++) {
1657
	for (bcount = 0; bcount < object->un_pager.swp.swp_bcount; bcount++) {
1652
		struct swblock *swap;
1658
		struct swblock *swap;
1653
1659
Lines 1655-1662 Link Here
1655
			for (i = 0; i < SWAP_META_PAGES; ++i) {
1661
			for (i = 0; i < SWAP_META_PAGES; ++i) {
1656
				daddr_t v = swap->swb_pages[i];
1662
				daddr_t v = swap->swb_pages[i];
1657
				if (v != SWAPBLK_NONE &&
1663
				if (v != SWAPBLK_NONE &&
1658
				    BLK2DEVIDX(v) == devidx)
1664
				    BLK2DEVIDX(v) == devidx) {
1665
					mtx_unlock(&swhash_mtx);
1659
					return 1;
1666
					return 1;
1667
				}
1660
			}
1668
			}
1661
		}
1669
		}
1662
1670
Lines 1664-1669 Link Here
1664
		if (index > 0x20000000)
1672
		if (index > 0x20000000)
1665
			panic("swap_pager_isswapped: failed to locate all swap meta blocks");
1673
			panic("swap_pager_isswapped: failed to locate all swap meta blocks");
1666
	}
1674
	}
1675
	mtx_unlock(&swhash_mtx);
1667
	return 0;
1676
	return 0;
1668
}
1677
}
1669
1678
Lines 1752-1757 Link Here
1752
1761
1753
full_rescan:
1762
full_rescan:
1754
	waitobj = NULL;
1763
	waitobj = NULL;
1764
	mtx_lock(&swhash_mtx);
1755
	for (i = 0; i <= swhash_mask; i++) { /* '<=' is correct here */
1765
	for (i = 0; i <= swhash_mask; i++) { /* '<=' is correct here */
1756
restart:
1766
restart:
1757
		pswap = &swhash[i];
1767
		pswap = &swhash[i];
Lines 1763-1769 Link Here
1763
                                        break;
1773
                                        break;
1764
                        }
1774
                        }
1765
			if (j < SWAP_META_PAGES) {
1775
			if (j < SWAP_META_PAGES) {
1776
				mtx_unlock(&swhash_mtx);
1766
				swp_pager_force_pagein(swap, j);
1777
				swp_pager_force_pagein(swap, j);
1778
				mtx_lock(&swhash_mtx);
1767
				goto restart;
1779
				goto restart;
1768
			} else if (swap->swb_object->paging_in_progress) {
1780
			} else if (swap->swb_object->paging_in_progress) {
1769
				if (!waitobj)
1781
				if (!waitobj)
Lines 1772-1777 Link Here
1772
			pswap = &swap->swb_hnext;
1784
			pswap = &swap->swb_hnext;
1773
		}
1785
		}
1774
	}
1786
	}
1787
	mtx_unlock(&swhash_mtx);
1788
1775
	if (waitobj && *sw_used) {
1789
	if (waitobj && *sw_used) {
1776
	    /*
1790
	    /*
1777
	     * We wait on an arbitrary object to clock our rescans
1791
	     * We wait on an arbitrary object to clock our rescans
Lines 1782-1787 Link Here
1782
	    VM_OBJECT_UNLOCK(waitobj);
1796
	    VM_OBJECT_UNLOCK(waitobj);
1783
	    goto full_rescan;
1797
	    goto full_rescan;
1784
	}
1798
	}
1799
1785
	if (*sw_used)
1800
	if (*sw_used)
1786
	    panic("swapoff: failed to locate %d swap blocks", *sw_used);
1801
	    panic("swapoff: failed to locate %d swap blocks", *sw_used);
1787
}
1802
}
Lines 1809-1814 Link Here
1809
 *	find a swapblk.
1824
 *	find a swapblk.
1810
 *
1825
 *
1811
 *	This routine must be called at splvm().
1826
 *	This routine must be called at splvm().
1827
 *	It is the caller's responsibility to obtain the swhash_mtx lock
1828
 *	before calling.
1812
 */
1829
 */
1813
static __inline struct swblock **
1830
static __inline struct swblock **
1814
swp_pager_hash(vm_object_t object, vm_pindex_t index)
1831
swp_pager_hash(vm_object_t object, vm_pindex_t index)
Lines 1817-1822 Link Here
1817
	struct swblock *swap;
1834
	struct swblock *swap;
1818
1835
1819
	index &= ~(vm_pindex_t)SWAP_META_MASK;
1836
	index &= ~(vm_pindex_t)SWAP_META_MASK;
1837
1820
	pswap = &swhash[(index ^ (int)(intptr_t)object) & swhash_mask];
1838
	pswap = &swhash[(index ^ (int)(intptr_t)object) & swhash_mask];
1821
	while ((swap = *pswap) != NULL) {
1839
	while ((swap = *pswap) != NULL) {
1822
		if (swap->swb_object == object &&
1840
		if (swap->swb_object == object &&
Lines 1826-1831 Link Here
1826
		}
1844
		}
1827
		pswap = &swap->swb_hnext;
1845
		pswap = &swap->swb_hnext;
1828
	}
1846
	}
1847
1829
	return (pswap);
1848
	return (pswap);
1830
}
1849
}
1831
1850
Lines 1883-1898 Link Here
1883
	 * and, since the hash table may have changed, retry.
1902
	 * and, since the hash table may have changed, retry.
1884
	 */
1903
	 */
1885
retry:
1904
retry:
1905
	mtx_lock(&swhash_mtx);
1886
	pswap = swp_pager_hash(object, pindex);
1906
	pswap = swp_pager_hash(object, pindex);
1887
1907
1888
	if ((swap = *pswap) == NULL) {
1908
	if ((swap = *pswap) == NULL) {
1889
		int i;
1909
		int i;
1890
1910
1891
		if (swapblk == SWAPBLK_NONE)
1911
		if (swapblk == SWAPBLK_NONE) {
1912
			mtx_unlock(&swhash_mtx);
1892
			return;
1913
			return;
1914
		}
1893
1915
1894
		swap = *pswap = uma_zalloc(swap_zone, M_NOWAIT);
1916
		swap = *pswap = uma_zalloc(swap_zone, M_NOWAIT);
1895
		if (swap == NULL) {
1917
		if (swap == NULL) {
1918
			mtx_unlock(&swhash_mtx);
1896
			VM_WAIT;
1919
			VM_WAIT;
1897
			goto retry;
1920
			goto retry;
1898
		}
1921
		}
Lines 1924-1929 Link Here
1924
	swap->swb_pages[idx] = swapblk;
1947
	swap->swb_pages[idx] = swapblk;
1925
	if (swapblk != SWAPBLK_NONE)
1948
	if (swapblk != SWAPBLK_NONE)
1926
		++swap->swb_count;
1949
		++swap->swb_count;
1950
1951
	mtx_unlock(&swhash_mtx);
1927
}
1952
}
1928
1953
1929
/*
1954
/*
Lines 1946-1951 Link Here
1946
	if (object->type != OBJT_SWAP)
1971
	if (object->type != OBJT_SWAP)
1947
		return;
1972
		return;
1948
1973
1974
	mtx_lock(&swhash_mtx);
1949
	while (count > 0) {
1975
	while (count > 0) {
1950
		struct swblock **pswap;
1976
		struct swblock **pswap;
1951
		struct swblock *swap;
1977
		struct swblock *swap;
Lines 1973-1978 Link Here
1973
			index += n;
1999
			index += n;
1974
		}
2000
		}
1975
	}
2001
	}
2002
	mtx_unlock(&swhash_mtx);
1976
}
2003
}
1977
2004
1978
/*
2005
/*
Lines 1993-1998 Link Here
1993
	if (object->type != OBJT_SWAP)
2020
	if (object->type != OBJT_SWAP)
1994
		return;
2021
		return;
1995
2022
2023
	mtx_lock(&swhash_mtx);
1996
	while (object->un_pager.swp.swp_bcount) {
2024
	while (object->un_pager.swp.swp_bcount) {
1997
		struct swblock **pswap;
2025
		struct swblock **pswap;
1998
		struct swblock *swap;
2026
		struct swblock *swap;
Lines 2018-2023 Link Here
2018
		if (index > 0x20000000)
2046
		if (index > 0x20000000)
2019
			panic("swp_pager_meta_free_all: failed to locate all swap meta blocks");
2047
			panic("swp_pager_meta_free_all: failed to locate all swap meta blocks");
2020
	}
2048
	}
2049
	mtx_unlock(&swhash_mtx);
2021
}
2050
}
2022
2051
2023
/*
2052
/*
Lines 2062-2067 Link Here
2062
		return (SWAPBLK_NONE);
2091
		return (SWAPBLK_NONE);
2063
2092
2064
	r1 = SWAPBLK_NONE;
2093
	r1 = SWAPBLK_NONE;
2094
	mtx_lock(&swhash_mtx);
2065
	pswap = swp_pager_hash(object, pindex);
2095
	pswap = swp_pager_hash(object, pindex);
2066
2096
2067
	if ((swap = *pswap) != NULL) {
2097
	if ((swap = *pswap) != NULL) {
Lines 2083-2088 Link Here
2083
			} 
2113
			} 
2084
		}
2114
		}
2085
	}
2115
	}
2116
	mtx_unlock(&swhash_mtx);
2086
	return (r1);
2117
	return (r1);
2087
}
2118
}
2088
2119

Return to bug 54690