GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / net / netfilter / ipvs / ip_vs_nq.c
blobc413e18308230e910cef0a6e392e752826a57e5f
1 /*
2 * IPVS: Never Queue 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.
11 * Changes:
16 * The NQ algorithm adopts a two-speed model. When there is an idle server
17 * available, the job will be sent to the idle server, instead of waiting
18 * for a fast one. When there is no idle server available, the job will be
19 * sent to the server that minimize its expected delay (The Shortest
20 * Expected Delay scheduling algorithm).
22 * See the following paper for more information:
23 * A. Weinrib and S. Shenker, Greed is not enough: Adaptive load sharing
24 * in large heterogeneous systems. In Proceedings IEEE INFOCOM'88,
25 * pages 986-994, 1988.
27 * Thanks must go to Marko Buuri <marko@buuri.name> for talking NQ to me.
29 * The difference between NQ and SED is that NQ can improve overall
30 * system utilization.
34 #define KMSG_COMPONENT "IPVS"
35 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
37 #include <linux/module.h>
38 #include <linux/kernel.h>
40 #include <net/ip_vs.h>
43 static inline unsigned int
44 ip_vs_nq_dest_overhead(struct ip_vs_dest *dest)
47 * We only use the active connection number in the cost
48 * calculation here.
50 return atomic_read(&dest->activeconns) + 1;
55 * Weighted Least Connection scheduling
57 static struct ip_vs_dest *
58 ip_vs_nq_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
60 struct ip_vs_dest *dest, *least = NULL;
61 unsigned int loh = 0, doh;
63 IP_VS_DBG(6, "%s(): Scheduling...\n", __func__);
66 * We calculate the load of each dest server as follows:
67 * (server expected overhead) / dest->weight
69 * Remember -- no floats in kernel mode!!!
70 * The comparison of h1*w2 > h2*w1 is equivalent to that of
71 * h1/w1 > h2/w2
72 * if every weight is larger than zero.
74 * The server with weight=0 is quiesced and will not receive any
75 * new connections.
78 list_for_each_entry(dest, &svc->destinations, n_list) {
80 if (dest->flags & IP_VS_DEST_F_OVERLOAD ||
81 !atomic_read(&dest->weight))
82 continue;
84 doh = ip_vs_nq_dest_overhead(dest);
86 /* return the server directly if it is idle */
87 if (atomic_read(&dest->activeconns) == 0) {
88 least = dest;
89 loh = doh;
90 goto out;
93 if (!least ||
94 (loh * atomic_read(&dest->weight) >
95 doh * atomic_read(&least->weight))) {
96 least = dest;
97 loh = doh;
101 if (!least) {
102 IP_VS_ERR_RL("NQ: no destination available\n");
103 return NULL;
106 out:
107 IP_VS_DBG_BUF(6, "NQ: server %s:%u "
108 "activeconns %d refcnt %d weight %d overhead %d\n",
109 IP_VS_DBG_ADDR(svc->af, &least->addr), ntohs(least->port),
110 atomic_read(&least->activeconns),
111 atomic_read(&least->refcnt),
112 atomic_read(&least->weight), loh);
114 return least;
118 static struct ip_vs_scheduler ip_vs_nq_scheduler =
120 .name = "nq",
121 .refcnt = ATOMIC_INIT(0),
122 .module = THIS_MODULE,
123 .n_list = LIST_HEAD_INIT(ip_vs_nq_scheduler.n_list),
124 .schedule = ip_vs_nq_schedule,
128 static int __init ip_vs_nq_init(void)
130 return register_ip_vs_scheduler(&ip_vs_nq_scheduler);
133 static void __exit ip_vs_nq_cleanup(void)
135 unregister_ip_vs_scheduler(&ip_vs_nq_scheduler);
138 module_init(ip_vs_nq_init);
139 module_exit(ip_vs_nq_cleanup);
140 MODULE_LICENSE("GPL");