linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Lord <liml@rtr.ca>
To: Fajun Chen <fajunchen@gmail.com>
Cc: "linux-ide@vger.kernel.org" <linux-ide@vger.kernel.org>,
	linux-scsi@vger.kernel.org, Tejun Heo <htejun@gmail.com>
Subject: Re: Process Scheduling Issue using sg/libata
Date: Sat, 17 Nov 2007 14:55:16 -0500	[thread overview]
Message-ID: <473F4724.6010107@rtr.ca> (raw)
In-Reply-To: <8202f4270711171120nddf24a8m8d1ece8c41b6c1ab@mail.gmail.com>

Fajun Chen wrote:
> On 11/17/07, Mark Lord <liml@rtr.ca> wrote:
>> Fajun Chen wrote:
>>> On 11/16/07, Mark Lord <liml@rtr.ca> wrote:
>>>> Fajun Chen wrote:
..
>>> This problem also happens with R/W DMA ops. Below are simplified code snippets:
>>>     // Open one sg device for read
>>>       if ((sg_fd  = open(dev_name, O_RDWR))<0)
>>>       {
>>>           ...
>>>       }
>>>       read_buffer = (U8 *)mmap(NULL, buf_sz, PROT_READ | PROT_WRITE,
>>>                              MAP_SHARED, sg_fd, 0);
>>>
>>>     // Open the same sg device for write
>>>       if ((sg_fd_wr = open(dev_name, O_RDWR))<0)
>>>       {
>>>          ...
>>>       }
>>>       write_buffer = (U8 *)mmap(NULL, buf_sz, PROT_READ | PROT_WRITE,
>>>                              MAP_SHARED, sg_fd_wr, 0);
>> ..
>>
>> Mmmm.. what is the purpose of those two mmap'd areas ?
>> I think this is important and relevant here:  what are they used for?
>>
>> As coded above, these are memory mapped areas taht (1) overlap,
>> and (2) will be demand paged automatically to/from the disk
>> as they are accessed/modified.  This *will* conflict with any SG_IO
>> operations happening at the same time on the same device.
..
> The purpose of using two memory mapped areas is to meet our
> requirement that certain data patterns for writing need to be kept
> across commands. For instance, if one buffer is used for both reads
> and writes, then this buffer will need to be re-populated with certain
> write data after each read command, which would be very costly for
> write-read mixed type of ops. This separate R/W buffer setting also
> facilitates data comparison.
> 
> These buffers are not used at the same time (one will be used only
> after the command on the other is completed). My application is the
> only program accessing disk using sg/libata and the rest of the
> programs run from ramdisk. Also, each buffer is only about 0.5MB and
> we have 64MB RAM on the target board.
> With this setup,  these two buffers should be pretty much independent
> and free from block layer/file system, correct?
..

No.  Those "buffers" as coded above are actually mmap'ed representations
of portions of the device (disk drive).  So any write into one of those
buffers will trigger disk writes, and just accessing ("read") the buffers
may trigger disk reads.

So what could be happening here, is when you trigger manual disk accesses
via SG_IO, that result in data being copied into those "buffers", the kernel
then automatically schedules disk writes to update the on-disk copies of
those mmap'd regions.

What you probably intended to do instead, was to use mmap to just allocate
some page-aligned RAM, not to actually mmap'd any on-disk data.  Right?

Here's how that's done:

       read_buffer = (U8 *)mmap(NULL, buf_sz, PROT_READ | PROT_WRITE,
                              MAP_SHARED|MAP_ANONYMOUS, -1, 0);

Cheers

  reply	other threads:[~2007-11-17 19:55 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-17  0:49 Process Scheduling Issue using sg/libata Fajun Chen
2007-11-17  3:02 ` Tejun Heo
2007-11-17  6:14   ` Fajun Chen
2007-11-17 17:13     ` James Chapman
2007-11-17 19:37       ` Fajun Chen
2007-11-17  4:30 ` Mark Lord
2007-11-17  7:20   ` Fajun Chen
2007-11-17 16:25     ` Mark Lord
2007-11-17 19:20       ` Fajun Chen
2007-11-17 19:55         ` Mark Lord [this message]
2007-11-18  6:48           ` Fajun Chen
2007-11-18 14:32             ` Mark Lord
2007-11-18 19:14               ` Fajun Chen
2007-11-18 19:54                 ` Mark Lord
2007-11-18 22:29                   ` Fajun Chen
2007-11-18 23:07                     ` Mark Lord
2007-11-19 16:40                       ` James Chapman
2007-11-19 16:51                         ` Tejun Heo
2007-11-19 17:17                           ` Alan Cox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=473F4724.6010107@rtr.ca \
    --to=liml@rtr.ca \
    --cc=fajunchen@gmail.com \
    --cc=htejun@gmail.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).