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 1lAcd5-0005D5-48 for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Feb 2021 17:53:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lAcd4-0006vW-2e for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Feb 2021 17:53:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lAcd3-0006vF-Rx for pgsql-hackers@lists.postgresql.org; Fri, 12 Feb 2021 17:53:17 +0000 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lAccw-0000aH-Fi for pgsql-hackers@postgresql.org; Fri, 12 Feb 2021 17:53:16 +0000 Received: by mail-ej1-x62e.google.com with SMTP id i8so537464ejc.7 for ; Fri, 12 Feb 2021 09:53:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=4U5ciGVmXcipZDnpOwlJHw+g7joj1SAbJOCWBU5KVQs=; b=ltpyfwCjr2Yill8vVhk9Sn6v8ayVqfM7LEI9FYBZp/e0q2QtxuhBBXzm+Fp+X8eazL 1JGfezPbQrvHhJKagyLT292FsvC+/xLrWjT2c6QSVwzn7evLrN4A9O1Rvr/5i2X07e8D nt3CqieuTIuGhFHoMrKULa5YVo2KZuLLSR92XAB4AQIMSYL9R1tE701hbAryi16ikfx1 1zbHDsnBV1d4KIHVgrUkifTyYgJcAW48nxHjvbfjFwEB0UH/gInv1nLzxbIu3E1JBQeX S4g/ofyXtc8Cxq11hfi6g1H8zSg13P8a2qDWwVuPQtZbRz28IDmHWfI+buzRaonC2h0b 5ZoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=4U5ciGVmXcipZDnpOwlJHw+g7joj1SAbJOCWBU5KVQs=; b=ivxHsx1D2Xrw/SCgc+TxypT6semWfyt3Do1N8Hd9vwItceXDCIT2z4rwLvtaLkz6uS DO5Co4OnpwFaAYxRRYwzYiPHBLB/9OOZzefCiMQeoWcMnUOApphfPwx85S7Tn1Jz240q FQVsV/l7+38gaBxBUQpBJicczk25vtNB1rBfWrrUkBkiIsDUfv2baU8NhzX9de1qkyFj NkSZa6gw8QHRmvJCK8dm88rFzmTqBfvCGfNT+/m8CI2BOhJ+lRE/vX5aMTM9cM4YHd2u P1iaQ7rZ32JXTUxthSVEdkZWwmOT93y9D1S7TXA+2rKUNiioWLvYIoZvcagXEvfIzs8d isCA== X-Gm-Message-State: AOAM531+HO3OCHzo2DKlcgzzQzamywZvmvMY+tpMXOjh73Rm7lLu/PXw 06/PFX4PoJuxNa63qtsvX+ewyyAkbdYoKhvdIYuIhBkoXhootBT5KnLje1YmVBQEmEwjGzZoJxq laQ8WmIHdOpPJO1iYdGnO6wdxj53yUXihMmQqyWZsf8UPUoppspsPzcvAioGiXccss3tG2Xmnea ytHpybk+TllD4X9P2gW+5u7G3K6Hcp44Jvj5gfXfqRj6dCvxGAR4sVQfzPWq2f88/FpBCFcAD1B yYLJA/cCAOEKQkOjbo942p/pZpHJ2bgamjcpg== X-Google-Smtp-Source: ABdhPJy+CQr9KQRlxprMiicL8AFjacHsd83qV5luWgr267hjRss4FB0KWtfA7nwZOUIdvaCajsE3Jw== X-Received: by 2002:a17:906:1457:: with SMTP id q23mr2343674ejc.43.1613152388507; Fri, 12 Feb 2021 09:53:08 -0800 (PST) Received: from [10.137.0.20] (ip-86-49-253-127.net.upcbroadband.cz. [86.49.253.127]) by smtp.gmail.com with ESMTPSA id w8sm5814233edd.39.2021.02.12.09.53.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Feb 2021 09:53:07 -0800 (PST) Subject: Re: WIP: WAL prefetch (another approach) To: Andres Freund Cc: Stephen Frost , Thomas Munro , Jakub Wartak , Alvaro Herrera , Tomas Vondra , Dmitry Dolgov <9erthalion6@gmail.com>, David Steele , pgsql-hackers References: <20201010112935.qrhm572v4djrjljo@development> <5437ce5b-d305-bd85-23ec-ddb15735d93f@enterprisedb.com> <20201113151344.GU16415@tamriel.snowman.net> <20210210215033.GA27507@tamriel.snowman.net> <103ec76d-8bbc-09e1-460c-8785751431b5@enterprisedb.com> <20210212044614.5wqjkjbcmbwzever@alap3.anarazel.de> From: Tomas Vondra Message-ID: <3f962e4f-a10d-dbe1-6e21-3dc851aa0938@enterprisedb.com> Date: Fri, 12 Feb 2021 18:53:03 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20210212044614.5wqjkjbcmbwzever@alap3.anarazel.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2/12/21 5:46 AM, Andres Freund wrote: > Hi, > > On 2021-02-12 00:42:04 +0100, Tomas Vondra wrote: >> Yeah, that's a good point. I think it'd make sense to keep track of recent >> FPIs and skip prefetching such blocks. But how exactly should we implement >> that, how many blocks do we need to track? If you get an FPI, how long >> should we skip prefetching of that block? >> >> I don't think the history needs to be very long, for two reasons. Firstly, >> the usual pattern is that we have FPI + several changes for that block >> shortly after it. Secondly, maintenance_io_concurrency limits this naturally >> - after crossing that, redo should place the FPI into shared buffers, >> allowing us to skip the prefetch. >> >> So I think using maintenance_io_concurrency is sufficient. We might track >> more buffers to allow skipping prefetches of blocks that were evicted from >> shared buffers, but that seems like an overkill. >> >> However, maintenance_io_concurrency can be quite high, so just a simple >> queue is not very suitable - searching it linearly for each block would be >> too expensive. But I think we can use a simple hash table, tracking >> (relfilenode, block, LSN), over-sized to minimize collisions. >> >> Imagine it's a simple array with (2 * maintenance_io_concurrency) elements, >> and whenever we prefetch a block or find an FPI, we simply add the block to >> the array as determined by hash(relfilenode, block) >> >> hashtable[hash(...)] = {relfilenode, block, LSN} >> >> and then when deciding whether to prefetch a block, we look at that one >> position. If the (relfilenode, block) match, we check the LSN and skip the >> prefetch if it's sufficiently recent. Otherwise we prefetch. > > I'm a bit doubtful this is really needed at this point. Yes, the > prefetching will do a buffer table lookup - but it's a lookup that > already happens today. And the patch already avoids doing a second > lookup after prefetching (by optimistically caching the last Buffer id, > and re-checking). > > I think there's potential for some significant optimization going > forward, but I think it's basically optimization over what we're doing > today. As this is already a nontrivial patch, I'd argue for doing so > separately. > I agree with treating this as an improvement - it's not something that needs to be solved in the first verson. OTOH I think Stephen has a point that just skipping FPIs like we do now has limited effect, because the WAL usually contains additional changes to the same block. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company