1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * IPVS: Overflow-Connection Scheduling module
5 * Authors: Raducu Deaconu <rhadoo_io@yahoo.com>
7 * Scheduler implements "overflow" loadbalancing according to number of active
8 * connections , will keep all connections to the node with the highest weight
9 * and overflow to the next node if the number of connections exceeds the node's
11 * Note that this scheduler might not be suitable for UDP because it only uses
15 #define KMSG_COMPONENT "IPVS"
16 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
18 #include <linux/module.h>
19 #include <linux/kernel.h>
21 #include <net/ip_vs.h>
23 /* OVF Connection scheduling */
24 static struct ip_vs_dest *
25 ip_vs_ovf_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
26 struct ip_vs_iphdr *iph)
28 struct ip_vs_dest *dest, *h = NULL;
31 IP_VS_DBG(6, "ip_vs_ovf_schedule(): Scheduling...\n");
32 /* select the node with highest weight, go to next in line if active
33 * connections exceed weight
35 list_for_each_entry_rcu(dest, &svc->destinations, n_list) {
36 w = atomic_read(&dest->weight);
37 if ((dest->flags & IP_VS_DEST_F_OVERLOAD) ||
38 atomic_read(&dest->activeconns) > w ||
48 IP_VS_DBG_BUF(6, "OVF: server %s:%u active %d w %d\n",
49 IP_VS_DBG_ADDR(h->af, &h->addr),
51 atomic_read(&h->activeconns),
52 atomic_read(&h->weight));
56 ip_vs_scheduler_err(svc, "no destination available");
60 static struct ip_vs_scheduler ip_vs_ovf_scheduler = {
62 .refcnt = ATOMIC_INIT(0),
63 .module = THIS_MODULE,
64 .n_list = LIST_HEAD_INIT(ip_vs_ovf_scheduler.n_list),
65 .schedule = ip_vs_ovf_schedule,
68 static int __init ip_vs_ovf_init(void)
70 return register_ip_vs_scheduler(&ip_vs_ovf_scheduler);
73 static void __exit ip_vs_ovf_cleanup(void)
75 unregister_ip_vs_scheduler(&ip_vs_ovf_scheduler);
79 module_init(ip_vs_ovf_init);
80 module_exit(ip_vs_ovf_cleanup);
81 MODULE_LICENSE("GPL");