# Is it true that QuestDB uses mmap for file I/O?

**URL:** <https://community.questdb.com/t/is-it-true-that-questdb-uses-mmap-for-file-i-o/61>\
**Category:** Community\
**Tags:** question\
**Created:** [June 27, 2024, 4:13pm UTC](https://community.questdb.com/t/is-it-true-that-questdb-uses-mmap-for-file-i-o/61 "2024-06-27T16:13:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![puzpuzpuz](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.questdb.com/puzpuzpuz/32/25_2.png) [@puzpuzpuz](https://community.questdb.com/u/puzpuzpuz)\
**Post date:** [June 27, 2024, 4:13pm UTC](https://community.questdb.com/t/is-it-true-that-questdb-uses-mmap-for-file-i-o/61/1 "2024-06-27T16:13:26Z")

</div>

Sharing a question from the community 🙂

Q: I saw QuestDB mentioned in a list of databases from the “Are You Sure You Want to Use MMAP in Your Database Management System?” paper. Does it use mmap for both reads and writes?

---

<div class="post-metadata">

**Author:** ![puzpuzpuz](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.questdb.com/puzpuzpuz/32/25_2.png) [@puzpuzpuz](https://community.questdb.com/u/puzpuzpuz)\
**Post date:** [June 27, 2024, 4:18pm UTC](https://community.questdb.com/t/is-it-true-that-questdb-uses-mmap-for-file-i-o/61/2 "2024-06-27T16:18:10Z")

</div>

A: As often, the reality is a bit more complicated than what’s in the papers.

As of v8.0, QuestDB uses `mmap` to read column and metadata files. To avoid paying the cost of mmap call, such as TLB shootdowns, we reuse the mmapped memory across query executions and use `mremap` when column files grow and a reader needs to switch to the newest transaction. We also use `pread` calls when merging out-of-order (O3) data. Finally, our parallel CSV import uses io\_uring, Linux asynchronous syscall and I/O mechanism, to speed up reading of the CSV rows.

Regarding writes, we use both `mmap` and `pwrite` depending on the task. For instance, WAL (Write-Ahead Log) append-only data is written via `mmap`, in sliding pages. On the other hand, when merging O3 data we prefer writing data via `pwrite`.

In general, there is no point in using only a single I/O mechanism in a database. For example, `mmap` works well for reads, involving table scans, as it avoids the overhead of `pread` memory copying in subsequent executions while also benefiting from the OS page cache.
