Skip to content

Commit f28cdf0

Browse files
Matthew WilcoxDominique Martinet
authored andcommitted
9p: Replace the fidlist with an IDR
The p9_idpool being used to allocate the IDs uses an IDR to allocate the IDs ... which we then keep in a doubly-linked list, rather than in the IDR which allocated them. We can use an IDR directly which saves two pointers per p9_fid, and a tiny memory allocation per p9_client. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Matthew Wilcox <[email protected]> Cc: Eric Van Hensbergen <[email protected]> Cc: Ron Minnich <[email protected]> Cc: Latchesar Ionkov <[email protected]> Signed-off-by: Dominique Martinet <[email protected]>
1 parent b5303be commit f28cdf0

File tree

2 files changed

+19
-34
lines changed

2 files changed

+19
-34
lines changed

include/net/9p/client.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define NET_9P_CLIENT_H
2828

2929
#include <linux/utsname.h>
30+
#include <linux/idr.h>
3031

3132
/* Number of requests per row */
3233
#define P9_ROW_MAXTAG 255
@@ -128,8 +129,7 @@ struct p9_req_t {
128129
* @proto_version: 9P protocol version to use
129130
* @trans_mod: module API instantiated with this client
130131
* @trans: tranport instance state and API
131-
* @fidpool: fid handle accounting for session
132-
* @fidlist: List of active fid handles
132+
* @fids: All active FID handles
133133
* @tagpool - transaction id accounting for session
134134
* @reqs - 2D array of requests
135135
* @max_tag - current maximum tag id allocated
@@ -169,8 +169,7 @@ struct p9_client {
169169
} tcp;
170170
} trans_opts;
171171

172-
struct p9_idpool *fidpool;
173-
struct list_head fidlist;
172+
struct idr fids;
174173

175174
struct p9_idpool *tagpool;
176175
struct p9_req_t *reqs[P9_ROW_MAXTAG];
@@ -188,7 +187,6 @@ struct p9_client {
188187
* @iounit: the server reported maximum transaction size for this file
189188
* @uid: the numeric uid of the local user who owns this handle
190189
* @rdir: readdir accounting structure (allocated on demand)
191-
* @flist: per-client-instance fid tracking
192190
* @dlist: per-dentry fid tracking
193191
*
194192
* TODO: This needs lots of explanation.
@@ -204,7 +202,6 @@ struct p9_fid {
204202

205203
void *rdir;
206204

207-
struct list_head flist;
208205
struct hlist_node dlist; /* list of all fids attached to a dentry */
209206
};
210207

net/9p/client.c

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -909,30 +909,29 @@ static struct p9_fid *p9_fid_create(struct p9_client *clnt)
909909
{
910910
int ret;
911911
struct p9_fid *fid;
912-
unsigned long flags;
913912

914913
p9_debug(P9_DEBUG_FID, "clnt %p\n", clnt);
915914
fid = kmalloc(sizeof(struct p9_fid), GFP_KERNEL);
916915
if (!fid)
917916
return NULL;
918917

919-
ret = p9_idpool_get(clnt->fidpool);
920-
if (ret < 0)
921-
goto error;
922-
fid->fid = ret;
923-
924918
memset(&fid->qid, 0, sizeof(struct p9_qid));
925919
fid->mode = -1;
926920
fid->uid = current_fsuid();
927921
fid->clnt = clnt;
928922
fid->rdir = NULL;
929-
spin_lock_irqsave(&clnt->lock, flags);
930-
list_add(&fid->flist, &clnt->fidlist);
931-
spin_unlock_irqrestore(&clnt->lock, flags);
923+
fid->fid = 0;
932924

933-
return fid;
925+
idr_preload(GFP_KERNEL);
926+
spin_lock_irq(&clnt->lock);
927+
ret = idr_alloc_u32(&clnt->fids, fid, &fid->fid, P9_NOFID - 1,
928+
GFP_NOWAIT);
929+
spin_unlock_irq(&clnt->lock);
930+
idr_preload_end();
931+
932+
if (!ret)
933+
return fid;
934934

935-
error:
936935
kfree(fid);
937936
return NULL;
938937
}
@@ -944,9 +943,8 @@ static void p9_fid_destroy(struct p9_fid *fid)
944943

945944
p9_debug(P9_DEBUG_FID, "fid %d\n", fid->fid);
946945
clnt = fid->clnt;
947-
p9_idpool_put(fid->fid, clnt->fidpool);
948946
spin_lock_irqsave(&clnt->lock, flags);
949-
list_del(&fid->flist);
947+
idr_remove(&clnt->fids, fid->fid);
950948
spin_unlock_irqrestore(&clnt->lock, flags);
951949
kfree(fid->rdir);
952950
kfree(fid);
@@ -1029,7 +1027,7 @@ struct p9_client *p9_client_create(const char *dev_name, char *options)
10291027
memcpy(clnt->name, client_id, strlen(client_id) + 1);
10301028

10311029
spin_lock_init(&clnt->lock);
1032-
INIT_LIST_HEAD(&clnt->fidlist);
1030+
idr_init(&clnt->fids);
10331031

10341032
err = p9_tag_init(clnt);
10351033
if (err < 0)
@@ -1049,18 +1047,12 @@ struct p9_client *p9_client_create(const char *dev_name, char *options)
10491047
goto destroy_tagpool;
10501048
}
10511049

1052-
clnt->fidpool = p9_idpool_create();
1053-
if (IS_ERR(clnt->fidpool)) {
1054-
err = PTR_ERR(clnt->fidpool);
1055-
goto put_trans;
1056-
}
1057-
10581050
p9_debug(P9_DEBUG_MUX, "clnt %p trans %p msize %d protocol %d\n",
10591051
clnt, clnt->trans_mod, clnt->msize, clnt->proto_version);
10601052

10611053
err = clnt->trans_mod->create(clnt, dev_name, options);
10621054
if (err)
1063-
goto destroy_fidpool;
1055+
goto put_trans;
10641056

10651057
if (clnt->msize > clnt->trans_mod->maxsize)
10661058
clnt->msize = clnt->trans_mod->maxsize;
@@ -1073,8 +1065,6 @@ struct p9_client *p9_client_create(const char *dev_name, char *options)
10731065

10741066
close_trans:
10751067
clnt->trans_mod->close(clnt);
1076-
destroy_fidpool:
1077-
p9_idpool_destroy(clnt->fidpool);
10781068
put_trans:
10791069
v9fs_put_trans(clnt->trans_mod);
10801070
destroy_tagpool:
@@ -1087,7 +1077,8 @@ EXPORT_SYMBOL(p9_client_create);
10871077

10881078
void p9_client_destroy(struct p9_client *clnt)
10891079
{
1090-
struct p9_fid *fid, *fidptr;
1080+
struct p9_fid *fid;
1081+
int id;
10911082

10921083
p9_debug(P9_DEBUG_MUX, "clnt %p\n", clnt);
10931084

@@ -1096,14 +1087,11 @@ void p9_client_destroy(struct p9_client *clnt)
10961087

10971088
v9fs_put_trans(clnt->trans_mod);
10981089

1099-
list_for_each_entry_safe(fid, fidptr, &clnt->fidlist, flist) {
1090+
idr_for_each_entry(&clnt->fids, fid, id) {
11001091
pr_info("Found fid %d not clunked\n", fid->fid);
11011092
p9_fid_destroy(fid);
11021093
}
11031094

1104-
if (clnt->fidpool)
1105-
p9_idpool_destroy(clnt->fidpool);
1106-
11071095
p9_tag_cleanup(clnt);
11081096

11091097
kfree(clnt);

0 commit comments

Comments
 (0)