Commit 35b2e1b7 authored by Andriy Skulysh's avatar Andriy Skulysh Committed by Greg Kroah-Hartman

staging/lustre/ptlrpc: add rpc_cache

Add rpc_cache for allocating ptlrpc_requests.

Xyratex-bug-id: MRP-689
Signed-off-by: default avatarAndriy Skulysh <Andriy_Skulysh@xyratex.com>
Signed-off-by: default avatarNiu Yawei <yawei.niu@intel.com>
Reviewed-on: http://review.whamcloud.com/6874
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-2424Reviewed-by: default avatarAndreas Dilger <andreas.dilger@intel.com>
Reviewed-by: default avatarLai Siyao <lai.siyao@intel.com>
Signed-off-by: default avatarOleg Drokin <oleg.drokin@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 0dd08092
...@@ -379,6 +379,34 @@ static int ptlrpc_at_recv_early_reply(struct ptlrpc_request *req) ...@@ -379,6 +379,34 @@ static int ptlrpc_at_recv_early_reply(struct ptlrpc_request *req)
return rc; return rc;
} }
struct kmem_cache *request_cache;
int ptlrpc_request_cache_init(void)
{
request_cache = kmem_cache_create("ptlrpc_cache",
sizeof(struct ptlrpc_request),
0, SLAB_HWCACHE_ALIGN, NULL);
return request_cache == NULL ? -ENOMEM : 0;
}
void ptlrpc_request_cache_fini(void)
{
kmem_cache_destroy(request_cache);
}
struct ptlrpc_request *ptlrpc_request_cache_alloc(int flags)
{
struct ptlrpc_request *req;
OBD_SLAB_ALLOC_PTR_GFP(req, request_cache, flags);
return req;
}
void ptlrpc_request_cache_free(struct ptlrpc_request *req)
{
OBD_SLAB_FREE_PTR(req, request_cache);
}
/** /**
* Wind down request pool \a pool. * Wind down request pool \a pool.
* Frees all requests from the pool too * Frees all requests from the pool too
...@@ -397,7 +425,7 @@ void ptlrpc_free_rq_pool(struct ptlrpc_request_pool *pool) ...@@ -397,7 +425,7 @@ void ptlrpc_free_rq_pool(struct ptlrpc_request_pool *pool)
LASSERT(req->rq_reqbuf); LASSERT(req->rq_reqbuf);
LASSERT(req->rq_reqbuf_len == pool->prp_rq_size); LASSERT(req->rq_reqbuf_len == pool->prp_rq_size);
OBD_FREE_LARGE(req->rq_reqbuf, pool->prp_rq_size); OBD_FREE_LARGE(req->rq_reqbuf, pool->prp_rq_size);
OBD_FREE(req, sizeof(*req)); ptlrpc_request_cache_free(req);
} }
spin_unlock(&pool->prp_lock); spin_unlock(&pool->prp_lock);
OBD_FREE(pool, sizeof(*pool)); OBD_FREE(pool, sizeof(*pool));
...@@ -427,12 +455,12 @@ void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq) ...@@ -427,12 +455,12 @@ void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq)
struct lustre_msg *msg; struct lustre_msg *msg;
spin_unlock(&pool->prp_lock); spin_unlock(&pool->prp_lock);
OBD_ALLOC(req, sizeof(struct ptlrpc_request)); req = ptlrpc_request_cache_alloc(__GFP_IO);
if (!req) if (!req)
return; return;
OBD_ALLOC_LARGE(msg, size); OBD_ALLOC_LARGE(msg, size);
if (!msg) { if (!msg) {
OBD_FREE(req, sizeof(struct ptlrpc_request)); ptlrpc_request_cache_free(req);
return; return;
} }
req->rq_reqbuf = msg; req->rq_reqbuf = msg;
...@@ -668,7 +696,7 @@ struct ptlrpc_request *__ptlrpc_request_alloc(struct obd_import *imp, ...@@ -668,7 +696,7 @@ struct ptlrpc_request *__ptlrpc_request_alloc(struct obd_import *imp,
request = ptlrpc_prep_req_from_pool(pool); request = ptlrpc_prep_req_from_pool(pool);
if (!request) if (!request)
OBD_ALLOC_PTR(request); request = ptlrpc_request_cache_alloc(__GFP_IO);
if (request) { if (request) {
LASSERTF((unsigned long)imp > 0x1000, "%p", imp); LASSERTF((unsigned long)imp > 0x1000, "%p", imp);
...@@ -739,7 +767,7 @@ void ptlrpc_request_free(struct ptlrpc_request *request) ...@@ -739,7 +767,7 @@ void ptlrpc_request_free(struct ptlrpc_request *request)
if (request->rq_pool) if (request->rq_pool)
__ptlrpc_free_req_to_pool(request); __ptlrpc_free_req_to_pool(request);
else else
OBD_FREE_PTR(request); ptlrpc_request_cache_free(request);
} }
EXPORT_SYMBOL(ptlrpc_request_free); EXPORT_SYMBOL(ptlrpc_request_free);
...@@ -2233,7 +2261,7 @@ static void __ptlrpc_free_req(struct ptlrpc_request *request, int locked) ...@@ -2233,7 +2261,7 @@ static void __ptlrpc_free_req(struct ptlrpc_request *request, int locked)
if (request->rq_pool) if (request->rq_pool)
__ptlrpc_free_req_to_pool(request); __ptlrpc_free_req_to_pool(request);
else else
OBD_FREE(request, sizeof(*request)); ptlrpc_request_cache_free(request);
} }
static int __ptlrpc_req_finished(struct ptlrpc_request *request, int locked); static int __ptlrpc_req_finished(struct ptlrpc_request *request, int locked);
...@@ -3023,7 +3051,7 @@ void *ptlrpcd_alloc_work(struct obd_import *imp, ...@@ -3023,7 +3051,7 @@ void *ptlrpcd_alloc_work(struct obd_import *imp,
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
/* copy some code from deprecated fakereq. */ /* copy some code from deprecated fakereq. */
OBD_ALLOC_PTR(req); req = ptlrpc_request_cache_alloc(__GFP_IO);
if (req == NULL) { if (req == NULL) {
CERROR("ptlrpc: run out of memory!\n"); CERROR("ptlrpc: run out of memory!\n");
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
......
...@@ -307,7 +307,7 @@ void request_in_callback(lnet_event_t *ev) ...@@ -307,7 +307,7 @@ void request_in_callback(lnet_event_t *ev)
/* We moaned above already... */ /* We moaned above already... */
return; return;
} }
OBD_ALLOC_GFP(req, sizeof(*req), ALLOC_ATOMIC_TRY); req = ptlrpc_request_cache_alloc(ALLOC_ATOMIC_TRY);
if (req == NULL) { if (req == NULL) {
CERROR("Can't allocate incoming request descriptor: " CERROR("Can't allocate incoming request descriptor: "
"Dropping %s RPC from %s\n", "Dropping %s RPC from %s\n",
......
...@@ -55,6 +55,10 @@ int ptlrpcd_start(int index, int max, const char *name, struct ptlrpcd_ctl *pc); ...@@ -55,6 +55,10 @@ int ptlrpcd_start(int index, int max, const char *name, struct ptlrpcd_ctl *pc);
/* client.c */ /* client.c */
struct ptlrpc_bulk_desc *ptlrpc_new_bulk(unsigned npages, unsigned max_brw, struct ptlrpc_bulk_desc *ptlrpc_new_bulk(unsigned npages, unsigned max_brw,
unsigned type, unsigned portal); unsigned type, unsigned portal);
int ptlrpc_request_cache_init(void);
void ptlrpc_request_cache_fini(void);
struct ptlrpc_request *ptlrpc_request_cache_alloc(int flags);
void ptlrpc_request_cache_free(struct ptlrpc_request *req);
void ptlrpc_init_xid(void); void ptlrpc_init_xid(void);
/* events.c */ /* events.c */
......
...@@ -73,29 +73,34 @@ __init int ptlrpc_init(void) ...@@ -73,29 +73,34 @@ __init int ptlrpc_init(void)
return rc; return rc;
cleanup_phase = 1; cleanup_phase = 1;
rc = ptlrpc_request_cache_init();
if (rc)
GOTO(cleanup, rc);
cleanup_phase = 2;
rc = ptlrpc_init_portals(); rc = ptlrpc_init_portals();
if (rc) if (rc)
GOTO(cleanup, rc); GOTO(cleanup, rc);
cleanup_phase = 2;
cleanup_phase = 3;
rc = ptlrpc_connection_init(); rc = ptlrpc_connection_init();
if (rc) if (rc)
GOTO(cleanup, rc); GOTO(cleanup, rc);
cleanup_phase = 3;
cleanup_phase = 4;
ptlrpc_put_connection_superhack = ptlrpc_connection_put; ptlrpc_put_connection_superhack = ptlrpc_connection_put;
rc = ptlrpc_start_pinger(); rc = ptlrpc_start_pinger();
if (rc) if (rc)
GOTO(cleanup, rc); GOTO(cleanup, rc);
cleanup_phase = 4;
cleanup_phase = 5;
rc = ldlm_init(); rc = ldlm_init();
if (rc) if (rc)
GOTO(cleanup, rc); GOTO(cleanup, rc);
cleanup_phase = 5;
cleanup_phase = 6;
rc = sptlrpc_init(); rc = sptlrpc_init();
if (rc) if (rc)
GOTO(cleanup, rc); GOTO(cleanup, rc);
...@@ -115,19 +120,29 @@ __init int ptlrpc_init(void) ...@@ -115,19 +120,29 @@ __init int ptlrpc_init(void)
switch (cleanup_phase) { switch (cleanup_phase) {
case 8: case 8:
ptlrpc_nrs_fini(); ptlrpc_nrs_fini();
/* Fall through */
case 7: case 7:
sptlrpc_fini(); sptlrpc_fini();
case 5: /* Fall through */
case 6:
ldlm_exit(); ldlm_exit();
case 4: /* Fall through */
case 5:
ptlrpc_stop_pinger(); ptlrpc_stop_pinger();
case 3: /* Fall through */
case 4:
ptlrpc_connection_fini(); ptlrpc_connection_fini();
case 2: /* Fall through */
case 3:
ptlrpc_exit_portals(); ptlrpc_exit_portals();
/* Fall through */
case 2:
ptlrpc_request_cache_fini();
/* Fall through */
case 1: case 1:
ptlrpc_hr_fini(); ptlrpc_hr_fini();
req_layout_fini(); req_layout_fini();
/* Fall through */
default: ; default: ;
} }
...@@ -142,6 +157,7 @@ static void __exit ptlrpc_exit(void) ...@@ -142,6 +157,7 @@ static void __exit ptlrpc_exit(void)
ldlm_exit(); ldlm_exit();
ptlrpc_stop_pinger(); ptlrpc_stop_pinger();
ptlrpc_exit_portals(); ptlrpc_exit_portals();
ptlrpc_request_cache_fini();
ptlrpc_hr_fini(); ptlrpc_hr_fini();
ptlrpc_connection_fini(); ptlrpc_connection_fini();
} }
......
...@@ -904,7 +904,7 @@ int sptlrpc_import_check_ctx(struct obd_import *imp) ...@@ -904,7 +904,7 @@ int sptlrpc_import_check_ctx(struct obd_import *imp)
return -EACCES; return -EACCES;
} }
OBD_ALLOC_PTR(req); req = ptlrpc_request_cache_alloc(__GFP_IO);
if (!req) if (!req)
return -ENOMEM; return -ENOMEM;
...@@ -920,7 +920,7 @@ int sptlrpc_import_check_ctx(struct obd_import *imp) ...@@ -920,7 +920,7 @@ int sptlrpc_import_check_ctx(struct obd_import *imp)
rc = sptlrpc_req_refresh_ctx(req, 0); rc = sptlrpc_req_refresh_ctx(req, 0);
LASSERT(list_empty(&req->rq_ctx_chain)); LASSERT(list_empty(&req->rq_ctx_chain));
sptlrpc_cli_ctx_put(req->rq_cli_ctx, 1); sptlrpc_cli_ctx_put(req->rq_cli_ctx, 1);
OBD_FREE_PTR(req); ptlrpc_request_cache_free(req);
return rc; return rc;
} }
...@@ -1088,7 +1088,7 @@ int sptlrpc_cli_unwrap_early_reply(struct ptlrpc_request *req, ...@@ -1088,7 +1088,7 @@ int sptlrpc_cli_unwrap_early_reply(struct ptlrpc_request *req,
int early_bufsz, early_size; int early_bufsz, early_size;
int rc; int rc;
OBD_ALLOC_PTR(early_req); early_req = ptlrpc_request_cache_alloc(__GFP_IO);
if (early_req == NULL) if (early_req == NULL)
return -ENOMEM; return -ENOMEM;
...@@ -1160,7 +1160,7 @@ int sptlrpc_cli_unwrap_early_reply(struct ptlrpc_request *req, ...@@ -1160,7 +1160,7 @@ int sptlrpc_cli_unwrap_early_reply(struct ptlrpc_request *req,
err_buf: err_buf:
OBD_FREE_LARGE(early_buf, early_bufsz); OBD_FREE_LARGE(early_buf, early_bufsz);
err_req: err_req:
OBD_FREE_PTR(early_req); ptlrpc_request_cache_free(early_req);
return rc; return rc;
} }
...@@ -1177,7 +1177,7 @@ void sptlrpc_cli_finish_early_reply(struct ptlrpc_request *early_req) ...@@ -1177,7 +1177,7 @@ void sptlrpc_cli_finish_early_reply(struct ptlrpc_request *early_req)
sptlrpc_cli_ctx_put(early_req->rq_cli_ctx, 1); sptlrpc_cli_ctx_put(early_req->rq_cli_ctx, 1);
OBD_FREE_LARGE(early_req->rq_repbuf, early_req->rq_repbuf_len); OBD_FREE_LARGE(early_req->rq_repbuf, early_req->rq_repbuf_len);
OBD_FREE_PTR(early_req); ptlrpc_request_cache_free(early_req);
} }
/************************************************** /**************************************************
......
...@@ -842,7 +842,7 @@ static void ptlrpc_server_free_request(struct ptlrpc_request *req) ...@@ -842,7 +842,7 @@ static void ptlrpc_server_free_request(struct ptlrpc_request *req)
/* NB request buffers use an embedded /* NB request buffers use an embedded
* req if the incoming req unlinked the * req if the incoming req unlinked the
* MD; this isn't one of them! */ * MD; this isn't one of them! */
OBD_FREE(req, sizeof(*req)); ptlrpc_request_cache_free(req);
} }
} }
...@@ -1305,14 +1305,12 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req) ...@@ -1305,14 +1305,12 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req)
} }
newdl = cfs_time_current_sec() + at_get(&svcpt->scp_at_estimate); newdl = cfs_time_current_sec() + at_get(&svcpt->scp_at_estimate);
OBD_ALLOC(reqcopy, sizeof(*reqcopy)); reqcopy = ptlrpc_request_cache_alloc(__GFP_IO);
if (reqcopy == NULL) if (reqcopy == NULL)
return -ENOMEM; return -ENOMEM;
OBD_ALLOC_LARGE(reqmsg, req->rq_reqlen); OBD_ALLOC_LARGE(reqmsg, req->rq_reqlen);
if (!reqmsg) { if (!reqmsg)
OBD_FREE(reqcopy, sizeof(*reqcopy)); GOTO(out_free, rc = -ENOMEM);
return -ENOMEM;
}
*reqcopy = *req; *reqcopy = *req;
reqcopy->rq_reply_state = NULL; reqcopy->rq_reply_state = NULL;
...@@ -1369,7 +1367,8 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req) ...@@ -1369,7 +1367,8 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req)
out: out:
sptlrpc_svc_ctx_decref(reqcopy); sptlrpc_svc_ctx_decref(reqcopy);
OBD_FREE_LARGE(reqmsg, req->rq_reqlen); OBD_FREE_LARGE(reqmsg, req->rq_reqlen);
OBD_FREE(reqcopy, sizeof(*reqcopy)); out_free:
ptlrpc_request_cache_free(reqcopy);
return rc; return rc;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment