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 1mqiaL-0001ca-7s for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Nov 2021 21:16:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mqiaJ-0007TQ-2v for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Nov 2021 21:16:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mqiaI-0007TG-MG for pgsql-hackers@lists.postgresql.org; Fri, 26 Nov 2021 21:16:42 +0000 Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mqiaF-0001Rx-Vo for pgsql-hackers@postgresql.org; Fri, 26 Nov 2021 21:16:42 +0000 Received: by mail-io1-xd30.google.com with SMTP id x10so12978415ioj.9 for ; Fri, 26 Nov 2021 13:16:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=IIAESi5DEGxsrAXh95a6wECS029ye6QQkBNVvMYXQbY=; b=dujf/fh1LkmHVzLEMFoY4TuysVceFWZeym6sg6B11qWBeMRlc/mir0rUkOpAPopmum HLipgPSVkGB5Bp6lkfuvuPYsia3KTPvZ7UVDwZ/sUhTo74X0YGh2O7ywUae3FliZmYt0 9TLsBjwDvEScYaw6zVZiqbuN429+4NFrKQAAm1zW7Y1eJ/xJRPm95ZGlUP8AD8Tv1+AO sxWP8aTq44ZGU9NqglCihIHvesrc+A5WhW/s1HuxMQ+UQ6S4spOAGmaaBOg4cLboo9at pNZzhSU+DFY8anwuflULPNBuIDhS41zXrW5nD77t3yeFM3xvu3e7aYDwg+jVDcRmVcCb LqKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=IIAESi5DEGxsrAXh95a6wECS029ye6QQkBNVvMYXQbY=; b=M3O250SXpkdD5rl+ZgG4c8yGRN/9a/UCeOk8k5VNHtCCcKWrQmK2zym0Kqt3HIE49/ xoQDipC+ia4NaiJxEnIPuYhJFMSQLWWbmwd3TkCRwpPT73BCifjQCyNRqVsNRMi2L9Op KZVGjGh5LtO8AXbW9AJpQUU5CaviO2lC/iTtUK71GN7AaJWH2HgOim1hT5eZHTTUJkoo fbUgQrOB1+CKCktv2ZSgG+Tij+tzd8vkWzs9QC7mbLqdJk73AaL72RBxseAaGKRUuYEf KHtB8GN9Zk8wS+4Cqb63NF62HWHrje+x/gDvyYW1iU6v5NNwxa/O/QYZoz7hoJw+7RJH rrzw== X-Gm-Message-State: AOAM530yqK2mvs7wUYjo+Mxa3bXpfsqC061azRDchOhzUMYTO3lNRqme FT9jmryJJoJafeMWxBElNY5R+w== X-Google-Smtp-Source: ABdhPJwUZ83bHRjBnLf0F/V75K2lCv7r1oJA/pN2zzdTush/byfKvoNtx4ECdVklnsZvPMtV3AxVUg== X-Received: by 2002:a5e:8f0b:: with SMTP id c11mr39221594iok.105.1637961397886; Fri, 26 Nov 2021 13:16:37 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id m6sm4373194ilh.32.2021.11.26.13.16.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Nov 2021 13:16:37 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 70526800D7C; Fri, 26 Nov 2021 15:16:36 -0600 (CST) Date: Fri, 26 Nov 2021 15:16:36 -0600 From: Justin Pryzby To: Melanie Plageman Cc: Andres Freund , Alvaro Herrera , Kyotaro Horiguchi , Magnus Hagander , pgsql-hackers@postgresql.org, Lukas Fittl , Thomas Munro Subject: Re: pg_stat_bgwriter.buffers_backend is pretty meaningless (and more?) Message-ID: <20211126211636.GE17618@telsasoft.com> References: <202109302315.65qtfrmgbpzt@alvherre.pgsql> <20211008175620.nspjy6wwmzvyzkrg@alap3.anarazel.de> <20211019192931.eeeohw6yrvqe6bol@alap3.anarazel.de> <20211119164952.mlw7ecj4xxliuuut@alap3.anarazel.de> <20211125011559.GC17618@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211125011559.GC17618@telsasoft.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Nov 24, 2021 at 07:15:59PM -0600, Justin Pryzby wrote: > There's extraneous blank lines in these functions: > > +pgstat_sum_io_path_ops > +pgstat_report_live_backend_io_path_ops > +pgstat_recv_resetsharedcounter > +GetIOPathDesc > +StrategyRejectBuffer + an extra blank line pgstat_reset_shared_counters. In 0005: monitoring.sgml says that the columns in pg_stat_buffers are integers, but they're actually bigint. + tupstore = tuplestore_begin_heap(true, false, work_mem); You're passing a constant randomAccess=true to tuplestore_begin_heap ;) +Datum all_values[NROWS][COLUMN_LENGTH]; If you were to allocate this as an array, I think it could actually be 3-D: Datum all_values[BACKEND_NUM_TYPES-1][IOPATH_NUM_TYPES][COLUMN_LENGTH]; But I don't know if this is portable across postgres' supported platforms; I haven't seen any place which allocates a multidimensional array on the stack, nor passes one to a function: +static inline Datum * +get_pg_stat_buffers_row(Datum all_values[NROWS][COLUMN_LENGTH], BackendType backend_type, IOPath io_path) Maybe the allocation half is okay (I think it's ~3kB), but it seems easier to palloc the required amount than to research compiler behavior. That function is only used as a one-line helper, and doesn't use multidimensional array access anyway: + return all_values[(backend_type - 1) * IOPATH_NUM_TYPES + io_path]; I think it'd be better as a macro, like (I think) #define ROW(backend_type, io_path) all_values[NROWS*(backend_type-1)+io_path] Maybe it should take the column type as a 3 arg. The enum with COLUMN_LENGTH should be named. Or maybe it should be removed, and the enum names moved to comments, like: + /* backend_type */ + values[val++] = backend_type_desc; + /* io_path */ + values[val++] = CStringGetTextDatum(GetIOPathDesc(io_path)); + /* allocs */ + values[val++] += io_ops->allocs - resets->allocs; ... *Note the use of += and not =. Also: src/include/miscadmin.h:#define BACKEND_NUM_TYPES (B_LOGGER + 1) I think it's wrong to say NUM_TYPES = B_LOGGER + 1 (which would suggest using lessthan-or-equal instead of lessthan as you are). Since the valid backend types start at 1 , the "count" of backend types is currently B_LOGGER (13) - not 14. I think you should remove the "+1" here. Then NROWS (if it continued to exist at all) wouldn't need to subtract one. -- Justin