Lines Matching refs:pool

198 struct rds_ib_mr *rds_ib_reuse_mr(struct rds_ib_mr_pool *pool)  in rds_ib_reuse_mr()  argument
204 spin_lock_irqsave(&pool->clean_lock, flags); in rds_ib_reuse_mr()
205 ret = llist_del_first(&pool->clean_list); in rds_ib_reuse_mr()
206 spin_unlock_irqrestore(&pool->clean_lock, flags); in rds_ib_reuse_mr()
209 if (pool->pool_type == RDS_IB_MR_8K_POOL) in rds_ib_reuse_mr()
275 struct rds_ib_mr_pool *pool = ibmr->pool; in rds_ib_teardown_mr() local
277 atomic_sub(pinned, &pool->free_pinned); in rds_ib_teardown_mr()
281 static inline unsigned int rds_ib_flush_goal(struct rds_ib_mr_pool *pool, int free_all) in rds_ib_flush_goal() argument
285 item_count = atomic_read(&pool->item_count); in rds_ib_flush_goal()
342 int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *pool, in rds_ib_flush_mr_pool() argument
352 if (pool->pool_type == RDS_IB_MR_8K_POOL) in rds_ib_flush_mr_pool()
359 while (!mutex_trylock(&pool->flush_lock)) { in rds_ib_flush_mr_pool()
360 ibmr = rds_ib_reuse_mr(pool); in rds_ib_flush_mr_pool()
363 finish_wait(&pool->flush_wait, &wait); in rds_ib_flush_mr_pool()
367 prepare_to_wait(&pool->flush_wait, &wait, in rds_ib_flush_mr_pool()
369 if (llist_empty(&pool->clean_list)) in rds_ib_flush_mr_pool()
372 ibmr = rds_ib_reuse_mr(pool); in rds_ib_flush_mr_pool()
375 finish_wait(&pool->flush_wait, &wait); in rds_ib_flush_mr_pool()
379 finish_wait(&pool->flush_wait, &wait); in rds_ib_flush_mr_pool()
381 mutex_lock(&pool->flush_lock); in rds_ib_flush_mr_pool()
384 ibmr = rds_ib_reuse_mr(pool); in rds_ib_flush_mr_pool()
394 dirty_to_clean = llist_append_to_list(&pool->drop_list, &unmap_list); in rds_ib_flush_mr_pool()
395 dirty_to_clean += llist_append_to_list(&pool->free_list, &unmap_list); in rds_ib_flush_mr_pool()
399 spin_lock_irqsave(&pool->clean_lock, flags); in rds_ib_flush_mr_pool()
400 llist_append_to_list(&pool->clean_list, &unmap_list); in rds_ib_flush_mr_pool()
401 spin_unlock_irqrestore(&pool->clean_lock, flags); in rds_ib_flush_mr_pool()
404 free_goal = rds_ib_flush_goal(pool, free_all); in rds_ib_flush_mr_pool()
421 spin_lock_irqsave(&pool->clean_lock, flags); in rds_ib_flush_mr_pool()
423 &pool->clean_list); in rds_ib_flush_mr_pool()
424 spin_unlock_irqrestore(&pool->clean_lock, flags); in rds_ib_flush_mr_pool()
428 atomic_sub(unpinned, &pool->free_pinned); in rds_ib_flush_mr_pool()
429 atomic_sub(dirty_to_clean, &pool->dirty_count); in rds_ib_flush_mr_pool()
430 atomic_sub(nfreed, &pool->item_count); in rds_ib_flush_mr_pool()
433 mutex_unlock(&pool->flush_lock); in rds_ib_flush_mr_pool()
434 if (waitqueue_active(&pool->flush_wait)) in rds_ib_flush_mr_pool()
435 wake_up(&pool->flush_wait); in rds_ib_flush_mr_pool()
440 struct rds_ib_mr *rds_ib_try_reuse_ibmr(struct rds_ib_mr_pool *pool) in rds_ib_try_reuse_ibmr() argument
446 ibmr = rds_ib_reuse_mr(pool); in rds_ib_try_reuse_ibmr()
450 if (atomic_inc_return(&pool->item_count) <= pool->max_items) in rds_ib_try_reuse_ibmr()
453 atomic_dec(&pool->item_count); in rds_ib_try_reuse_ibmr()
456 if (pool->pool_type == RDS_IB_MR_8K_POOL) in rds_ib_try_reuse_ibmr()
464 if (pool->pool_type == RDS_IB_MR_8K_POOL) in rds_ib_try_reuse_ibmr()
469 rds_ib_flush_mr_pool(pool, 0, &ibmr); in rds_ib_try_reuse_ibmr()
479 struct rds_ib_mr_pool *pool = container_of(work, struct rds_ib_mr_pool, flush_worker.work); in rds_ib_mr_pool_flush_worker() local
481 rds_ib_flush_mr_pool(pool, 0, NULL); in rds_ib_mr_pool_flush_worker()
487 struct rds_ib_mr_pool *pool = ibmr->pool; in rds_ib_free_mr() local
505 atomic_add(ibmr->sg_len, &pool->free_pinned); in rds_ib_free_mr()
506 atomic_inc(&pool->dirty_count); in rds_ib_free_mr()
509 if (atomic_read(&pool->free_pinned) >= pool->max_free_pinned || in rds_ib_free_mr()
510 atomic_read(&pool->dirty_count) >= pool->max_items / 5) in rds_ib_free_mr()
511 queue_delayed_work(rds_ib_mr_wq, &pool->flush_worker, 10); in rds_ib_free_mr()
515 rds_ib_flush_mr_pool(pool, 0, NULL); in rds_ib_free_mr()
521 &pool->flush_worker, 10); in rds_ib_free_mr()
634 void rds_ib_destroy_mr_pool(struct rds_ib_mr_pool *pool) in rds_ib_destroy_mr_pool() argument
636 cancel_delayed_work_sync(&pool->flush_worker); in rds_ib_destroy_mr_pool()
637 rds_ib_flush_mr_pool(pool, 1, NULL); in rds_ib_destroy_mr_pool()
638 WARN_ON(atomic_read(&pool->item_count)); in rds_ib_destroy_mr_pool()
639 WARN_ON(atomic_read(&pool->free_pinned)); in rds_ib_destroy_mr_pool()
640 kfree(pool); in rds_ib_destroy_mr_pool()
646 struct rds_ib_mr_pool *pool; in rds_ib_create_mr_pool() local
648 pool = kzalloc(sizeof(*pool), GFP_KERNEL); in rds_ib_create_mr_pool()
649 if (!pool) in rds_ib_create_mr_pool()
652 pool->pool_type = pool_type; in rds_ib_create_mr_pool()
653 init_llist_head(&pool->free_list); in rds_ib_create_mr_pool()
654 init_llist_head(&pool->drop_list); in rds_ib_create_mr_pool()
655 init_llist_head(&pool->clean_list); in rds_ib_create_mr_pool()
656 spin_lock_init(&pool->clean_lock); in rds_ib_create_mr_pool()
657 mutex_init(&pool->flush_lock); in rds_ib_create_mr_pool()
658 init_waitqueue_head(&pool->flush_wait); in rds_ib_create_mr_pool()
659 INIT_DELAYED_WORK(&pool->flush_worker, rds_ib_mr_pool_flush_worker); in rds_ib_create_mr_pool()
663 pool->max_pages = RDS_MR_1M_MSG_SIZE + 1; in rds_ib_create_mr_pool()
664 pool->max_items = rds_ibdev->max_1m_mrs; in rds_ib_create_mr_pool()
667 pool->max_pages = RDS_MR_8K_MSG_SIZE + 1; in rds_ib_create_mr_pool()
668 pool->max_items = rds_ibdev->max_8k_mrs; in rds_ib_create_mr_pool()
671 pool->max_free_pinned = pool->max_items * pool->max_pages / 4; in rds_ib_create_mr_pool()
672 pool->max_items_soft = rds_ibdev->max_mrs * 3 / 4; in rds_ib_create_mr_pool()
674 return pool; in rds_ib_create_mr_pool()