Commit b552f7e3 authored by Changli Gao's avatar Changli Gao Committed by Simon Horman

ipvs: unify the formula to estimate the overhead of processing connections

lc and wlc use the same formula, but lblc and lblcr use another one. There
is no reason for using two different formulas for the lc variants.

The formula used by lc is used by all the lc variants in this patch.
Signed-off-by: default avatarChangli Gao <xiaosuo@gmail.com>
Acked-by: default avatarWensong Zhang <wensong@linux-vs.org>
Signed-off-by: default avatarSimon Horman <horms@verge.net.au>
parent 17a8f8e3
...@@ -1243,6 +1243,20 @@ static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp) ...@@ -1243,6 +1243,20 @@ static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp)
/* CONFIG_IP_VS_NFCT */ /* CONFIG_IP_VS_NFCT */
#endif #endif
static inline unsigned int
ip_vs_dest_conn_overhead(struct ip_vs_dest *dest)
{
/*
* We think the overhead of processing active connections is 256
* times higher than that of inactive connections in average. (This
* 256 times might not be accurate, we will change it later) We
* use the following formula to estimate the overhead now:
* dest->activeconns*256 + dest->inactconns
*/
return (atomic_read(&dest->activeconns) << 8) +
atomic_read(&dest->inactconns);
}
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
#endif /* _NET_IP_VS_H */ #endif /* _NET_IP_VS_H */
...@@ -389,12 +389,7 @@ __ip_vs_lblc_schedule(struct ip_vs_service *svc) ...@@ -389,12 +389,7 @@ __ip_vs_lblc_schedule(struct ip_vs_service *svc)
int loh, doh; int loh, doh;
/* /*
* We think the overhead of processing active connections is fifty * We use the following formula to estimate the load:
* times higher than that of inactive connections in average. (This
* fifty times might not be accurate, we will change it later.) We
* use the following formula to estimate the overhead:
* dest->activeconns*50 + dest->inactconns
* and the load:
* (dest overhead) / dest->weight * (dest overhead) / dest->weight
* *
* Remember -- no floats in kernel mode!!! * Remember -- no floats in kernel mode!!!
...@@ -410,8 +405,7 @@ __ip_vs_lblc_schedule(struct ip_vs_service *svc) ...@@ -410,8 +405,7 @@ __ip_vs_lblc_schedule(struct ip_vs_service *svc)
continue; continue;
if (atomic_read(&dest->weight) > 0) { if (atomic_read(&dest->weight) > 0) {
least = dest; least = dest;
loh = atomic_read(&least->activeconns) * 50 loh = ip_vs_dest_conn_overhead(least);
+ atomic_read(&least->inactconns);
goto nextstage; goto nextstage;
} }
} }
...@@ -425,8 +419,7 @@ __ip_vs_lblc_schedule(struct ip_vs_service *svc) ...@@ -425,8 +419,7 @@ __ip_vs_lblc_schedule(struct ip_vs_service *svc)
if (dest->flags & IP_VS_DEST_F_OVERLOAD) if (dest->flags & IP_VS_DEST_F_OVERLOAD)
continue; continue;
doh = atomic_read(&dest->activeconns) * 50 doh = ip_vs_dest_conn_overhead(dest);
+ atomic_read(&dest->inactconns);
if (loh * atomic_read(&dest->weight) > if (loh * atomic_read(&dest->weight) >
doh * atomic_read(&least->weight)) { doh * atomic_read(&least->weight)) {
least = dest; least = dest;
......
...@@ -178,8 +178,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set) ...@@ -178,8 +178,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set)
if ((atomic_read(&least->weight) > 0) if ((atomic_read(&least->weight) > 0)
&& (least->flags & IP_VS_DEST_F_AVAILABLE)) { && (least->flags & IP_VS_DEST_F_AVAILABLE)) {
loh = atomic_read(&least->activeconns) * 50 loh = ip_vs_dest_conn_overhead(least);
+ atomic_read(&least->inactconns);
goto nextstage; goto nextstage;
} }
} }
...@@ -192,8 +191,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set) ...@@ -192,8 +191,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set)
if (dest->flags & IP_VS_DEST_F_OVERLOAD) if (dest->flags & IP_VS_DEST_F_OVERLOAD)
continue; continue;
doh = atomic_read(&dest->activeconns) * 50 doh = ip_vs_dest_conn_overhead(dest);
+ atomic_read(&dest->inactconns);
if ((loh * atomic_read(&dest->weight) > if ((loh * atomic_read(&dest->weight) >
doh * atomic_read(&least->weight)) doh * atomic_read(&least->weight))
&& (dest->flags & IP_VS_DEST_F_AVAILABLE)) { && (dest->flags & IP_VS_DEST_F_AVAILABLE)) {
...@@ -228,8 +226,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_max(struct ip_vs_dest_set *set) ...@@ -228,8 +226,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_max(struct ip_vs_dest_set *set)
list_for_each_entry(e, &set->list, list) { list_for_each_entry(e, &set->list, list) {
most = e->dest; most = e->dest;
if (atomic_read(&most->weight) > 0) { if (atomic_read(&most->weight) > 0) {
moh = atomic_read(&most->activeconns) * 50 moh = ip_vs_dest_conn_overhead(most);
+ atomic_read(&most->inactconns);
goto nextstage; goto nextstage;
} }
} }
...@@ -239,8 +236,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_max(struct ip_vs_dest_set *set) ...@@ -239,8 +236,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_max(struct ip_vs_dest_set *set)
nextstage: nextstage:
list_for_each_entry(e, &set->list, list) { list_for_each_entry(e, &set->list, list) {
dest = e->dest; dest = e->dest;
doh = atomic_read(&dest->activeconns) * 50 doh = ip_vs_dest_conn_overhead(dest);
+ atomic_read(&dest->inactconns);
/* moh/mw < doh/dw ==> moh*dw < doh*mw, where mw,dw>0 */ /* moh/mw < doh/dw ==> moh*dw < doh*mw, where mw,dw>0 */
if ((moh * atomic_read(&dest->weight) < if ((moh * atomic_read(&dest->weight) <
doh * atomic_read(&most->weight)) doh * atomic_read(&most->weight))
...@@ -563,12 +559,7 @@ __ip_vs_lblcr_schedule(struct ip_vs_service *svc) ...@@ -563,12 +559,7 @@ __ip_vs_lblcr_schedule(struct ip_vs_service *svc)
int loh, doh; int loh, doh;
/* /*
* We think the overhead of processing active connections is fifty * We use the following formula to estimate the load:
* times higher than that of inactive connections in average. (This
* fifty times might not be accurate, we will change it later.) We
* use the following formula to estimate the overhead:
* dest->activeconns*50 + dest->inactconns
* and the load:
* (dest overhead) / dest->weight * (dest overhead) / dest->weight
* *
* Remember -- no floats in kernel mode!!! * Remember -- no floats in kernel mode!!!
...@@ -585,8 +576,7 @@ __ip_vs_lblcr_schedule(struct ip_vs_service *svc) ...@@ -585,8 +576,7 @@ __ip_vs_lblcr_schedule(struct ip_vs_service *svc)
if (atomic_read(&dest->weight) > 0) { if (atomic_read(&dest->weight) > 0) {
least = dest; least = dest;
loh = atomic_read(&least->activeconns) * 50 loh = ip_vs_dest_conn_overhead(least);
+ atomic_read(&least->inactconns);
goto nextstage; goto nextstage;
} }
} }
...@@ -600,8 +590,7 @@ __ip_vs_lblcr_schedule(struct ip_vs_service *svc) ...@@ -600,8 +590,7 @@ __ip_vs_lblcr_schedule(struct ip_vs_service *svc)
if (dest->flags & IP_VS_DEST_F_OVERLOAD) if (dest->flags & IP_VS_DEST_F_OVERLOAD)
continue; continue;
doh = atomic_read(&dest->activeconns) * 50 doh = ip_vs_dest_conn_overhead(dest);
+ atomic_read(&dest->inactconns);
if (loh * atomic_read(&dest->weight) > if (loh * atomic_read(&dest->weight) >
doh * atomic_read(&least->weight)) { doh * atomic_read(&least->weight)) {
least = dest; least = dest;
......
...@@ -22,22 +22,6 @@ ...@@ -22,22 +22,6 @@
#include <net/ip_vs.h> #include <net/ip_vs.h>
static inline unsigned int
ip_vs_lc_dest_overhead(struct ip_vs_dest *dest)
{
/*
* We think the overhead of processing active connections is 256
* times higher than that of inactive connections in average. (This
* 256 times might not be accurate, we will change it later) We
* use the following formula to estimate the overhead now:
* dest->activeconns*256 + dest->inactconns
*/
return (atomic_read(&dest->activeconns) << 8) +
atomic_read(&dest->inactconns);
}
/* /*
* Least Connection scheduling * Least Connection scheduling
*/ */
...@@ -62,7 +46,7 @@ ip_vs_lc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb) ...@@ -62,7 +46,7 @@ ip_vs_lc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
if ((dest->flags & IP_VS_DEST_F_OVERLOAD) || if ((dest->flags & IP_VS_DEST_F_OVERLOAD) ||
atomic_read(&dest->weight) == 0) atomic_read(&dest->weight) == 0)
continue; continue;
doh = ip_vs_lc_dest_overhead(dest); doh = ip_vs_dest_conn_overhead(dest);
if (!least || doh < loh) { if (!least || doh < loh) {
least = dest; least = dest;
loh = doh; loh = doh;
......
...@@ -27,22 +27,6 @@ ...@@ -27,22 +27,6 @@
#include <net/ip_vs.h> #include <net/ip_vs.h>
static inline unsigned int
ip_vs_wlc_dest_overhead(struct ip_vs_dest *dest)
{
/*
* We think the overhead of processing active connections is 256
* times higher than that of inactive connections in average. (This
* 256 times might not be accurate, we will change it later) We
* use the following formula to estimate the overhead now:
* dest->activeconns*256 + dest->inactconns
*/
return (atomic_read(&dest->activeconns) << 8) +
atomic_read(&dest->inactconns);
}
/* /*
* Weighted Least Connection scheduling * Weighted Least Connection scheduling
*/ */
...@@ -71,7 +55,7 @@ ip_vs_wlc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb) ...@@ -71,7 +55,7 @@ ip_vs_wlc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) && if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) &&
atomic_read(&dest->weight) > 0) { atomic_read(&dest->weight) > 0) {
least = dest; least = dest;
loh = ip_vs_wlc_dest_overhead(least); loh = ip_vs_dest_conn_overhead(least);
goto nextstage; goto nextstage;
} }
} }
...@@ -85,7 +69,7 @@ ip_vs_wlc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb) ...@@ -85,7 +69,7 @@ ip_vs_wlc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
list_for_each_entry_continue(dest, &svc->destinations, n_list) { list_for_each_entry_continue(dest, &svc->destinations, n_list) {
if (dest->flags & IP_VS_DEST_F_OVERLOAD) if (dest->flags & IP_VS_DEST_F_OVERLOAD)
continue; continue;
doh = ip_vs_wlc_dest_overhead(dest); doh = ip_vs_dest_conn_overhead(dest);
if (loh * atomic_read(&dest->weight) > if (loh * atomic_read(&dest->weight) >
doh * atomic_read(&least->weight)) { doh * atomic_read(&least->weight)) {
least = dest; least = dest;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment