2 * IPVS: Weighted Least-Connection Scheduling module
4 * Authors: Wensong Zhang <wensong@linuxvirtualserver.org>
5 * Peter Kese <peter.kese@ijs.si>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
13 * Wensong Zhang : changed the ip_vs_wlc_schedule to return dest
14 * Wensong Zhang : changed to use the inactconns in scheduling
15 * Wensong Zhang : changed some comestics things for debugging
16 * Wensong Zhang : changed for the d-linked destination list
17 * Wensong Zhang : added the ip_vs_wlc_update_svc
18 * Wensong Zhang : added any dest with weight=0 is quiesced
22 #include <linux/module.h>
23 #include <linux/kernel.h>
25 #include <net/ip_vs.h>
29 ip_vs_wlc_init_svc(struct ip_vs_service *svc)
36 ip_vs_wlc_done_svc(struct ip_vs_service *svc)
43 ip_vs_wlc_update_svc(struct ip_vs_service *svc)
49 static inline unsigned int
50 ip_vs_wlc_dest_overhead(struct ip_vs_dest *dest)
53 * We think the overhead of processing active connections is 256
54 * times higher than that of inactive connections in average. (This
55 * 256 times might not be accurate, we will change it later) We
56 * use the following formula to estimate the overhead now:
57 * dest->activeconns*256 + dest->inactconns
59 return (atomic_read(&dest->activeconns) << 8) +
60 atomic_read(&dest->inactconns);
65 * Weighted Least Connection scheduling
67 static struct ip_vs_dest *
68 ip_vs_wlc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
70 struct ip_vs_dest *dest, *least;
71 unsigned int loh, doh;
73 IP_VS_DBG(6, "ip_vs_wlc_schedule(): Scheduling...\n");
76 * We calculate the load of each dest server as follows:
77 * (dest overhead) / dest->weight
79 * Remember -- no floats in kernel mode!!!
80 * The comparison of h1*w2 > h2*w1 is equivalent to that of
82 * if every weight is larger than zero.
84 * The server with weight=0 is quiesced and will not receive any
88 list_for_each_entry(dest, &svc->destinations, n_list) {
89 if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) &&
90 atomic_read(&dest->weight) > 0) {
92 loh = ip_vs_wlc_dest_overhead(least);
99 * Find the destination with the least load.
102 list_for_each_entry_continue(dest, &svc->destinations, n_list) {
103 if (dest->flags & IP_VS_DEST_F_OVERLOAD)
105 doh = ip_vs_wlc_dest_overhead(dest);
106 if (loh * atomic_read(&dest->weight) >
107 doh * atomic_read(&least->weight)) {
113 IP_VS_DBG(6, "WLC: server %u.%u.%u.%u:%u "
114 "activeconns %d refcnt %d weight %d overhead %d\n",
115 NIPQUAD(least->addr), ntohs(least->port),
116 atomic_read(&least->activeconns),
117 atomic_read(&least->refcnt),
118 atomic_read(&least->weight), loh);
124 static struct ip_vs_scheduler ip_vs_wlc_scheduler =
127 .refcnt = ATOMIC_INIT(0),
128 .module = THIS_MODULE,
129 .n_list = LIST_HEAD_INIT(ip_vs_wlc_scheduler.n_list),
130 .init_service = ip_vs_wlc_init_svc,
131 .done_service = ip_vs_wlc_done_svc,
132 .update_service = ip_vs_wlc_update_svc,
133 .schedule = ip_vs_wlc_schedule,
137 static int __init ip_vs_wlc_init(void)
139 return register_ip_vs_scheduler(&ip_vs_wlc_scheduler);
142 static void __exit ip_vs_wlc_cleanup(void)
144 unregister_ip_vs_scheduler(&ip_vs_wlc_scheduler);
147 module_init(ip_vs_wlc_init);
148 module_exit(ip_vs_wlc_cleanup);
149 MODULE_LICENSE("GPL");