All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peng Tao <bergwolf@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org,
	Andriy Skulysh <Andriy_Skulysh@xyratex.com>,
	Niu Yawei <yawei.niu@intel.com>, Peng Tao <bergwolf@gmail.com>,
	Andreas Dilger <andreas.dilger@intel.com>
Subject: [PATCH 05/39] staging/lustre/ptlrpc: add rpc_cache
Date: Fri, 15 Nov 2013 00:32:28 +0800	[thread overview]
Message-ID: <1384446782-13741-6-git-send-email-bergwolf@gmail.com> (raw)
In-Reply-To: <1384446782-13741-1-git-send-email-bergwolf@gmail.com>

From: Andriy Skulysh <Andriy_Skulysh@xyratex.com>

Add rpc_cache for allocating ptlrpc_requests.

Lustre-change: http://review.whamcloud.com/6874
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-2424
Signed-off-by: Andriy Skulysh <Andriy_Skulysh@xyratex.com>
Signed-off-by: Niu Yawei <yawei.niu@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Lai Siyao <lai.siyao@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
Signed-off-by: Peng Tao <bergwolf@gmail.com>
Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
---
 drivers/staging/lustre/lustre/ptlrpc/client.c      |   42 ++++++++++++++++----
 drivers/staging/lustre/lustre/ptlrpc/events.c      |    2 +-
 .../staging/lustre/lustre/ptlrpc/ptlrpc_internal.h |    4 ++
 .../staging/lustre/lustre/ptlrpc/ptlrpc_module.c   |   24 +++++++----
 drivers/staging/lustre/lustre/ptlrpc/sec.c         |    6 +--
 drivers/staging/lustre/lustre/ptlrpc/service.c     |   13 +++---
 6 files changed, 65 insertions(+), 26 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c
index faa982a..9cdee5e 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/client.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/client.c
@@ -378,6 +378,34 @@ static int ptlrpc_at_recv_early_reply(struct ptlrpc_request *req)
 	return rc;
 }
 
+struct kmem_cache *request_cache;
+
+int ptlrpc_request_cache_init()
+{
+	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()
+{
+	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.
  * Frees all requests from the pool too
@@ -396,7 +424,7 @@ void ptlrpc_free_rq_pool(struct ptlrpc_request_pool *pool)
 		LASSERT(req->rq_reqbuf);
 		LASSERT(req->rq_reqbuf_len == 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);
 	OBD_FREE(pool, sizeof(*pool));
@@ -426,12 +454,12 @@ void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq)
 		struct lustre_msg *msg;
 
 		spin_unlock(&pool->prp_lock);
-		OBD_ALLOC(req, sizeof(struct ptlrpc_request));
+		req = ptlrpc_request_cache_alloc(__GFP_IO);
 		if (!req)
 			return;
 		OBD_ALLOC_LARGE(msg, size);
 		if (!msg) {
-			OBD_FREE(req, sizeof(struct ptlrpc_request));
+			ptlrpc_request_cache_free(req);
 			return;
 		}
 		req->rq_reqbuf = msg;
@@ -667,7 +695,7 @@ struct ptlrpc_request *__ptlrpc_request_alloc(struct obd_import *imp,
 		request = ptlrpc_prep_req_from_pool(pool);
 
 	if (!request)
-		OBD_ALLOC_PTR(request);
+		request = ptlrpc_request_cache_alloc(__GFP_IO);
 
 	if (request) {
 		LASSERTF((unsigned long)imp > 0x1000, "%p", imp);
@@ -738,7 +766,7 @@ void ptlrpc_request_free(struct ptlrpc_request *request)
 	if (request->rq_pool)
 		__ptlrpc_free_req_to_pool(request);
 	else
-		OBD_FREE_PTR(request);
+		ptlrpc_request_cache_free(request);
 }
 EXPORT_SYMBOL(ptlrpc_request_free);
 
@@ -2216,7 +2244,7 @@ static void __ptlrpc_free_req(struct ptlrpc_request *request, int locked)
 	if (request->rq_pool)
 		__ptlrpc_free_req_to_pool(request);
 	else
-		OBD_FREE(request, sizeof(*request));
+		ptlrpc_request_cache_free(request);
 }
 
 static int __ptlrpc_req_finished(struct ptlrpc_request *request, int locked);
@@ -2934,7 +2962,7 @@ void *ptlrpcd_alloc_work(struct obd_import *imp,
 		return ERR_PTR(-EINVAL);
 
 	/* copy some code from deprecated fakereq. */
-	OBD_ALLOC_PTR(req);
+	req = ptlrpc_request_cache_alloc(__GFP_IO);
 	if (req == NULL) {
 		CERROR("ptlrpc: run out of memory!\n");
 		return ERR_PTR(-ENOMEM);
diff --git a/drivers/staging/lustre/lustre/ptlrpc/events.c b/drivers/staging/lustre/lustre/ptlrpc/events.c
index 58d089c..f5e0d31 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/events.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/events.c
@@ -307,7 +307,7 @@ void request_in_callback(lnet_event_t *ev)
 			/* We moaned above already... */
 			return;
 		}
-		OBD_ALLOC_GFP(req, sizeof(*req), ALLOC_ATOMIC_TRY);
+		req = ptlrpc_request_cache_alloc(ALLOC_ATOMIC_TRY);
 		if (req == NULL) {
 			CERROR("Can't allocate incoming request descriptor: "
 			       "Dropping %s RPC from %s\n",
diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h
index ab36347..fa54c5a 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h
+++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h
@@ -55,6 +55,10 @@ int ptlrpcd_start(int index, int max, const char *name, struct ptlrpcd_ctl *pc);
 /* client.c */
 struct ptlrpc_bulk_desc *ptlrpc_new_bulk(unsigned npages, unsigned max_brw,
 					 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);
 
 /* events.c */
diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_module.c b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_module.c
index 419e634..938aaed 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_module.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_module.c
@@ -73,29 +73,34 @@ __init int ptlrpc_init(void)
 		return rc;
 
 	cleanup_phase = 1;
+	rc = ptlrpc_request_cache_init();
+	if (rc)
+		GOTO(cleanup, rc);
 
+	cleanup_phase = 2;
 	rc = ptlrpc_init_portals();
 	if (rc)
 		GOTO(cleanup, rc);
-	cleanup_phase = 2;
+
+	cleanup_phase = 3;
 
 	rc = ptlrpc_connection_init();
 	if (rc)
 		GOTO(cleanup, rc);
-	cleanup_phase = 3;
 
+	cleanup_phase = 4;
 	ptlrpc_put_connection_superhack = ptlrpc_connection_put;
 
 	rc = ptlrpc_start_pinger();
 	if (rc)
 		GOTO(cleanup, rc);
-	cleanup_phase = 4;
 
+	cleanup_phase = 5;
 	rc = ldlm_init();
 	if (rc)
 		GOTO(cleanup, rc);
-	cleanup_phase = 5;
 
+	cleanup_phase = 6;
 	rc = sptlrpc_init();
 	if (rc)
 		GOTO(cleanup, rc);
@@ -117,14 +122,16 @@ cleanup:
 		ptlrpc_nrs_fini();
 	case 7:
 		sptlrpc_fini();
-	case 5:
+	case 6:
 		ldlm_exit();
-	case 4:
+	case 5:
 		ptlrpc_stop_pinger();
-	case 3:
+	case 4:
 		ptlrpc_connection_fini();
-	case 2:
+	case 3:
 		ptlrpc_exit_portals();
+	case 2:
+		ptlrpc_request_cache_fini();
 	case 1:
 		ptlrpc_hr_fini();
 		req_layout_fini();
@@ -142,6 +149,7 @@ static void __exit ptlrpc_exit(void)
 	ldlm_exit();
 	ptlrpc_stop_pinger();
 	ptlrpc_exit_portals();
+	ptlrpc_request_cache_fini();
 	ptlrpc_hr_fini();
 	ptlrpc_connection_fini();
 }
diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec.c b/drivers/staging/lustre/lustre/ptlrpc/sec.c
index 962b31d..7a10f73 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/sec.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec.c
@@ -904,7 +904,7 @@ int sptlrpc_import_check_ctx(struct obd_import *imp)
 		return -EACCES;
 	}
 
-	OBD_ALLOC_PTR(req);
+	req = ptlrpc_request_cache_alloc(__GFP_IO);
 	if (!req)
 		return -ENOMEM;
 
@@ -920,7 +920,7 @@ int sptlrpc_import_check_ctx(struct obd_import *imp)
 	rc = sptlrpc_req_refresh_ctx(req, 0);
 	LASSERT(list_empty(&req->rq_ctx_chain));
 	sptlrpc_cli_ctx_put(req->rq_cli_ctx, 1);
-	OBD_FREE_PTR(req);
+	ptlrpc_request_cache_free(req);
 
 	return rc;
 }
@@ -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);
 	OBD_FREE_LARGE(early_req->rq_repbuf, early_req->rq_repbuf_len);
-	OBD_FREE_PTR(early_req);
+	ptlrpc_request_cache_free(early_req);
 }
 
 /**************************************************
diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c
index 21de868..abd0b8d 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/service.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/service.c
@@ -842,7 +842,7 @@ static void ptlrpc_server_free_request(struct ptlrpc_request *req)
 		/* NB request buffers use an embedded
 		 * req if the incoming req unlinked the
 		 * MD; this isn't one of them! */
-		OBD_FREE(req, sizeof(*req));
+		ptlrpc_request_cache_free(req);
 	}
 }
 
@@ -1306,14 +1306,12 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req)
 	}
 	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)
 		return -ENOMEM;
 	OBD_ALLOC_LARGE(reqmsg, req->rq_reqlen);
-	if (!reqmsg) {
-		OBD_FREE(reqcopy, sizeof(*reqcopy));
-		return -ENOMEM;
-	}
+	if (!reqmsg)
+		GOTO(out_free, rc = -ENOMEM);
 
 	*reqcopy = *req;
 	reqcopy->rq_reply_state = NULL;
@@ -1370,7 +1368,8 @@ out_put:
 out:
 	sptlrpc_svc_ctx_decref(reqcopy);
 	OBD_FREE_LARGE(reqmsg, req->rq_reqlen);
-	OBD_FREE(reqcopy, sizeof(*reqcopy));
+out_free:
+	ptlrpc_request_cache_free(reqcopy);
 	return rc;
 }
 
-- 
1.7.9.5


  parent reply	other threads:[~2013-11-14 16:39 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-14 16:32 [PATCH 00/39] staging/lustre: patch bomb 2 Peng Tao
2013-11-14 16:32 ` [PATCH 01/39] staging/lustre/hsm: remove hsm_nl proc file Peng Tao
2013-11-15  4:26   ` Greg Kroah-Hartman
2013-11-15 10:32     ` Peng Tao
2013-11-14 16:32 ` [PATCH 02/39] staging/lustre/clio: wrong cl_lock usage Peng Tao
2013-11-14 16:32 ` [PATCH 03/39] staging/lustre/build: fix 'deadcode' errors Peng Tao
2013-11-14 16:32 ` [PATCH 04/39] staging/lustre/build: fix 'integer handling' issues Peng Tao
2013-11-14 16:32 ` Peng Tao [this message]
2013-11-14 16:32 ` [PATCH 06/39] staging/lustre/lnet: build Lustre with Intel OFED for Xeon Phi Peng Tao
2013-11-14 16:32 ` [PATCH 07/39] staging/lustre/osd-ldiskfs: remove dependency on mdd module Peng Tao
2013-11-14 16:32 ` [PATCH 08/39] staging/lustre/libcfs: improve validity test for valid file descriptors Peng Tao
2013-11-14 16:32 ` [PATCH 09/39] staging/lustre/llite: use 64bits flags in ll_lov_setea() Peng Tao
2013-11-14 16:32 ` [PATCH 10/39] staging/lustre/hsm: small fixes for HSM Peng Tao
2013-11-14 16:32 ` [PATCH 11/39] staging/lustre/mdt: CDT cleanup follow-on patch Peng Tao
2013-11-14 16:32 ` [PATCH 12/39] staging/lustre/utils: Posix copytool fixes Peng Tao
2013-11-14 16:32 ` [PATCH 13/39] staging/lustre/lmv: update coding style Peng Tao
2013-11-14 16:32 ` [PATCH 14/39] staging/lustre/hsm: copy start error should set HP_FLAG_COMPLETED Peng Tao
2013-11-14 16:32 ` [PATCH 15/39] staging/lustre/lov: Get the correct address of lmm_objects Peng Tao
2013-11-14 16:32 ` [PATCH 16/39] staging/lustre/lvfs: remove llog_lvfs.c and other lvfs code from llog Peng Tao
2013-11-14 16:32 ` [PATCH 17/39] staging/lustre/llite: reset writeback index in ll_writepages Peng Tao
2013-11-14 16:32 ` [PATCH 18/39] staging/lustre/llite: Delaying creation of client side proc entries Peng Tao
2013-11-14 16:32 ` [PATCH 19/39] staging/lustre/libcfs: Add relocation function to libcfs heap Peng Tao
2013-11-14 16:32 ` [PATCH 20/39] staging/lustre/build: fix 'data race condition' issues Peng Tao
2013-11-14 16:32 ` [PATCH 21/39] staging/lustre/autoconf: remove LC_LOCK_MAP_ACQUIRE test Peng Tao
2013-11-14 16:32 ` [PATCH 22/39] staging/lustre/mdc: document mdc_rpc_lock Peng Tao
2013-11-14 16:32 ` [PATCH 23/39] staging/lustre/autoconf: remove LC_FS_STRUCT_USE_PATH Peng Tao
2013-11-14 16:32 ` [PATCH 24/39] staging/lustre/obdclass: fix wrong device put in case of race Peng Tao
2013-11-14 16:32 ` [PATCH 25/39] staging/lustre/lmv: choose right MDT for open by FID Peng Tao
2013-11-14 16:32 ` [PATCH 26/39] staging/lustre/osd: remove fld lookup during configuration Peng Tao
2013-11-14 16:32 ` [PATCH 27/39] staging/lustre/mdt: HSM EXIST event not triggered at last rm/mv Peng Tao
2013-11-14 16:32 ` [PATCH 28/39] staging/lustre/ldlm: ldlm_flock_deadlock() ASSERTION( req != lock ) failed Peng Tao
2013-11-14 16:32 ` [PATCH 29/39] staging/lustre/changelogs: Account for changelog_ext_rec in CR_MAXSIZE Peng Tao
2013-11-14 16:32 ` [PATCH 30/39] staging/lustre/build: build error with gcc 4.7.0 20110509 Peng Tao
2013-11-14 16:32 ` [PATCH 31/39] staging/lustre/build: fix 'NULL pointer dereference' errors Peng Tao
2013-11-14 16:32 ` [PATCH 32/39] staging/lustre/clio: honor O_NOATIME Peng Tao
2013-11-14 16:32 ` [PATCH 33/39] staging/lustre/llite: return compatible fsid for statfs Peng Tao
2013-11-14 16:32 ` [PATCH 34/39] staging/lustre/llite: cancel open lock before closing file Peng Tao
2013-11-14 16:32 ` [PATCH 35/39] staging/lustre/hsm: Add support to drop all pages for ll_data_version Peng Tao
2013-11-14 16:32 ` [PATCH 36/39] staging/lustre/build: fix 'no effect' errors Peng Tao
2013-11-14 16:33 ` [PATCH 37/39] staging/lustre/obd: add md_stats to MDC and LMV devices Peng Tao
2013-11-14 16:33 ` [PATCH 38/39] staging/lustre/autoconf: remove LC_SECURITY_PLUG test Peng Tao
2013-11-14 16:33 ` [PATCH 39/39] staging/lustre/osc: Lustre returns EINTR from writes when SA_RESTART is set Peng Tao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1384446782-13741-6-git-send-email-bergwolf@gmail.com \
    --to=bergwolf@gmail.com \
    --cc=Andriy_Skulysh@xyratex.com \
    --cc=andreas.dilger@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yawei.niu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.