Scatter – gather I/O

To help explain this topic, let's say that we are commissioned with writing data to a file such that three discontiguous data regions A, B, and C are written (filled with As, Bs, and Cs, respectively); the following diagram shows this:

+------+-----------+---------+-----------+------+-----------+
| | ... A ... | | ... B ... | | ... C ... |
+------+-----------+---------+-----------+------+-----------+
|A_HOLE| A_LEN | B_HOLE | B_LEN |C_HOLE| C_LEN |
+------+-----------+---------+-----------+------+-----------+
^ ^ ^
A_START_OFF B_START_OFF C_START_OFF
The discontiguous data file

Notice how the files have holes—regions that do not contain any data content; this is possible to achieve with regular files (files that are largely holes are termed sparse files). How do you create the hole? Simple: just perform an lseek(2) and then write(2) data; the length seeked forward determines the size of the hole in the file.

So, how can we achieve this data file layout as shown? We shall show two approaches—one, the traditional manner, and two, a far more optimized-for-performance approach. Let's get started with the traditional approach.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset