fs: Make write(2) interruptible by a fatal signal

Kernel Space
linux-fsdevel@vger.kernel.org :


Currently write(2)  to a file  is not interruptible by  any signal.
Sometimes this is  desirable, e.g. when you want  to quickly kill a
process  hogging your  disk. Also,  with commit  499d05ecf990 ("mm:
Make  task in balance_dirty_pages()  killable"), it's  necessary to
abort the  current write accordingly  to avoid it  quickly dirtying
lots more pages at unthrottled rate.

balance_dirty_pages_ratelimited_nr - balance dirty memory state

Processes which  are dirtying memory  should call in here  once for
each page which was  newly dirtied.  The function will periodically
check  the system's  dirty  state and  will  initiate writeback  if
needed.  On really  big machines, get_writeback_state is expensive,
so try to avoid calling it too often (ratelimiting). But once we're
over the dirty memory limit  we decrease the ratelimiting by a lot,
to  prevent individual  processes  from overshooting  the limit  by
(ratelimit_pages) each.

Classroom

A memory-mapped file is a  segment of virtual memory which has been
assigned a direct byte-for-byte  correlation with some portion of a
file or file-like resource. This  resource is typically a file that
is physically  present on-disk,  but can also  be a  device, shared
memory  object,  or  other   resource  that  the  operating  system
canreference  through   a  file  descriptor.   Once  present,  this
correlation  between   the  file  and  the   memory  space  permits
applications  to treat  the mapped  portion as  if it  were primary
memory.


source: http://en.wikipedia.org/wiki/Memory-mapped_file

User Space
write - write to a file descriptor


A successful return  from write() does not make  any guarantee that
data  has  been  committed  to   disk.   In  fact,  on  some  buggy
implementations,  it  does  not   even  guarantee  that  space  has
successfully been reserved  for the data.  The only  way to be sure
is to call fsync(2) after you are done writing all your data.  If a
write() is  interrupted by  a signal handler  before any  bytes are
written,  then  the call  fails  with the  error  EINTR;  if it  is
interrupted  after at  least one  byte has  been written,  the call
succeeds, andreturns the number of bytes written.


fsync, fdatasync - synchronize a file's in-core state with storage device

fsync() transfers  ("flushes") all modified in-core  data of (i.e.,
modified buffer cache  pages for) the file referred  to by the file
descriptor  fd  to the  disk  device  (or  other permanent  storage
device) where that file resides.   The call blocks until the device
reports that the transfer  has completed.  It also flushes metadata
information  associated  with  the  file  (see  stat(2)).   Calling
fsync() does not necessarily ensure that the entry in the directory
containing the  file has also  reached disk.  For that  an explicit
fsync() on a file descriptor for the directory is also needed.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s