From: Karel Zak <kzak@redhat.com>
To: Rodrigo Campos <rodrigo@sdfg.com.ar>
Cc: util-linux@vger.kernel.org
Subject: Re: [PATCH v3] fallocate: Add "--dig-holes" option
Date: Fri, 14 Feb 2014 11:47:56 +0100 [thread overview]
Message-ID: <20140214104756.GA28125@x2.net.home> (raw)
In-Reply-To: <1390748810-14517-1-git-send-email-rodrigo@sdfg.com.ar>
On Sun, Jan 26, 2014 at 03:06:50PM +0000, Rodrigo Campos wrote:
> bash-completion/fallocate | 2 +-
> sys-utils/fallocate.1 | 19 +++++++-
> sys-utils/fallocate.c | 114 ++++++++++++++++++++++++++++++++++++++++------
> 3 files changed, 120 insertions(+), 15 deletions(-)
Applied with some changes and I believe that the code still need some
improvements, see below
> + */
> +static int detect_holes(int fd, size_t hole_size)
> +{
> + int ret = 0;
> + int err;
> +
> + if (hole_size >= 100 * 1024 * 1024) {
> + size_t ram_mb = hole_size / 1024 / 1024;
> + printf("WARNING: %zu MB RAM will be used\n", ram_mb);
> + sleep(3);
> + }
I have removed this thing...
I don't like all the detection algorithm. Do we really need to allocate
all hole size and the buffer?
IMHO it would be enough to:
* add posix_fadvise(... POSIX_FADV_SEQUENTIAL | POSIX_FADV_NOREUSE)
* read the file in small chunks -- for example BUFSIZ and compare
this with small empty static buffer.
.. it's kernel business to read from FS/device in optimal way and I
don't think that context switches are so critical issue when all the
thing is about I/O.
I didn't test it, so maybe I'm wrong, but the current code where we
eat RAM seems too crazy. Comments?
> + /* Create a buffer of '\0's to compare against */
> + /* XXX: Use mmap() with MAP_PRIVATE so Linux can avoid this allocation */
> + void *zeros = mmap(NULL, hole_size, PROT_READ,
> + MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
> + if (zeros == MAP_FAILED) {
> + perror("mmap");
we use err.h stuff, and it's usually good enough to exit after error
than waste time with memory deallocation and another clean ups. The
kernel is smart enough to clean up after exit().
> + off_t end = lseek(fd, 0, SEEK_END);
^^^^^^^^^^^^^^
> + if (end == -1) {
> + perror("lseek");
> + ret = -1;
> + goto out;
> + }
> +
> + for (off_t offset = 0; offset + hole_size <= end; offset += buf_len) {
^^^^^^^^^^^
Yes it's expected by C standards, but it sucks. Don't use it, it's
reader's nightmare.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
next prev parent reply other threads:[~2014-02-14 10:48 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-25 19:17 fallocate: Add "--dig-holes" options and minor fixes Rodrigo Campos
2014-01-25 19:17 ` [PATCH 1/3] fallocate: Clarify that space can also be deallocated Rodrigo Campos
2014-01-25 19:17 ` [PATCH 2/3] fallocate: Hide #ifdef tricks to call fallocate in a function Rodrigo Campos
2014-01-25 19:17 ` [PATCH 3/3] fallocate: Add "--dig-holes" option Rodrigo Campos
2014-01-26 14:43 ` [PATCH v2] " Rodrigo Campos
2014-01-26 15:06 ` [PATCH v3] " Rodrigo Campos
2014-02-14 10:47 ` Karel Zak [this message]
2014-02-14 11:34 ` Karel Zak
2014-02-14 13:16 ` Rodrigo Campos
2014-02-14 13:07 ` Rodrigo Campos
2014-02-14 13:30 ` Karel Zak
2014-02-14 13:35 ` Rodrigo Campos
2014-02-17 10:32 ` Karel Zak
2014-02-17 14:15 ` Rodrigo Campos
2014-02-17 14:49 ` Karel Zak
2014-02-17 15:42 ` Rodrigo Campos
2014-01-25 19:23 ` fallocate: Add "--dig-holes" options and minor fixes Rodrigo Campos
[not found] ` <20140201040414.GA23360@sdfg.com.ar>
2014-02-11 11:31 ` Rodrigo Campos
2014-02-11 18:34 ` Karel Zak
2014-02-11 18:43 ` Rodrigo Campos
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=20140214104756.GA28125@x2.net.home \
--to=kzak@redhat.com \
--cc=rodrigo@sdfg.com.ar \
--cc=util-linux@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