Re: [PATCH net-next] rds: reduce memory footprint for RDS when transport is RDMA

2017-08-03 Thread David Miller
From: Sowmini Varadhan 
Date: Wed,  2 Aug 2017 10:34:31 -0700

> RDS over IB does not use multipath RDS, so the array
> of additional rds_conn_path structures is always superfluous
> in this case. Reduce the memory footprint of the rds module
> by making this a dynamic allocation predicated on whether
> the transport is mp_capable.
> 
> Signed-off-by: Sowmini Varadhan 
> Acked-by: Santosh Shilimkar 
> Tested-by: Efrain Galaviz 

Applied, thank you.


[PATCH net-next] rds: reduce memory footprint for RDS when transport is RDMA

2017-08-02 Thread Sowmini Varadhan
RDS over IB does not use multipath RDS, so the array
of additional rds_conn_path structures is always superfluous
in this case. Reduce the memory footprint of the rds module
by making this a dynamic allocation predicated on whether
the transport is mp_capable.

Signed-off-by: Sowmini Varadhan 
Acked-by: Santosh Shilimkar 
Tested-by: Efrain Galaviz 
---
 net/rds/connection.c |   34 +-
 net/rds/rds.h|2 +-
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/net/rds/connection.c b/net/rds/connection.c
index 005bca6..7ee2d5d 100644
--- a/net/rds/connection.c
+++ b/net/rds/connection.c
@@ -151,6 +151,7 @@ static void __rds_conn_path_init(struct rds_connection 
*conn,
struct rds_transport *loop_trans;
unsigned long flags;
int ret, i;
+   int npaths = (trans->t_mp_capable ? RDS_MPATH_WORKERS : 1);
 
rcu_read_lock();
conn = rds_conn_lookup(net, head, laddr, faddr, trans);
@@ -172,6 +173,12 @@ static void __rds_conn_path_init(struct rds_connection 
*conn,
conn = ERR_PTR(-ENOMEM);
goto out;
}
+   conn->c_path = kcalloc(npaths, sizeof(struct rds_conn_path), gfp);
+   if (!conn->c_path) {
+   kmem_cache_free(rds_conn_slab, conn);
+   conn = ERR_PTR(-ENOMEM);
+   goto out;
+   }
 
INIT_HLIST_NODE(>c_hash_node);
conn->c_laddr = laddr;
@@ -181,6 +188,7 @@ static void __rds_conn_path_init(struct rds_connection 
*conn,
 
ret = rds_cong_get_maps(conn);
if (ret) {
+   kfree(conn->c_path);
kmem_cache_free(rds_conn_slab, conn);
conn = ERR_PTR(ret);
goto out;
@@ -207,13 +215,14 @@ static void __rds_conn_path_init(struct rds_connection 
*conn,
conn->c_trans = trans;
 
init_waitqueue_head(>c_hs_waitq);
-   for (i = 0; i < RDS_MPATH_WORKERS; i++) {
+   for (i = 0; i < npaths; i++) {
__rds_conn_path_init(conn, >c_path[i],
 is_outgoing);
conn->c_path[i].cp_index = i;
}
ret = trans->conn_alloc(conn, gfp);
if (ret) {
+   kfree(conn->c_path);
kmem_cache_free(rds_conn_slab, conn);
conn = ERR_PTR(ret);
goto out;
@@ -236,6 +245,7 @@ static void __rds_conn_path_init(struct rds_connection 
*conn,
/* Creating passive conn */
if (parent->c_passive) {
trans->conn_free(conn->c_path[0].cp_transport_data);
+   kfree(conn->c_path);
kmem_cache_free(rds_conn_slab, conn);
conn = parent->c_passive;
} else {
@@ -252,7 +262,7 @@ static void __rds_conn_path_init(struct rds_connection 
*conn,
struct rds_conn_path *cp;
int i;
 
-   for (i = 0; i < RDS_MPATH_WORKERS; i++) {
+   for (i = 0; i < npaths; i++) {
cp = >c_path[i];
/* The ->conn_alloc invocation may have
 * allocated resource for all paths, so all
@@ -261,6 +271,7 @@ static void __rds_conn_path_init(struct rds_connection 
*conn,
if (cp->cp_transport_data)
trans->conn_free(cp->cp_transport_data);
}
+   kfree(conn->c_path);
kmem_cache_free(rds_conn_slab, conn);
conn = found;
} else {
@@ -407,6 +418,7 @@ void rds_conn_destroy(struct rds_connection *conn)
unsigned long flags;
int i;
struct rds_conn_path *cp;
+   int npaths = (conn->c_trans->t_mp_capable ? RDS_MPATH_WORKERS : 1);
 
rdsdebug("freeing conn %p for %pI4 -> "
 "%pI4\n", conn, >c_laddr,
@@ -420,7 +432,7 @@ void rds_conn_destroy(struct rds_connection *conn)
synchronize_rcu();
 
/* shut the connection down */
-   for (i = 0; i < RDS_MPATH_WORKERS; i++) {
+   for (i = 0; i < npaths; i++) {
cp = >c_path[i];
rds_conn_path_destroy(cp);
BUG_ON(!list_empty(>cp_retrans));
@@ -434,6 +446,7 @@ void rds_conn_destroy(struct rds_connection *conn)
rds_cong_remove_conn(conn);
 
put_net(conn->c_net);
+   kfree(conn->c_path);
kmem_cache_free(rds_conn_slab, conn);
 
spin_lock_irqsave(_conn_lock, flags);
@@ -464,8 +477,12 @@ static void rds_conn_message_info(struct socket *sock, 
unsigned int len,
 i++, head++) {
hlist_for_each_entry_rcu(conn, head, c_hash_node) {
struct rds_conn_path *cp;
+   int npaths;