coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] dd: add a flag to discard cached data


From: Jim Meyering
Subject: Re: [PATCH] dd: add a flag to discard cached data
Date: Thu, 24 Feb 2011 08:52:35 +0100

Pádraig Brady wrote:

> I noticed fadvise(DONTNEED) getting some love in the kernel recently
>    http://lkml.org/lkml/2011/2/17/169
> Which prompted me to implement this. With the attached one can now:
>
>   # Advise to drop cache for whole file
>   dd if=ifile iflag=nocache count=0
>
>   # Ensure drop cache for whole file
>   dd of=ofile oflag=nocache conv=notrunc,fdatasync count=0
>
>   # Drop cache for part of file
>   dd if=ifile iflag=nocache skip=10 count=10 of=/dev/null
>
>   # Stream data just using readahead cache
>   dd if=ifile of=ofile iflag=nocache oflag=nocache
>
> When count=0, i.e. when only manipulating the cache,
> we propagate the posix_fadvise() return to the exit status.
>
> Note this will invalidate the cache even if another
> process has the file open. That could be avoided with mincor:
>    http://insights.oetiker.ch/linux/fadvise.html
> However, I don't think that's needed for a tool like dd.

I agree.

> Subject: [PATCH] dd: add a flag to discard cached data
>
> * src/dd.c (usage): Add the 'nocache' flag.
> (cache_round): A new function to help ignore cache
> drop requests less than page_size.
> (invalidate_cache): A new function to call posix_fadvise()
> with the appropriate offset and length.  Note we don't
> use fdadvise() so we can detect errors when count=0.
> (dd_copy): Call invalidate_cache() for the processed portions.
> (main): Call invalidate_cache for page_size slop or
> for full file when count=0.
> * cfg.mk (sc_dd_O_FLAGS): Adjust to pass.
> * doc/coreutils.texi (dd invocation): Describe the 'nocache' flag,
> and give some examples of how it can be used.
> * tests/dd/nocache: A new test.
> * tests/Makefile.am: Reference the new test.
> * NEWS: Mention the new feature.

This looks great.  Thanks!
I'll try it out today.
One quick question: does the test need
something to make it skip (not fail)
on systems that lack kernel support for the feature?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]