Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1izFms-0006hi-EG for pgsql-hackers@arkaria.postgresql.org; Wed, 05 Feb 2020 08:11:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1izFmr-0001Uv-6v for pgsql-hackers@arkaria.postgresql.org; Wed, 05 Feb 2020 08:11:53 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1izFmq-0001Uo-QO for pgsql-hackers@lists.postgresql.org; Wed, 05 Feb 2020 08:11:52 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1izFmk-00015E-FI for pgsql-hackers@postgresql.org; Wed, 05 Feb 2020 08:11:51 +0000 Received: by mail-wr1-x444.google.com with SMTP id y11so1461942wrt.6 for ; Wed, 05 Feb 2020 00:11:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=z+BtUjGCRkgnL3kcO03lStYAFD+yNrt7kBBQd67Jr7c=; b=Ks0F0crpoJJ67dlqUlavHp4JHet8SHl4hNb/IABtWFFZwqq9khvJupuiAv+pOZLYpK SURG/2xsKQPz0BEdQgtELZd7Es3mRy/ATWRwTkdwU5sKogVcw+fmILFvcWTuiyYARQ5L sylHK5KfxRhV9IrDe/20/b/3oQshnh2tzFqXW8q8psMt/4MLu9IzuJV4yKFCFYpOlDrJ RGiBDCPmmf3O3B3Ez2IagkGvjxANs9lKsAFHzfh44hh5iNKqLJ/u2+g/sK4BGo1QV/Go jXoZgv15qFQlDh6hrCCbTUOoDa5MXSfCLF3Z+ffu5Y5HhECdXIyxRrhS9xXJCSJGGN17 qjGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=z+BtUjGCRkgnL3kcO03lStYAFD+yNrt7kBBQd67Jr7c=; b=CZbRYqIeVr0mq1ox2Ia/4EgM4CmE09gtt28CKvBWm0Etd6NI7btBbKHarEcK1owO8g 0JWgPrE6y7xJwFAaiw/QH6uJKq6CsJLjEP3CickahI9JrjNKXp7cbAZTXUD82rKpwLfB PAlEG8vkn2vRXi7cSwzkmV0IMHR/4HuwxgpVFpJ8T4NzE3Oss9m0FIQpfDxeGMJMAfef IRerkSQHrQ3Sgv3dVPiZIc6AMJUmlTTldW0fDvnLAonDwNVH0AaQJntHUCF5vBj5DtYv jzBMkVfKmOrKQELKo+yXmXAA2+B67ipi8MUTiQygbcuY2/B1eCIRSE1pnZi/yc1oQPMU Ql4A== X-Gm-Message-State: APjAAAUTy5vcobU0RL7aXPQUMbtUwlhrBbUZkK/Y1Y+UGOwaLPRpBEka SEt0rBHce2emwycUUCs4lbJZaJgGkPsuIg== X-Google-Smtp-Source: APXvYqzZiUieeeHz+F0dc/l+4sEnJzcuobZLBGq/ToMMHGVnPCYVpfzOiJbokt2E1RS0srB1UT8gXw== X-Received: by 2002:a5d:5381:: with SMTP id d1mr26482832wrv.259.1580890304798; Wed, 05 Feb 2020 00:11:44 -0800 (PST) Received: from nol ([2a01:e0a:c:bcf0:dbc8:f7e9:89ae:5cd7]) by smtp.gmail.com with ESMTPSA id 11sm8156064wmb.14.2020.02.05.00.11.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 00:11:44 -0800 (PST) Date: Wed, 5 Feb 2020 09:13:42 +0100 From: Julien Rouhaud To: Fujii Masao Cc: pgsql-hackers@postgresql.org Subject: Re: A bug in LWLOCK_STATS Message-ID: <20200205081342.GA22009@nol> References: <26359edb-798a-568f-d93a-6aafac49752d@oss.nttdata.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <26359edb-798a-568f-d93a-6aafac49752d@oss.nttdata.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Feb 05, 2020 at 02:43:49PM +0900, Fujii Masao wrote: > Hi, > > When I compiled PostgreSQL with -DLWLOCK_STATS and tried to check > the statistics of light-weight locks, I observed that more than one > statistics entries were output *for the same backend process and > the same lwlock*. For example, I got the following four statistics > when I checked how the process with PID 81141 processed ProcArrayLock. > This is strange, and IMO only one statistics should be output for > the same backend process and lwlock. > > $ grep "PID 81141 lwlock ProcArrayLock" data/log/postgresql-2020-02-05_141842.log > PID 81141 lwlock ProcArrayLock 0x111e87780: shacq 4000 exacq 0 blk 0 spindelay 0 dequeue self 0 > PID 81141 lwlock ProcArrayLock 0x111e87780: shacq 2 exacq 0 blk 0 spindelay 0 dequeue self 0 > PID 81141 lwlock ProcArrayLock 0x111e87780: shacq 6001 exacq 1 blk 0 spindelay 0 dequeue self 0 > PID 81141 lwlock ProcArrayLock 0x111e87780: shacq 5 exacq 1 blk 0 spindelay 0 dequeue self 0 > > The cause of this issue is that the key variable used for lwlock hash > table was not fully initialized. The key consists of two fields and > they are initialized as follows. But the following 4 bytes allocated > for the alignment was not initialized. So even if the same key was > specified, hash_search(HASH_ENTER) could not find the existing > entry for that key and created new one. > > key.tranche = lock->tranche; > key.instance = lock; > > Attached is the patch fixing this issue by initializing the key > variable with zero. In the patched version, I confirmed that only one > statistics is output for the same process and the same lwlock. > Also this patch would reduce the volume of lwlock statistics > very much. > > This issue was introduced by commit 3761fe3c20. So the patch needs > to be back-patch to v10. Good catch! The patch looks good to me. Just in case I looked at other users of HASH_BLOBS and AFAICT there's no other cases of key that can contain padding bytes that aren't memset first.