Commit 8bd2a055 authored by Yejune Deng's avatar Yejune Deng Committed by David S. Miller

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: default avatarEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: default avatarYejune Deng <yejune.deng@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 093b036a
...@@ -65,7 +65,7 @@ EXPORT_SYMBOL_GPL(inet_peer_base_init); ...@@ -65,7 +65,7 @@ EXPORT_SYMBOL_GPL(inet_peer_base_init);
#define PEER_MAX_GC 32 #define PEER_MAX_GC 32
/* Exported for sysctl_net_ipv4. */ /* Exported for sysctl_net_ipv4. */
int inet_peer_threshold __read_mostly = 65536 + 128; /* start to throw entries more int inet_peer_threshold __read_mostly; /* start to throw entries more
* aggressively at this stage */ * aggressively at this stage */
int inet_peer_minttl __read_mostly = 120 * HZ; /* TTL under high load: 120 sec */ int inet_peer_minttl __read_mostly = 120 * HZ; /* TTL under high load: 120 sec */
int inet_peer_maxttl __read_mostly = 10 * 60 * HZ; /* usual time to live: 10 min */ int inet_peer_maxttl __read_mostly = 10 * 60 * HZ; /* usual time to live: 10 min */
...@@ -73,20 +73,13 @@ int inet_peer_maxttl __read_mostly = 10 * 60 * HZ; /* usual time to live: 10 min ...@@ -73,20 +73,13 @@ int inet_peer_maxttl __read_mostly = 10 * 60 * HZ; /* usual time to live: 10 min
/* Called from ip_output.c:ip_init */ /* Called from ip_output.c:ip_init */
void __init inet_initpeers(void) void __init inet_initpeers(void)
{ {
struct sysinfo si; u64 nr_entries;
/* Use the straight interface to information about memory. */ /* 1% of physical memory */
si_meminfo(&si); nr_entries = div64_ul((u64)totalram_pages() << PAGE_SHIFT,
/* The values below were suggested by Alexey Kuznetsov 100 * L1_CACHE_ALIGN(sizeof(struct inet_peer)));
* <kuznet@ms2.inr.ac.ru>. I don't have any opinion about the values
* myself. --SAW inet_peer_threshold = clamp_val(nr_entries, 4096, 65536 + 128);
*/
if (si.totalram <= (32768*1024)/PAGE_SIZE)
inet_peer_threshold >>= 1; /* max pool size about 1MB on IA32 */
if (si.totalram <= (16384*1024)/PAGE_SIZE)
inet_peer_threshold >>= 1; /* about 512KB */
if (si.totalram <= (8192*1024)/PAGE_SIZE)
inet_peer_threshold >>= 2; /* about 128KB */
peer_cachep = kmem_cache_create("inet_peer_cache", peer_cachep = kmem_cache_create("inet_peer_cache",
sizeof(struct inet_peer), sizeof(struct inet_peer),
......
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