search for: is_zero

Displaying 20 results from an estimated 72 matches for "is_zero".

2020 Jan 30
2
[PATCH libnbd] python: Add AIO buffer is_zero method.
...The clever approach here was suggested by Eric Blake. See: + * https://www.redhat.com/archives/libguestfs/2017-April/msg00171.html + * https://rusty.ozlabs.org/?p=560 + * + * See also: + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69908 + */ +static inline bool __attribute__((__nonnull__ (1))) +is_zero (const char *buffer, size_t size) +{ + size_t i; + const size_t limit = size < 16 ? size : 16; + + for (i = 0; i < limit; ++i) + if (buffer[i]) + return false; + if (size != limit) + return ! memcmp (buffer, buffer + 16, size - 16); + + return true; +} + +#endif /* NBDKIT_ISZE...
2017 Apr 19
4
[PATCH v2 0/2] daemon: Move the useful 'is_zero' function into common code.
v1 -> v2: The first patch is the same (the pure refactoring), but in the second patch I implement Eric Blake's suggested version. Rich.
2017 Apr 19
2
[PATCH] daemon: Move the useful 'is_zero' function into common code.
...enamev, int fd) return combined_index; } -/* Return true iff the buffer is all zero bytes. - * - * Note that gcc is smart enough to optimize this properly: - * http://stackoverflow.com/questions/1493936/faster-means-of-checking-for-an-empty-buffer-in-c/1493989#1493989 - */ -static inline int -is_zero (const unsigned char *buffer, size_t size) -{ - size_t i; - - for (i = 0; i < size; ++i) { - if (buffer[i] != 0) - return 0; - } - - return 1; -} - struct global_state { /* Current iterator. Threads update this, but it is protected by a * mutex, and each thread takes a copy...
2019 Aug 15
2
[nbdkit PATCH] data, memory: Optimize .zero > PAGE_SIZE
When sparse_array_zero() is used for a range larger than a page, there's no need to waste time in memset() or is_zero() - we already know the page will be free()d. Signed-off-by: Eric Blake <eblake@redhat.com> --- Here's a fun one :) common/sparse/sparse.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/common/sparse/sparse.c b/common/sparse/sparse.c index cb44743c..5e08576...
2017 Apr 19
1
Re: [PATCH] daemon: Move the useful 'is_zero' function into common code.
...ue iff the buffer is all zero bytes. > > + * > > + * Note that gcc is smart enough to optimize this properly: > > + * http://stackoverflow.com/questions/1493936/faster-means-of-checking-for-an-empty-buffer-in-c/1493989#1493989 > > + */ > > +static inline int > > +is_zero (const char *buffer, size_t size) > > +{ > > + size_t i; > > + > > + for (i = 0; i < size; ++i) { > > + if (buffer[i] != 0) > > + return 0; > > + } > > + > > + return 1; > > +} > > This is still byte-at-a-time. Often...
2017 Apr 19
0
Re: [PATCH] daemon: Move the useful 'is_zero' function into common code.
.... > --- > +/* Return true iff the buffer is all zero bytes. > + * > + * Note that gcc is smart enough to optimize this properly: > + * http://stackoverflow.com/questions/1493936/faster-means-of-checking-for-an-empty-buffer-in-c/1493989#1493989 > + */ > +static inline int > +is_zero (const char *buffer, size_t size) > +{ > + size_t i; > + > + for (i = 0; i < size; ++i) { > + if (buffer[i] != 0) > + return 0; > + } > + > + return 1; > +} This is still byte-at-a-time. Often, you can get even faster results by exploiting libc's o...
2017 Apr 20
0
Re: [PATCH v2 0/2] daemon: Move the useful 'is_zero' function into common code.
On Wednesday, 19 April 2017 18:46:37 CEST Richard W.M. Jones wrote: > v1 -> v2: > > The first patch is the same (the pure refactoring), but in the second > patch I implement Eric Blake's suggested version. LGTM -- can you please add Eric's text to the comment of is_zero, so it is easier to remember why the 16-bytes trick is done? Thanks, -- Pino Toscano
2020 Jan 30
0
Re: [PATCH libnbd] python: Add AIO buffer is_zero method.
On 1/30/20 8:05 AM, Richard W.M. Jones wrote: > Fast testing whether the AIO buffer (or regions within it) contain all > zeroes, which allows Python code to quickly do sparsification when > copying. > > This includes the iszero.h header from nbdkit which is distributed > under a compatible license. > --- > common/include/Makefile.am | 5 +-- >
2020 Jan 30
0
Re: [PATCH libnbd] python: Add AIO buffer is_zero method.
On Thu, Jan 30, 2020 at 02:29:21PM +0000, Richard W.M. Jones wrote: >On Thu, Jan 30, 2020 at 08:16:30AM -0600, Eric Blake wrote: >> On 1/30/20 8:05 AM, Richard W.M. Jones wrote: >> >Fast testing whether the AIO buffer (or regions within it) contain all >> >zeroes, which allows Python code to quickly do sparsification when >> >copying. >> > >>
2020 Jan 30
1
Re: [PATCH libnbd] python: Add AIO buffer is_zero method.
On Thu, Jan 30, 2020 at 04:16:09PM +0100, Martin Kletzander wrote: > I know this probably got answered somewhere, but I've never gotten > any when asking myself. So let me use this opportunity. > > Because I really despise useless processes and duplicated > information I always hated the way all the "mandatory" file headers. > As far as I understand it's
2019 Aug 15
0
Re: [nbdkit PATCH] data, memory: Optimize .zero > PAGE_SIZE
On Wed, Aug 14, 2019 at 09:10:15PM -0500, Eric Blake wrote: > When sparse_array_zero() is used for a range larger than a page, > there's no need to waste time in memset() or is_zero() - we already > know the page will be free()d. > > Signed-off-by: Eric Blake <eblake@redhat.com> > --- > > Here's a fun one :) > > common/sparse/sparse.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/common/sparse/sp...
2020 Jan 30
2
Re: [PATCH libnbd] python: Add AIO buffer is_zero method.
On Thu, Jan 30, 2020 at 08:16:30AM -0600, Eric Blake wrote: > On 1/30/20 8:05 AM, Richard W.M. Jones wrote: > >Fast testing whether the AIO buffer (or regions within it) contain all > >zeroes, which allows Python code to quickly do sparsification when > >copying. > > > >This includes the iszero.h header from nbdkit which is distributed > >under a compatible
2020 Feb 18
1
Re: Cross-project NBD extension proposal: NBD_INFO_INIT_STATE
On 2/17/20 9:13 AM, Max Reitz wrote: > Hi, > > It’s my understanding that without some is_zero infrastructure for QEMU, > it’s impossible to implement this flag in qemu’s NBD server. You're right that we may need some more infrastructure before being able to decide when to report this bit in all cases. But for raw files, that infrastructure already exists: does block_status at off...
2020 Feb 17
0
Re: Cross-project NBD extension proposal: NBD_INFO_INIT_STATE
Hi, It’s my understanding that without some is_zero infrastructure for QEMU, it’s impossible to implement this flag in qemu’s NBD server. At the same time, I still haven’t understood what we need the flag for. As far as I understood in our discussion on your qemu series, there is no case where anyone would need to know whether an image is zero. A...
2018 Aug 01
1
Re: [PATCH v2 nbdkit 5/6] Add truncate filter for truncating or extending the size of plugins.
..._up - 1'; I think we favor the spaces everywhere... > + if (round_down > 0) > + size &= ~(round_down-1); ...in which case the spacing here is also suspect. > + if (count > 0) { > + /* The caller must be writing zeroes, else it's an error. */ > + if (!is_zero (buf, count)) { > + nbdkit_error ("truncate: write beyond end of underlying device"); > + *err = EIO; Would ENOSPC be better here? -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
2014 Aug 08
3
[PATCH] daemon: add CLEANUP_CLOSE
...const char *fmt, ...) extern void cleanup_free (void *ptr); extern void cleanup_free_string_list (void *ptr); extern void cleanup_unlink_free (void *ptr); +extern void cleanup_close (void *ptr); /*-- in names.c (auto-generated) --*/ extern const char *function_names[]; @@ -405,10 +406,12 @@ is_zero (const char *buffer, size_t size) #define CLEANUP_FREE_STRING_LIST \ __attribute__((cleanup(cleanup_free_string_list))) #define CLEANUP_UNLINK_FREE __attribute__((cleanup(cleanup_unlink_free))) +#define CLEANUP_CLOSE __attribute__((cleanup(cleanup_close))) #else #def...
2015 Jun 23
2
[PATCH] lib: Add optional 'append' parameter to copy-(device|file)-to-file APIs.
...touch"; "/copyff2/dest"]; ["truncate_size"; "/copyff2/dest"; string_of_int size]; - ["copy_file_to_file"; "/copyff2/src"; "/copyff2/dest"; ""; ""; ""; "true"]; - ["is_zero"; "/copyff2/dest"]]), [] + ["copy_file_to_file"; "/copyff2/src"; "/copyff2/dest"; ""; ""; ""; "true"; "false"]; + ["is_zero"; "/copyff2/dest"]]), []; + InitScratch...
2019 Apr 23
2
Re: [PATCH nbdkit v5 FINAL 14/19] data, memory: Implement extents.
...I know in earlier review I asked whether we can move the clamping... > + > + /* Work out the type of this extent. */ > + if (p == NULL) > + /* No backing page, so it's a hole. */ > + type = NBDKIT_EXTENT_HOLE | NBDKIT_EXTENT_ZERO; > + else { > + if (is_zero (p, n)) > + /* A backing page and it's all zero, it's a zero extent. */ > + type = NBDKIT_EXTENT_ZERO; > + else > + /* Normal allocated data. */ > + type = 0; > + } > + if (nbdkit_add_extent (extents, offset, n, type) == -1) > +...
2015 Jun 23
0
Re: [PATCH] lib: Add optional 'append' parameter to copy-(device|file)-to-file APIs.
...uot;/copyff2/dest"]; > ["truncate_size"; "/copyff2/dest"; string_of_int size]; > - ["copy_file_to_file"; "/copyff2/src"; "/copyff2/dest"; ""; ""; ""; "true"]; > - ["is_zero"; "/copyff2/dest"]]), [] > + ["copy_file_to_file"; "/copyff2/src"; "/copyff2/dest"; ""; ""; ""; "true"; "false"]; > + ["is_zero"; "/copyff2/dest"]]), []; > +...
2019 Apr 23
0
Re: [PATCH nbdkit v5 FINAL 14/19] data, memory: Implement extents.
...we can move the clamping... > > > + > > + /* Work out the type of this extent. */ > > + if (p == NULL) > > + /* No backing page, so it's a hole. */ > > + type = NBDKIT_EXTENT_HOLE | NBDKIT_EXTENT_ZERO; > > + else { > > + if (is_zero (p, n)) > > + /* A backing page and it's all zero, it's a zero extent. */ > > + type = NBDKIT_EXTENT_ZERO; > > + else > > + /* Normal allocated data. */ > > + type = 0; > > + } > > + if (nbdkit_add_extent (exte...