diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /net/ipv4/ipvs/ip_vs_lc.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'net/ipv4/ipvs/ip_vs_lc.c')
-rw-r--r-- | net/ipv4/ipvs/ip_vs_lc.c | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/net/ipv4/ipvs/ip_vs_lc.c b/net/ipv4/ipvs/ip_vs_lc.c new file mode 100644 index 000000000000..d88fef90a641 --- /dev/null +++ b/net/ipv4/ipvs/ip_vs_lc.c | |||
@@ -0,0 +1,123 @@ | |||
1 | /* | ||
2 | * IPVS: Least-Connection Scheduling module | ||
3 | * | ||
4 | * Version: $Id: ip_vs_lc.c,v 1.10 2003/04/18 09:03:16 wensong Exp $ | ||
5 | * | ||
6 | * Authors: Wensong Zhang <wensong@linuxvirtualserver.org> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License | ||
10 | * as published by the Free Software Foundation; either version | ||
11 | * 2 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | * Changes: | ||
14 | * Wensong Zhang : added the ip_vs_lc_update_svc | ||
15 | * Wensong Zhang : added any dest with weight=0 is quiesced | ||
16 | * | ||
17 | */ | ||
18 | |||
19 | #include <linux/module.h> | ||
20 | #include <linux/kernel.h> | ||
21 | |||
22 | #include <net/ip_vs.h> | ||
23 | |||
24 | |||
25 | static int ip_vs_lc_init_svc(struct ip_vs_service *svc) | ||
26 | { | ||
27 | return 0; | ||
28 | } | ||
29 | |||
30 | |||
31 | static int ip_vs_lc_done_svc(struct ip_vs_service *svc) | ||
32 | { | ||
33 | return 0; | ||
34 | } | ||
35 | |||
36 | |||
37 | static int ip_vs_lc_update_svc(struct ip_vs_service *svc) | ||
38 | { | ||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | |||
43 | static inline unsigned int | ||
44 | ip_vs_lc_dest_overhead(struct ip_vs_dest *dest) | ||
45 | { | ||
46 | /* | ||
47 | * We think the overhead of processing active connections is 256 | ||
48 | * times higher than that of inactive connections in average. (This | ||
49 | * 256 times might not be accurate, we will change it later) We | ||
50 | * use the following formula to estimate the overhead now: | ||
51 | * dest->activeconns*256 + dest->inactconns | ||
52 | */ | ||
53 | return (atomic_read(&dest->activeconns) << 8) + | ||
54 | atomic_read(&dest->inactconns); | ||
55 | } | ||
56 | |||
57 | |||
58 | /* | ||
59 | * Least Connection scheduling | ||
60 | */ | ||
61 | static struct ip_vs_dest * | ||
62 | ip_vs_lc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb) | ||
63 | { | ||
64 | struct ip_vs_dest *dest, *least = NULL; | ||
65 | unsigned int loh = 0, doh; | ||
66 | |||
67 | IP_VS_DBG(6, "ip_vs_lc_schedule(): Scheduling...\n"); | ||
68 | |||
69 | /* | ||
70 | * Simply select the server with the least number of | ||
71 | * (activeconns<<5) + inactconns | ||
72 | * Except whose weight is equal to zero. | ||
73 | * If the weight is equal to zero, it means that the server is | ||
74 | * quiesced, the existing connections to the server still get | ||
75 | * served, but no new connection is assigned to the server. | ||
76 | */ | ||
77 | |||
78 | list_for_each_entry(dest, &svc->destinations, n_list) { | ||
79 | if ((dest->flags & IP_VS_DEST_F_OVERLOAD) || | ||
80 | atomic_read(&dest->weight) == 0) | ||
81 | continue; | ||
82 | doh = ip_vs_lc_dest_overhead(dest); | ||
83 | if (!least || doh < loh) { | ||
84 | least = dest; | ||
85 | loh = doh; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | if (least) | ||
90 | IP_VS_DBG(6, "LC: server %u.%u.%u.%u:%u activeconns %d inactconns %d\n", | ||
91 | NIPQUAD(least->addr), ntohs(least->port), | ||
92 | atomic_read(&least->activeconns), | ||
93 | atomic_read(&least->inactconns)); | ||
94 | |||
95 | return least; | ||
96 | } | ||
97 | |||
98 | |||
99 | static struct ip_vs_scheduler ip_vs_lc_scheduler = { | ||
100 | .name = "lc", | ||
101 | .refcnt = ATOMIC_INIT(0), | ||
102 | .module = THIS_MODULE, | ||
103 | .init_service = ip_vs_lc_init_svc, | ||
104 | .done_service = ip_vs_lc_done_svc, | ||
105 | .update_service = ip_vs_lc_update_svc, | ||
106 | .schedule = ip_vs_lc_schedule, | ||
107 | }; | ||
108 | |||
109 | |||
110 | static int __init ip_vs_lc_init(void) | ||
111 | { | ||
112 | INIT_LIST_HEAD(&ip_vs_lc_scheduler.n_list); | ||
113 | return register_ip_vs_scheduler(&ip_vs_lc_scheduler) ; | ||
114 | } | ||
115 | |||
116 | static void __exit ip_vs_lc_cleanup(void) | ||
117 | { | ||
118 | unregister_ip_vs_scheduler(&ip_vs_lc_scheduler); | ||
119 | } | ||
120 | |||
121 | module_init(ip_vs_lc_init); | ||
122 | module_exit(ip_vs_lc_cleanup); | ||
123 | MODULE_LICENSE("GPL"); | ||