]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/rds/ib_recv.c
RDS: Refill recv ring directly from tasklet
[net-next-2.6.git] / net / rds / ib_recv.c
index c74e9904a6b2c20872917c79bf06a905c1ecd403..8f041f7954a28d11528037d3a79feba64b4a703f 100644 (file)
@@ -53,7 +53,7 @@ static void rds_ib_frag_drop_page(struct rds_page_frag *frag)
 static void rds_ib_frag_free(struct rds_page_frag *frag)
 {
        rdsdebug("frag %p page %p\n", frag, frag->f_page);
-       BUG_ON(frag->f_page != NULL);
+       BUG_ON(frag->f_page);
        kmem_cache_free(rds_ib_frag_slab, frag);
 }
 
@@ -95,15 +95,15 @@ void rds_ib_recv_init_ring(struct rds_ib_connection *ic)
                recv->r_wr.sg_list = recv->r_sge;
                recv->r_wr.num_sge = RDS_IB_RECV_SGE;
 
-               sge = rds_ib_data_sge(ic, recv->r_sge);
-               sge->addr = 0;
-               sge->length = RDS_FRAG_SIZE;
-               sge->lkey = ic->i_mr->lkey;
-
-               sge = rds_ib_header_sge(ic, recv->r_sge);
+               sge = &recv->r_sge[0];
                sge->addr = ic->i_recv_hdrs_dma + (i * sizeof(struct rds_header));
                sge->length = sizeof(struct rds_header);
                sge->lkey = ic->i_mr->lkey;
+
+               sge = &recv->r_sge[1];
+               sge->addr = 0;
+               sge->length = RDS_FRAG_SIZE;
+               sge->lkey = ic->i_mr->lkey;
        }
 }
 
@@ -135,22 +135,20 @@ void rds_ib_recv_clear_ring(struct rds_ib_connection *ic)
 }
 
 static int rds_ib_recv_refill_one(struct rds_connection *conn,
-                                 struct rds_ib_recv_work *recv,
-                                 gfp_t kptr_gfp, gfp_t page_gfp)
+                                 struct rds_ib_recv_work *recv)
 {
        struct rds_ib_connection *ic = conn->c_transport_data;
        dma_addr_t dma_addr;
        struct ib_sge *sge;
        int ret = -ENOMEM;
 
-       if (recv->r_ibinc == NULL) {
+       if (!recv->r_ibinc) {
                if (!atomic_add_unless(&rds_ib_allocation, 1, rds_ib_sysctl_max_recv_allocation)) {
                        rds_ib_stats_inc(s_ib_rx_alloc_limit);
                        goto out;
                }
-               recv->r_ibinc = kmem_cache_alloc(rds_ib_incoming_slab,
-                                                kptr_gfp);
-               if (recv->r_ibinc == NULL) {
+               recv->r_ibinc = kmem_cache_alloc(rds_ib_incoming_slab, GFP_NOWAIT);
+               if (!recv->r_ibinc) {
                        atomic_dec(&rds_ib_allocation);
                        goto out;
                }
@@ -158,17 +156,17 @@ static int rds_ib_recv_refill_one(struct rds_connection *conn,
                rds_inc_init(&recv->r_ibinc->ii_inc, conn, conn->c_faddr);
        }
 
-       if (recv->r_frag == NULL) {
-               recv->r_frag = kmem_cache_alloc(rds_ib_frag_slab, kptr_gfp);
-               if (recv->r_frag == NULL)
+       if (!recv->r_frag) {
+               recv->r_frag = kmem_cache_alloc(rds_ib_frag_slab, GFP_NOWAIT);
+               if (!recv->r_frag)
                        goto out;
                INIT_LIST_HEAD(&recv->r_frag->f_item);
                recv->r_frag->f_page = NULL;
        }
 
-       if (ic->i_frag.f_page == NULL) {
-               ic->i_frag.f_page = alloc_page(page_gfp);
-               if (ic->i_frag.f_page == NULL)
+       if (!ic->i_frag.f_page) {
+               ic->i_frag.f_page = alloc_page(GFP_NOWAIT);
+               if (!ic->i_frag.f_page)
                        goto out;
                ic->i_frag.f_offset = 0;
        }
@@ -190,14 +188,14 @@ static int rds_ib_recv_refill_one(struct rds_connection *conn,
        recv->r_frag->f_offset = ic->i_frag.f_offset;
        recv->r_frag->f_mapped = dma_addr;
 
-       sge = rds_ib_data_sge(ic, recv->r_sge);
-       sge->addr = dma_addr;
-       sge->length = RDS_FRAG_SIZE;
-
-       sge = rds_ib_header_sge(ic, recv->r_sge);
+       sge = &recv->r_sge[0];
        sge->addr = ic->i_recv_hdrs_dma + (recv - ic->i_recvs) * sizeof(struct rds_header);
        sge->length = sizeof(struct rds_header);
 
+       sge = &recv->r_sge[1];
+       sge->addr = dma_addr;
+       sge->length = RDS_FRAG_SIZE;
+
        get_page(recv->r_frag->f_page);
 
        if (ic->i_frag.f_offset < RDS_PAGE_LAST_OFF) {
@@ -221,8 +219,7 @@ out:
  *
  * -1 is returned if posting fails due to temporary resource exhaustion.
  */
-int rds_ib_recv_refill(struct rds_connection *conn, gfp_t kptr_gfp,
-                      gfp_t page_gfp, int prefill)
+int rds_ib_recv_refill(struct rds_connection *conn, int prefill)
 {
        struct rds_ib_connection *ic = conn->c_transport_data;
        struct rds_ib_recv_work *recv;
@@ -241,7 +238,7 @@ int rds_ib_recv_refill(struct rds_connection *conn, gfp_t kptr_gfp,
                }
 
                recv = &ic->i_recvs[pos];
-               ret = rds_ib_recv_refill_one(conn, recv, kptr_gfp, page_gfp);
+               ret = rds_ib_recv_refill_one(conn, recv);
                if (ret) {
                        ret = -1;
                        break;
@@ -273,7 +270,7 @@ int rds_ib_recv_refill(struct rds_connection *conn, gfp_t kptr_gfp,
        return ret;
 }
 
-void rds_ib_inc_purge(struct rds_incoming *inc)
+static void rds_ib_inc_purge(struct rds_incoming *inc)
 {
        struct rds_ib_incoming *ibinc;
        struct rds_page_frag *frag;
@@ -557,47 +554,6 @@ u64 rds_ib_piggyb_ack(struct rds_ib_connection *ic)
        return rds_ib_get_ack(ic);
 }
 
-static struct rds_header *rds_ib_get_header(struct rds_connection *conn,
-                                           struct rds_ib_recv_work *recv,
-                                           u32 data_len)
-{
-       struct rds_ib_connection *ic = conn->c_transport_data;
-       void *hdr_buff = &ic->i_recv_hdrs[recv - ic->i_recvs];
-       void *addr;
-       u32 misplaced_hdr_bytes;
-
-       /*
-        * Support header at the front (RDS 3.1+) as well as header-at-end.
-        *
-        * Cases:
-        * 1) header all in header buff (great!)
-        * 2) header all in data page (copy all to header buff)
-        * 3) header split across hdr buf + data page
-        *    (move bit in hdr buff to end before copying other bit from data page)
-        */
-       if (conn->c_version > RDS_PROTOCOL_3_0 || data_len == RDS_FRAG_SIZE)
-               return hdr_buff;
-
-       if (data_len <= (RDS_FRAG_SIZE - sizeof(struct rds_header))) {
-               addr = kmap_atomic(recv->r_frag->f_page, KM_SOFTIRQ0);
-               memcpy(hdr_buff,
-                      addr + recv->r_frag->f_offset + data_len,
-                      sizeof(struct rds_header));
-               kunmap_atomic(addr, KM_SOFTIRQ0);
-               return hdr_buff;
-       }
-
-       misplaced_hdr_bytes = (sizeof(struct rds_header) - (RDS_FRAG_SIZE - data_len));
-
-       memmove(hdr_buff + misplaced_hdr_bytes, hdr_buff, misplaced_hdr_bytes);
-
-       addr = kmap_atomic(recv->r_frag->f_page, KM_SOFTIRQ0);
-       memcpy(hdr_buff, addr + recv->r_frag->f_offset + data_len,
-              sizeof(struct rds_header) - misplaced_hdr_bytes);
-       kunmap_atomic(addr, KM_SOFTIRQ0);
-       return hdr_buff;
-}
-
 /*
  * It's kind of lame that we're copying from the posted receive pages into
  * long-lived bitmaps.  We could have posted the bitmaps and rdma written into
@@ -710,7 +666,7 @@ static void rds_ib_process_recv(struct rds_connection *conn,
        }
        data_len -= sizeof(struct rds_header);
 
-       ihdr = rds_ib_get_header(conn, recv, data_len);
+       ihdr = &ic->i_recv_hdrs[recv - ic->i_recvs];
 
        /* Validate the checksum. */
        if (!rds_message_verify_checksum(ihdr)) {
@@ -757,7 +713,7 @@ static void rds_ib_process_recv(struct rds_connection *conn,
         * into the inc and save the inc so we can hang upcoming fragments
         * off its list.
         */
-       if (ibinc == NULL) {
+       if (!ibinc) {
                ibinc = recv->r_ibinc;
                recv->r_ibinc = NULL;
                ic->i_ibinc = ibinc;
@@ -897,11 +853,8 @@ void rds_ib_recv_tasklet_fn(unsigned long data)
        if (rds_ib_ring_empty(&ic->i_recv_ring))
                rds_ib_stats_inc(s_ib_rx_ring_empty);
 
-       /*
-        * If the ring is running low, then schedule the thread to refill.
-        */
        if (rds_ib_ring_low(&ic->i_recv_ring))
-               queue_delayed_work(rds_wq, &conn->c_recv_w, 0);
+               rds_ib_recv_refill(conn, 0);
 }
 
 int rds_ib_recv(struct rds_connection *conn)
@@ -916,7 +869,7 @@ int rds_ib_recv(struct rds_connection *conn)
         * we're really low and we want the caller to back off for a bit.
         */
        mutex_lock(&ic->i_recv_mutex);
-       if (rds_ib_recv_refill(conn, GFP_KERNEL, GFP_HIGHUSER, 0))
+       if (rds_ib_recv_refill(conn, 0))
                ret = -ENOMEM;
        else
                rds_ib_stats_inc(s_ib_rx_refill_from_thread);
@@ -940,13 +893,13 @@ int __init rds_ib_recv_init(void)
        rds_ib_incoming_slab = kmem_cache_create("rds_ib_incoming",
                                        sizeof(struct rds_ib_incoming),
                                        0, 0, NULL);
-       if (rds_ib_incoming_slab == NULL)
+       if (!rds_ib_incoming_slab)
                goto out;
 
        rds_ib_frag_slab = kmem_cache_create("rds_ib_frag",
                                        sizeof(struct rds_page_frag),
                                        0, 0, NULL);
-       if (rds_ib_frag_slab == NULL)
+       if (!rds_ib_frag_slab)
                kmem_cache_destroy(rds_ib_incoming_slab);
        else
                ret = 0;