libqos: add a simple first-fit memory allocator

Implement a simple first-fit memory allocator that
attempts to keep track of leased blocks of memory
in order to be able to re-use blocks.

Additionally, allow the user to specify when
initializing the device that upon cleanup,
we would like to assert that there are no
blocks in use. This may be useful for identifying
problems in qtests that use more complicated
set-up and tear-down routines.

This functionality is used in my upcoming ahci-test v2
patch set, but I didn't see fit to enable it for any
existing tests, which will continue to operate the
same as they have prior.

Signed-off-by: John Snow <jsnow@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
John Snow 2014-08-01 11:38:58 -04:00 committed by Stefan Hajnoczi
parent 53b33231f7
commit ec2f160538
2 changed files with 280 additions and 11 deletions

View file

@ -15,6 +15,15 @@
#include "libqos/malloc.h"
typedef enum {
PC_ALLOC_NO_FLAGS = 0x00,
PC_ALLOC_LEAK_WARN = 0x01,
PC_ALLOC_LEAK_ASSERT = 0x02,
PC_ALLOC_PARANOID = 0x04
} PCAllocOpts;
QGuestAllocator *pc_alloc_init(void);
QGuestAllocator *pc_alloc_init_flags(PCAllocOpts flags);
void pc_alloc_uninit(QGuestAllocator *allocator);
#endif