1 /* 2 * QEMU Host Memory Backend 3 * 4 * Copyright (C) 2013-2014 Red Hat Inc 5 * 6 * Authors: 7 * Igor Mammedov <imammedo@redhat.com> 8 * 9 * This work is licensed under the terms of the GNU GPL, version 2 or later. 10 * See the COPYING file in the top-level directory. 11 */ 12 13 #ifndef SYSEMU_HOSTMEM_H 14 #define SYSEMU_HOSTMEM_H 15 16 #include "sysemu/numa.h" 17 #include "qapi/qapi-types-machine.h" 18 #include "qom/object.h" 19 #include "exec/memory.h" 20 #include "qemu/bitmap.h" 21 22 #define TYPE_MEMORY_BACKEND "memory-backend" 23 typedef struct HostMemoryBackend HostMemoryBackend; 24 typedef struct HostMemoryBackendClass HostMemoryBackendClass; 25 DECLARE_OBJ_CHECKERS(HostMemoryBackend, HostMemoryBackendClass, 26 MEMORY_BACKEND, TYPE_MEMORY_BACKEND) 27 28 /* hostmem-ram.c */ 29 /** 30 * @TYPE_MEMORY_BACKEND_RAM: 31 * name of backend that uses mmap on the anonymous RAM 32 */ 33 34 #define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram" 35 36 /* hostmem-file.c */ 37 /** 38 * @TYPE_MEMORY_BACKEND_FILE: 39 * name of backend that uses mmap on a file descriptor 40 */ 41 #define TYPE_MEMORY_BACKEND_FILE "memory-backend-file" 42 43 44 /** 45 * HostMemoryBackendClass: 46 * @parent_class: opaque parent class container 47 */ 48 struct HostMemoryBackendClass { 49 ObjectClass parent_class; 50 51 void (*alloc)(HostMemoryBackend *backend, Error **errp); 52 }; 53 54 /** 55 * @HostMemoryBackend 56 * 57 * @parent: opaque parent object container 58 * @size: amount of memory backend provides 59 * @mr: MemoryRegion representing host memory belonging to backend 60 * @prealloc_threads: number of threads to be used for preallocatining RAM 61 */ 62 struct HostMemoryBackend { 63 /* private */ 64 Object parent; 65 66 /* protected */ 67 uint64_t size; 68 bool merge, dump, use_canonical_path; 69 bool prealloc, is_mapped, share; 70 uint32_t prealloc_threads; 71 DECLARE_BITMAP(host_nodes, MAX_NODES + 1); 72 HostMemPolicy policy; 73 74 MemoryRegion mr; 75 }; 76 77 bool host_memory_backend_mr_inited(HostMemoryBackend *backend); 78 MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend); 79 80 void host_memory_backend_set_mapped(HostMemoryBackend *backend, bool mapped); 81 bool host_memory_backend_is_mapped(HostMemoryBackend *backend); 82 size_t host_memory_backend_pagesize(HostMemoryBackend *memdev); 83 char *host_memory_backend_get_name(HostMemoryBackend *backend); 84 85 #endif 86