From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51583) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1auS3F-0000jW-Ns for qemu-devel@nongnu.org; Sun, 24 Apr 2016 17:58:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1auS3A-0000ow-LO for qemu-devel@nongnu.org; Sun, 24 Apr 2016 17:58:49 -0400 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:44761) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1auS3A-0000os-G8 for qemu-devel@nongnu.org; Sun, 24 Apr 2016 17:58:44 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 163AD24206 for ; Sun, 24 Apr 2016 17:58:44 -0400 (EDT) Date: Sun, 24 Apr 2016 17:58:43 -0400 From: "Emilio G. Cota" Message-ID: <20160424215843.GA1122@flamenco> References: <1461107270-19234-1-git-send-email-cota@braap.org> <1461107270-19234-9-git-send-email-cota@braap.org> <571D261B.40406@twiddle.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <571D261B.40406@twiddle.net> Subject: Re: [Qemu-devel] [PATCH v3 08/11] qht: QEMU's fast, resizable and scalable Hash Table List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Richard Henderson Cc: QEMU Developers , MTTCG Devel , Alex =?iso-8859-1?Q?Benn=E9e?= , Paolo Bonzini , Peter Crosthwaite , Peter Maydell , Sergey Fedorov On Sun, Apr 24, 2016 at 13:01:31 -0700, Richard Henderson wrote: > On 04/19/2016 04:07 PM, Emilio G. Cota wrote: > >+static void qht_insert__locked(struct qht *ht, struct qht_map *map, > >+ struct qht_bucket *head, void *p, uint32_t hash) > >+{ > >+ struct qht_bucket *b = head; > >+ struct qht_bucket *prev = NULL; > >+ struct qht_bucket *new = NULL; > >+ int i; > >+ > >+ for (;;) { > >+ if (b == NULL) { > >+ b = qemu_memalign(QHT_BUCKET_ALIGN, sizeof(*b)); > >+ memset(b, 0, sizeof(*b)); > >+ new = b; > >+ } > >+ for (i = 0; i < QHT_BUCKET_ENTRIES; i++) { > >+ if (b->hashes[i]) { > >+ continue; > >+ } > > Surely that's b->pointers[i] != NULL. We've made no provision that the hash > function must return non-zero. Good catch! I initially banned 0 from being a valid hash value, knowing that I'd have to eventually test how stupid this assumption was, but I forgot to do so. It turns out that banning any hash value is a stupid idea. For example, looping over [0,0xffffffff] shows that xxh32(0x7aac3812, seed=1) == 0. Will fix this in v4 -- the only assumption will be that the passed pointer should be !NULL. > >+static inline bool qht_remove__locked(struct qht_map *map, struct qht_bucket *b, > >+ const void *p, uint32_t hash) > >+{ > >+ int i; > >+ > >+ do { > >+ for (i = 0; i < QHT_BUCKET_ENTRIES; i++) { > >+ if (b->hashes[i] == hash && b->pointers[i] == p) { > > Don't you only need to test p here? Fair point. Will fix in v4. Thanks, Emilio