Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

inetpeer: use div64_ul() and clamp_val() calculate inet_peer_threshold

In inet_initpeers(), struct inet_peer on IA32 uses 128 bytes in nowdays.
Get rid of the cascade and use div64_ul() and clamp_val() calculate that
will not need to be adjusted in the future as suggested by Eric Dumazet.

Suggested-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Yejune Deng <yejune.deng@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Yejune Deng and committed by
David S. Miller
8bd2a055 093b036a

+7 -14
+7 -14
net/ipv4/inetpeer.c
··· 65 65 #define PEER_MAX_GC 32 66 66 67 67 /* Exported for sysctl_net_ipv4. */ 68 - int inet_peer_threshold __read_mostly = 65536 + 128; /* start to throw entries more 68 + int inet_peer_threshold __read_mostly; /* start to throw entries more 69 69 * aggressively at this stage */ 70 70 int inet_peer_minttl __read_mostly = 120 * HZ; /* TTL under high load: 120 sec */ 71 71 int inet_peer_maxttl __read_mostly = 10 * 60 * HZ; /* usual time to live: 10 min */ ··· 73 73 /* Called from ip_output.c:ip_init */ 74 74 void __init inet_initpeers(void) 75 75 { 76 - struct sysinfo si; 76 + u64 nr_entries; 77 77 78 - /* Use the straight interface to information about memory. */ 79 - si_meminfo(&si); 80 - /* The values below were suggested by Alexey Kuznetsov 81 - * <kuznet@ms2.inr.ac.ru>. I don't have any opinion about the values 82 - * myself. --SAW 83 - */ 84 - if (si.totalram <= (32768*1024)/PAGE_SIZE) 85 - inet_peer_threshold >>= 1; /* max pool size about 1MB on IA32 */ 86 - if (si.totalram <= (16384*1024)/PAGE_SIZE) 87 - inet_peer_threshold >>= 1; /* about 512KB */ 88 - if (si.totalram <= (8192*1024)/PAGE_SIZE) 89 - inet_peer_threshold >>= 2; /* about 128KB */ 78 + /* 1% of physical memory */ 79 + nr_entries = div64_ul((u64)totalram_pages() << PAGE_SHIFT, 80 + 100 * L1_CACHE_ALIGN(sizeof(struct inet_peer))); 81 + 82 + inet_peer_threshold = clamp_val(nr_entries, 4096, 65536 + 128); 90 83 91 84 peer_cachep = kmem_cache_create("inet_peer_cache", 92 85 sizeof(struct inet_peer),