Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aMFrJ-0007nN-P8 for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Jan 2016 14:05:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aMFrJ-0006CF-BU for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Jan 2016 14:05:09 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aMFpy-00049J-Su for pgsql-hackers@postgresql.org; Thu, 21 Jan 2016 14:03:47 +0000 Received: from newmail.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by makus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1aMFpt-00005o-J6 for pgsql-hackers@postgresql.org; Thu, 21 Jan 2016 14:03:45 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 6460F21C5AFE for ; Thu, 21 Jan 2016 17:03:39 +0300 (MSK) Received: from mail.postgrespro.ru ([127.0.0.1]) by localhost (mail.postgrespro.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id p47v4yRkxpby for ; Thu, 21 Jan 2016 17:03:34 +0300 (MSK) Received: from [192.168.27.79] (unknown [192.168.27.1]) by mail.postgrespro.ru (Postfix) with ESMTPSA id 387AC21C5AEF for ; Thu, 21 Jan 2016 17:03:34 +0300 (MSK) Subject: Re: Patch: fix lock contention for HASHHDR.mutex To: pgsql-hackers References: <20151211170001.78ded9d7@fujitsu> <20151215122513.GC17724@alap3.anarazel.de> <20151217151418.GB2224@awork2.anarazel.de> <20151217190342.07e4533a@fujitsu> <56740E41.4010708@sigaev.ru> <20151222183953.771cb58b@fujitsu> <20151228120112.6a847dfd@fujitsu> <20151229184851.1bb7d1bd@fujitsu> <20151230160137.034371e0@fujitsu> From: Anastasia Lubennikova Message-ID: <56A0E536.8020504@postgrespro.ru> Date: Thu, 21 Jan 2016 17:03:34 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <20151230160137.034371e0@fujitsu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org 30.12.2015 16:01, Aleksander Alekseev: > Here is a clean version of the patch. Step 1 is an optimization. Step 2 > refactors this: > > HTAB * > ShmemInitHash(const char *name, /* table string name for shmem index */ > - long init_size, /* initial table size */ > + long init_size, /* initial table size XXX ignored, > refactor! */ Hi, I found that the patch is still not reviewed, so I've looked it over. I haven't dived into this subject before, so my comments will be more general than relating to your investigation. Sorry if some things seem like nitpicks, I just suppose that clear patch would be more convenient for reviewers. First of all, why not merge both patches into one? They aren't too big anyway. Then, this thread became too tangled. I think it's worth to write a new message with the patch, the test script, some results and brief overview of how does it really works. It will make following review much easier. + /* number of entries in hash table */ + long nentries[NUM_LOCK_PARTITIONS]; + /* linked list of free elements */ + HASHELEMENT *freeList[NUM_LOCK_PARTITIONS]; I think comments should be changed, to be more informative here. + if (IS_PARTITIONED(hashp->hctl)) + partitions_number = NUM_LOCK_PARTITIONS; + else + partitions_number = 1; + + nelem_alloc = ((int) nelem) / partitions_number; + if (nelem_alloc == 0) + nelem_alloc = 1; Add a comment here too. -/* Number of partitions of the shared buffer mapping hashtable */ -#define NUM_BUFFER_PARTITIONS 128 - /* Number of partitions the shared lock tables are divided into */ -#define LOG2_NUM_LOCK_PARTITIONS 4 +#define LOG2_NUM_LOCK_PARTITIONS 7 #define NUM_LOCK_PARTITIONS (1 << LOG2_NUM_LOCK_PARTITIONS) +/* Number of partitions of the shared buffer mapping hashtable */ +#define NUM_BUFFER_PARTITIONS NUM_LOCK_PARTITIONS + I'm sure, it was discussed above. but these definitions do not look obvious at all. Maybe you should explain this magic number 7 in the comment above? -- Anastasia Lubennikova Postgres Professional: http://www.postgrespro.com The Russian Postgres Company -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers