diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c
index 53bc584..d4b2d42 100644
--- a/net/ipv4/tcp_metrics.c
+++ b/net/ipv4/tcp_metrics.c
@@ -1,7 +1,6 @@
 #include <linux/rcupdate.h>
 #include <linux/spinlock.h>
 #include <linux/jiffies.h>
-#include <linux/bootmem.h>
 #include <linux/module.h>
 #include <linux/cache.h>
 #include <linux/slab.h>
@@ -9,6 +8,7 @@
 #include <linux/tcp.h>
 #include <linux/hash.h>
 #include <linux/tcp_metrics.h>
+#include <linux/mmzone.h>
 
 #include <net/inet_connection_sock.h>
 #include <net/net_namespace.h>
@@ -1025,10 +1025,12 @@ static int __net_init tcp_net_metrics_init(struct net *net)
 
 	slots = tcpmhash_entries;
 	if (!slots) {
-		if (totalram_pages >= 128 * 1024)
-			slots = 16 * 1024;
-		else
-			slots = 8 * 1024;
+		int order = PAGE_ALLOC_COSTLY_ORDER;
+
+		if (totalram_pages < 128 * 1024)
+			order--;
+		slots = (PAGE_SIZE << order) /
+			sizeof(struct tcpm_hash_bucket);
 	}
 
 	net->ipv4.tcp_metrics_hash_log = order_base_2(slots);
