Re: Add pg_stat_vfdcache view for VFD cache statistics

From: David Geier <geidav(dot)pg(at)gmail(dot)com>
To: Ayoub Kazar <kazarayoub2004(at)gmail(dot)com>
Cc: KAZAR Ayoub <ma_kazar(at)esi(dot)dz>, Tomas Vondra <tomas(at)vondra(dot)me>, Jakub Wartak <jakub(dot)wartak(at)enterprisedb(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Add pg_stat_vfdcache view for VFD cache statistics
Date: 2026-09-09 07:22:47
Message-ID: 4228e051-f702-454c-8890-b868c2b47518@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>>> Yes of course, I’d be happy to take a look.
>> Attached is the patch. It's pretty small and passes regress tests.
>>
> Nice one.
> Few comments on it:
> #1:
> + oldcontext = MemoryContextSwitchTo(VfdCxt);
> + newVfdCache = repalloc_array(VfdCache, Vfd, newCacheSize);
> + MemoryContextSwitchTo(oldcontext);
>
> Can't we just do this?
> + newVfdCache = repalloc_array(VfdCache, Vfd, newCacheSize);
>
> because repalloc doesn't need CurrentMemoryContext.

Yes. You can then make it even simpler and get rid of newVfdCache via

VfdCache = repalloc_array(VfdCache, Vfd, newCacheSize);

> #2:
> + newDescs = MemoryContextAllocExtended(VfdCxt,
> + newMax * sizeof(AllocateDesc), MCXT_ALLOC_NO_OOM);
> if (newDescs == NULL)
> return false;
> + memcpy(newDescs, allocatedDescs, maxAllocatedDescs *
> sizeof(AllocateDesc));
> + pfree(allocatedDescs);
>
> We can also just replace it with:
> + newDescs = repalloc_array_extended(allocatedDescs, AllocateDesc,
> + newMax, MCXT_ALLOC_NO_OOM);
> Correct?

Yes.

v7-0001: looks good to me.

v7-0003: I'm wondering if we still want cache_bytes in pg_stat_vfdcache,
now where it's exposed via pg_backend_memory_contexts. It seems to me
that other stats functionality also doesn't expose memory info that is
accessible via pg_backend_memory_contexts. But I'm not completely sure
what's best here.

--
David Geier

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message vignesh C 2026-09-09 07:28:40 Re: Include sequences in publications created by pg_createsubscriber
Previous Message Xuneng Zhou 2026-09-09 07:13:10 Re: Reject WAIT FOR earlier in transaction-snapshot mode