aio: use g_slice_alloc() for AIOCB pooling

AIO control blocks are frequently acquired and released because each aio
request involves at least one AIOCB.  Therefore, we pool them to avoid
heap allocation overhead.

The problem with the freelist approach in AIOPool is thread-safety.  If
we want BlockDriverStates to associate with AioContexts that execute in
multiple threads, then a global freelist becomes a problem.

This patch drops the freelist and instead uses g_slice_alloc() which is
tuned for per-thread fixed-size object pools.  qemu_aio_get() and
qemu_aio_release() are now thread-safe.

Note that the change from g_malloc0() to g_slice_alloc() should be safe
since the freelist reuse case doesn't zero the AIOCB either.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2 files changed
tree: 284796e24c44051fe9ff58b910d48d34e5184211
  1. audio/
  2. block/
  3. bsd-user/
  4. default-configs/
  5. docs/
  6. fpu/
  7. fsdev/
  8. gdb-xml/
  9. hw/
  10. include/
  11. libcacard/
  12. linux-headers/
  13. linux-user/
  14. net/
  15. pc-bios/
  16. qapi/
  17. qga/
  18. QMP/
  19. qom/
  20. roms/
  21. scripts/
  22. slirp/
  23. sysconfigs/
  24. target-alpha/
  25. target-arm/
  26. target-cris/
  27. target-i386/
  28. target-lm32/
  29. target-m68k/
  30. target-microblaze/
  31. target-mips/
  32. target-openrisc/
  33. target-ppc/
  34. target-s390x/
  35. target-sh4/
  36. target-sparc/
  37. target-unicore32/
  38. target-xtensa/
  39. tcg/
  40. tests/
  41. trace/
  42. ui/
  43. .exrc
  44. .gitignore
  45. .gitmodules
  46. .mailmap
  47. a.out.h
  48. acl.c
  49. acl.h
  50. aes.c
  51. aes.h
  52. aio-posix.c
  53. aio-win32.c
  54. alpha-dis.c
  55. alpha.ld
  56. arch_init.c
  57. arch_init.h
  58. arm-dis.c
  59. arm.ld
  60. async.c
  61. balloon.c
  62. balloon.h
  63. bitmap.c
  64. bitmap.h
  65. bitops.c
  66. bitops.h
  67. block-migration.c
  68. block-migration.h
  69. block.c
  70. block.h
  71. block_int.h
  72. blockdev-nbd.c
  73. blockdev.c
  74. blockdev.h
  75. blockjob.c
  76. blockjob.h
  77. bswap.h
  78. bt-host.c
  79. bt-host.h
  80. bt-vhci.c
  81. buffered_file.c
  82. buffered_file.h
  83. cache-utils.c
  84. cache-utils.h
  85. Changelog
  86. cmd.c
  87. cmd.h
  88. CODING_STYLE
  89. compatfd.c
  90. compatfd.h
  91. compiler.h
  92. config.h
  93. configure
  94. console.c
  95. console.h
  96. COPYING
  97. COPYING.LIB
  98. coroutine-gthread.c
  99. coroutine-sigaltstack.c
  100. coroutine-ucontext.c
  101. coroutine-win32.c
  102. cpu-all.h
  103. cpu-common.h
  104. cpu-defs.h
  105. cpu-exec.c
  106. cpus.c
  107. cpus.h
  108. cputlb.c
  109. cputlb.h
  110. cris-dis.c
  111. cursor.c
  112. cursor_hidden.xpm
  113. cursor_left_ptr.xpm
  114. cutils.c
  115. def-helper.h
  116. device_tree.c
  117. device_tree.h
  118. dis-asm.h
  119. disas.c
  120. disas.h
  121. dma-helpers.c
  122. dma.h
  123. dump-stub.c
  124. dump.c
  125. dump.h
  126. elf.h
  127. envlist.c
  128. envlist.h
  129. error.c
  130. error.h
  131. event_notifier-posix.c
  132. event_notifier-win32.c
  133. event_notifier.h
  134. exec-all.h
  135. exec-memory.h
  136. exec.c
  137. gdbstub.c
  138. gdbstub.h
  139. gen-icount.h
  140. HACKING
  141. hmp-commands.hx
  142. hmp.c
  143. hmp.h
  144. host-utils.c
  145. host-utils.h
  146. hppa-dis.c
  147. hppa.ld
  148. hwaddr.h
  149. i386-dis.c
  150. i386.ld
  151. ia64-dis.c
  152. ia64.ld
  153. input.c
  154. int128.h
  155. iohandler.c
  156. ioport.c
  157. ioport.h
  158. iorange.h
  159. iov.c
  160. iov.h
  161. json-lexer.c
  162. json-lexer.h
  163. json-parser.c
  164. json-parser.h
  165. json-streamer.c
  166. json-streamer.h
  167. kvm-all.c
  168. kvm-stub.c
  169. kvm.h
  170. libfdt_env.h
  171. LICENSE
  172. lm32-dis.c
  173. m68k-dis.c
  174. m68k.ld
  175. main-loop.c
  176. main-loop.h
  177. MAINTAINERS
  178. Makefile
  179. Makefile.dis
  180. Makefile.objs
  181. Makefile.target
  182. Makefile.user
  183. memory-internal.h
  184. memory.c
  185. memory.h
  186. memory_mapping-stub.c
  187. memory_mapping.c
  188. memory_mapping.h
  189. microblaze-dis.c
  190. migration-exec.c
  191. migration-fd.c
  192. migration-tcp.c
  193. migration-unix.c
  194. migration.c
  195. migration.h
  196. mips-dis.c
  197. mips.ld
  198. module.c
  199. module.h
  200. monitor.c
  201. monitor.h
  202. nbd.c
  203. nbd.h
  204. net.c
  205. net.h
  206. notify.c
  207. notify.h
  208. os-posix.c
  209. os-win32.c
  210. osdep.c
  211. osdep.h
  212. oslib-posix.c
  213. oslib-win32.c
  214. page_cache.c
  215. path.c
  216. pci-ids.txt
  217. poison.h
  218. ppc-dis.c
  219. ppc.ld
  220. ppc64.ld
  221. qapi-schema-guest.json
  222. qapi-schema-test.json
  223. qapi-schema.json
  224. qbool.c
  225. qbool.h
  226. qdict-test-data.txt
  227. qdict.c
  228. qdict.h
  229. qemu-aio.h
  230. qemu-barrier.h
  231. qemu-bridge-helper.c
  232. qemu-char.c
  233. qemu-char.h
  234. qemu-common.h
  235. qemu-config.c
  236. qemu-config.h
  237. qemu-coroutine-int.h
  238. qemu-coroutine-io.c
  239. qemu-coroutine-lock.c
  240. qemu-coroutine-sleep.c
  241. qemu-coroutine.c
  242. qemu-coroutine.h
  243. qemu-doc.texi
  244. qemu-error.c
  245. qemu-error.h
  246. qemu-file.h
  247. qemu-ga.c
  248. qemu-img-cmds.hx
  249. qemu-img.c
  250. qemu-img.texi
  251. qemu-io.c
  252. qemu-lock.h
  253. qemu-log.c
  254. qemu-log.h
  255. qemu-nbd.c
  256. qemu-nbd.texi
  257. qemu-objects.h
  258. qemu-option-internal.h
  259. qemu-option.c
  260. qemu-option.h
  261. qemu-options-wrapper.h
  262. qemu-options.h
  263. qemu-options.hx
  264. qemu-os-posix.h
  265. qemu-os-win32.h
  266. qemu-pixman.c
  267. qemu-pixman.h
  268. qemu-progress.c
  269. qemu-queue.h
  270. qemu-seccomp.c
  271. qemu-seccomp.h
  272. qemu-sockets.c
  273. qemu-tech.texi
  274. qemu-thread-posix.c
  275. qemu-thread-posix.h
  276. qemu-thread-win32.c
  277. qemu-thread-win32.h
  278. qemu-thread.h
  279. qemu-timer-common.c
  280. qemu-timer.c
  281. qemu-timer.h
  282. qemu-tls.h
  283. qemu-tool.c
  284. qemu-user.c
  285. qemu-x509.h
  286. qemu-xattr.h
  287. qemu.sasl
  288. qemu_socket.h
  289. qerror.c
  290. qerror.h
  291. qfloat.c
  292. qfloat.h
  293. qint.c
  294. qint.h
  295. qjson.c
  296. qjson.h
  297. qlist.c
  298. qlist.h
  299. qmp-commands.hx
  300. qmp.c
  301. qobject.h
  302. qstring.c
  303. qstring.h
  304. qtest.c
  305. qtest.h
  306. range.h
  307. readline.c
  308. readline.h
  309. README
  310. rules.mak
  311. s390-dis.c
  312. s390.ld
  313. savevm.c
  314. sh4-dis.c
  315. softmmu-semi.h
  316. softmmu_defs.h
  317. softmmu_exec.h
  318. softmmu_header.h
  319. softmmu_template.h
  320. sparc-dis.c
  321. sparc.ld
  322. sparc64.ld
  323. spice-qemu-char.c
  324. sysemu.h
  325. tcg-runtime.c
  326. tci-dis.c
  327. tci.c
  328. thread-pool.c
  329. thread-pool.h
  330. thunk.c
  331. thunk.h
  332. TODO
  333. trace-events
  334. translate-all.c
  335. uboot_image.h
  336. uri.c
  337. uri.h
  338. user-exec.c
  339. VERSION
  340. version.rc
  341. vgafont.h
  342. vl.c
  343. vmstate.h
  344. x86_64.ld
  345. xen-all.c
  346. xen-mapcache.c
  347. xen-mapcache.h
  348. xen-stub.c