ipvs: convert rr scheduler to rcu
The schedule method now needs _rcu list-traversal primitive for svc->destinations. As the previous entry could be unlinked, limit the list traversals to 2 when lookup started from previous entry. Signed-off-by: Julian Anastasov <ja@ssi.bg> Signed-off-by: Simon Horman <horms@verge.net.au>
This commit is contained in:
parent
f92ea8f096
commit
c0d0c0a1c0
1 changed files with 37 additions and 22 deletions
|
@ -35,9 +35,18 @@ static int ip_vs_rr_init_svc(struct ip_vs_service *svc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int ip_vs_rr_update_svc(struct ip_vs_service *svc)
|
static int ip_vs_rr_del_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest)
|
||||||
{
|
{
|
||||||
svc->sched_data = &svc->destinations;
|
struct list_head *p;
|
||||||
|
|
||||||
|
write_lock_bh(&svc->sched_lock);
|
||||||
|
p = (struct list_head *) svc->sched_data;
|
||||||
|
/* dest is already unlinked, so p->prev is not valid but
|
||||||
|
* p->next is valid, use it to reach previous entry.
|
||||||
|
*/
|
||||||
|
if (p == &dest->n_list)
|
||||||
|
svc->sched_data = p->next->prev;
|
||||||
|
write_unlock_bh(&svc->sched_lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,35 +57,40 @@ static int ip_vs_rr_update_svc(struct ip_vs_service *svc)
|
||||||
static struct ip_vs_dest *
|
static struct ip_vs_dest *
|
||||||
ip_vs_rr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
|
ip_vs_rr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct list_head *p, *q;
|
struct list_head *p;
|
||||||
struct ip_vs_dest *dest;
|
struct ip_vs_dest *dest, *last;
|
||||||
|
int pass = 0;
|
||||||
|
|
||||||
IP_VS_DBG(6, "%s(): Scheduling...\n", __func__);
|
IP_VS_DBG(6, "%s(): Scheduling...\n", __func__);
|
||||||
|
|
||||||
write_lock(&svc->sched_lock);
|
write_lock(&svc->sched_lock);
|
||||||
p = (struct list_head *)svc->sched_data;
|
p = (struct list_head *) svc->sched_data;
|
||||||
p = p->next;
|
last = dest = list_entry(p, struct ip_vs_dest, n_list);
|
||||||
q = p;
|
|
||||||
do {
|
|
||||||
/* skip list head */
|
|
||||||
if (q == &svc->destinations) {
|
|
||||||
q = q->next;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
dest = list_entry(q, struct ip_vs_dest, n_list);
|
do {
|
||||||
if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) &&
|
list_for_each_entry_continue_rcu(dest,
|
||||||
atomic_read(&dest->weight) > 0)
|
&svc->destinations,
|
||||||
/* HIT */
|
n_list) {
|
||||||
goto out;
|
if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) &&
|
||||||
q = q->next;
|
atomic_read(&dest->weight) > 0)
|
||||||
} while (q != p);
|
/* HIT */
|
||||||
|
goto out;
|
||||||
|
if (dest == last)
|
||||||
|
goto stop;
|
||||||
|
}
|
||||||
|
pass++;
|
||||||
|
/* Previous dest could be unlinked, do not loop forever.
|
||||||
|
* If we stay at head there is no need for 2nd pass.
|
||||||
|
*/
|
||||||
|
} while (pass < 2 && p != &svc->destinations);
|
||||||
|
|
||||||
|
stop:
|
||||||
write_unlock(&svc->sched_lock);
|
write_unlock(&svc->sched_lock);
|
||||||
ip_vs_scheduler_err(svc, "no destination available");
|
ip_vs_scheduler_err(svc, "no destination available");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
svc->sched_data = q;
|
svc->sched_data = &dest->n_list;
|
||||||
write_unlock(&svc->sched_lock);
|
write_unlock(&svc->sched_lock);
|
||||||
IP_VS_DBG_BUF(6, "RR: server %s:%u "
|
IP_VS_DBG_BUF(6, "RR: server %s:%u "
|
||||||
"activeconns %d refcnt %d weight %d\n",
|
"activeconns %d refcnt %d weight %d\n",
|
||||||
|
@ -94,7 +108,8 @@ static struct ip_vs_scheduler ip_vs_rr_scheduler = {
|
||||||
.module = THIS_MODULE,
|
.module = THIS_MODULE,
|
||||||
.n_list = LIST_HEAD_INIT(ip_vs_rr_scheduler.n_list),
|
.n_list = LIST_HEAD_INIT(ip_vs_rr_scheduler.n_list),
|
||||||
.init_service = ip_vs_rr_init_svc,
|
.init_service = ip_vs_rr_init_svc,
|
||||||
.update_service = ip_vs_rr_update_svc,
|
.add_dest = NULL,
|
||||||
|
.del_dest = ip_vs_rr_del_dest,
|
||||||
.schedule = ip_vs_rr_schedule,
|
.schedule = ip_vs_rr_schedule,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue