From: Ursula Braun <ubraun-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: hch-jcswGhMUV9g@public.gmane.org,
schwidefsky-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org,
heiko.carstens-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org,
hwippel-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org,
raspl-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org,
ubraun-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org
Subject: [RFC net-next 09/10] net/smc: cleanup function __smc_buf_create()
Date: Thu, 20 Jul 2017 14:09:45 +0200 [thread overview]
Message-ID: <20170720120946.67234-10-ubraun@linux.vnet.ibm.com> (raw)
In-Reply-To: <20170720120946.67234-1-ubraun-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Split function __smc_buf_create() for better readability.
Signed-off-by: Ursula Braun <ubraun-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
net/smc/smc_core.c | 111 ++++++++++++++++++++++++++++++-----------------------
1 file changed, 62 insertions(+), 49 deletions(-)
diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
index 744a61f21572..3232ae2d32e3 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -487,6 +487,64 @@ static inline int smc_rmb_wnd_update_limit(int rmbe_size)
return min_t(int, rmbe_size / 10, SOCK_MIN_SNDBUF / 2);
}
+static struct smc_buf_desc *smc_new_buf_create(struct smc_link_group *lgr,
+ bool is_rmb, int bufsize)
+{
+ struct smc_buf_desc *buf_desc;
+ struct smc_link *lnk;
+ int rc;
+
+ /* try to alloc a new buffer */
+ buf_desc = kzalloc(sizeof(*buf_desc), GFP_KERNEL);
+ if (!buf_desc)
+ return ERR_PTR(-ENOMEM);
+
+ buf_desc->cpu_addr =
+ (void *)__get_free_pages(GFP_KERNEL | __GFP_NOWARN |
+ __GFP_NOMEMALLOC |
+ __GFP_NORETRY | __GFP_ZERO,
+ get_order(bufsize));
+ if (!buf_desc->cpu_addr) {
+ kfree(buf_desc);
+ return NULL;
+ }
+ buf_desc->order = get_order(bufsize);
+
+ /* build the sg table from the pages */
+ lnk = &lgr->lnk[SMC_SINGLE_LINK];
+ rc = sg_alloc_table(&buf_desc->sgt[SMC_SINGLE_LINK], 1,
+ GFP_KERNEL);
+ if (rc) {
+ smc_buf_free(buf_desc, lnk, is_rmb);
+ return NULL;
+ }
+ sg_set_buf(buf_desc->sgt[SMC_SINGLE_LINK].sgl,
+ buf_desc->cpu_addr, bufsize);
+
+ /* map sg table to DMA address */
+ rc = smc_ib_buf_map_sg(lnk->smcibdev, buf_desc,
+ is_rmb ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
+ /* SMC protocol depends on mapping to one DMA address only */
+ if (rc != 1) {
+ smc_buf_free(buf_desc, lnk, is_rmb);
+ return NULL;
+ }
+
+ /* create a new memory region for the RMB */
+ if (is_rmb) {
+ rc = smc_ib_get_memory_region(lnk->roce_pd,
+ IB_ACCESS_REMOTE_WRITE |
+ IB_ACCESS_LOCAL_WRITE,
+ buf_desc);
+ if (rc) {
+ smc_buf_free(buf_desc, lnk, is_rmb);
+ return NULL;
+ }
+ }
+
+ return buf_desc;
+}
+
static int __smc_buf_create(struct smc_sock *smc, bool is_rmb)
{
struct smc_connection *conn = &smc->conn;
@@ -494,12 +552,9 @@ struct smc_link_group *lgr = conn->lgr;
struct smc_buf_desc *buf_desc = NULL;
struct list_head *buf_list;
int bufsize, bufsize_short;
- struct smc_link *lnk;
int sk_buf_size;
rwlock_t *lock;
- int rc;
- lnk = &lgr->lnk[SMC_SINGLE_LINK];
if (is_rmb)
/* use socket recv buffer size (w/o overhead) as start value */
sk_buf_size = smc->sk.sk_rcvbuf / 2;
@@ -528,53 +583,11 @@ struct smc_link_group *lgr = conn->lgr;
break; /* found reusable slot */
}
- /* try to allocate the determined number of pages */
- buf_desc = kzalloc(sizeof(*buf_desc), GFP_KERNEL);
+ buf_desc = smc_new_buf_create(lgr, is_rmb, bufsize);
+ if (IS_ERR(buf_desc))
+ break;
if (!buf_desc)
- break; /* give up with -ENOMEM */
-
- buf_desc->cpu_addr =
- (void *)__get_free_pages(GFP_KERNEL | __GFP_NOWARN |
- __GFP_NOMEMALLOC |
- __GFP_NORETRY | __GFP_ZERO,
- get_order(bufsize));
- if (!buf_desc->cpu_addr) {
- kfree(buf_desc);
- continue;
- }
-
- rc = sg_alloc_table(&buf_desc->sgt[SMC_SINGLE_LINK], 1,
- GFP_KERNEL);
- if (rc) {
- smc_buf_free(buf_desc, lnk, is_rmb);
- buf_desc = NULL;
- continue;
- }
- sg_set_buf(buf_desc->sgt[SMC_SINGLE_LINK].sgl,
- buf_desc->cpu_addr, bufsize);
-
- /* map sg table to DMA address */
- rc = smc_ib_buf_map_sg(lnk->smcibdev, buf_desc, is_rmb ?
- DMA_FROM_DEVICE : DMA_TO_DEVICE);
- /* SMC protocol depends on mapping to one DMA address only */
- if (rc != 1) {
- smc_buf_free(buf_desc, lnk, is_rmb);
- buf_desc = NULL;
- continue; /* if mapping failed, try smaller one */
- }
-
- /* create a new memory region for the RMB */
- if (is_rmb) {
- rc = smc_ib_get_memory_region(lnk->roce_pd,
- IB_ACCESS_REMOTE_WRITE |
- IB_ACCESS_LOCAL_WRITE,
- buf_desc);
- if (rc) {
- smc_buf_free(buf_desc, lnk, is_rmb);
- buf_desc = NULL;
- continue;
- }
- }
+ break;
buf_desc->used = 1;
write_lock_bh(lock);
--
2.11.2
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2017-07-20 12:09 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-20 12:09 [RFC net-next 00/10] net/smc: get rid of unsafe_global_rkey Ursula Braun
[not found] ` <20170720120946.67234-1-ubraun-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2017-07-20 12:09 ` [RFC net-next 01/10] net/smc: serialize connection creation in all cases Ursula Braun
2017-07-20 12:09 ` [RFC net-next 02/10] net/smc: shorten local bufsize variables Ursula Braun
2017-07-20 12:09 ` [RFC net-next 03/10] net/smc: introduce sg-logic for RMBs Ursula Braun
[not found] ` <20170720120946.67234-4-ubraun-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2017-07-20 15:13 ` Sagi Grimberg
2017-07-20 12:09 ` [RFC net-next 04/10] net/smc: use separate memory regions " Ursula Braun
2017-07-20 12:09 ` [RFC net-next 05/10] net/smc: register RMB-related memory region Ursula Braun
[not found] ` <20170720120946.67234-6-ubraun-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2017-07-20 15:17 ` Sagi Grimberg
[not found] ` <8df0459f-b2be-53f1-a7c3-388ca22a128c-NQWnxTmZq1alnMjI0IkVqw@public.gmane.org>
2017-07-20 15:47 ` Parav Pandit
2017-07-21 7:47 ` Ursula Braun
2017-07-20 12:09 ` [RFC net-next 06/10] net/smc: remove Kconfig warning Ursula Braun
2017-07-20 12:09 ` [RFC net-next 07/10] net/smc: introduce sg-logic for send buffers Ursula Braun
2017-07-20 12:09 ` [RFC net-next 08/10] net/smc: common functions for RMBs and " Ursula Braun
2017-07-20 12:09 ` Ursula Braun [this message]
2017-07-20 12:09 ` [RFC net-next 10/10] net/smc: synchronize buffer usage with device Ursula Braun
2017-07-20 15:06 ` [RFC net-next 00/10] net/smc: get rid of unsafe_global_rkey Sagi Grimberg
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=20170720120946.67234-10-ubraun@linux.vnet.ibm.com \
--to=ubraun-23vcf4htsmix0ybbhkvfkdbpr1lh4cv8@public.gmane.org \
--cc=hch-jcswGhMUV9g@public.gmane.org \
--cc=heiko.carstens-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org \
--cc=hwippel-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=raspl-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org \
--cc=schwidefsky-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox