<p>Hi Pranay,<br>
Your answers assume that there is always a filesystem above the block device driver which is not necessarily condition.</p>
<p>Regards,<br>
Neha<br>
</p>
<div class="gmail_quote">On Nov 2, 2013 8:58 AM, &quot;Pranay Srivastava&quot; &lt;<a href="mailto:pranjas@gmail.com">pranjas@gmail.com</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<p dir="ltr"><br>
On 01-Nov-2013 10:57 PM, &quot;neha naik&quot; &lt;<a href="mailto:nehanaik27@gmail.com" target="_blank">nehanaik27@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; Hi,<br>
&gt;   I am writing a block device driver and i am using the<br>
&gt; &#39;blq_queue_make_request&#39; call while registering my block device<br>
&gt; driver.<br>
&gt;   Now as far as i understand this will bypass the linux kernel queue<br>
&gt; for each block device driver (bypassing the elevator algorithm etc).<br>
&gt; However, i am still not very clear about exactly how i get a request.<br>
&gt;<br>
&gt;  1.  Consider i am doing a dd on the block device directly :<br>
&gt;   Will it bypass the buffer cache(/page cache) or will it use it.</p>
<p dir="ltr">Page cache use is for file system. Block driver has got nothing to do with it. So lets keep these separate.</p>
<p dir="ltr">Bios don&#39;t care which page you give them all it needs is a page in bvec. The file system would wait on that page to be uptodate which might be done in bio_end_io if i/o was good.</p>
<p dir="ltr">In case of buffer heads the same thing. Submit_bh would create a bio for that bh so really same stuff.</p>
<p dir="ltr">&gt; Example if i register my block device with set_blocksize() as 512. And<br>
&gt; i do a dd of 512 bytes will i get a read because it passes through the<br>
&gt; buffer cache and since the minimum page size is 4096 it has to read<br>
&gt; the page first and then pass it to me.</p>
<p dir="ltr">If you are writing why it would read the page? Reads would initiate write outs i think. Take a look at generic_file_aio_write. </p>
<p dir="ltr">&gt;     I am still unclear about the &#39;page&#39; in the bvec. What does that<br>
&gt; refer to? Is it a page from the page cache or a user buffer (DMA).</p>
<p dir="ltr">Whatever filesystem gave it. If it uses the generic functions that should come from page cache but again it depends on how filesystem created bio.</p>
<p dir="ltr">So for block driver you need to know if the page you are given in bvec is something you can use or you need to check and take measures to successfully do i/o.</p>
<p dir="ltr">&gt;<br>
&gt;<br>
&gt; 2. Another thing i am not clear about is a queue. When i register my<br>
&gt; driver, the &#39;make_request&#39; function gets called whenever there is an<br>
&gt; io. Now in my device driver, i have some more logic about  writing<br>
&gt; this io i.e some time may be spent in the device driver for each io.<br>
&gt; In such a case, if i get two ios on the same block one after the other<br>
&gt; (say one is writing &#39;a&#39; and the other is writing &#39;b&#39;) then isn&#39;t it<br>
&gt; possible that i may end up passing &#39;b&#39; followed by &#39;a&#39; to the layer<br>
&gt; below me (changing the order because thread &#39;a&#39; took more time than<br>
&gt; thread &#39;b&#39;). <br>
Then in that case should i be using a queue in my layer -<br>
&gt; put the ios in the queue whenever i get a call to &#39;make_request&#39;.<br>
&gt; Another thread keeps pulling the ios from the queue and processing<br>
&gt; them and passing it to the layer below.<br>
&gt;<br>
You mean layer above right? that is the filesystem correct? But if thats the case then wouldn&#39;t your second request be blocked until the page was unlocked by file system which would happen i think after your driver was done with i/o. Thats because you won&#39;t mark the request as complete so i guess threads would wait_on_page to be unlocked.</p>


<p dir="ltr">If however your driver &quot;lies&quot; about completing requests then yeah you need to take appropriate measure.</p>
<p dir="ltr">&gt;<br>
&gt; Regards,<br>
&gt; Neha<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Kernelnewbies mailing list<br>
&gt; <a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank">Kernelnewbies@kernelnewbies.org</a><br>
&gt; <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a></p>
<p dir="ltr">        --P.K.S</p>
</blockquote></div>