PageRenderTime 61ms CodeModel.GetById 32ms RepoModel.GetById 2ms app.codeStats 0ms

/net/ipv4/ipvs/ip_vs_wlc.c

https://bitbucket.org/abioy/linux
C | 155 lines | 84 code | 24 blank | 47 comment | 3 complexity | 492d4dd86a5b5e4182734977085d399e MD5 | raw file
Possible License(s): CC-BY-SA-3.0, GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /*
  2. * IPVS: Weighted Least-Connection Scheduling module
  3. *
  4. * Version: $Id: ip_vs_wlc.c,v 1.13 2003/04/18 09:03:16 wensong Exp $
  5. *
  6. * Authors: Wensong Zhang <wensong@linuxvirtualserver.org>
  7. * Peter Kese <peter.kese@ijs.si>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your option) any later version.
  13. *
  14. * Changes:
  15. * Wensong Zhang : changed the ip_vs_wlc_schedule to return dest
  16. * Wensong Zhang : changed to use the inactconns in scheduling
  17. * Wensong Zhang : changed some comestics things for debugging
  18. * Wensong Zhang : changed for the d-linked destination list
  19. * Wensong Zhang : added the ip_vs_wlc_update_svc
  20. * Wensong Zhang : added any dest with weight=0 is quiesced
  21. *
  22. */
  23. #include <linux/config.h>
  24. #include <linux/module.h>
  25. #include <linux/init.h>
  26. #include <linux/types.h>
  27. #include <linux/kernel.h>
  28. #include <linux/errno.h>
  29. #include <net/ip_vs.h>
  30. static int
  31. ip_vs_wlc_init_svc(struct ip_vs_service *svc)
  32. {
  33. return 0;
  34. }
  35. static int
  36. ip_vs_wlc_done_svc(struct ip_vs_service *svc)
  37. {
  38. return 0;
  39. }
  40. static int
  41. ip_vs_wlc_update_svc(struct ip_vs_service *svc)
  42. {
  43. return 0;
  44. }
  45. static inline unsigned int
  46. ip_vs_wlc_dest_overhead(struct ip_vs_dest *dest)
  47. {
  48. /*
  49. * We think the overhead of processing active connections is 256
  50. * times higher than that of inactive connections in average. (This
  51. * 256 times might not be accurate, we will change it later) We
  52. * use the following formula to estimate the overhead now:
  53. * dest->activeconns*256 + dest->inactconns
  54. */
  55. return (atomic_read(&dest->activeconns) << 8) +
  56. atomic_read(&dest->inactconns);
  57. }
  58. /*
  59. * Weighted Least Connection scheduling
  60. */
  61. static struct ip_vs_dest *
  62. ip_vs_wlc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
  63. {
  64. struct ip_vs_dest *dest, *least;
  65. unsigned int loh, doh;
  66. IP_VS_DBG(6, "ip_vs_wlc_schedule(): Scheduling...\n");
  67. /*
  68. * We calculate the load of each dest server as follows:
  69. * (dest overhead) / dest->weight
  70. *
  71. * Remember -- no floats in kernel mode!!!
  72. * The comparison of h1*w2 > h2*w1 is equivalent to that of
  73. * h1/w1 > h2/w2
  74. * if every weight is larger than zero.
  75. *
  76. * The server with weight=0 is quiesced and will not receive any
  77. * new connections.
  78. */
  79. list_for_each_entry(dest, &svc->destinations, n_list) {
  80. if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) &&
  81. atomic_read(&dest->weight) > 0) {
  82. least = dest;
  83. loh = ip_vs_wlc_dest_overhead(least);
  84. goto nextstage;
  85. }
  86. }
  87. return NULL;
  88. /*
  89. * Find the destination with the least load.
  90. */
  91. nextstage:
  92. list_for_each_entry_continue(dest, &svc->destinations, n_list) {
  93. if (dest->flags & IP_VS_DEST_F_OVERLOAD)
  94. continue;
  95. doh = ip_vs_wlc_dest_overhead(dest);
  96. if (loh * atomic_read(&dest->weight) >
  97. doh * atomic_read(&least->weight)) {
  98. least = dest;
  99. loh = doh;
  100. }
  101. }
  102. IP_VS_DBG(6, "WLC: server %u.%u.%u.%u:%u "
  103. "activeconns %d refcnt %d weight %d overhead %d\n",
  104. NIPQUAD(least->addr), ntohs(least->port),
  105. atomic_read(&least->activeconns),
  106. atomic_read(&least->refcnt),
  107. atomic_read(&least->weight), loh);
  108. return least;
  109. }
  110. static struct ip_vs_scheduler ip_vs_wlc_scheduler =
  111. {
  112. .name = "wlc",
  113. .refcnt = ATOMIC_INIT(0),
  114. .module = THIS_MODULE,
  115. .init_service = ip_vs_wlc_init_svc,
  116. .done_service = ip_vs_wlc_done_svc,
  117. .update_service = ip_vs_wlc_update_svc,
  118. .schedule = ip_vs_wlc_schedule,
  119. };
  120. static int __init ip_vs_wlc_init(void)
  121. {
  122. INIT_LIST_HEAD(&ip_vs_wlc_scheduler.n_list);
  123. return register_ip_vs_scheduler(&ip_vs_wlc_scheduler);
  124. }
  125. static void __exit ip_vs_wlc_cleanup(void)
  126. {
  127. unregister_ip_vs_scheduler(&ip_vs_wlc_scheduler);
  128. }
  129. module_init(ip_vs_wlc_init);
  130. module_exit(ip_vs_wlc_cleanup);
  131. MODULE_LICENSE("GPL");