/* * Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU * General Public License (GPL) Version 2, available from the file * COPYING in the main directory of this source tree, or the * OpenIB.org BSD license below: * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * * - Redistributions of source code must retain the above * copyright notice, this list of conditions and the following * disclaimer. * * - Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. *
*/ #include <linux/kernel.h> #include <linux/slab.h> #include <linux/rculist.h> #include <linux/llist.h>
/* conn was previously on the nodev_conns_list */
spin_lock_irq(&ib_nodev_conns_lock);
BUG_ON(list_empty(&ib_nodev_conns));
BUG_ON(list_empty(&ic->ib_node));
list_del(&ic->ib_node);
/* Release the s/g list */ if (ibmr->sg_len) { unsignedint i;
for (i = 0; i < ibmr->sg_len; ++i) { struct page *page = sg_page(&ibmr->sg[i]);
/* FIXME we need a way to tell a r/w MR
* from a r/o MR */
WARN_ON(!page->mapping && irqs_disabled());
set_page_dirty(page);
put_page(page);
}
kfree(ibmr->sg);
__rds_ib_teardown_mr(ibmr); if (pinned) { struct rds_ib_mr_pool *pool = ibmr->pool;
atomic_sub(pinned, &pool->free_pinned);
}
}
staticinlineunsignedint rds_ib_flush_goal(struct rds_ib_mr_pool *pool, int free_all)
{ unsignedint item_count;
item_count = atomic_read(&pool->item_count); if (free_all) return item_count;
return 0;
}
/* * given an llist of mrs, put them all into the list_head for more processing
*/ staticunsignedint llist_append_to_list(struct llist_head *llist, struct list_head *list)
{ struct rds_ib_mr *ibmr; struct llist_node *node; struct llist_node *next; unsignedint count = 0;
/* * this takes a list head of mrs and turns it into linked llist nodes * of clusters. Each cluster has linked llist nodes of * MR_CLUSTER_SIZE mrs that are ready for reuse.
*/ staticvoid list_to_llist_nodes(struct list_head *list, struct llist_node **nodes_head, struct llist_node **nodes_tail)
{ struct rds_ib_mr *ibmr; struct llist_node *cur = NULL; struct llist_node **next = nodes_head;
/* * Flush our pool of MRs. * At a minimum, all currently unused MRs are unmapped. * If the number of MRs allocated exceeds the limit, we also try * to free as many MRs as needed to get back to this limit.
*/ int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *pool, int free_all, struct rds_ib_mr **ibmr_ret)
{ struct rds_ib_mr *ibmr; struct llist_node *clean_nodes; struct llist_node *clean_tail;
LIST_HEAD(unmap_list); unsignedlong unpinned = 0; unsignedint nfreed = 0, dirty_to_clean = 0, free_goal;
if (pool->pool_type == RDS_IB_MR_8K_POOL)
rds_ib_stats_inc(s_ib_rdma_mr_8k_pool_flush); else
rds_ib_stats_inc(s_ib_rdma_mr_1m_pool_flush);
if (ibmr_ret) {
DEFINE_WAIT(wait); while (!mutex_trylock(&pool->flush_lock)) {
ibmr = rds_ib_reuse_mr(pool); if (ibmr) {
*ibmr_ret = ibmr;
finish_wait(&pool->flush_wait, &wait); goto out_nolock;
}
prepare_to_wait(&pool->flush_wait, &wait,
TASK_UNINTERRUPTIBLE); if (llist_empty(&pool->clean_list))
schedule();
if (ibmr_ret) {
ibmr = rds_ib_reuse_mr(pool); if (ibmr) {
*ibmr_ret = ibmr; goto out;
}
}
/* Get the list of all MRs to be dropped. Ordering matters - * we want to put drop_list ahead of free_list.
*/
dirty_to_clean = llist_append_to_list(&pool->drop_list, &unmap_list);
dirty_to_clean += llist_append_to_list(&pool->free_list, &unmap_list); if (free_all) { unsignedlong flags;
out:
mutex_unlock(&pool->flush_lock); if (waitqueue_active(&pool->flush_wait))
wake_up(&pool->flush_wait);
out_nolock: return 0;
}
struct rds_ib_mr *rds_ib_try_reuse_ibmr(struct rds_ib_mr_pool *pool)
{ struct rds_ib_mr *ibmr = NULL; int iter = 0;
while (1) {
ibmr = rds_ib_reuse_mr(pool); if (ibmr) return ibmr;
if (atomic_inc_return(&pool->item_count) <= pool->max_items) break;
atomic_dec(&pool->item_count);
if (++iter > 2) { if (pool->pool_type == RDS_IB_MR_8K_POOL)
rds_ib_stats_inc(s_ib_rdma_mr_8k_pool_depleted); else
rds_ib_stats_inc(s_ib_rdma_mr_1m_pool_depleted); break;
}
/* We do have some empty MRs. Flush them out. */ if (pool->pool_type == RDS_IB_MR_8K_POOL)
rds_ib_stats_inc(s_ib_rdma_mr_8k_pool_wait); else
rds_ib_stats_inc(s_ib_rdma_mr_1m_pool_wait);
rds_ib_flush_mr_pool(pool, 0, &ibmr); if (ibmr) return ibmr;
}
if (ibmr->odp) { /* A MR created and marked as use_once. We use delayed work, * because there is a change that we are in interrupt and can't * call to ib_dereg_mr() directly.
*/
INIT_DELAYED_WORK(&ibmr->work, rds_ib_odp_mr_worker);
queue_delayed_work(rds_ib_mr_wq, &ibmr->work, 0); return;
}
/* Return it to the pool's free list */
rds_ib_free_frmr_list(ibmr);
/* If we've pinned too many pages, request a flush */ if (atomic_read(&pool->free_pinned) >= pool->max_free_pinned ||
atomic_read(&pool->dirty_count) >= pool->max_items / 5)
queue_delayed_work(rds_ib_mr_wq, &pool->flush_worker, 10);
if (invalidate) { if (likely(!in_interrupt())) {
rds_ib_flush_mr_pool(pool, 0, NULL);
} else { /* We get here if the user created a MR marked * as use_once and invalidate at the same time.
*/
queue_delayed_work(rds_ib_mr_wq,
&pool->flush_worker, 10);
}
}
if (IS_ERR(ib_mr)) {
rdsdebug("rds_ib_get_user_mr returned %d\n",
IS_ERR(ib_mr));
ret = PTR_ERR(ib_mr); goto out;
} if (key_ret)
*key_ret = ib_mr->rkey;
ibmr = kzalloc(sizeof(*ibmr), GFP_KERNEL); if (!ibmr) {
ib_dereg_mr(ib_mr);
ret = -ENOMEM; goto out;
}
ibmr->u.mr = ib_mr;
ibmr->odp = 1;
int rds_ib_mr_init(void)
{
rds_ib_mr_wq = alloc_workqueue("rds_mr_flushd", WQ_MEM_RECLAIM, 0); if (!rds_ib_mr_wq) return -ENOMEM; return 0;
}
/* By the time this is called all the IB devices should have been torn down and * had their pools freed. As each pool is freed its work struct is waited on, * so the pool flushing work queue should be idle by the time we get here.
*/ void rds_ib_mr_exit(void)
{
destroy_workqueue(rds_ib_mr_wq);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.