Skip to content

Commit eefa32d

Browse files
rhadoohorms
authored andcommitted
ipvs: Add ovf scheduler
The weighted overflow scheduling algorithm directs network connections to the server with the highest weight that is currently available and overflows to the next when active connections exceed the node's weight. Signed-off-by: Raducu Deaconu <[email protected]> Acked-by: Julian Anastasov <[email protected]> Signed-off-by: Simon Horman <[email protected]>
1 parent 81bf1c6 commit eefa32d

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

net/netfilter/ipvs/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,17 @@ config IP_VS_FO
162162
If you want to compile it in kernel, say Y. To compile it as a
163163
module, choose M here. If unsure, say N.
164164

165+
config IP_VS_OVF
166+
tristate "weighted overflow scheduling"
167+
---help---
168+
The weighted overflow scheduling algorithm directs network
169+
connections to the server with the highest weight that is
170+
currently available and overflows to the next when active
171+
connections exceed the node's weight.
172+
173+
If you want to compile it in kernel, say Y. To compile it as a
174+
module, choose M here. If unsure, say N.
175+
165176
config IP_VS_LBLC
166177
tristate "locality-based least-connection scheduling"
167178
---help---

net/netfilter/ipvs/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ obj-$(CONFIG_IP_VS_WRR) += ip_vs_wrr.o
2727
obj-$(CONFIG_IP_VS_LC) += ip_vs_lc.o
2828
obj-$(CONFIG_IP_VS_WLC) += ip_vs_wlc.o
2929
obj-$(CONFIG_IP_VS_FO) += ip_vs_fo.o
30+
obj-$(CONFIG_IP_VS_OVF) += ip_vs_ovf.o
3031
obj-$(CONFIG_IP_VS_LBLC) += ip_vs_lblc.o
3132
obj-$(CONFIG_IP_VS_LBLCR) += ip_vs_lblcr.o
3233
obj-$(CONFIG_IP_VS_DH) += ip_vs_dh.o

net/netfilter/ipvs/ip_vs_ovf.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* IPVS: Overflow-Connection Scheduling module
3+
*
4+
* Authors: Raducu Deaconu <[email protected]>
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License
8+
* as published by the Free Software Foundation; either version
9+
* 2 of the License, or (at your option) any later version.
10+
*
11+
* Scheduler implements "overflow" loadbalancing according to number of active
12+
* connections , will keep all conections to the node with the highest weight
13+
* and overflow to the next node if the number of connections exceeds the node's
14+
* weight.
15+
* Note that this scheduler might not be suitable for UDP because it only uses
16+
* active connections
17+
*
18+
*/
19+
20+
#define KMSG_COMPONENT "IPVS"
21+
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
22+
23+
#include <linux/module.h>
24+
#include <linux/kernel.h>
25+
26+
#include <net/ip_vs.h>
27+
28+
/* OVF Connection scheduling */
29+
static struct ip_vs_dest *
30+
ip_vs_ovf_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
31+
struct ip_vs_iphdr *iph)
32+
{
33+
struct ip_vs_dest *dest, *h = NULL;
34+
int hw = 0, w;
35+
36+
IP_VS_DBG(6, "ip_vs_ovf_schedule(): Scheduling...\n");
37+
/* select the node with highest weight, go to next in line if active
38+
* connections exceed weight
39+
*/
40+
list_for_each_entry_rcu(dest, &svc->destinations, n_list) {
41+
w = atomic_read(&dest->weight);
42+
if ((dest->flags & IP_VS_DEST_F_OVERLOAD) ||
43+
atomic_read(&dest->activeconns) > w ||
44+
w == 0)
45+
continue;
46+
if (!h || w > hw) {
47+
h = dest;
48+
hw = w;
49+
}
50+
}
51+
52+
if (h) {
53+
IP_VS_DBG_BUF(6, "OVF: server %s:%u active %d w %d\n",
54+
IP_VS_DBG_ADDR(h->af, &h->addr),
55+
ntohs(h->port),
56+
atomic_read(&h->activeconns),
57+
atomic_read(&h->weight));
58+
return h;
59+
}
60+
61+
ip_vs_scheduler_err(svc, "no destination available");
62+
return NULL;
63+
}
64+
65+
static struct ip_vs_scheduler ip_vs_ovf_scheduler = {
66+
.name = "ovf",
67+
.refcnt = ATOMIC_INIT(0),
68+
.module = THIS_MODULE,
69+
.n_list = LIST_HEAD_INIT(ip_vs_ovf_scheduler.n_list),
70+
.schedule = ip_vs_ovf_schedule,
71+
};
72+
73+
static int __init ip_vs_ovf_init(void)
74+
{
75+
return register_ip_vs_scheduler(&ip_vs_ovf_scheduler);
76+
}
77+
78+
static void __exit ip_vs_ovf_cleanup(void)
79+
{
80+
unregister_ip_vs_scheduler(&ip_vs_ovf_scheduler);
81+
synchronize_rcu();
82+
}
83+
84+
module_init(ip_vs_ovf_init);
85+
module_exit(ip_vs_ovf_cleanup);
86+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)