Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rbTpc-00Fc39-Qf for pgsql-hackers@arkaria.postgresql.org; Sat, 17 Feb 2024 23:10:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rbTpb-008Yos-Bl for pgsql-hackers@arkaria.postgresql.org; Sat, 17 Feb 2024 23:10:51 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rbTpb-008Yok-1D for pgsql-hackers@lists.postgresql.org; Sat, 17 Feb 2024 23:10:51 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rbTpX-007HE9-TK for pgsql-hackers@postgresql.org; Sat, 17 Feb 2024 23:10:49 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4125e435b38so4372365e9.0 for ; Sat, 17 Feb 2024 15:10:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1708211446; x=1708816246; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=dYPif+PC+BJlWYPLpk11F4Gy0gOBSwS8JqMpvKuDOK8=; b=N0S4hWARhQXyM2NdA4XGaSRpcruqU0LFd7E5jfVdQov/6d2EkNErok2I+DiKuDn3C7 LCVU+u6JFIgzPmyedq94DQbNSgyDEL5huzFx573pcICI3t61UPnW84iwZhfupV+EEbVC HCdcD8DhpADeQlAwy+UJwVP5SmJozY3XupaV0OPpmYnoDISO0pTM45BoxcL8xrwCDcbi TPq0VZhtLL+VJUMMNSOl0fHoYbyX86UC5NV37LG54X6+r+BIa76bKmXp1Da2xdjEgwj3 D0XixI+YPui3wImyv/t6RxeJADs1gUHZF2ZrVy5bu9m9x8+07W8uosmiGMJEUoSd54C0 jb7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708211446; x=1708816246; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dYPif+PC+BJlWYPLpk11F4Gy0gOBSwS8JqMpvKuDOK8=; b=i8iKxustA4tiEL3gX66vnp4T6ROLx0HRzq1bNdGBmztlsYmaj8BI0BTua0GaDeaMGS b8vY5cFjIcasadqY1VaOMKB9cEql9NsOW6LUVb1CQxyns1IW0f2O/gB/zyxgXMuUec2X suMU7Glvxd/aipV8syCpveLqeri3FVorDI7HrmxO2Qf2aPgiW0kt2iNb1/nmlvzA8s8c +OR7iiUxFvlTmIJdGHisLUKiDEa5G9ybTi0s2MKg2iieCaUjPe1CXteynQuSCO608ftq zq/w7KcQF2Vhk667NT7qAviUIo3pi+gNwEKZdrGfe/1pNrV3Iq6LDy82Cj7X9SYQTrGb JZxA== X-Gm-Message-State: AOJu0Yx0+Z6hld/pdklBJn6yf3MH2juY1d0turUn1q6UfkaKw2XBBxpY 9vUpPqriWEg4oxLpp1ODSDB1iwPyCnzYuwh3XdAJMFZeEeO4SjLhx+U12edIPYdd5VfB5/p91oX KEq59kZVTVDp4p6jhk6ZAoHIUcyYLvuF18HZUwUrIkH4REA9/IHItrLJ3AaHUwOJ70/qECzUCqT Eol/4SzY74aaB+fiN7/G0YDsH7NXXiNjQ9IUqeVgM6sUw51dg+0hCHiQ== X-Google-Smtp-Source: AGHT+IGCmnidr/AF6iEiUeGFPsFcfvHR2Ze1eZrBomAe4zPuXoEMnvwepLoHTVBSAO20NpqCpvGwuw== X-Received: by 2002:a05:600c:518e:b0:412:5edd:4aa2 with SMTP id fa14-20020a05600c518e00b004125edd4aa2mr1146114wmb.30.1708211445628; Sat, 17 Feb 2024 15:10:45 -0800 (PST) Received: from [10.137.0.18] (ip-86-49-229-30.bb.vodafone.cz. [86.49.229.30]) by smtp.gmail.com with ESMTPSA id k5-20020adfe3c5000000b0033b66c2d61esm5897977wrm.48.2024.02.17.15.10.45 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 17 Feb 2024 15:10:45 -0800 (PST) Message-ID: <2f1236b2-7722-4471-ac80-3a47d090244c@enterprisedb.com> Date: Sun, 18 Feb 2024 00:10:44 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: linux cachestat in file Readv and Prefetch Content-Language: en-US To: pgsql-hackers References: From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 1/18/24 01:25, Cedric Villemain wrote: > Hi, > > I was testing the index prefetch and streamIO patches and I added > cachestat() syscall to get a better view of the prefetching. > > It's a new linux syscall, it requires 6.5, it provides numerous > interesting information from the VM for the range of pages examined. > It's way way faster than the old mincore() and provides much more > valuable information: > > uint64 nr_cache; /* Number of cached pages */ > uint64 nr_dirty; /* Number of dirty pages */ > uint64 nr_writeback; /* Number of pages marked for writeback. */ > uint64 nr_evicted; /* Number of pages evicted from the cache. */ > /* > * Number of recently evicted pages. A page is recently evicted if its > * last eviction was recent enough that its reentry to the cache would > * indicate that it is actively being used by the system, and that there > * is memory pressure on the system. > */ > uint64 nr_recently_evicted; > > > While here I also added some quick tweaks to suspend prefetching on > memory pressure. I may be missing some important bit behind this idea, but this does not seem like a great idea to me. The comment added to FilePrefetch says this: /* * last time we visit this file (somewhere), nr_recently_evicted pages * of the range were just removed from vm cache, it's a sign a memory * pressure. so do not prefetch further. * it is hard to guess if it is always the right choice in absence of * more information like: * - prefetching distance expected overall * - access pattern/backend maybe */ Firstly, is this even a good way to detect memory pressure? It's clearly limited to a single 1GB segment, so what's the chance we'll even see the "pressure" on a big database with many files? If we close/reopen the file (which on large databases we tend to do very often) how does that affect the data reported for the file descriptor? I'm not sure I even agree with the idea that we should stop prefetching when there is memory pressure. IMHO it's perfectly fine to keep prefetching stuff even if it triggers eviction of unnecessary pages from page cache. That's kinda why the eviction exists. > It's working but I have absolutely not checked the performance impact of > my additions. > Well ... I'd argue at least some basic evaluation of performance is a rather important / expected part of a proposal for a patch that aims to improve a performance-focused feature. It's impossible to have any sort of discussion about such patch without that. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company