Hi!
Can you provide information about how much memory is being saved from 0004+0005?
Attached the output for a query on catcache/relcache memory context
data, with output of master and the full patchset.
From Master to 0003, we go from 287872 bytes total to 141312 bytes
total spent on "index info" contexts (some of which moved into other
contexts, some new, but a net saving of 130kB). 0004+0005 bring that
down all the way to 45392 bytes; most of which is just avoiding the
large overhead of the pre-allocated Blocks of memory, saving another
95kB.
I tested your patch with my real world database schema consisting of
38,966 tables and 148,468 indexes. The results are attached. They look
great:
Total used_bytes of all relcache memory contexts shrank from
776 MiB -> 633 MiB. Saving of 143 MiB!
--
David Geier
-- Creates a relcache entry for each table and index in the connection's
backend process
SET max_parallel_workers_per_gather = 0;
SELECT COUNT(pg_relation_size(oid)) FROM pg_class WHERE relkind IN ('i', 'r');
SELECT name,
"type",
count(*),
sum(total_bytes) total_bytes,
sum(total_nblocks) total_nblocks,
sum(free_bytes) free_bytes,
sum(free_chunks) free_chunks,
sum(used_bytes) used_bytes,
sum(used_bytes) / sum(total_nblocks) AS hinky_chunk_size
FROM pg_backend_memory_contexts
WHERE path @> (SELECT path FROM pg_backend_memory_contexts WHERE name =
'CacheMemoryContext')
GROUP BY GROUPING SETS ((name, "type"), ());
master
name | type | count | total_bytes | total_nblocks |
free_bytes | free_chunks | used_bytes | hinky_chunk_size
--------------------+----------+--------+-------------+---------------+------------+-------------+------------+-----------------------
CacheMemoryContext | AllocSet | 1 | 624091472 | 1654 |
6070048 | 106 | 618021424 | 373652.614268440145
index info | AllocSet | 178355 | 291233360 | 231489 |
95564464 | 156244 | 195668896 | 845.2621766045038857
relation rules | AllocSet | 1 | 8192 | 4 |
3840 | 1 | 4352 | 1088.0000000000000000
| | 178357 | 915333024 | 233147 |
101638352 | 156351 | 813694672 | 3490.0499341617091363
patched
name | type | count | total_bytes | total_nblocks |
free_bytes | free_chunks | used_bytes | hinky_chunk_size
----------------------+----------+--------+-------------+---------------+------------+-------------+------------+-----------------------
CacheMemoryContext | AllocSet | 1 | 624091472 | 1654 |
5922416 | 104 | 618169056 | 373741.871825876663
index info | Proxy | 178355 | 45610512 | 535092 |
0 | 0 | 45610512 | 85.2386355991119284
index shape | Proxy | 225 | 305160 | 225 |
0 | 0 | 305160 | 1356.2666666666666667
relation rules | AllocSet | 1 | 8192 | 4 |
3840 | 1 | 4352 | 1088.0000000000000000
Relation shape cache | AllocSet | 1 | 32768 | 3 |
15928 | 0 | 16840 | 5613.3333333333333333
Relation shape hash | AllocSet | 1 | 65536 | 4 |
37320 | 15 | 28216 | 7054.0000000000000000
| | 178584 | 670113640 | 536982 |
5979504 | 120 | 664134136 | 1236.7903132693460861