On Fri, Jul 17, 2020 at 4:07 PM Christian Ehrhardt < christian.ehrha...@canonical.com> wrote:
> 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. > > 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 :-). > Signed-off-by: Christian Ehrhardt <christian.ehrha...@canonical.com> > --- > accel/tcg/translate-all.c | 23 +++++++++++++++++++++++ > 1 file changed, 23 insertions(+) > > diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c > index 2afa46bd2b..ffcd67060e 100644 > --- a/accel/tcg/translate-all.c > +++ b/accel/tcg/translate-all.c > @@ -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; > -- > 2.27.0 > > -- Christian Ehrhardt Staff Engineer, Ubuntu Server Canonical Ltd