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 1nNPHd-0007lw-PK for pgsql-hackers@arkaria.postgresql.org; Fri, 25 Feb 2022 01:20:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nNPHc-00061G-F5 for pgsql-hackers@arkaria.postgresql.org; Fri, 25 Feb 2022 01:20:32 +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 1nNPHc-000617-3z for pgsql-hackers@lists.postgresql.org; Fri, 25 Feb 2022 01:20:32 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nNPHZ-0005hY-Gq for pgsql-hackers@postgresql.org; Fri, 25 Feb 2022 01:20:31 +0000 Received: by mail-pl1-x636.google.com with SMTP id c9so3471929pll.0 for ; Thu, 24 Feb 2022 17:20:29 -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=BFi2sKQ1nSryAu33JEzWCe1Hv2JlvFS25tPqL86fGM0=; b=oSMMC4E0OzstFSX2kvhiUJng9FEs7J9+ka4REqGBbg/Ivo7CExFJwWw83m750/Hcgz uTrSaIUzt+VH19cia0oGZpk9xCtrsU54JicjeGEUHwQYSveuG2FS5eFNb9bR/aKtO/m1 kTlV8SvOF2MX9KS3rJJ5GBWawS29Ra5zl91dZ4sT5KghWXBVFo7/6+w+hWAQXoSsxBMp HxHrvdj1ZjWl29ba0nk5nx5U3X5vG8hMXwvYWf33KamAHHeI+O0yFHJuxMlG1wtjvfdL drJPVi/NaL4wGqzZbfM24aeXjs2ZOW//sS0+UL9ULXGkQ+4Y30h4hcH2jYtBUCskDLKc iNLg== 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=BFi2sKQ1nSryAu33JEzWCe1Hv2JlvFS25tPqL86fGM0=; b=VkTLmRjeApm00AdGfcs5PLTZoGv+ibnJa2Xp0tmgbJyor/hLWoiUDfalUf6gF+fX8W VE/a5e8es8Xtdo5avZscdx+mXnYFtGs0tGAxYvKn88fOelkNJn1CDuqGvMpmja2lG69Y 25Sc2K2hgTk+ELrp2yvQGgt/bMDedAIC76NgKBWcEKSMeWRUTQHoptJgF2U6wRGx1Ua6 11gKSMDeuv9xUfa4CUaaLJiTx0S9aKkK2CmlHN3OknjONcnGxen/dIY+eEXuwXcgJ8jk lC101nPp2GfZBd3nvlUKakq1F4WE6Y2dee4hSbROdhs0FTYvhhalrfoa0kpyQ/tBd5V9 zBiQ== X-Gm-Message-State: AOAM530TgULaIwW8g7S9VDLl8SFfGVO9Y3kX/lLDwhqec6I7Kps4MMne MYljhH1il5o53A900KAJqwo= X-Google-Smtp-Source: ABdhPJwOSix+6I6lW0EP61ltHFxISxzEU2zvBgbdQeKYRgxgW6k/QGjM2xK+RV4aUPZQthHRJQAK9g== X-Received: by 2002:a17:902:ed8c:b0:14f:d623:f41e with SMTP id e12-20020a170902ed8c00b0014fd623f41emr4928316plj.167.1645752027738; Thu, 24 Feb 2022 17:20:27 -0800 (PST) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id y191-20020a6264c8000000b004e1bf2f580csm745467pfb.78.2022.02.24.17.20.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 24 Feb 2022 17:20:27 -0800 (PST) Date: Fri, 25 Feb 2022 10:20:25 +0900 (JST) Message-Id: <20220225.102025.173579582113640633.horikyota.ntt@gmail.com> To: simon.riggs@enterprisedb.com Cc: Yura Sokolov , pgsql-hackers@postgresql.org Subject: Re: Buffer Manager and Contention 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=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk (I added Yura, as the author of a related patch) At Thu, 24 Feb 2022 12:58:23 +0000, Simon Riggs wrote in > Thinking about poor performance in the case where the data fits in > RAM, but the working set is too big for shared_buffers, I notice a > couple of things that seem bad in BufMgr, but don't understand why > they are like that. > > 1. If we need to allocate a buffer to a new block we do this in one > step, while holding both partition locks for the old and the new tag. > Surely it would cause less contention to make the old block/tag > invalid (after flushing), drop the old partition lock and then switch > to the new one? i.e. just hold one mapping partition lock at a time. > Is there a specific reason we do it this way? I'm not sure but I guess the developer wanted to make the operation atomic. Yura Sokolov is proposing a patch to separte the two partition locks. https://www.postgresql.org/message-id/1edbb61981fe1d99c3f20e3d56d6c88999f4227c.camel%40postgrespro.ru And it seems to me viable for me and a benchmarking in the thread showed a good result. I'd appreciate your input on that thread. > 2. Possibly connected to the above, we issue BufTableInsert() BEFORE > we issue BufTableDelete(). That means we need extra entries in the > buffer mapping hash table to allow us to hold both the old and the new > at the same time, for a short period. The way dynahash.c works, we try Yes. > to allocate an entry from the freelist and if that doesn't work, we > begin searching ALL the freelists for free entries to steal. So if we > get enough people trying to do virtual I/O at the same time, then we > will hit a "freelist storm" where everybody is chasing the last few > entries. It would make more sense if we could do BufTableDelete() To reduce that overhead, Yura proposed a surgically modification on dynahash, but I didn't like that and the latest patch doesn't contain that part. > first, then hold onto the buffer mapping entry rather than add it to > the freelist, so we can use it again when we do BufTableInsert() very > shortly afterwards. That way we wouldn't need to search the freelist > at all. What is the benefit or reason of doing the Delete after the > Insert? Hmm. something like hash_swap_key() or hash_reinsert_entry()? That sounds reasonable. (Yura's proposal was taking out an entry from hash then attach it with a new key again.) > Put that another way, it looks like BufTable functions are used in a > way that mismatches against the way dynahash is designed. > > Thoughts? On the first part, I think Yura's patch works. On the second point, Yura already showed it gives a certain amount of gain if we do that. regards. -- Kyotaro Horiguchi NTT Open Source Software Center