I have a server application requiring usage of huge memory but can take little time. I therefore thought it should be economical to run it with a big swap and normal ram.

I was reading about serving large files from disk when I learned about asynchronous disk io and heard it is better supported in FreeBSD than Linux.

My question is: Does Asynchronous Disk IO affect the performance of swap space because a swap partition will be doing lot of disk reads and writes. Is there a reason to go for FreeBSD. I have reasonable experience working on Linux(Ubuntu) and prefer using it for the application.

  • Should this question be moved to ServerFault.SE? Jun 7, 2014 at 12:49
  • I doubt this question should be migrated to Server Fault, at least as it is. It would likely be shot down there, based on likely being considered highly theoretical as well as not demonstrating much effort of finding the answer on your own before posting the question.
    – user
    Jun 8, 2014 at 12:39

1 Answer 1

  1. Asynchronous IO in FreeBSD isn't totally better than in Linux. I think your source meant that AIO call family (aio_read, etc.) is implemented in FreeBSD kernel directly but converts its requests to IOCPs internally where possible (sockets, pipes, flat disk access, etc.) and creates kernel threads only for filesystem I/O. Unlike this, Linux uses userland threads for AIO call family which are more explicit but expose their work and need larger thread context. All other aspects are related to common kernel architecture and performance which depends on lots of percularities, including sysadmin tuning skills.
  2. There are approaches when threads are explicitly needed for AIO - the main case is when a file is memory mapped and reading as memory region, and real reading is handled as page fault. As page fault interrupts a particular control flow (i.e. thread), it requires separate thread to be handled independently. Seems this is very close to your supposed mechanism, but only if you control RAM usage properly; this means at least mass madvise calls for specifying which regions are needed and which aren't. Sometimes direct *read()/*write() are easier because they don't require keeping already processed segments exposed to RAM.
  3. AIO by itself doesn't correlate with swap in any manner. Using any IO manner requires input and output at the best rate. But, the issue is that if you keep huge data amounts in process memory, it will be swapped out and in. If your "working set" (page set which shall be in RAM for working without obvious process' performance degradation) is larger than fits in RAM (including spendings for kernel data, disk cache, etc.), you'll fall into constant swapping. In that case, algorithms shall be adapted to keep working set small enough, that's the only solution.
  4. Particularly for Linux, please keep issue 12309 in mind. It's reported as fixed but the ticket misses imporant part of history and consequences, so, the issue with late disk cache purging and following mass swapping-out can return. The important FreeBSD difference is that BSD systems never had this issue.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .