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 #define KMSG_COMPONENT "IPVS"
18 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
20 #include <linux/module.h>
21 #include <linux/kernel.h>
23 #include <net/ip_vs.h>
26 static inline unsigned int
27 ip_vs_lc_dest_overhead(struct ip_vs_dest
*dest
)
30 * We think the overhead of processing active connections is 256
31 * times higher than that of inactive connections in average. (This
32 * 256 times might not be accurate, we will change it later) We
33 * use the following formula to estimate the overhead now:
34 * dest->activeconns*256 + dest->inactconns
36 return (atomic_read(&dest
->activeconns
) << 8) +
37 atomic_read(&dest
->inactconns
);
42 * Least Connection scheduling
44 static struct ip_vs_dest
*
45 ip_vs_lc_schedule(struct ip_vs_service
*svc
, const struct sk_buff
*skb
)
47 struct ip_vs_dest
*dest
, *least
= NULL
;
48 unsigned int loh
= 0, doh
;
50 IP_VS_DBG(6, "%s(): Scheduling...\n", __func__
);
53 * Simply select the server with the least number of
54 * (activeconns<<5) + inactconns
55 * Except whose weight is equal to zero.
56 * If the weight is equal to zero, it means that the server is
57 * quiesced, the existing connections to the server still get
58 * served, but no new connection is assigned to the server.
61 list_for_each_entry(dest
, &svc
->destinations
, n_list
) {
62 if ((dest
->flags
& IP_VS_DEST_F_OVERLOAD
) ||
63 atomic_read(&dest
->weight
) == 0)
65 doh
= ip_vs_lc_dest_overhead(dest
);
66 if (!least
|| doh
< loh
) {
73 IP_VS_ERR_RL("LC: no destination available\n");
75 IP_VS_DBG_BUF(6, "LC: server %s:%u activeconns %d "
77 IP_VS_DBG_ADDR(svc
->af
, &least
->addr
),
79 atomic_read(&least
->activeconns
),
80 atomic_read(&least
->inactconns
));
86 static struct ip_vs_scheduler ip_vs_lc_scheduler
= {
88 .refcnt
= ATOMIC_INIT(0),
89 .module
= THIS_MODULE
,
90 .n_list
= LIST_HEAD_INIT(ip_vs_lc_scheduler
.n_list
),
91 .schedule
= ip_vs_lc_schedule
,
95 static int __init
ip_vs_lc_init(void)
97 return register_ip_vs_scheduler(&ip_vs_lc_scheduler
) ;
100 static void __exit
ip_vs_lc_cleanup(void)
102 unregister_ip_vs_scheduler(&ip_vs_lc_scheduler
);
105 module_init(ip_vs_lc_init
);
106 module_exit(ip_vs_lc_cleanup
);
107 MODULE_LICENSE("GPL");