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 1hzy7l-0000pG-PP for pgsql-bugs@arkaria.postgresql.org; Tue, 20 Aug 2019 07:00:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hzy7k-0007u1-2F for pgsql-bugs@arkaria.postgresql.org; Tue, 20 Aug 2019 07:00:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hzy7j-0007tu-OQ for pgsql-bugs@lists.postgresql.org; Tue, 20 Aug 2019 07:00:07 +0000 Received: from mail-lj1-x241.google.com ([2a00:1450:4864:20::241]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hzy7g-0000No-8g for pgsql-bugs@lists.postgresql.org; Tue, 20 Aug 2019 07:00:07 +0000 Received: by mail-lj1-x241.google.com with SMTP id h15so4062523ljg.10 for ; Tue, 20 Aug 2019 00:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:references:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=FBqIaZNuoCYh7REBHuqLVgGq+L4W92W8Nu/THzjsuW4=; b=fg/s/vvKcVSIC0OIXsNE8ZaePRSC7EpOtJ4FVUNvpekoJ41IR3jzM5q8f2XToGzk9J Oq5aKkYWUFncgg1KCCG1RUAAcb6D2D1SqigTI4vyeVALlPZ+LNhdJ4HcjGqAYFPvwVob ivhSucKvNbp7Nx84sllOFlbYdVlmcyle4/pNtkOLGkkKfcEaTz9mLyM344Tc/G2wgf/z F+CkAN5sZiPS/Ir+HHddtLOWdXlfOCa1F56uPNRsy7dZBxYZamDCJjswPEXaDH+YdH1D IsKOVfYbWnfRX1Yub6RAvpBdTDdk0klGjelaGzOw6KnbZlGtS4Omad4PfdhBPEFVOgwm hK+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=FBqIaZNuoCYh7REBHuqLVgGq+L4W92W8Nu/THzjsuW4=; b=sBTQqQVGd/FY32OlCzLmCaYAFsjOYt9Rk198JIu+9gOPgzhznKCZUvhTEAKQMvCp2a SaCyUZWYsAR/meDVAF8K+DvR+lR/QyrhwcFJQKsost4+g91ZmenDCXJyb3dHv3pjHX9x aadgoNoB61JtcBRIhFHpIii5kwr4umJBas3mYsF6m8SUJN951y0xZGu13uAu61KPYk2i rNDa5f/oDRzyl6PP04POoKu+aXiFl6V6CPZMtUtG3jKH+lMTtl0Vf871TJHdEJJMyfjp B9bMAHapuuq0Sf1zEbjMfZzAv2fToICe04Fpd/ksnbM/tA6yHHtu/o6W8xacfIUmKUvl HB6w== X-Gm-Message-State: APjAAAX5BGiZafuRIbCtGvZjPm0KKfYmwquibQPV2Gk1UPAvFd9C5VfO nD5brF16miiaTeAOlbNBoxHqhMF7 X-Google-Smtp-Source: APXvYqxf8xhisLG0f99xaKHWAvfM6+3ekxTITozvlt9AAnUhotFitlGXC16nwbEtaYBoPO0Y96d1PQ== X-Received: by 2002:a2e:924b:: with SMTP id v11mr15082371ljg.139.1566284403641; Tue, 20 Aug 2019 00:00:03 -0700 (PDT) Received: from [1.0.0.7] ([178.155.4.164]) by smtp.gmail.com with ESMTPSA id f22sm2662613ljh.22.2019.08.20.00.00.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Aug 2019 00:00:02 -0700 (PDT) Subject: Re: BUG #15943: Valgrind-detected error in SlruPhysicalWritePage From: Alexander Lakhin To: Andres Freund , pgsql-bugs@lists.postgresql.org References: <15943-c7232c75bb276d6c@postgresql.org> <902AFCEA-F078-4D47-AF53-1D2FD3022657@anarazel.de> <8c31c946-f2e8-3b07-3191-9f5698e3dd14@gmail.com> Message-ID: <7b8cbcf5-58a4-c119-b25a-e82358b44f9e@gmail.com> Date: Tue, 20 Aug 2019 10:00:01 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <8c31c946-f2e8-3b07-3191-9f5698e3dd14@gmail.com> Content-Type: multipart/mixed; boundary="------------793F9C75C030853A6213116D" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------793F9C75C030853A6213116D Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Hello hackers, > 08.08.2019 13:33, Andres Freund wrote: >> On August 8, 2019 12:44:43 AM EDT, PG Bug reporting form wrote: >>> The following bug has been logged on the website: >>> >>> Bug reference: 15943 >>> Logged by: Alexander Lakhin >>> Email address: exclusion@gmail.com >>> PostgreSQL version: 12beta2 >>> Operating system: Ubuntu 18.04 >>> Description: >>> >>> When running under valgrind (sitting on the master branch): >>> printf "SELECT pg_notify('notify_async1',NULL); %.0s" `seq 2048` | psql >>> >> That seems likely to be padding. Probably easier to see if you enable read-var-info and track-origins. > Indeed, "memset(&qe, 0, sizeof(qe));" added in the beginning of > asyncQueueAddEntries fixes the issue. > More interestingly, "memset(qe.data, 0, sizeof(qe.data));" in the same > place fixes it too (the patch is attached). > So it seems, the padding in AsyncQueueEntry has an alibi. Andres, you're right. The padding is found guilty (inside the qe.data itself). Please look at the patch addressing the cause of the problem (inspired by btree_bit.c). But if a valgrind suppression is preferred, look at the alternate patch. Best regards, Alexander --------------793F9C75C030853A6213116D Content-Type: text/x-patch; name="fix-aqe-padding.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fix-aqe-padding.patch" diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c index 6cb2d445f0..a9d5362dc5 100644 --- a/src/backend/commands/async.c +++ b/src/backend/commands/async.c @@ -1321,19 +1321,23 @@ asyncQueueNotificationToEntry(Notification *n, AsyncQueueEntry *qe) { size_t channellen = n->channel_len; size_t payloadlen = n->payload_len; + int rawLength; int entryLength; Assert(channellen < NAMEDATALEN); Assert(payloadlen < NOTIFY_PAYLOAD_MAX_LENGTH); /* The terminators are already included in AsyncQueueEntryEmptySize */ - entryLength = AsyncQueueEntryEmptySize + payloadlen + channellen; - entryLength = QUEUEALIGN(entryLength); + rawLength = AsyncQueueEntryEmptySize + payloadlen + channellen; + entryLength = QUEUEALIGN(rawLength); qe->length = entryLength; qe->dboid = MyDatabaseId; qe->xid = GetCurrentTransactionId(); qe->srcPid = MyProcPid; memcpy(qe->data, n->data, channellen + payloadlen + 2); + /* initialize the padding bytes to zero */ + for (int i = 0; i < entryLength - rawLength; i++) + qe->data[channellen + payloadlen + 2 + i] = 0; } /* --------------793F9C75C030853A6213116D Content-Type: text/x-patch; name="valgrind_slru_write.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="valgrind_slru_write.patch" diff --git a/src/tools/valgrind.supp b/src/tools/valgrind.supp index ec47a228ae..72ef2a9fb1 100644 --- a/src/tools/valgrind.supp +++ b/src/tools/valgrind.supp @@ -112,6 +112,14 @@ fun:BootStrapXLOG } +{ + padding_slru_page_write + Memcheck:Param + write(buf) + ... + fun:SlruPhysicalWritePage +} + { bootstrap_write_relmap_overlap Memcheck:Overlap --------------793F9C75C030853A6213116D--