Mistake in freespace/README?

From: Aleksander Alekseev <aleksander(at)timescale(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Mistake in freespace/README?
Date: 2023-04-22 09:58:40
Message-ID: CAJ7c6TN1ttyckp-8F98W8Qthdcc0Tq28uYCmbq=xURh85RaDKg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I think there could be a mistake in freespace/README. There are
several places where it says about ~4000 slots per FSM page for the
default BLKSZ:

"""
For example, assuming each FSM page can hold information about 4 pages (in
reality, it holds (BLCKSZ - headers) / 2, or ~4000 with default BLCKSZ),
"""

and:

"""
To keep things simple, the tree is always constant height. To cover the
maximum relation size of 2^32-1 blocks, three levels is enough with the default
BLCKSZ (4000^3 > 2^32).
"""

Let's determine the amount of levels in each FSM page first. I'm going
to use Python for this. Note that range(0,13) returns 13 numbers from
0 to 12:

```
>>> sum([pow(2,n) for n in range(0,13) ])
8191
>>> 8*1024
8192
```

13 levels are not going to fit since we need extra 24 bytes per
PageHeaderData and a few more bytes for an int value fp_next_slot.
Which gives us 12 levels and the number of slots:

```
>>> # there are pow(2,0) == 1 byte on the 1st level of the tree
>>> pow(2,12 - 1)
2048
```

The number of levels in the entire, high-level tree, seems to be correct:

```
>>> pow(2048,3) > pow(2,32) - 1
True
```

Hopefully I didn't miss or misunderstood anything.

Thoughts?

--
Best regards,
Aleksander Alekseev

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Aleksander Alekseev 2023-04-22 10:21:46 Re: Mistake in freespace/README?
Previous Message Fujii Masao 2023-04-22 09:52:27 Re: Fix documentation for max_wal_size and min_wal_size