Skip to content

Commit c83d628

Browse files
committed
accel/tcg: better handle memory constrained systems
It turns out there are some 64 bit systems that have relatively low amounts of physical memory available to them (typically CI system). Even with swapping available a 1GB translation buffer that fills up can put the machine under increased memory pressure. Detect these low memory situations and reduce tb_size appropriately. Fixes: 600e17b ("accel/tcg: increase default code gen buffer size for 64 bit") Signed-off-by: Alex Bennée <[email protected]> Reviewed-by: Richard Henderson <[email protected]> Reviewed-by: Robert Foley <[email protected]> Cc: BALATON Zoltan <[email protected]> Cc: Christian Ehrhardt <[email protected]> Message-Id: <[email protected]>
1 parent 986baba commit c83d628

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

accel/tcg/translate-all.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,12 @@ static inline size_t size_code_gen_buffer(size_t tb_size)
976976
{
977977
/* Size the buffer. */
978978
if (tb_size == 0) {
979-
tb_size = DEFAULT_CODE_GEN_BUFFER_SIZE;
979+
size_t phys_mem = qemu_get_host_physmem();
980+
if (phys_mem == 0) {
981+
tb_size = DEFAULT_CODE_GEN_BUFFER_SIZE;
982+
} else {
983+
tb_size = MIN(DEFAULT_CODE_GEN_BUFFER_SIZE, phys_mem / 8);
984+
}
980985
}
981986
if (tb_size < MIN_CODE_GEN_BUFFER_SIZE) {
982987
tb_size = MIN_CODE_GEN_BUFFER_SIZE;

0 commit comments

Comments
 (0)