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 1nSYnP-0000hY-Uh for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Mar 2022 06:30:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nSYnO-0005RU-I6 for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Mar 2022 06:30:38 +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 1nSYnO-0005RL-7P for pgsql-hackers@lists.postgresql.org; Fri, 11 Mar 2022 06:30:38 +0000 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nSYnM-00027A-AS for pgsql-hackers@lists.postgresql.org; Fri, 11 Mar 2022 06:30:37 +0000 Received: by mail-pj1-x1030.google.com with SMTP id 15-20020a17090a098f00b001bef0376d5cso7310140pjo.5 for ; Thu, 10 Mar 2022 22:30:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:message-id:to:cc:subject:from:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=fBv6/UZ7UdGDNvGDLnJkuq+srE0IKyJi0S0SlpInnbw=; b=K5Wcr0NUVttMtnPHOZoOD6prqlVNoN1m9PZIWWfkjrvdgzbXPR0NcuJZ4lGjFcR8Tg K69gz3CeUPkSJj/fbTLJ83a2gap4mxscBX5LWkdvBkijODm7r+Egww3y8IF8t5MS8paB 2RJQOooL+63mKNgM3xhrh4maLQfDHsqnR9+SWqJXYd5niBgi0VsXtgzhT2xIBvNqYgCV oq/Jge3XMtNGczDc3Mixws9ybyK/PdBxhpe+gUvsreJjbJp3dQNHACSjf4TE7Jce0DTO M7ckh6bKVaDBZPh93EEEX4OM6X1+cGunI7wezEtgvRepxJ96+PTLZVaoyyHdssFUPjcv cyIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:to:cc:subject:from:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=fBv6/UZ7UdGDNvGDLnJkuq+srE0IKyJi0S0SlpInnbw=; b=LGxhaDkdjyxtNAIFo3Gw/8y2EclmcFJeDFhNy8PQJ8zqAJYjBHbacjmXzV0IRN8t3B y8i80Lw7ZHCJdVF0qaQK0p7ExfR8Cmjp4S/DqPs56Ny7KGILYbvMPQSb/w8KzhP2UvEb mkeEZTlqcycPoZOEQxCRcPpvKmiMfg1zTflRSJ5+dwbRgxpx2qgzSUKDLdKt2xqepizd 03C5Z0jcvRvDBd7EQSQKTg7JArsfTlZa0fvmLkSxOvX9K78cNAbaKrrAcHAJdH7YnbsM UXvdEtIel9fGN4/23R9s8HfINhrZSt2POUX30izUIsiCcku1rhk1kN+kQkR7inq5RLJj aOyw== X-Gm-Message-State: AOAM5308tzD+Cz4ZTsVxK9hIRDdReG6U5nsP8rTRfnKXLh0N9kf4jXCG gnGShDVasj/sLnP2UTaWiVE= X-Google-Smtp-Source: ABdhPJziskgjE5NvXewvA77vnv2FD3XY+2N3tZNQAPtx4Zg7waKyDUeDVAEmeRU7y/MD8TefI/0s9g== X-Received: by 2002:a17:90b:517:b0:1be:dde4:f848 with SMTP id r23-20020a17090b051700b001bedde4f848mr20202773pjz.233.1646980234103; Thu, 10 Mar 2022 22:30:34 -0800 (PST) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id x135-20020a62868d000000b004f7550f7f60sm8744735pfd.110.2022.03.10.22.30.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 10 Mar 2022 22:30:33 -0800 (PST) Date: Fri, 11 Mar 2022 15:30:30 +0900 (JST) Message-Id: <20220311.153030.1881495127262295773.horikyota.ntt@gmail.com> To: y.sokolov@postgrespro.ru Cc: pgsql-hackers@lists.postgresql.org, michail.nikolaev@gmail.com, x4mmm@yandex-team.ru, andres@anarazel.de, simon.riggs@enterprisedb.com Subject: Re: BufferAlloc: don't take two simultaneous locks From: Kyotaro Horiguchi In-Reply-To: References: User-Agent: Mew version 6.8 on Emacs 26.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=koi8-r Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk At Thu, 03 Mar 2022 01:35:57 +0300, Yura Sokolov wrote in = > =F7 =F7=D4, 01/03/2022 =D7 10:24 +0300, Yura Sokolov =D0=C9=DB=C5=D4:= > > Ok, here is v4. > = > And here is v5. > = > First, there was compilation error in Assert in dynahash.c . > Excuse me for not checking before sending previous version. > = > Second, I add third commit that reduces HASHHDR allocation > size for non-partitioned dynahash: > - moved freeList to last position > - alloc and memset offset(HASHHDR, freeList[1]) for > non-partitioned hash tables. > I didn't benchmarked it, but I will be surprised if it > matters much in performance sence. > = > Third, I put all three commits into single file to not > confuse commitfest application. Thanks! I looked into dynahash part. struct HASHHDR { - /* - * The freelist can become a point of contention in high-concurrency = hash Why did you move around the freeList? - long nentries; /* number of entries in associated buckets */ + long nfree; /* number of free entries in the list */ + long nalloced; /* number of entries initially allocated for Why do we need nfree? HASH_ASSING should do the same thing with HASH_REMOVE. Maybe the reason is the code tries to put the detached bucket to different free list, but we can just remember the freelist_idx for the detached bucket as we do for hashp. I think that should largely reduce the footprint of this patch. -static void hdefault(HTAB *hashp); +static void hdefault(HTAB *hashp, bool partitioned); That optimization may work even a bit, but it is not irrelevant to this patch? + case HASH_REUSE: + if (currBucket !=3D NULL) + { + /* check there is no unfinished HASH_REUSE+HASH_ASSIGN pair */ + Assert(DynaHashReuse.hashp =3D=3D NULL); + Assert(DynaHashReuse.element =3D=3D NULL); I think all cases in the switch(action) other than HASH_ASSIGN needs this assertion and no need for checking both, maybe only for element would be enough. regards. -- = Kyotaro Horiguchi NTT Open Source Software Center