Skip to content

Commit 124552d

Browse files
Zhu Yanjungerd-rausch
authored andcommitted
net: rds: fix rds_ib_sysctl_max_recv_allocation error
Before the commit 942d5a3 ("net/rds: reduce memory footprint during ib_post_recv in IB transport"), rds_ib_allocation increases by one. So the function atomic_add_unless will work. After the commit, rds_ib_allocation increases by 4 if the frag is 16K. Then atomic_add_unless will not work. Fixes: 942d5a3 ("net/rds: reduce memory footprint during ib_post_recv in IB transport") Orabug: 29003168 Signed-off-by: Zhu Yanjun <[email protected]> Reported-by: Joe Jin <[email protected]> Reviewed-by: Joe Jin <[email protected]> Reviewed-by: Håkon Bugge <[email protected]>
1 parent 890b069 commit 124552d

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

net/rds/ib_recv.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ MODULE_PARM_DESC(rds_ib_srq_lwm_refill, "SRQ LWM refill");
5757
static struct kmem_cache *rds_ib_incoming_slab;
5858
static struct kmem_cache *rds_ib_frag_slab;
5959
static atomic_t rds_ib_allocation = ATOMIC_INIT(0);
60-
static unsigned long rds_ib_allocation_warn = 1;
6160

6261
void rds_ib_recv_init_ring(struct rds_ib_connection *ic)
6362
{
@@ -357,7 +356,6 @@ static struct rds_page_frag *rds_ib_refill_one_frag(struct rds_ib_connection *ic
357356
struct list_head *cache_item;
358357
struct scatterlist *sg;
359358
struct scatterlist *s;
360-
int avail_allocs;
361359
int ret;
362360
int i;
363361
int j;
@@ -368,21 +366,19 @@ static struct rds_page_frag *rds_ib_refill_one_frag(struct rds_ib_connection *ic
368366
atomic_sub(ic->i_frag_sz/1024, &ic->i_cache_allocs);
369367
rds_ib_stats_add(s_ib_recv_removed_from_cache, ic->i_frag_sz);
370368
} else {
371-
frag = kmem_cache_alloc(rds_ib_frag_slab, slab_mask);
372-
if (!frag)
369+
if (unlikely(atomic_add_return(ic->i_frag_pages,
370+
&rds_ib_allocation) >=
371+
rds_ib_sysctl_max_recv_allocation)) {
372+
printk_once(KERN_NOTICE "RDS/IB: WARNING - recv memory exceeded max_recv_allocation %d\n",
373+
atomic_read(&rds_ib_allocation));
374+
atomic_sub(ic->i_frag_pages, &rds_ib_allocation);
375+
rds_ib_stats_inc(s_ib_rx_alloc_limit);
373376
return NULL;
377+
}
374378

375-
avail_allocs = atomic_add_unless(&rds_ib_allocation,
376-
ic->i_frag_pages,
377-
rds_ib_sysctl_max_recv_allocation);
378-
if (!avail_allocs) {
379-
if (test_and_clear_bit(0, &rds_ib_allocation_warn)) {
380-
printk(KERN_NOTICE "RDS/IB: WARNING - "
381-
"recv memory exceeded max_recv_allocation %d\n",
382-
atomic_read(&rds_ib_allocation));
383-
}
384-
rds_ib_stats_inc(s_ib_rx_alloc_limit);
385-
kmem_cache_free(rds_ib_frag_slab, frag);
379+
frag = kmem_cache_alloc(rds_ib_frag_slab, slab_mask);
380+
if (!frag) {
381+
atomic_sub(ic->i_frag_pages, &rds_ib_allocation);
386382
return NULL;
387383
}
388384

0 commit comments

Comments
 (0)