Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 57413ebc authored by Miquel van Smoorenburg's avatar Miquel van Smoorenburg Committed by David S. Miller
Browse files

tcp: calculate tcp_mem based on low memory instead of all memory



The tcp_mem array which contains limits on the total amount of memory
used by TCP sockets is calculated based on nr_all_pages.  On a 32 bits
x86 system, we should base this on the number of lowmem pages.

Signed-off-by: default avatarMiquel van Smoorenburg <miquels@cistron.nl>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 47979821
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -260,6 +260,8 @@
#include <linux/socket.h>
#include <linux/random.h>
#include <linux/bootmem.h>
#include <linux/highmem.h>
#include <linux/swap.h>
#include <linux/cache.h>
#include <linux/err.h>
#include <linux/crypto.h>
@@ -2620,7 +2622,7 @@ __setup("thash_entries=", set_thash_entries);
void __init tcp_init(void)
{
	struct sk_buff *skb = NULL;
	unsigned long limit;
	unsigned long nr_pages, limit;
	int order, i, max_share;

	BUILD_BUG_ON(sizeof(struct tcp_skb_cb) > sizeof(skb->cb));
@@ -2689,8 +2691,9 @@ void __init tcp_init(void)
	 * is up to 1/2 at 256 MB, decreasing toward zero with the amount of
	 * memory, with a floor of 128 pages.
	 */
	limit = min(nr_all_pages, 1UL<<(28-PAGE_SHIFT)) >> (20-PAGE_SHIFT);
	limit = (limit * (nr_all_pages >> (20-PAGE_SHIFT))) >> (PAGE_SHIFT-11);
	nr_pages = totalram_pages - totalhigh_pages;
	limit = min(nr_pages, 1UL<<(28-PAGE_SHIFT)) >> (20-PAGE_SHIFT);
	limit = (limit * (nr_pages >> (20-PAGE_SHIFT))) >> (PAGE_SHIFT-11);
	limit = max(limit, 128UL);
	sysctl_tcp_mem[0] = limit / 4 * 3;
	sysctl_tcp_mem[1] = limit;