[Qemu-devel] Re: memory usage and ioports
Samuel Thibault, le Mon 19 Nov 2007 15:20:16 +, a écrit : Qemu currently uses 6 65k tables of pointers for handling ioports, which makes 3MB on 64bit machines. There's a comment that says XXX: use a two level table to limit memory usage. But wouldn't it be more simple and effective to just allocate them through mmap() and when a NULL pointer is read, call the default handlers? For the ioport_opaque array (500KB on 64bit), it's much simpler, as the attached patch suggests. Samuel diff -r 6a6eace79e93 tools/ioemu/vl.c --- qemu/vl.c Mon Nov 19 15:04:05 2007 + +++ qemu/vl.c Mon Nov 19 15:31:35 2007 + @@ -139,7 +139,7 @@ const char *bios_dir = CONFIG_QEMU_SHAREDIR; char phys_ram_file[1024]; -void *ioport_opaque[MAX_IOPORTS]; +void **ioport_opaque; IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS]; IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS]; /* Note: bs_table[MAX_DISKS] is a dummy block driver if none available @@ -265,6 +265,7 @@ void init_ioports(void) { int i; +ioport_opaque = malloc(MAX_IOPORTS * sizeof(*ioport_opaque)); for(i = 0; i MAX_IOPORTS; i++) { ioport_read_table[0][i] = default_ioport_readb; ioport_write_table[0][i] = default_ioport_writeb;
Re: [Qemu-devel] Re: memory usage and ioports
On Monday 19 November 2007, Samuel Thibault wrote: Samuel Thibault, le Mon 19 Nov 2007 15:20:16 +, a écrit : Qemu currently uses 6 65k tables of pointers for handling ioports, which makes 3MB on 64bit machines. There's a comment that says XXX: use a two level table to limit memory usage. But wouldn't it be more simple and effective to just allocate them through mmap() and when a NULL pointer is read, call the default handlers? For the ioport_opaque array (500KB on 64bit), it's much simpler, as the attached patch suggests. AFAICS This makes absolutely no difference to memory usage. Paul
Re: [Qemu-devel] Re: memory usage and ioports
Paul Brook, le Mon 19 Nov 2007 16:17:26 +, a écrit : On Monday 19 November 2007, Samuel Thibault wrote: Samuel Thibault, le Mon 19 Nov 2007 15:20:16 +, a écrit : Qemu currently uses 6 65k tables of pointers for handling ioports, which makes 3MB on 64bit machines. There's a comment that says XXX: use a two level table to limit memory usage. But wouldn't it be more simple and effective to just allocate them through mmap() and when a NULL pointer is read, call the default handlers? For the ioport_opaque array (500KB on 64bit), it's much simpler, as the attached patch suggests. AFAICS This makes absolutely no difference to memory usage. Ah, sorry, in a unix environment it doesn't indeed. In an embedded environment or so which has to provide a fully allocated bss because it doesn't have cow support early enough, that makes a difference. Samuel