Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mETjj-0000g8-D3 for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Aug 2021 09:44:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mETjh-0001hN-Bv for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Aug 2021 09:44:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mETjh-0001hD-2b for pgsql-hackers@lists.postgresql.org; Fri, 13 Aug 2021 09:44:21 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mETjf-0006cY-0d for pgsql-hackers@lists.postgresql.org; Fri, 13 Aug 2021 09:44:20 +0000 Received: from mail.postgrespro.ru (cyclops.postgrespro.ru [93.174.131.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id EFE8021C8BFA; Fri, 13 Aug 2021 12:44:17 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1628847857; bh=+2qH9Q999cTdCiiQyzon4IWmkvPITF5rxiEW3NUqc4Y=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=FvmIALGuGrutwcePaVGWSWJugmdVMZhVHQ6J/3/yRXMPkdFt5GCjEHJTm2z4DTczi Zqf5RO7AbdjZafNe/nh5rNAQlCa85kOVJC9GoySVnmD9w7QUhtj0d7dvO9RLFkA9kR iO9Q0qqtrtFY5A9sPf5AvTRy5aSYowkJUk9npqe0= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Fri, 13 Aug 2021 12:44:17 +0300 From: Yura Sokolov To: Andres Freund Cc: pgsql-hackers@lists.postgresql.org, Tomas Vondra Subject: Re: Bug in huge simplehash In-Reply-To: <20210813092133.6it4ztxlz4jncmia@alap3.anarazel.de> References: <20210813092133.6it4ztxlz4jncmia@alap3.anarazel.de> User-Agent: Roundcube Webmail/1.4.0 Message-ID: <5a51d54ad3a8e3cddccc4bd6cfce5dd3@postgrespro.ru> X-Sender: y.sokolov@postgrespro.ru List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andres Freund писал 2021-08-13 12:21: > Hi, > > On 2021-08-10 11:52:59 +0300, Yura Sokolov wrote: >> - sizemask is set only in SH_COMPUTE_PARAMETERS . And it is set in >> this way: >> >> /* now set size */ >> tb->size = size; >> >> if (tb->size == SH_MAX_SIZE) >> tb->sizemask = 0; >> else >> tb->sizemask = tb->size - 1; >> >> that means, when we are resizing to SH_MAX_SIZE, sizemask becomes >> zero. > > I think that was intended to be ~0. I believe so. >> Ahh... ok, patch is updated to fix this as well. > > Any chance you'd write a test for simplehash with such huge amount of > values? It'd require a small bit of trickery to be practical. On > systems > with MAP_NORESERVE it should be feasible. Which way C structures should be tested in postgres? dynahash/simplhash - do they have any tests currently? I'll do if hint is given. >> static inline void >> -SH_COMPUTE_PARAMETERS(SH_TYPE * tb, uint32 newsize) >> +SH_COMPUTE_PARAMETERS(SH_TYPE * tb, uint64 newsize) >> { >> uint64 size; >> >> @@ -322,11 +322,7 @@ SH_COMPUTE_PARAMETERS(SH_TYPE * tb, uint32 >> newsize) >> >> /* now set size */ >> tb->size = size; >> - >> - if (tb->size == SH_MAX_SIZE) >> - tb->sizemask = 0; >> - else >> - tb->sizemask = tb->size - 1; >> + tb->sizemask = (uint32)(size - 1); > > ISTM using ~0 would be nicer here? I don't think so. To be rigid it should be `~(uint32)0`. But I believe it doesn't differ from `tb->sizemask = (uint32)(size - 1)` that is landed with patch, therefore why `if` is needed? > > Greetings, > > Andres Freund