mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-25 19:57:43 +03:00
Switch KM_SLEEP to KM_PUSHPAGE
Differences between how paging is done on Solaris and Linux can cause deadlocks if KM_SLEEP is used in any the following contexts. * The txg_sync thread * The zvol write/discard threads * The zpl_putpage() VFS callback This is because KM_SLEEP will allow for direct reclaim which may result in the VM calling back in to the filesystem or block layer to write out pages. If a lock is held over this operation the potential exists to deadlock the system. To ensure forward progress all memory allocations in these contexts must us KM_PUSHPAGE which disables performing any I/O to accomplish the memory allocation. Previously, this behavior was acheived by setting PF_MEMALLOC on the thread. However, that resulted in unexpected side effects such as the exhaustion of pages in ZONE_DMA. This approach touchs more of the zfs code, but it is more consistent with the right way to handle these cases under Linux. This is patch lays the ground work for being able to safely revert the following commits which used PF_MEMALLOC:21ade34Disable direct reclaim for z_wr_* threadscfc9a5cFix zpl_writepage() deadlockeec8164Fix ASSERTION(!dsl_pool_sync_context(tx->tx_pool)) Signed-off-by: Richard Yao <ryao@cs.stonybrook.edu> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Issue #726
This commit is contained in:
committed by
Brian Behlendorf
parent
991fc1d7ae
commit
b8d06fca08
+37
-37
@@ -150,7 +150,7 @@ spa_prop_add_list(nvlist_t *nvl, zpool_prop_t prop, char *strval,
|
||||
const char *propname = zpool_prop_to_name(prop);
|
||||
nvlist_t *propval;
|
||||
|
||||
VERIFY(nvlist_alloc(&propval, NV_UNIQUE_NAME, KM_SLEEP) == 0);
|
||||
VERIFY(nvlist_alloc(&propval, NV_UNIQUE_NAME, KM_PUSHPAGE) == 0);
|
||||
VERIFY(nvlist_add_uint64(propval, ZPROP_SOURCE, src) == 0);
|
||||
|
||||
if (strval != NULL)
|
||||
@@ -237,7 +237,7 @@ spa_prop_get(spa_t *spa, nvlist_t **nvp)
|
||||
zap_attribute_t za;
|
||||
int err;
|
||||
|
||||
err = nvlist_alloc(nvp, NV_UNIQUE_NAME, KM_SLEEP);
|
||||
err = nvlist_alloc(nvp, NV_UNIQUE_NAME, KM_PUSHPAGE);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
@@ -289,7 +289,7 @@ spa_prop_get(spa_t *spa, nvlist_t **nvp)
|
||||
|
||||
strval = kmem_alloc(
|
||||
MAXNAMELEN + strlen(MOS_DIR_NAME) + 1,
|
||||
KM_SLEEP);
|
||||
KM_PUSHPAGE);
|
||||
dsl_dataset_name(ds, strval);
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
rw_exit(&dp->dp_config_rwlock);
|
||||
@@ -308,7 +308,7 @@ spa_prop_get(spa_t *spa, nvlist_t **nvp)
|
||||
|
||||
case 1:
|
||||
/* string property */
|
||||
strval = kmem_alloc(za.za_num_integers, KM_SLEEP);
|
||||
strval = kmem_alloc(za.za_num_integers, KM_PUSHPAGE);
|
||||
err = zap_lookup(mos, spa->spa_pool_props_object,
|
||||
za.za_name, 1, za.za_num_integers, strval);
|
||||
if (err) {
|
||||
@@ -528,7 +528,7 @@ spa_configfile_set(spa_t *spa, nvlist_t *nvp, boolean_t need_sync)
|
||||
return;
|
||||
|
||||
dp = kmem_alloc(sizeof (spa_config_dirent_t),
|
||||
KM_SLEEP);
|
||||
KM_PUSHPAGE);
|
||||
|
||||
if (cachefile[0] == '\0')
|
||||
dp->scd_path = spa_strdup(spa_config_path);
|
||||
@@ -1140,7 +1140,7 @@ spa_load_spares(spa_t *spa)
|
||||
* active configuration, then we also mark this vdev as an active spare.
|
||||
*/
|
||||
spa->spa_spares.sav_vdevs = kmem_alloc(nspares * sizeof (void *),
|
||||
KM_SLEEP);
|
||||
KM_PUSHPAGE);
|
||||
for (i = 0; i < spa->spa_spares.sav_count; i++) {
|
||||
VERIFY(spa_config_parse(spa, &vd, spares[i], NULL, 0,
|
||||
VDEV_ALLOC_SPARE) == 0);
|
||||
@@ -1188,7 +1188,7 @@ spa_load_spares(spa_t *spa)
|
||||
DATA_TYPE_NVLIST_ARRAY) == 0);
|
||||
|
||||
spares = kmem_alloc(spa->spa_spares.sav_count * sizeof (void *),
|
||||
KM_SLEEP);
|
||||
KM_PUSHPAGE);
|
||||
for (i = 0; i < spa->spa_spares.sav_count; i++)
|
||||
spares[i] = vdev_config_generate(spa,
|
||||
spa->spa_spares.sav_vdevs[i], B_TRUE, VDEV_CONFIG_SPARE);
|
||||
@@ -1222,7 +1222,7 @@ spa_load_l2cache(spa_t *spa)
|
||||
if (sav->sav_config != NULL) {
|
||||
VERIFY(nvlist_lookup_nvlist_array(sav->sav_config,
|
||||
ZPOOL_CONFIG_L2CACHE, &l2cache, &nl2cache) == 0);
|
||||
newvdevs = kmem_alloc(nl2cache * sizeof (void *), KM_SLEEP);
|
||||
newvdevs = kmem_alloc(nl2cache * sizeof (void *), KM_PUSHPAGE);
|
||||
} else {
|
||||
nl2cache = 0;
|
||||
}
|
||||
@@ -1316,7 +1316,7 @@ spa_load_l2cache(spa_t *spa)
|
||||
VERIFY(nvlist_remove(sav->sav_config, ZPOOL_CONFIG_L2CACHE,
|
||||
DATA_TYPE_NVLIST_ARRAY) == 0);
|
||||
|
||||
l2cache = kmem_alloc(sav->sav_count * sizeof (void *), KM_SLEEP);
|
||||
l2cache = kmem_alloc(sav->sav_count * sizeof (void *), KM_PUSHPAGE);
|
||||
for (i = 0; i < sav->sav_count; i++)
|
||||
l2cache[i] = vdev_config_generate(spa,
|
||||
sav->sav_vdevs[i], B_TRUE, VDEV_CONFIG_L2CACHE);
|
||||
@@ -1342,7 +1342,7 @@ load_nvlist(spa_t *spa, uint64_t obj, nvlist_t **value)
|
||||
nvsize = *(uint64_t *)db->db_data;
|
||||
dmu_buf_rele(db, FTAG);
|
||||
|
||||
packed = kmem_alloc(nvsize, KM_SLEEP | KM_NODEBUG);
|
||||
packed = kmem_alloc(nvsize, KM_PUSHPAGE | KM_NODEBUG);
|
||||
error = dmu_read(spa->spa_meta_objset, obj, 0, nvsize, packed,
|
||||
DMU_READ_PREFETCH);
|
||||
if (error == 0)
|
||||
@@ -1398,8 +1398,8 @@ spa_config_valid(spa_t *spa, nvlist_t *config)
|
||||
uint64_t idx = 0;
|
||||
|
||||
child = kmem_alloc(rvd->vdev_children * sizeof (nvlist_t **),
|
||||
KM_SLEEP);
|
||||
VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0);
|
||||
KM_PUSHPAGE);
|
||||
VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_PUSHPAGE) == 0);
|
||||
|
||||
for (c = 0; c < rvd->vdev_children; c++) {
|
||||
vdev_t *tvd = rvd->vdev_child[c];
|
||||
@@ -1754,7 +1754,7 @@ spa_try_repair(spa_t *spa, nvlist_t *config)
|
||||
&glist, &gcount) != 0)
|
||||
return;
|
||||
|
||||
vd = kmem_zalloc(gcount * sizeof (vdev_t *), KM_SLEEP);
|
||||
vd = kmem_zalloc(gcount * sizeof (vdev_t *), KM_PUSHPAGE);
|
||||
|
||||
/* attempt to online all the vdevs & validate */
|
||||
attempt_reopen = B_TRUE;
|
||||
@@ -1840,7 +1840,7 @@ spa_load(spa_t *spa, spa_load_state_t state, spa_import_type_t type,
|
||||
if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_SPLIT,
|
||||
&nvl) == 0) {
|
||||
VERIFY(nvlist_dup(nvl, &spa->spa_config_splitting,
|
||||
KM_SLEEP) == 0);
|
||||
KM_PUSHPAGE) == 0);
|
||||
}
|
||||
|
||||
gethrestime(&spa->spa_loaded_ts);
|
||||
@@ -2497,7 +2497,7 @@ spa_open_common(const char *pool, spa_t **spapp, void *tag, nvlist_t *nvpolicy,
|
||||
*/
|
||||
if (config != NULL && spa->spa_config) {
|
||||
VERIFY(nvlist_dup(spa->spa_config, config,
|
||||
KM_SLEEP) == 0);
|
||||
KM_PUSHPAGE) == 0);
|
||||
VERIFY(nvlist_add_nvlist(*config,
|
||||
ZPOOL_CONFIG_LOAD_INFO,
|
||||
spa->spa_load_info) == 0);
|
||||
@@ -2873,13 +2873,13 @@ spa_set_aux_vdevs(spa_aux_vdev_t *sav, nvlist_t **devs, int ndevs,
|
||||
&olddevs, &oldndevs) == 0);
|
||||
|
||||
newdevs = kmem_alloc(sizeof (void *) *
|
||||
(ndevs + oldndevs), KM_SLEEP);
|
||||
(ndevs + oldndevs), KM_PUSHPAGE);
|
||||
for (i = 0; i < oldndevs; i++)
|
||||
VERIFY(nvlist_dup(olddevs[i], &newdevs[i],
|
||||
KM_SLEEP) == 0);
|
||||
KM_PUSHPAGE) == 0);
|
||||
for (i = 0; i < ndevs; i++)
|
||||
VERIFY(nvlist_dup(devs[i], &newdevs[i + oldndevs],
|
||||
KM_SLEEP) == 0);
|
||||
KM_PUSHPAGE) == 0);
|
||||
|
||||
VERIFY(nvlist_remove(sav->sav_config, config,
|
||||
DATA_TYPE_NVLIST_ARRAY) == 0);
|
||||
@@ -2894,7 +2894,7 @@ spa_set_aux_vdevs(spa_aux_vdev_t *sav, nvlist_t **devs, int ndevs,
|
||||
* Generate a new dev list.
|
||||
*/
|
||||
VERIFY(nvlist_alloc(&sav->sav_config, NV_UNIQUE_NAME,
|
||||
KM_SLEEP) == 0);
|
||||
KM_PUSHPAGE) == 0);
|
||||
VERIFY(nvlist_add_nvlist_array(sav->sav_config, config,
|
||||
devs, ndevs) == 0);
|
||||
}
|
||||
@@ -3020,7 +3020,7 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props,
|
||||
if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES,
|
||||
&spares, &nspares) == 0) {
|
||||
VERIFY(nvlist_alloc(&spa->spa_spares.sav_config, NV_UNIQUE_NAME,
|
||||
KM_SLEEP) == 0);
|
||||
KM_PUSHPAGE) == 0);
|
||||
VERIFY(nvlist_add_nvlist_array(spa->spa_spares.sav_config,
|
||||
ZPOOL_CONFIG_SPARES, spares, nspares) == 0);
|
||||
spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
|
||||
@@ -3035,7 +3035,7 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props,
|
||||
if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE,
|
||||
&l2cache, &nl2cache) == 0) {
|
||||
VERIFY(nvlist_alloc(&spa->spa_l2cache.sav_config,
|
||||
NV_UNIQUE_NAME, KM_SLEEP) == 0);
|
||||
NV_UNIQUE_NAME, KM_PUSHPAGE) == 0);
|
||||
VERIFY(nvlist_add_nvlist_array(spa->spa_l2cache.sav_config,
|
||||
ZPOOL_CONFIG_L2CACHE, l2cache, nl2cache) == 0);
|
||||
spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
|
||||
@@ -3173,7 +3173,7 @@ spa_generate_rootconf(char *devpath, char *devid, uint64_t *guid)
|
||||
/*
|
||||
* Put this pool's top-level vdevs into a root vdev.
|
||||
*/
|
||||
VERIFY(nvlist_alloc(&nvroot, NV_UNIQUE_NAME, KM_SLEEP) == 0);
|
||||
VERIFY(nvlist_alloc(&nvroot, NV_UNIQUE_NAME, KM_PUSHPAGE) == 0);
|
||||
VERIFY(nvlist_add_string(nvroot, ZPOOL_CONFIG_TYPE,
|
||||
VDEV_TYPE_ROOT) == 0);
|
||||
VERIFY(nvlist_add_uint64(nvroot, ZPOOL_CONFIG_ID, 0ULL) == 0);
|
||||
@@ -3484,7 +3484,7 @@ spa_import(const char *pool, nvlist_t *config, nvlist_t *props, uint64_t flags)
|
||||
ZPOOL_CONFIG_SPARES, DATA_TYPE_NVLIST_ARRAY) == 0);
|
||||
else
|
||||
VERIFY(nvlist_alloc(&spa->spa_spares.sav_config,
|
||||
NV_UNIQUE_NAME, KM_SLEEP) == 0);
|
||||
NV_UNIQUE_NAME, KM_PUSHPAGE) == 0);
|
||||
VERIFY(nvlist_add_nvlist_array(spa->spa_spares.sav_config,
|
||||
ZPOOL_CONFIG_SPARES, spares, nspares) == 0);
|
||||
spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
|
||||
@@ -3499,7 +3499,7 @@ spa_import(const char *pool, nvlist_t *config, nvlist_t *props, uint64_t flags)
|
||||
ZPOOL_CONFIG_L2CACHE, DATA_TYPE_NVLIST_ARRAY) == 0);
|
||||
else
|
||||
VERIFY(nvlist_alloc(&spa->spa_l2cache.sav_config,
|
||||
NV_UNIQUE_NAME, KM_SLEEP) == 0);
|
||||
NV_UNIQUE_NAME, KM_PUSHPAGE) == 0);
|
||||
VERIFY(nvlist_add_nvlist_array(spa->spa_l2cache.sav_config,
|
||||
ZPOOL_CONFIG_L2CACHE, l2cache, nl2cache) == 0);
|
||||
spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
|
||||
@@ -3582,7 +3582,7 @@ spa_tryimport(nvlist_t *tryconfig)
|
||||
* pools are bootable.
|
||||
*/
|
||||
if ((!error || error == EEXIST) && spa->spa_bootfs) {
|
||||
char *tmpname = kmem_alloc(MAXPATHLEN, KM_SLEEP);
|
||||
char *tmpname = kmem_alloc(MAXPATHLEN, KM_PUSHPAGE);
|
||||
|
||||
/*
|
||||
* We have to play games with the name since the
|
||||
@@ -3591,7 +3591,7 @@ spa_tryimport(nvlist_t *tryconfig)
|
||||
if (dsl_dsobj_to_dsname(spa_name(spa),
|
||||
spa->spa_bootfs, tmpname) == 0) {
|
||||
char *cp;
|
||||
char *dsname = kmem_alloc(MAXPATHLEN, KM_SLEEP);
|
||||
char *dsname = kmem_alloc(MAXPATHLEN, KM_PUSHPAGE);
|
||||
|
||||
cp = strchr(tmpname, '/');
|
||||
if (cp == NULL) {
|
||||
@@ -3996,7 +3996,7 @@ spa_vdev_attach(spa_t *spa, uint64_t guid, nvlist_t *nvroot, int replacing)
|
||||
if (strcmp(oldvd->vdev_path, newvd->vdev_path) == 0) {
|
||||
spa_strfree(oldvd->vdev_path);
|
||||
oldvd->vdev_path = kmem_alloc(strlen(newvd->vdev_path) + 5,
|
||||
KM_SLEEP);
|
||||
KM_PUSHPAGE);
|
||||
(void) sprintf(oldvd->vdev_path, "%s/%s",
|
||||
newvd->vdev_path, "old");
|
||||
if (oldvd->vdev_devid != NULL) {
|
||||
@@ -4391,8 +4391,8 @@ spa_vdev_split_mirror(spa_t *spa, char *newname, nvlist_t *config,
|
||||
nvlist_lookup_nvlist(nvl, ZPOOL_CONFIG_L2CACHE, &tmp) == 0)
|
||||
return (spa_vdev_exit(spa, NULL, txg, EINVAL));
|
||||
|
||||
vml = kmem_zalloc(children * sizeof (vdev_t *), KM_SLEEP);
|
||||
glist = kmem_zalloc(children * sizeof (uint64_t), KM_SLEEP);
|
||||
vml = kmem_zalloc(children * sizeof (vdev_t *), KM_PUSHPAGE);
|
||||
glist = kmem_zalloc(children * sizeof (uint64_t), KM_PUSHPAGE);
|
||||
|
||||
/* then, loop over each vdev and validate it */
|
||||
for (c = 0; c < children; c++) {
|
||||
@@ -4472,7 +4472,7 @@ spa_vdev_split_mirror(spa_t *spa, char *newname, nvlist_t *config,
|
||||
* Temporarily record the splitting vdevs in the spa config. This
|
||||
* will disappear once the config is regenerated.
|
||||
*/
|
||||
VERIFY(nvlist_alloc(&nvl, NV_UNIQUE_NAME, KM_SLEEP) == 0);
|
||||
VERIFY(nvlist_alloc(&nvl, NV_UNIQUE_NAME, KM_PUSHPAGE) == 0);
|
||||
VERIFY(nvlist_add_uint64_array(nvl, ZPOOL_CONFIG_SPLIT_LIST,
|
||||
glist, children) == 0);
|
||||
kmem_free(glist, children * sizeof (uint64_t));
|
||||
@@ -4519,7 +4519,7 @@ spa_vdev_split_mirror(spa_t *spa, char *newname, nvlist_t *config,
|
||||
/* if that worked, generate a real config for the new pool */
|
||||
if (newspa->spa_root_vdev != NULL) {
|
||||
VERIFY(nvlist_alloc(&newspa->spa_config_splitting,
|
||||
NV_UNIQUE_NAME, KM_SLEEP) == 0);
|
||||
NV_UNIQUE_NAME, KM_PUSHPAGE) == 0);
|
||||
VERIFY(nvlist_add_uint64(newspa->spa_config_splitting,
|
||||
ZPOOL_CONFIG_SPLIT_GUID, spa_guid(spa)) == 0);
|
||||
spa_config_set(newspa, spa_config_generate(newspa, NULL, -1ULL,
|
||||
@@ -4631,12 +4631,12 @@ spa_vdev_remove_aux(nvlist_t *config, char *name, nvlist_t **dev, int count,
|
||||
int i, j;
|
||||
|
||||
if (count > 1)
|
||||
newdev = kmem_alloc((count - 1) * sizeof (void *), KM_SLEEP);
|
||||
newdev = kmem_alloc((count - 1) * sizeof (void *), KM_PUSHPAGE);
|
||||
|
||||
for (i = 0, j = 0; i < count; i++) {
|
||||
if (dev[i] == dev_to_remove)
|
||||
continue;
|
||||
VERIFY(nvlist_dup(dev[i], &newdev[j++], KM_SLEEP) == 0);
|
||||
VERIFY(nvlist_dup(dev[i], &newdev[j++], KM_PUSHPAGE) == 0);
|
||||
}
|
||||
|
||||
VERIFY(nvlist_remove(config, name, DATA_TYPE_NVLIST_ARRAY) == 0);
|
||||
@@ -5291,10 +5291,10 @@ spa_sync_nvlist(spa_t *spa, uint64_t obj, nvlist_t *nv, dmu_tx_t *tx)
|
||||
* saves us a pre-read to get data we don't actually care about.
|
||||
*/
|
||||
bufsize = P2ROUNDUP(nvsize, SPA_CONFIG_BLOCKSIZE);
|
||||
packed = vmem_alloc(bufsize, KM_SLEEP);
|
||||
packed = vmem_alloc(bufsize, KM_PUSHPAGE);
|
||||
|
||||
VERIFY(nvlist_pack(nv, &packed, &nvsize, NV_ENCODE_XDR,
|
||||
KM_SLEEP) == 0);
|
||||
KM_PUSHPAGE) == 0);
|
||||
bzero(packed + nvsize, bufsize - nvsize);
|
||||
|
||||
dmu_write(spa->spa_meta_objset, obj, 0, bufsize, packed, tx);
|
||||
@@ -5332,11 +5332,11 @@ spa_sync_aux_dev(spa_t *spa, spa_aux_vdev_t *sav, dmu_tx_t *tx,
|
||||
&sav->sav_object, tx) == 0);
|
||||
}
|
||||
|
||||
VERIFY(nvlist_alloc(&nvroot, NV_UNIQUE_NAME, KM_SLEEP) == 0);
|
||||
VERIFY(nvlist_alloc(&nvroot, NV_UNIQUE_NAME, KM_PUSHPAGE) == 0);
|
||||
if (sav->sav_count == 0) {
|
||||
VERIFY(nvlist_add_nvlist_array(nvroot, config, NULL, 0) == 0);
|
||||
} else {
|
||||
list = kmem_alloc(sav->sav_count * sizeof (void *), KM_SLEEP);
|
||||
list = kmem_alloc(sav->sav_count * sizeof (void *), KM_PUSHPAGE);
|
||||
for (i = 0; i < sav->sav_count; i++)
|
||||
list[i] = vdev_config_generate(spa, sav->sav_vdevs[i],
|
||||
B_FALSE, VDEV_CONFIG_L2CACHE);
|
||||
|
||||
Reference in New Issue
Block a user