Mistake in freespace/README? - Mailing list pgsql-hackers

From Aleksander Alekseev
Subject Mistake in freespace/README?
Date
Msg-id CAJ7c6TN1ttyckp-8F98W8Qthdcc0Tq28uYCmbq=xURh85RaDKg@mail.gmail.com
Whole thread Raw
Responses Re: Mistake in freespace/README?  (Aleksander Alekseev <aleksander@timescale.com>)
List 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



pgsql-hackers by date:

Previous
From: Fujii Masao
Date:
Subject: Re: Fix documentation for max_wal_size and min_wal_size
Next
From: Aleksander Alekseev
Date:
Subject: Re: Mistake in freespace/README?