Skip to content

Commit 84a80f6

Browse files
committed
NFSv4.1: Convert pNFS deviceid to use kfree_rcu()
Use of synchronize_rcu() when unmounting and potentially freeing a lot of deviceids is problematic. There really is no reason why we can't just use kfree_rcu() here. Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
1 parent 2854475 commit 84a80f6

6 files changed

Lines changed: 7 additions & 8 deletions

File tree

‎fs/nfs/blocklayout/dev.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ bl_free_deviceid_node(struct nfs4_deviceid_node *d)
3333
container_of(d, struct pnfs_block_dev, node);
3434

3535
bl_free_device(dev);
36-
kfree(dev);
36+
kfree_rcu(dev, node.rcu);
3737
}
3838

3939
static int

‎fs/nfs/filelayout/filelayoutdev.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ nfs4_fl_free_deviceid(struct nfs4_file_layout_dsaddr *dsaddr)
5555
nfs4_pnfs_ds_put(ds);
5656
}
5757
kfree(dsaddr->stripe_indices);
58-
kfree(dsaddr);
58+
kfree_rcu(dsaddr, id_node.rcu);
5959
}
6060

6161
/* Decode opaque device data and return the result */

‎fs/nfs/flexfilelayout/flexfilelayoutdev.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void nfs4_ff_layout_free_deviceid(struct nfs4_ff_layout_ds *mirror_ds)
3030
{
3131
nfs4_print_deviceid(&mirror_ds->id_node.deviceid);
3232
nfs4_pnfs_ds_put(mirror_ds->ds);
33-
kfree(mirror_ds);
33+
kfree_rcu(mirror_ds, id_node.rcu);
3434
}
3535

3636
/* Decode opaque device data and construct new_ds using it */

‎fs/nfs/objlayout/objio_osd.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ objio_free_deviceid_node(struct nfs4_deviceid_node *d)
5757

5858
dprintk("%s: free od=%p\n", __func__, de->od.od);
5959
osduld_put_device(de->od.od);
60-
kfree(de);
60+
kfree_rcu(d, rcu);
6161
}
6262

6363
struct objio_segment {

‎fs/nfs/pnfs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ struct nfs4_deviceid_node {
302302
unsigned long flags;
303303
unsigned long timestamp_unavailable;
304304
struct nfs4_deviceid deviceid;
305+
struct rcu_head rcu;
305306
atomic_t ref;
306307
};
307308

‎fs/nfs/pnfs_dev.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ __nfs4_find_get_deviceid(struct nfs_server *server,
175175
rcu_read_lock();
176176
d = _lookup_deviceid(server->pnfs_curr_ld, server->nfs_client, id,
177177
hash);
178-
if (d != NULL)
179-
atomic_inc(&d->ref);
178+
if (d != NULL && !atomic_inc_not_zero(&d->ref))
179+
d = NULL;
180180
rcu_read_unlock();
181181
return d;
182182
}
@@ -236,7 +236,6 @@ nfs4_delete_deviceid(const struct pnfs_layoutdriver_type *ld,
236236
}
237237
hlist_del_init_rcu(&d->node);
238238
spin_unlock(&nfs4_deviceid_lock);
239-
synchronize_rcu();
240239

241240
/* balance the initial ref set in pnfs_insert_deviceid */
242241
if (atomic_dec_and_test(&d->ref))
@@ -321,7 +320,6 @@ _deviceid_purge_client(const struct nfs_client *clp, long hash)
321320
if (hlist_empty(&tmp))
322321
return;
323322

324-
synchronize_rcu();
325323
while (!hlist_empty(&tmp)) {
326324
d = hlist_entry(tmp.first, struct nfs4_deviceid_node, tmpnode);
327325
hlist_del(&d->tmpnode);

0 commit comments

Comments
 (0)