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 1mEVXr-0003hB-Ug for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Aug 2021 11:40:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mEVXq-0001qq-TI for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Aug 2021 11:40:14 +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 1mEVXq-0001qg-6Y for pgsql-hackers@lists.postgresql.org; Fri, 13 Aug 2021 11:40:14 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mEVXm-0007br-8D for pgsql-hackers@lists.postgresql.org; Fri, 13 Aug 2021 11:40:13 +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 CAF7421CBCA9; Fri, 13 Aug 2021 14:40:08 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1628854808; bh=s2pb2fFJNdW9L9/wW6sSY+VCi7DyxT3QpWIlU27GCGo=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=j69jWE5Gy9c6w8kqbv6Bn2L41ECja9WPdDvBxs5YBibBxTKQ6X+b9XIAj0gKJbo5L 7O4cuxDITlenm0iAUvw6HXfO3H57M05rfVQv+IeoWueBG3swb6XcK6YELfBkNkjsjh kEyXmZzbTtk9/T/sYM6+iFvbEv3JQcutTdKyHDwA= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Fri, 13 Aug 2021 14:40:08 +0300 From: Yura Sokolov To: Ranier Vilela Cc: Andres Freund , PostgreSQL Hackers , Tomas Vondra Subject: Re: Bug in huge simplehash In-Reply-To: References: <20210813092133.6it4ztxlz4jncmia@alap3.anarazel.de> <5a51d54ad3a8e3cddccc4bd6cfce5dd3@postgrespro.ru> <20210813101543.bkncnioyqi472man@alap3.anarazel.de> User-Agent: Roundcube Webmail/1.4.0 Message-ID: X-Sender: y.sokolov@postgrespro.ru List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Ranier Vilela писал 2021-08-13 14:12: > Em sex., 13 de ago. de 2021 às 07:15, Andres Freund > escreveu: > >> Hi, >> >> On 2021-08-13 12:44:17 +0300, Yura Sokolov wrote: >>> Andres Freund писал 2021-08-13 12:21: >>>> 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. >> >> We don't have a great way right now :(. I think the best is to have >> a >> SQL callable function that uses some API. See e.g. test_atomic_ops() >> et >> al in src/test/regress/regress.c >> >>>> > 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? >> >> Personally I find it more obvious to understand the intended >> behaviour >> with ~0 (i.e. all bits set) than with a width truncation. > > https://godbolt.org/z/57WcjKqMj > The generated code is identical. I believe, you mean https://godbolt.org/z/qWzE1ePTE > regards, > Ranier Vilela