accel/tcg: reduce default code gen buffer on small hosts
PATCH 1/1 accel/tcg: reduce default code gen buffer on small hosts
Since v5.0.0 and 600e17b2 "accel/tcg: increase default code gen buffer size for 64 bit" in particular qemu with TCG regularly gets OOM Killed on small hosts.
The former 47a2def4 "accel/tcg: remove link between guest ram and TCG cache size" removed the link to guest size which is right, but at least some connection to the host size needs to be retained to avoid growing out of control on common CI setups which run at 1-2G host sizes.
The lower value of 1/8th of the host memory size and the default (of currently 1G) will be taken to initialize the TB. There already is a Min/Max check in place to not reach ridiculously small values.
--- accel/tcg/translate-all.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
accel/tcg/translate-all.c +23 -0
@@ -977,6 +977,29 @@ static inline size_t size_code_gen_buffer(size_t tb_size)/* Size the buffer. */ if (tb_size ==0 ) { tb_size =DEFAULT_CODE_GEN_BUFFER_SIZE ; +/* +* A static default of 1G turned out to break (OOM Kill) many common +* CI setups that run at 1-2G Host memory size. +* At the same time the former default of ram_size/4 wasted performance +* on large host systems when running small guests. +* Common CI guest sizes are 0.5-1G which meant ~128M-256M TB size. +* A Default of 1/8th of the host size will get small hosts a +* similar TB size than they had prior to v5.0 and common bare metal +* systems (>=8G) the new 1G default that was set in v5.0 +*/ +#if defined _SC_PHYS_PAGES && defined _SC_PAGESIZE + { +unsigned long max =DEFAULT_CODE_GEN_BUFFER_SIZE ; +double pages = (double )sysconf (_SC_PHYS_PAGES); + +if (pages >0 && pagesize >0 ) { + max = (unsigned long )((pages * qemu_real_host_page_size) /8 ); + } +if (max <DEFAULT_CODE_GEN_BUFFER_SIZE ) { + tb_size = max; + } + } +#endif }if (tb_size <MIN_CODE_GEN_BUFFER_SIZE ) { tb_size =MIN_CODE_GEN_BUFFER_SIZE ;
Signature · 1 line
2.27.0
Quoted 9 lines · Christian Ehrhardt
Since v5.0.0 and
600e17b2"accel/tcg: increase default code gen buffer size for 64 bit" in particular qemu with TCG regularly gets OOM Killed on small hosts.The former
47a2def4"accel/tcg: remove link between guest ram and TCG cache size" removed the link to guest size which is right, but at least some connection to the host size needs to be retained to avoid growing out of control on common CI setups which run at 1-2G host sizes.
Quoted 6 lines
The lower value of 1/8th of the host memory size and the default (of currently 1G) will be taken to initialize the TB. There already is a Min/Max check in place to not reach ridiculously small values.
Fixes 600e17b2
Just found "[PATCH v1 0/5] candidate fixes for 5.1-rc1 (shippable, semihosting, OOM tcg)"
which was submitted while I was prepping this one (this is a busy day since I'll be off for a week).
Please ignore this patch here and give the series of Alex a look as it is the more advanced version :-).
Quoted 49 lines
Signed-off-by Christian Ehrhardt <[email protected]>--- accel/tcg/translate-all.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)accel/tcg/translate-all.c +2
-0@@ -977,6 +977,29 @@ static inline size_t size_code_gen_buffer(size_t tb_size)/* Size the buffer. */ if (tb_size ==0 ) { tb_size =DEFAULT_CODE_GEN_BUFFER_SIZE ; +/* +* A static default of 1G turned out to break (OOM Kill) many common
accel/tcg/translate-all.c +2
-0+* CI setups that run at 1-2G Host memory size. +* At the same time the former default of ram_size/4 wasted performance
accel/tcg/translate-all.c +2
-0+* on large host systems when running small guests. +* Common CI guest sizes are 0.5-1G which meant ~128M-256M TB size.
accel/tcg/translate-all.c +2
-0+* A Default of 1/8th of the host size will get small hosts a +* similar TB size than they had prior to v5.0 and common bare metal
accel/tcg/translate-all.c +9
-0+* systems (>=8G) the new 1G default that was set in v5.0 +*/ +#if defined _SC_PHYS_PAGES && defined _SC_PAGESIZE + { +unsigned long max =DEFAULT_CODE_GEN_BUFFER_SIZE ; +double pages = (double )sysconf (_SC_PHYS_PAGES); + +if (pages >0 && pagesize >0 ) { + max = (unsigned long)((pages * qemu_real_host_page_size)/ 8);
accel/tcg/translate-all.c +6
-1+ } +if (max <DEFAULT_CODE_GEN_BUFFER_SIZE ) { + tb_size = max; + } + } +#endif }if (tb_size <MIN_CODE_GEN_BUFFER_SIZE ) { tb_size =MIN_CODE_GEN_BUFFER_SIZE ; --2.27.0
Signature · 3 lines
Christian Ehrhardt Staff Engineer, Ubuntu Server Canonical Ltd