~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/netfilter/ipvs/ip_vs_wlc.c

Version: ~ [ linux-5.8 ] ~ [ linux-5.7.14 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.57 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.138 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.193 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.232 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.232 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * IPVS:        Weighted Least-Connection Scheduling module
  3  *
  4  * Authors:     Wensong Zhang <wensong@linuxvirtualserver.org>
  5  *              Peter Kese <peter.kese@ijs.si>
  6  *
  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.
 11  *
 12  * Changes:
 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
 19  *
 20  */
 21 
 22 #define KMSG_COMPONENT "IPVS"
 23 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
 24 
 25 #include <linux/module.h>
 26 #include <linux/kernel.h>
 27 
 28 #include <net/ip_vs.h>
 29 
 30 /*
 31  *      Weighted Least Connection scheduling
 32  */
 33 static struct ip_vs_dest *
 34 ip_vs_wlc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
 35                    struct ip_vs_iphdr *iph)
 36 {
 37         struct ip_vs_dest *dest, *least;
 38         int loh, doh;
 39 
 40         IP_VS_DBG(6, "ip_vs_wlc_schedule(): Scheduling...\n");
 41 
 42         /*
 43          * We calculate the load of each dest server as follows:
 44          *                (dest overhead) / dest->weight
 45          *
 46          * Remember -- no floats in kernel mode!!!
 47          * The comparison of h1*w2 > h2*w1 is equivalent to that of
 48          *                h1/w1 > h2/w2
 49          * if every weight is larger than zero.
 50          *
 51          * The server with weight=0 is quiesced and will not receive any
 52          * new connections.
 53          */
 54 
 55         list_for_each_entry_rcu(dest, &svc->destinations, n_list) {
 56                 if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) &&
 57                     atomic_read(&dest->weight) > 0) {
 58                         least = dest;
 59                         loh = ip_vs_dest_conn_overhead(least);
 60                         goto nextstage;
 61                 }
 62         }
 63         ip_vs_scheduler_err(svc, "no destination available");
 64         return NULL;
 65 
 66         /*
 67          *    Find the destination with the least load.
 68          */
 69   nextstage:
 70         list_for_each_entry_continue_rcu(dest, &svc->destinations, n_list) {
 71                 if (dest->flags & IP_VS_DEST_F_OVERLOAD)
 72                         continue;
 73                 doh = ip_vs_dest_conn_overhead(dest);
 74                 if ((__s64)loh * atomic_read(&dest->weight) >
 75                     (__s64)doh * atomic_read(&least->weight)) {
 76                         least = dest;
 77                         loh = doh;
 78                 }
 79         }
 80 
 81         IP_VS_DBG_BUF(6, "WLC: server %s:%u "
 82                       "activeconns %d refcnt %d weight %d overhead %d\n",
 83                       IP_VS_DBG_ADDR(svc->af, &least->addr), ntohs(least->port),
 84                       atomic_read(&least->activeconns),
 85                       atomic_read(&least->refcnt),
 86                       atomic_read(&least->weight), loh);
 87 
 88         return least;
 89 }
 90 
 91 
 92 static struct ip_vs_scheduler ip_vs_wlc_scheduler =
 93 {
 94         .name =                 "wlc",
 95         .refcnt =               ATOMIC_INIT(0),
 96         .module =               THIS_MODULE,
 97         .n_list =               LIST_HEAD_INIT(ip_vs_wlc_scheduler.n_list),
 98         .schedule =             ip_vs_wlc_schedule,
 99 };
100 
101 
102 static int __init ip_vs_wlc_init(void)
103 {
104         return register_ip_vs_scheduler(&ip_vs_wlc_scheduler);
105 }
106 
107 static void __exit ip_vs_wlc_cleanup(void)
108 {
109         unregister_ip_vs_scheduler(&ip_vs_wlc_scheduler);
110         synchronize_rcu();
111 }
112 
113 module_init(ip_vs_wlc_init);
114 module_exit(ip_vs_wlc_cleanup);
115 MODULE_LICENSE("GPL");
116 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp