Re: Restructured Shared Buffer Hash Table

Поиск
Список
Период
Сортировка
Искать

Re: Restructured Shared Buffer Hash Table

От:
Dhruv Aron <dhruv.aron@gmail.com>
Дата:
On Thu, Aug 13, 2026 at 12:52 PM Alexandre Felipe <o.alexandre.felipe@gmail.com> wrote:
> I don't really understand the race condition this is trying to address:
>
>> +     /* Unlock buffer header after the entry is deleted to avoid a race condition:
>> +      * If unlocked prior, a concurrent GetVictimBuffer() could insert a new entry
>> +      * for the same buffer and overwrite the entry slot. Then, the BufTableDelete()
>> +      * would be unable to find the entry and would corrupt the hashtable. */
>> +     UnlockBufHdrExt(buf, buf_state,
>> +             0,
>> +             BUF_FLAG_MASK | BUF_USAGECOUNT_MASK,
>> +             0);
>
>How could there be a concurrent insertion while the buffer partition lock is
>held?


I am removing that part as there is a consensus among the big guys that
we shouldn't hold a spin-lock while doing the BufferTableDelete.

I think I could explain why this is necessary, but I want to see your argument.
Was it safe before? if so, what is the property of dynhash that we lost on this
patch.

I could argue that BufferTableDelete is safe if we check for the bounds of
.next and make sure there are no cycles in the chain. But again I will let
you elaborate that argument. 

Regards,
Alexandre

Apologies for the inadequate race condition description in the comment.
Without the spinlock change, a concurrent backend can overwrite the entry slot that is supposed to be deleted imminently after the header lock is released, corrupting the bucket chains.
Consider two concurrent backends b1 and b2 in the following scenario:
  1. b1 executes within InvalidateVictimBuffer(), clearing the header for buffer x and unlocking the header lock.
  2. b2 calls GetVictimBuffer() which returns x, and b2 proceeds to insert a new entry into entry slot x via BufTableInsert(). This overwrites the original entry in that slot and breaks the bucket chain the original entry was part of.
  3. b1 continues with BufTableDelete() to delete the entry that is no longer in slot x (since b2 overwrote it) and is unable to find it.   
I do not believe simply following the .next indices and checking for cycles is sufficient for two main reasons:    
  1. The entry p that used to chain to entry x through its .next still also points to the new entry x. If the new entry x hashes to a different bucket than entry p and the original entry x, following entry p to the new entry x would jump buckets (which is incorrect) and potentially bypass the partition locking paradigm, causing further concurrency issues.
  2. The entries that were once reached by following the .next of the original entry x are now unreachable, causing false lookup misses.
This is not an issue with dynahash because it allocates new entries via the freelist, which safely allows inserting a new entry while the stale one waits to be deleted.
Since the patched table instead maintains that entry x describes buffer x, we cannot have both the new entry and the stale one present simultaneously; the old one must be fully deleted (with the bucket chains adjusted appropriately) before the new one is inserted.
As such, the patched code is unsafe without the lock change, though I admit that holding the lock while calling BufTableDelete is not ideal and other solutions should be explored.  

Best,
Dhruv Aron
 

Re: Restructured Shared Buffer Hash Table

От:
Alexandre Felipe <o.alexandre.felipe@gmail.com>
Дата:
Вложения:
Hello,

I want to create a commit fest entry for this, but I can't find Dhruv Aron there.



On Mon, Sep 14, 2026 at 7:34 PM Alexandre Felipe <o.alexandre.felipe@gmail.com> wrote:
v4.0 is not so fancy, but it works.

No apparent bugs on this version, passing check-world [1]
The best test to stress this feature is in the recovery suite [2]
The main open question is whether we should add a second attempt if we have
a lookup miss and the partition is locked (who knows it was locked by someone
inserting the tag we want).

I am curious to see the results of this with some real pgbench. So I would be
grateful if some of you can stress that out.

This version keeps the lock for insertion (and deletions), on the first failure at 
lookup, it acquires a LW_SHARED there too. These failures are very rare
so the impact of that lock in performance should be negligible compared to
acquiring the lock for every lookup.

Not having to acquire a lock on its own can make the buffer lookup faster (buffer hits).

I am pasting three tables from my own benchmarks, from which I would like
to highlight a few results.
LWLockAcquire, LWLockRelease (nothing in between)
Uncontended with 10 workers: 218ns
Contended with 10 workers : 555 microseconds in one run 1.03ms in the other

Notice that the average is above q3 (0.57 quantile), indicating that it is very
skewed, it is fast, but when it gets slow it becomes very slow. And this is
precisely what I have seen with LWLock BufferMapping waits, they either
don't show up, or they take the cluster down (I am not a DBA, so it is anecdotal
evidence).


Average uncontended hit and miss. 
2 workers, with lock (36, 38)
10 workers, with lock (225,409)
10 workers, without lock (156,252) 



 workers | op / wait  |   avg   |   q1    |   med   |   q3    | count  
---------+------------+---------+---------+---------+---------+--------
       2 | delete / 0 |   42.58 |   39.76 |   42.28 |   44.28 | 127999
       2 | delete / 1 | 5625.00 | 5625.00 | 5625.00 | 5625.00 |      1
       2 | hit / 0    |   36.01 |   33.86 |   35.81 |   37.77 | 128000
       2 | insert / 0 |   36.59 |   35.11 |   36.47 |   38.41 | 128000
       2 | LWLock / 0 |   35.59 |   33.23 |   35.17 |   37.14 | 128000
       2 | miss / 0   |   37.63 |   35.78 |   37.72 |   39.09 | 128000



 workers | op / wait  |    avg     |    q1     |    med    |     q3     | count  
---------+------------+------------+-----------+-----------+------------+--------
      10 | delete / 0 |     792.11 |    166.58 |    225.58 |     277.75 | 119522
      10 | delete / 1 | 1844238.60 |  45823.00 | 470479.00 | 2568042.25 |    478
      10 | hit / 0    |     224.66 |     76.42 |    121.50 |     187.42 | 120000
      10 | insert / 0 |     952.21 |    104.25 |    180.58 |     246.42 | 119566
      10 | insert / 1 | 2154981.29 |  76708.00 | 703666.00 | 3334916.00 |    434
      10 | LWLock / 0 |     218.06 |     69.33 |    104.17 |     152.67 | 119987
      10 | LWLock / 1 | 1029929.62 | 126708.00 | 488459.00 |  836708.00 |     13
      10 | miss / 0   |     408.87 |     76.42 |    156.08 |     184.00 | 120000

 workers | op / wait  |    avg     |    q1     |    med    |     q3     | count  
---------+------------+------------+-----------+-----------+------------+--------
      10 | delete / 0 |     628.94 |    166.58 |    236.08 |     291.85 | 119595
      10 | delete / 1 | 2135859.85 |  80125.00 | 704750.00 | 3329688.00 |    405
      10 | hit / 0    |     155.96 |     55.33 |    104.17 |     145.67 | 120000
      10 | insert / 0 |     792.89 |    100.67 |    190.83 |     250.00 | 119634
      10 | insert / 1 | 2272327.08 | 114083.00 | 666959.00 | 3580042.00 |    366
      10 | LWLock / 0 |     305.68 |     69.50 |    107.58 |     159.75 | 119993
      10 | LWLock / 1 |  555255.86 |  77437.50 | 390458.00 |  528979.50 |      7
      10 | miss / 0   |     251.58 |     45.25 |     93.83 |     121.58 | 120000


1. With './configure'  '--prefix' ... '--without-icu' '--without-readline' '--enable-tap-tests' --enable-cassert && make -j -s clean && make -j -s && make check-world
2. make -C src/test/recovery check PROVE_TESTS="t/027_stream_regress.pl"

PS.: I nearly forgot to attach the patches 🤣

Re: Restructured Shared Buffer Hash Table

От:
Dhruv Aron <dhruv.aron@gmail.com>
Дата:
Вложения:
Hi,

Just logged into commitfest for the first time, perhaps that's why.
Can you try again?


Best,
Dhruv Aron

On Mon, Sep 21, 2026 at 4:56 AM Alexandre Felipe <o.alexandre.felipe@gmail.com> wrote:
Hello,

I want to create a commit fest entry for this, but I can't find Dhruv Aron there.



On Mon, Sep 14, 2026 at 7:34 PM Alexandre Felipe <o.alexandre.felipe@gmail.com> wrote:
v4.0 is not so fancy, but it works.

No apparent bugs on this version, passing check-world [1]
The best test to stress this feature is in the recovery suite [2]
The main open question is whether we should add a second attempt if we have
a lookup miss and the partition is locked (who knows it was locked by someone
inserting the tag we want).

I am curious to see the results of this with some real pgbench. So I would be
grateful if some of you can stress that out.

This version keeps the lock for insertion (and deletions), on the first failure at 
lookup, it acquires a LW_SHARED there too. These failures are very rare
so the impact of that lock in performance should be negligible compared to
acquiring the lock for every lookup.

Not having to acquire a lock on its own can make the buffer lookup faster (buffer hits).

I am pasting three tables from my own benchmarks, from which I would like
to highlight a few results.
LWLockAcquire, LWLockRelease (nothing in between)
Uncontended with 10 workers: 218ns
Contended with 10 workers : 555 microseconds in one run 1.03ms in the other

Notice that the average is above q3 (0.57 quantile), indicating that it is very
skewed, it is fast, but when it gets slow it becomes very slow. And this is
precisely what I have seen with LWLock BufferMapping waits, they either
don't show up, or they take the cluster down (I am not a DBA, so it is anecdotal
evidence).


Average uncontended hit and miss. 
2 workers, with lock (36, 38)
10 workers, with lock (225,409)
10 workers, without lock (156,252) 



 workers | op / wait  |   avg   |   q1    |   med   |   q3    | count  
---------+------------+---------+---------+---------+---------+--------
       2 | delete / 0 |   42.58 |   39.76 |   42.28 |   44.28 | 127999
       2 | delete / 1 | 5625.00 | 5625.00 | 5625.00 | 5625.00 |      1
       2 | hit / 0    |   36.01 |   33.86 |   35.81 |   37.77 | 128000
       2 | insert / 0 |   36.59 |   35.11 |   36.47 |   38.41 | 128000
       2 | LWLock / 0 |   35.59 |   33.23 |   35.17 |   37.14 | 128000
       2 | miss / 0   |   37.63 |   35.78 |   37.72 |   39.09 | 128000



 workers | op / wait  |    avg     |    q1     |    med    |     q3     | count  
---------+------------+------------+-----------+-----------+------------+--------
      10 | delete / 0 |     792.11 |    166.58 |    225.58 |     277.75 | 119522
      10 | delete / 1 | 1844238.60 |  45823.00 | 470479.00 | 2568042.25 |    478
      10 | hit / 0    |     224.66 |     76.42 |    121.50 |     187.42 | 120000
      10 | insert / 0 |     952.21 |    104.25 |    180.58 |     246.42 | 119566
      10 | insert / 1 | 2154981.29 |  76708.00 | 703666.00 | 3334916.00 |    434
      10 | LWLock / 0 |     218.06 |     69.33 |    104.17 |     152.67 | 119987
      10 | LWLock / 1 | 1029929.62 | 126708.00 | 488459.00 |  836708.00 |     13
      10 | miss / 0   |     408.87 |     76.42 |    156.08 |     184.00 | 120000

 workers | op / wait  |    avg     |    q1     |    med    |     q3     | count  
---------+------------+------------+-----------+-----------+------------+--------
      10 | delete / 0 |     628.94 |    166.58 |    236.08 |     291.85 | 119595
      10 | delete / 1 | 2135859.85 |  80125.00 | 704750.00 | 3329688.00 |    405
      10 | hit / 0    |     155.96 |     55.33 |    104.17 |     145.67 | 120000
      10 | insert / 0 |     792.89 |    100.67 |    190.83 |     250.00 | 119634
      10 | insert / 1 | 2272327.08 | 114083.00 | 666959.00 | 3580042.00 |    366
      10 | LWLock / 0 |     305.68 |     69.50 |    107.58 |     159.75 | 119993
      10 | LWLock / 1 |  555255.86 |  77437.50 | 390458.00 |  528979.50 |      7
      10 | miss / 0   |     251.58 |     45.25 |     93.83 |     121.58 | 120000


1. With './configure'  '--prefix' ... '--without-icu' '--without-readline' '--enable-tap-tests' --enable-cassert && make -j -s clean && make -j -s && make check-world
2. make -C src/test/recovery check PROVE_TESTS="t/027_stream_regress.pl"

PS.: I nearly forgot to attach the patches 🤣

Re: Restructured Shared Buffer Hash Table

От:
Alexandre Felipe <o.alexandre.felipe@gmail.com>
Дата:
On Mon, Sep 21, 2026 at 4:13 PM Dhruv Aron <dhruv.aron@gmail.com> wrote:
Hi,

Just logged into commitfest for the first time, perhaps that's why.
Can you try again?

Created, it will be good to see how it behaves in different environments.

Regards,
Alexandre.

Re: Restructured Shared Buffer Hash Table

От:
Alexandre Felipe <o.alexandre.felipe@gmail.com>
Дата:


On Mon, Sep 21, 2026 at 4:58 PM Alexandre Felipe <o.alexandre.felipe@gmail.com> wrote:
On Mon, Sep 21, 2026 at 4:13 PM Dhruv Aron <dhruv.aron@gmail.com> wrote:
Hi,

Just logged into commitfest for the first time, perhaps that's why.
Can you try again?

Created, it will be good to see how it behaves in different environments.


All during the same test (recovery/027_stream_regress) that I pointed out above to
be the best to detect issues. Coincidence or not it passed on MacOS (the environment
I tested locally).

Am I being naive with my hopes to make this partially lock-free?
Is there any proof that such an algorithm doesn't exist for this particular problem?

Kind regards,
Alexandre

Re: Restructured Shared Buffer Hash Table

От:
Alexandre Felipe <o.alexandre.felipe@gmail.com>
Дата:
Вложения:
I am withdrawing my attempt on lock-free buffer mapping.

And I will try to address some of Andres questions.

On Tue, Aug 11, 2026 at 9:50 PM Andres Freund <andres@anarazel.de> wrote:

Agreed, it's quite terrible.


> To give a brief overview, our new table operates primarily on two arrays,
> one for the entries and one for the bucket heads, and it enforces the
> invariant that *entries[x]* describes the page in buffer *x*. Each entry
> stores only a BufferTag and a ‘next’ index (representing the next entry in
> the same bucket chain), with each bucket head only storing a ‘head’ index
> (representing the first entry in the bucket chain). At a high-level, the
> table essentially creates a logical linked list for each bucket on top of
> the flat physical arrays.

Why did you choose a design that is effectively pointered? Pointered conflict
handling tends to be a good bit slower due to the typically unprefetchable
accesses.  That's also - I suspect at least - part of what's pushing you
towards having both buckets[] and entries[], which seems like an unnecessary
indirection to me.  Although admittedly the partition locking handling would
be more complicated without the separate array.

Using pointers makes it easier to move a buffer from one bucket to another.
Having P partitions and N buffers, and no dynamic allocation we would need
to allocate N * P entries, because all the buffers can be mapped into one partition.
Additionally, I would expect the memory copy to have a noticeable impact.
 
I also suspect that it'd be better to store a hash value in the buckets,
BufferTagsEqual() is decidedly not cheap, and you'll obviously get a lot of
"false" matches from hashcode % num_buckets that would be much cheaper to
detect with a stored hash value.

In the current implementation that is a modest gain. And that agrees with theory
If num_buckets = NBuffers, about (1 - 1/e) of the buckets are
is expected to 63%, without hashcode we can expect  
5*0.63 + 10*(1 - 0.63) = 6.85 comparisons per entry
with hashcode 6 * 0.63 + 7 * (1 - 0.63) = 6.37 comparisons
lower occupation ratios favours noo hashcode.

On a different implementation where one would read the tag from the
buffer descriptor instead of storing in the buffer mapping, this hash code would
make more difference.

Additionally, one could store a different hashcode, not the one used to map
on the buckets, because at NBuffers = INT_MAX/2-1, the using the same
32-bit hash code leads to 25% false matches.
 
My higher level problems with the current architecture of the buffer mapping
infrastructure are the following:

1) We need a way to iterate over all buffers for a relation in an efficient
   way

A solution for this would be having an additional Map<Relation, List<Buffer> >
To be conservative the same number of buckets as BufTable

Storage: ~16 bytes per buffer
Insert: 1 hash lookup, 1 list insertion.
Lookup: unchanged
Deletion: 1 list removal (two pointer dereferences, and two pointer updates)

2) I think any buffer mapping lookup datastructure with 20 byte keys is going
   to considerably not great for performance.
 
Will we relax the limits, it was proposed to reduce the number of databases.
I think we could reduce the number of tablespaces instead, I think that its
limit is not documented. What I like about 16 is that it could be copied and
compared as 2 x 64-bit, or a single simd vector.

3) We should have efficient ordered lookup, to make things like "are there any
   not-present blocks in the next N blocks" cheap. Today we need to do full
   buffer lookups for readahead, which requires us to be very minimal about
   lookahead when having a high cache hit ratio, to avoid performance
   regressions - but that also prevents us from avoiding synchronous misses in
   such cases.
 
This is an upgrade from 1, ordered data structures are very powerful, a red-black
three in javascript works beautifully, but in C the cost of the pointer lookups is
huge. In postgres world probably one would want an in-memory B-tree (as everyone
is familiar with that algorithm). Probably pages aligned to cache lines
(currently declared as 128 bytes), reserving a few bytes for prev, parent, next, and count
we would end up with 28 block numbers per page. Maybe one could use a
special encoding for N..N+k, but I don't have any good insight on how to do that on fixed
32-bit entries.
 
4) Acquiring a lock for every lookup scales badly on larger machines, even if
   the lock itself is not contended, due to the cacheline contention it
   creates

You might be interested in [1]

This is unfortunate. Initially I saw this as a reason for the linked lists bucket.
I tried a custom design, then I tried to go by the book with a Harris wait-free
design. The problem is that under buffer reuse and a backend that can sleep
an arbitrarily long while walking the chain. If while one backend holds a given
buffer, that buffer can be removed and then inserted again, in the same bucket
with a larger hash code, ending up after of some buffer that were initially after
it, e.g. if a bucket has a, -b-, c, d, and while a backend walks that list on b, that
gets deleted and reinserted after c changes to a, c, -b-, d, the backend holding
-b- doesn't notice that it was deleted.

 
5) The datastructure should benefit from spatial locality

   It's much more common for subsequent buffer mapping lookups to look up
   nearby blocks than blocks very far away. But with hash tables, the
   likelihood of finding blocks N and N+1 in the CPU cache is no better than
   looking up two entirely independent blocks.

How common? How much do you think is there to gain?
Once 3 is implemented this might be doable.
I have seen a lot in this list, when a new idea is proposed, someone will have
questions about the worst case scenario. And if we apply that to this feature
I think it is very hard to beat Dhruv's implementation.

The lion share of the gain comes from not using dynhash.

For 1-3), I think we should move towards a two-layer datastructure:


a) a mapping from relation+fork to a per-"logical file" datastructure

   Keyed by database, tablespace, relfilenode, fork (although the fork
   could be handled differently).

   This lookup would be cached somewhere below Relation, so we only would need
   to occasionally do it, so the size of the key would not matter for
   performance.

   This addresses 1+2.

Below relation?

We would have to assign a global identifier to the relation, across all backends.
So I think that is another hashmap
At a given moment we can have one buffer of each relation, so the lookup
of one single relation would be as complex as the buffer lookup today.

When scanning many buffers of one relation this could help. For one single
buffer it would be about twice as slow.

   (there's plenty complexity here, don't get me wrong)
Exactly

 
b) A block-number keyed lookup datastructure returning buffer IDs

   If this datastructure is ordered, it addresses 3).

   Due to the small key, something like a radix tree is viable (not a plain
   one, but something like what we have in radixtree.h, with the missing
   optimization from the referenced paper added).

   A radix tree would also address 5).

OK, a radix tree with blocks of size 16 would have deepth 8, and if it is sparse
would require ~16x more memory. It might be a win for long sequential scans,
but would be much slower for random access (as mentioned before the hash
table does about 1.6 sequential pointer dereference on average, a 8GB table here
would do 5)


To address 4) I think we should eventually allow to make lookups in b)
lock-free, using something like RCU or EBR (arguably a form of RCU).  I would
definitely not tackle that at the same time, but I think it's worth keeping in
mind.

I missed this suggestion when I tried to do my lock-free implementation.
One thing here is that it would drop the entry[id] => buffer[id] invariant,
but if we can do it lock-free that is totally worth it.
 
I'm of a somewhat split mind about improving the efficiency of the current
design without addressing any of the architectural problems.  It's of course
nice to make it faster, but it also takes bandwidth that can't be spent on
the architectural problems...

Dhruv's patch is trivial, and gives a noticeable improvement compared to the previous
dynhash based algorithm algorithm. The only potential downside is requiring two
relatively large contiguous blocks of shared memory, one of 24GB and one of 4GB.
Buffer descriptors already allocate a 64GB continuous block at the shared_buffers
GUC limit.



Re: Restructured Shared Buffer Hash Table

От:
Alexandre Felipe <o.alexandre.felipe@gmail.com>
Дата:
Dhruv,

A few details I would like your attention,

1. mod vs bitwise and
Instead of computing [hashcode % num_buckets] you could save 
bucket_mask = num_bucket - 1, and do hashcode & bucket_mask.

2. the 1.5 factor
On my first review I pointed out that in one specific test for shared_buffers
as a power of two the number of buckets in your patch ended up being half
as many as the previous version (maybe that is the correct way to go).
Or maybe you want at least to rewrite that line using integer arithmetic.

4. scalability
In your 16 GB test the gains are minimal. What changes at that scale?
That suggests that maybe the gain at 4 GB was due to a high cache hit
(not a bad thing, but important to have it clear).


Regards,
Alexandre

Re: Restructured Shared Buffer Hash Table

От:
Dhruv Aron <dhruv.aron@gmail.com>
Дата:
On Mon, Oct 12, 2026 at 1:40 PM Alexandre Felipe <o.alexandre.felipe@gmail.com> wrote:
1. mod vs bitwise and
Instead of computing [hashcode % num_buckets] you could save 
bucket_mask = num_bucket - 1, and do hashcode & bucket_mask.

2. the 1.5 factor
On my first review I pointed out that in one specific test for shared_buffers
as a power of two the number of buckets in your patch ended up being half
as many as the previous version (maybe that is the correct way to go).
Or maybe you want at least to rewrite that line using integer arithmetic.

Regarding 1: Yes, the bitwise-AND should work and would most likely be more performant than using modulo. 
Regarding 2: Since the patched table does not allow inserting a new entry before deleting the stale entry for the same slot, there was no need to additionally allocate NUM_BUFFER_PARTITIONS buckets (the reason why the number of buckets for the master code was rounded up to 0x8000 instead of 0x4000 for 128MB SB). Could you elaborate more on what you mean by '[rewriting] that line using integer arithmetic?'  
 
4. scalability
In your 16 GB test the gains are minimal. What changes at that scale?
That suggests that maybe the gain at 4 GB was due to a high cache hit
(not a bad thing, but important to have it clear).

As you point out, the primary factor should be that larger sizes result in higher cache hit rates, which boosts the mainstream buffer table's performance closer to that of the patched code.

Best,
Dhruv 

Re: Restructured Shared Buffer Hash Table

От:
Alexandre Felipe <o.alexandre.felipe@gmail.com>
Дата:


On Mon, Oct 12, 2026 at 9:02 PM Dhruv Aron <dhruv.aron@gmail.com> wrote:
On Mon, Oct 12, 2026 at 1:40 PM Alexandre Felipe <o.alexandre.felipe@gmail.com> wrote:
1. mod vs bitwise and
Instead of computing [hashcode % num_buckets] you could save 
bucket_mask = num_bucket - 1, and do hashcode & bucket_mask.

2. the 1.5 factor
On my first review I pointed out that in one specific test for shared_buffers
as a power of two the number of buckets in your patch ended up being half
as many as the previous version (maybe that is the correct way to go).
Or maybe you want at least to rewrite that line using integer arithmetic.

Regarding 1: Yes, the bitwise-AND should work and would most likely be more performant than using modulo. 
Regarding 2: Since the patched table does not allow inserting a new entry before deleting the stale entry for the same slot, there was no need to additionally allocate NUM_BUFFER_PARTITIONS buckets (the reason why the number of buckets for the master code was rounded up to 0x8000 instead of 0x4000 for 128MB SB). Could you elaborate more on what you mean by '[rewriting] that line using integer arithmetic?' 

1.5 * num_bucket implicitly casts to floating point, and later back to integer, that was not meant to be permanent.
A safer option would be (num_buckets | (num_buckets >> 1)), no wrap-around if some day
this gets increased to UINT_MAX. Or simply num_buckets, without multiplication at all.

Regards,
Alexandre

Re: Restructured Shared Buffer Hash Table

От:
Dhruv Aron <dhruv.aron@gmail.com>
Дата:
On Mon, Oct 12, 2026 at 3:08 PM Alexandre Felipe <o.alexandre.felipe@gmail.com> wrote:
1.5 * num_bucket implicitly casts to floating point, and later back to integer, that was not meant to be permanent.
A safer option would be (num_buckets | (num_buckets >> 1)), no wrap-around if some day
this gets increased to UINT_MAX. Or simply num_buckets, without multiplication at all.

Apologies, I am experiencing trouble finding the line where we perform "1.5 * num_bucket"; perhaps it has been too long since I last worked on the patch. 
Could you point me towards where it is in the restructured_shared_buffer_table.patch file?
Otherwise, yes, the bitwise arithmetic in this case should also be more performant.

Best,
Dhruv

Re: Restructured Shared Buffer Hash Table

От:
Alexandre Felipe <o.alexandre.felipe@gmail.com>
Дата:


On Tue, Oct 13, 2026 at 5:38 AM Dhruv Aron <dhruv.aron@gmail.com> wrote:
On Mon, Oct 12, 2026 at 3:08 PM Alexandre Felipe <o.alexandre.felipe@gmail.com> wrote:
1.5 * num_bucket implicitly casts to floating point, and later back to integer, that was not meant to be permanent.
A safer option would be (num_buckets | (num_buckets >> 1)), no wrap-around if some day
this gets increased to UINT_MAX. Or simply num_buckets, without multiplication at all.

Apologies, I am experiencing trouble finding the line where we perform "1.5 * num_bucket"; perhaps it has been too long since I last worked on the patch. 
Could you point me towards where it is in the restructured_shared_buffer_table.patch file?
Otherwise, yes, the bitwise arithmetic in this case should also be more performant.


It was a modification that I did

If you are working from your original patch my comment doesn't apply.

Regards,
Alexandre
FAQ