2 * IPVS: Least-Connection Scheduling module
4 * Authors: Wensong Zhang <wensong@linuxvirtualserver.org>
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.
12 * Wensong Zhang : added the ip_vs_lc_update_svc
13 * Wensong Zhang : added any dest with weight=0 is quiesced
17 #include <linux/module.h>
18 #include <linux/kernel.h>
20 #include <net/ip_vs.h>
23 static inline unsigned int
24 ip_vs_lc_dest_overhead(struct ip_vs_dest
*dest
)
27 * We think the overhead of processing active connections is 256
28 * times higher than that of inactive connections in average. (This
29 * 256 times might not be accurate, we will change it later) We
30 * use the following formula to estimate the overhead now:
31 * dest->activeconns*256 + dest->inactconns
33 return (atomic_read(&dest
->activeconns
) << 8) +
34 atomic_read(&dest
->inactconns
);
39 * Least Connection scheduling
41 static struct ip_vs_dest
*
42 ip_vs_lc_schedule(struct ip_vs_service
*svc
, const struct sk_buff
*skb
)
44 struct ip_vs_dest
*dest
, *least
= NULL
;
45 unsigned int loh
= 0, doh
;
47 IP_VS_DBG(6, "ip_vs_lc_schedule(): Scheduling...\n");
50 * Simply select the server with the least number of
51 * (activeconns<<5) + inactconns
52 * Except whose weight is equal to zero.
53 * If the weight is equal to zero, it means that the server is
54 * quiesced, the existing connections to the server still get
55 * served, but no new connection is assigned to the server.
58 list_for_each_entry(dest
, &svc
->destinations
, n_list
) {
59 if ((dest
->flags
& IP_VS_DEST_F_OVERLOAD
) ||
60 atomic_read(&dest
->weight
) == 0)
62 doh
= ip_vs_lc_dest_overhead(dest
);
63 if (!least
|| doh
< loh
) {
70 IP_VS_ERR_RL("LC: no destination available\n");
72 IP_VS_DBG_BUF(6, "LC: server %s:%u activeconns %d "
74 IP_VS_DBG_ADDR(svc
->af
, &least
->addr
),
76 atomic_read(&least
->activeconns
),
77 atomic_read(&least
->inactconns
));
83 static struct ip_vs_scheduler ip_vs_lc_scheduler
= {
85 .refcnt
= ATOMIC_INIT(0),
86 .module
= THIS_MODULE
,
87 .n_list
= LIST_HEAD_INIT(ip_vs_lc_scheduler
.n_list
),
88 .schedule
= ip_vs_lc_schedule
,
92 static int __init
ip_vs_lc_init(void)
94 return register_ip_vs_scheduler(&ip_vs_lc_scheduler
) ;
97 static void __exit
ip_vs_lc_cleanup(void)
99 unregister_ip_vs_scheduler(&ip_vs_lc_scheduler
);
102 module_init(ip_vs_lc_init
);
103 module_exit(ip_vs_lc_cleanup
);
104 MODULE_LICENSE("GPL");