﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	uname	nginx_version
352	cache line size wrongly detected on virtual instance	Antoine Musso		"I found out nginx is reporting the wrong cache line size on a virtual system.

On startup it reports:

Restarting nginx: nginx: [emerg] could not build the types_hash, you should
increase either types_hash_max_size: 1024 or types_hash_bucket_size: 32

This is caused by /etc/nginx/mime.types having a key which is 36 bytes long:

 echo -n application/vnd.google-earth.kml+xml |wc -c
 36

In src/core/ngx_cpuinfo.c , the ngx_cpuinfo() reports my CPU has having a 32 bytes cache line which is then used as the default value for types_hash_bucket_size and thus trigger the startup error.

Looking at the ngx_cpuinfo() code, the values are hardcoded.  For GenuineIntel the values yields are:

 family 5 -> 32
 family 6 -> 32 or 64 depending on model
 family 15 -> 128

My virtual machine is based on QEMU which reports a family of 6, a model of 2 but a cache_alignement of 64 :

$ cat /proc/cpuinfo 
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 2
model name	: QEMU Virtual CPU version 1.0
stepping	: 3
microcode	: 0x1
cpu MHz		: 2659.998
cache size	: 4096 KB
fpu		: yes
fpu_exception	: yes
cpuid level	: 4
wp		: yes
flags		: fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pse36 clflush mmx fxsr sse sse2 syscall nx lm up rep_good nopl pni vmx cx16 popcnt hypervisor lahf_lm
bogomips	: 5319.99
clflush size	: 64
cache_alignment	: 64
address sizes	: 40 bits physical, 48 bits virtual
power management:


I do not have that issue on a real server which reports:

processor       : 7
vendor_id       : GenuineIntel
cpu family      : 6
model           : 30
model name      : Intel(R) Xeon(R) CPU           X3450  @ 2.67GHz
stepping        : 5
microcode       : 0x4
cpu MHz         : 2659.886
cache size      : 8192 KB
physical id     : 0
siblings        : 8
core id         : 3
cpu cores       : 4
apicid          : 7
initial apicid  : 7
fpu             : yes
fpu_exception   : yes
cpuid level     : 11
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 popcnt lahf_lm ida dtherm tpr_shadow vnmi flexpriority ept vpid
bogomips        : 5319.72
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:



The workaround is to hardcode types_hash_bucket_size to 64.



It would be nice to enhance the detection system to rely on the cache_alignement has reported by cpuinfo on linux.


The ngx_cpuinfo() seems to have the same issue in nginx 1.4.1 and 1.5.0.



"	defect	closed	minor		nginx-core	1.1.x	fixed			Linux deployment-nginx-test 3.2.0-41-virtual #66-Ubuntu SMP Thu Apr 25 03:47:17 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux	"nginx version: nginx/1.1.19
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-debug --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module --add-module=/mnt/nginx-1.1.19/debian/modules/nginx-auth-pam --add-module=/mnt/nginx-1.1.19/debian/modules/nginx-echo --add-module=/mnt/nginx-1.1.19/debian/modules/nginx-upstream-fair --add-module=/mnt/nginx-1.1.19/debian/modules/nginx-dav-ext-module --add-module=/mnt/nginx-1.1.19/debian/modules/nginx-udplog"
