Recently I'm reading virtio code in linux kernel. I came across "indirect buffer" and "indirect descriptor" in the source code. I wonder what is the meaning of "indirect"?
1 Answers
You've probably come across virtqueue concept. virtqueue ring has a certain (limited) capacity, and, since some devices may work way more effective by concurrently dispatching a large number of large requests, indirect descriptor feature comes in handy to allow this kind of operation. The idea is simply to increase ring capacity, and this is achieved by storing an indirect descriptor table anywhere in memory and inserting its desciptor in main virtqueue (INDIRECT
flag is set on such a descriptor to show its nature). So, when such indirect descriptor is processed in the main ring, control is passed to the indirect descriptor table (which resides in memory buffer described by addr
and len
of that indirect descriptor in the main ring). Then descriptors from within such a table get processed, and the end of the table is determined by absence of NEXT
flag in the current descriptor. When the flag is found unset, control is passed back to the virtqueue.
So, roughly, it's just a trick to "substitute" an ordinary descriptor in the ring by a handful of descriptors thus increasing overall capacity. So, indirect descriptor - is an ordinary descriptor in the ring which has INDIRECT
flag set and which references an indirect buffer. The latter is a chunk of memory which contains a table of ordinary descriptors to be processed.
Also please note descriptors from within indirect descriptor table can't be indirect themselves.