Skip to content

Commit 146cd6b

Browse files
committed
Simon Horman says: ==================== IPVS Updates for v4.18 please consider these IPVS enhancements for v4.18. * Whitepace cleanup * Add Maglev hashing algorithm as a IPVS scheduler Inju Song says "Implements the Google's Maglev hashing algorithm as a IPVS scheduler. Basically it provides consistent hashing but offers some special features about disruption and load balancing. 1) minimal disruption: when the set of destinations changes, a connection will likely be sent to the same destination as it was before. 2) load balancing: each destination will receive an almost equal number of connections. Seel also: [3.4 Consistent Hasing] in https://www.usenix.org/system/files/conference/nsdi16/nsdi16-paper-eisenbud.pdf " * Fix to correct implementation of Knuth's multiplicative hashing which is used in sh/dh/lblc/lblcr algorithms. Instead the implementation provided by the hash_32() macro is used. ==================== Signed-off-by: Pablo Neira Ayuso <[email protected]>
2 parents d010315 + 9a17740 commit 146cd6b

File tree

10 files changed

+593
-6
lines changed

10 files changed

+593
-6
lines changed

include/net/ip_vs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ struct ip_vs_dest {
668668
volatile unsigned int flags; /* dest status flags */
669669
atomic_t conn_flags; /* flags to copy to conn */
670670
atomic_t weight; /* server weight */
671+
atomic_t last_weight; /* server latest weight */
671672

672673
refcount_t refcnt; /* reference counter */
673674
struct ip_vs_stats stats; /* statistics */

net/netfilter/ipvs/Kconfig

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,25 @@ config IP_VS_SH
225225
If you want to compile it in kernel, say Y. To compile it as a
226226
module, choose M here. If unsure, say N.
227227

228+
config IP_VS_MH
229+
tristate "maglev hashing scheduling"
230+
---help---
231+
The maglev consistent hashing scheduling algorithm provides the
232+
Google's Maglev hashing algorithm as a IPVS scheduler. It assigns
233+
network connections to the servers through looking up a statically
234+
assigned special hash table called the lookup table. Maglev hashing
235+
is to assign a preference list of all the lookup table positions
236+
to each destination.
237+
238+
Through this operation, The maglev hashing gives an almost equal
239+
share of the lookup table to each of the destinations and provides
240+
minimal disruption by using the lookup table. When the set of
241+
destinations changes, a connection will likely be sent to the same
242+
destination as it was before.
243+
244+
If you want to compile it in kernel, say Y. To compile it as a
245+
module, choose M here. If unsure, say N.
246+
228247
config IP_VS_SED
229248
tristate "shortest expected delay scheduling"
230249
---help---
@@ -266,6 +285,24 @@ config IP_VS_SH_TAB_BITS
266285
needs to be large enough to effectively fit all the destinations
267286
multiplied by their respective weights.
268287

288+
comment 'IPVS MH scheduler'
289+
290+
config IP_VS_MH_TAB_INDEX
291+
int "IPVS maglev hashing table index of size (the prime numbers)"
292+
range 8 17
293+
default 12
294+
---help---
295+
The maglev hashing scheduler maps source IPs to destinations
296+
stored in a hash table. This table is assigned by a preference
297+
list of the positions to each destination until all slots in
298+
the table are filled. The index determines the prime for size of
299+
the table as�251, 509, 1021, 2039, 4093, 8191, 16381, 32749,
300+
65521 or 131071.�When using weights to allow destinations to
301+
receive more connections,�the table is assigned an amount
302+
proportional to the weights specified.�The table needs to be large
303+
enough to effectively fit all the destinations multiplied by their
304+
respective weights.
305+
269306
comment 'IPVS application helper'
270307

271308
config IP_VS_FTP

net/netfilter/ipvs/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ obj-$(CONFIG_IP_VS_LBLC) += ip_vs_lblc.o
3333
obj-$(CONFIG_IP_VS_LBLCR) += ip_vs_lblcr.o
3434
obj-$(CONFIG_IP_VS_DH) += ip_vs_dh.o
3535
obj-$(CONFIG_IP_VS_SH) += ip_vs_sh.o
36+
obj-$(CONFIG_IP_VS_MH) += ip_vs_mh.o
3637
obj-$(CONFIG_IP_VS_SED) += ip_vs_sed.o
3738
obj-$(CONFIG_IP_VS_NQ) += ip_vs_nq.o
3839

net/netfilter/ipvs/ip_vs_ctl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,10 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
821821
if (add && udest->af != svc->af)
822822
ipvs->mixed_address_family_dests++;
823823

824+
/* keep the last_weight with latest non-0 weight */
825+
if (add || udest->weight != 0)
826+
atomic_set(&dest->last_weight, udest->weight);
827+
824828
/* set the weight and the flags */
825829
atomic_set(&dest->weight, udest->weight);
826830
conn_flags = udest->conn_flags & IP_VS_CONN_F_DEST_MASK;

net/netfilter/ipvs/ip_vs_dh.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <linux/module.h>
4444
#include <linux/kernel.h>
4545
#include <linux/skbuff.h>
46+
#include <linux/hash.h>
4647

4748
#include <net/ip_vs.h>
4849

@@ -81,7 +82,7 @@ static inline unsigned int ip_vs_dh_hashkey(int af, const union nf_inet_addr *ad
8182
addr_fold = addr->ip6[0]^addr->ip6[1]^
8283
addr->ip6[2]^addr->ip6[3];
8384
#endif
84-
return (ntohl(addr_fold)*2654435761UL) & IP_VS_DH_TAB_MASK;
85+
return hash_32(ntohl(addr_fold), IP_VS_DH_TAB_BITS);
8586
}
8687

8788

net/netfilter/ipvs/ip_vs_lblc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <linux/kernel.h>
4949
#include <linux/skbuff.h>
5050
#include <linux/jiffies.h>
51+
#include <linux/hash.h>
5152

5253
/* for sysctl */
5354
#include <linux/fs.h>
@@ -160,7 +161,7 @@ ip_vs_lblc_hashkey(int af, const union nf_inet_addr *addr)
160161
addr_fold = addr->ip6[0]^addr->ip6[1]^
161162
addr->ip6[2]^addr->ip6[3];
162163
#endif
163-
return (ntohl(addr_fold)*2654435761UL) & IP_VS_LBLC_TAB_MASK;
164+
return hash_32(ntohl(addr_fold), IP_VS_LBLC_TAB_BITS);
164165
}
165166

166167

net/netfilter/ipvs/ip_vs_lblcr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <linux/jiffies.h>
4848
#include <linux/list.h>
4949
#include <linux/slab.h>
50+
#include <linux/hash.h>
5051

5152
/* for sysctl */
5253
#include <linux/fs.h>
@@ -323,7 +324,7 @@ ip_vs_lblcr_hashkey(int af, const union nf_inet_addr *addr)
323324
addr_fold = addr->ip6[0]^addr->ip6[1]^
324325
addr->ip6[2]^addr->ip6[3];
325326
#endif
326-
return (ntohl(addr_fold)*2654435761UL) & IP_VS_LBLCR_TAB_MASK;
327+
return hash_32(ntohl(addr_fold), IP_VS_LBLCR_TAB_BITS);
327328
}
328329

329330

0 commit comments

Comments
 (0)