From: Yejune Deng <hidden> Date: 2021-02-26 10:59:21
In inet_initpeers(), if si.totalram <= (8192*1024)/PAGE_SIZE, it will
be judged three times. Use else if instead of if, it only needs to be
judged once.
Signed-off-by: Yejune Deng <redacted>
---
net/ipv4/inetpeer.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
@@ -81,12 +81,12 @@ void __init inet_initpeers(void)*<kuznet@ms2.inr.ac.ru>.Idon'thaveanyopinionaboutthevalues*myself.--SAW*/-if(si.totalram<=(32768*1024)/PAGE_SIZE)+if(si.totalram<=(8192*1024)/PAGE_SIZE)+inet_peer_threshold>>=4;/* about 128KB */+elseif(si.totalram<=(16384*1024)/PAGE_SIZE)+inet_peer_threshold>>=2;/* about 512KB */+elseif(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",sizeof(structinet_peer),
From: Eric Dumazet <hidden> Date: 2021-02-26 14:51:10
On 2/26/21 11:57 AM, Yejune Deng wrote:
quoted hunk
In inet_initpeers(), if si.totalram <= (8192*1024)/PAGE_SIZE, it will
be judged three times. Use else if instead of if, it only needs to be
judged once.
Signed-off-by: Yejune Deng <redacted>
---
net/ipv4/inetpeer.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
@@ -81,12 +81,12 @@ void __init inet_initpeers(void)*<kuznet@ms2.inr.ac.ru>.Idon'thaveanyopinionaboutthevalues*myself.--SAW*/-if(si.totalram<=(32768*1024)/PAGE_SIZE)+if(si.totalram<=(8192*1024)/PAGE_SIZE)+inet_peer_threshold>>=4;/* about 128KB */+elseif(si.totalram<=(16384*1024)/PAGE_SIZE)+inet_peer_threshold>>=2;/* about 512KB */+elseif(si.totalram<=(32768*1024)/PAGE_SIZE)inet_peer_threshold>>=1;/* max pool size about 1MB on IA32 */
If you really want to change this stuff, I would suggest updating comments,
because nowadays, struct inet_peer on IA32 uses 128 bytes.
So 32768 entries would consume 4 MB,
16384 entries would consume 2 MB
and 4096 entries would consume 512KB
Another idea would be to get rid of the cascade and use something that
will not need to be adjusted in the future.
@@ -65,7 +65,7 @@ EXPORT_SYMBOL_GPL(inet_peer_base_init);#define PEER_MAX_GC 32/* Exported for sysctl_net_ipv4. */-intinet_peer_threshold__read_mostly=65536+128;/* start to throw entries more+intinet_peer_threshold__read_mostly;/* start to throw entries more*aggressivelyatthisstage*/intinet_peer_minttl__read_mostly=120*HZ;/* TTL under high load: 120 sec */intinet_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 */void__initinet_initpeers(void){-structsysinfosi;+u64nr_entries;-/* Use the straight interface to information about memory. */-si_meminfo(&si);-/* The values below were suggested by Alexey Kuznetsov-*<kuznet@ms2.inr.ac.ru>.Idon'thaveanyopinionaboutthevalues-*myself.--SAW-*/-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 */+/* 1% of physical memory */+nr_entries=div64_ul((u64)totalram_pages()<<PAGE_SHIFT,+100*L1_CACHE_ALIGN(sizeof(structinet_peer)));++inet_peer_threshold=clamp_val(nr_entries,4096,65536+128);peer_cachep=kmem_cache_create("inet_peer_cache",sizeof(structinet_peer),
From: Yejune Deng <hidden> Date: 2021-03-01 01:44:39
Thanks,I will adopt it and resubmit.
On Fri, Feb 26, 2021 at 10:50 PM Eric Dumazet [off-list ref] wrote:
quoted hunk
On 2/26/21 11:57 AM, Yejune Deng wrote:
quoted
In inet_initpeers(), if si.totalram <= (8192*1024)/PAGE_SIZE, it will
be judged three times. Use else if instead of if, it only needs to be
judged once.
Signed-off-by: Yejune Deng <redacted>
---
net/ipv4/inetpeer.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
@@ -81,12 +81,12 @@ void __init inet_initpeers(void)*<kuznet@ms2.inr.ac.ru>.Idon'thaveanyopinionaboutthevalues*myself.--SAW*/-if(si.totalram<=(32768*1024)/PAGE_SIZE)+if(si.totalram<=(8192*1024)/PAGE_SIZE)+inet_peer_threshold>>=4;/* about 128KB */+elseif(si.totalram<=(16384*1024)/PAGE_SIZE)+inet_peer_threshold>>=2;/* about 512KB */+elseif(si.totalram<=(32768*1024)/PAGE_SIZE)inet_peer_threshold>>=1;/* max pool size about 1MB on IA32 */
If you really want to change this stuff, I would suggest updating comments,
because nowadays, struct inet_peer on IA32 uses 128 bytes.
So 32768 entries would consume 4 MB,
16384 entries would consume 2 MB
and 4096 entries would consume 512KB
Another idea would be to get rid of the cascade and use something that
will not need to be adjusted in the future.
@@ -65,7 +65,7 @@ EXPORT_SYMBOL_GPL(inet_peer_base_init);#define PEER_MAX_GC 32/* Exported for sysctl_net_ipv4. */-intinet_peer_threshold__read_mostly=65536+128;/* start to throw entries more+intinet_peer_threshold__read_mostly;/* start to throw entries more*aggressivelyatthisstage*/intinet_peer_minttl__read_mostly=120*HZ;/* TTL under high load: 120 sec */intinet_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 */void__initinet_initpeers(void){-structsysinfosi;+u64nr_entries;-/* Use the straight interface to information about memory. */-si_meminfo(&si);-/* The values below were suggested by Alexey Kuznetsov-*<kuznet@ms2.inr.ac.ru>.Idon'thaveanyopinionaboutthevalues-*myself.--SAW-*/-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 */+/* 1% of physical memory */+nr_entries=div64_ul((u64)totalram_pages()<<PAGE_SHIFT,+100*L1_CACHE_ALIGN(sizeof(structinet_peer)));++inet_peer_threshold=clamp_val(nr_entries,4096,65536+128);peer_cachep=kmem_cache_create("inet_peer_cache",sizeof(structinet_peer),