LCOV - differential code coverage report
Current view: top level - src/include/access - multixact_internal.h (source / functions) Coverage Total Hit UNC GNC
Current: 0e5ff9b9b45a657aea12440478dc002e9b01f138 vs 0123ce131fca454009439dfa3b2266d1d40737d7 Lines: 84.6 % 26 22 4 22
Current Date: 2026-03-14 14:10:32 -0400 Functions: 77.8 % 9 7 2 7
Baseline: lcov-20260315-024220-baseline Branches: 50.0 % 2 1 1 1
Baseline Date: 2026-03-14 15:27:56 +0100 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(30,360] days: 84.6 % 26 22 4 22
Function coverage date bins:
(30,360] days: 77.8 % 9 7 2 7
Branch coverage date bins:
(30,360] days: 50.0 % 2 1 1 1

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*
                                  2                 :                :  * multixact_internal.h
                                  3                 :                :  *
                                  4                 :                :  * PostgreSQL multi-transaction-log manager internal declarations
                                  5                 :                :  *
                                  6                 :                :  * These functions and definitions are for dealing with pg_multixact SLRU
                                  7                 :                :  * pages.  They are internal to multixact.c, but they are exported here to
                                  8                 :                :  * allow pg_upgrade to write pg_multixact files directly.
                                  9                 :                :  *
                                 10                 :                :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
                                 11                 :                :  * Portions Copyright (c) 1994, Regents of the University of California
                                 12                 :                :  *
                                 13                 :                :  * src/include/access/multixact_internal.h
                                 14                 :                :  */
                                 15                 :                : #ifndef MULTIXACT_INTERNAL_H
                                 16                 :                : 
                                 17                 :                : /*
                                 18                 :                :  * Note: This is not only to prevent including this file twice.
                                 19                 :                :  * MULTIXACT_INTERNAL_H is checked explicitly in multixact_read_v18.c.
                                 20                 :                :  */
                                 21                 :                : #define MULTIXACT_INTERNAL_H
                                 22                 :                : 
                                 23                 :                : #include "access/multixact.h"
                                 24                 :                : 
                                 25                 :                : 
                                 26                 :                : /*
                                 27                 :                :  * Defines for MultiXactOffset page sizes.  A page is the same BLCKSZ as is
                                 28                 :                :  * used everywhere else in Postgres.
                                 29                 :                :  */
                                 30                 :                : 
                                 31                 :                : /* We need 8 bytes per offset */
                                 32                 :                : #define MULTIXACT_OFFSETS_PER_PAGE (BLCKSZ / sizeof(MultiXactOffset))
                                 33                 :                : 
                                 34                 :                : static inline int64
   96 heikki.linnakangas@i       35                 :GNC      196052 : MultiXactIdToOffsetPage(MultiXactId multi)
                                 36                 :                : {
                                 37                 :         196052 :     return multi / MULTIXACT_OFFSETS_PER_PAGE;
                                 38                 :                : }
                                 39                 :                : 
                                 40                 :                : static inline int
                                 41                 :         200353 : MultiXactIdToOffsetEntry(MultiXactId multi)
                                 42                 :                : {
                                 43                 :         200353 :     return multi % MULTIXACT_OFFSETS_PER_PAGE;
                                 44                 :                : }
                                 45                 :                : 
                                 46                 :                : static inline int64
   96 heikki.linnakangas@i       47                 :UNC           0 : MultiXactIdToOffsetSegment(MultiXactId multi)
                                 48                 :                : {
                                 49                 :              0 :     return MultiXactIdToOffsetPage(multi) / SLRU_PAGES_PER_SEGMENT;
                                 50                 :                : }
                                 51                 :                : 
                                 52                 :                : /*
                                 53                 :                :  * The situation for members is a bit more complex: we store one byte of
                                 54                 :                :  * additional flag bits for each TransactionId.  To do this without getting
                                 55                 :                :  * into alignment issues, we store four bytes of flags, and then the
                                 56                 :                :  * corresponding 4 Xids.  Each such 5-word (20-byte) set we call a "group", and
                                 57                 :                :  * are stored as a whole in pages.  Thus, with 8kB BLCKSZ, we keep 409 groups
                                 58                 :                :  * per page.  This wastes 12 bytes per page, but that's OK -- simplicity (and
                                 59                 :                :  * performance) trumps space efficiency here.
                                 60                 :                :  *
                                 61                 :                :  * Note that the "offset" macros work with byte offset, not array indexes, so
                                 62                 :                :  * arithmetic must be done using "char *" pointers.
                                 63                 :                :  */
                                 64                 :                : /* We need eight bits per xact, so one xact fits in a byte */
                                 65                 :                : #define MXACT_MEMBER_BITS_PER_XACT          8
                                 66                 :                : #define MXACT_MEMBER_FLAGS_PER_BYTE         1
                                 67                 :                : #define MXACT_MEMBER_XACT_BITMASK   ((1 << MXACT_MEMBER_BITS_PER_XACT) - 1)
                                 68                 :                : 
                                 69                 :                : /* how many full bytes of flags are there in a group? */
                                 70                 :                : #define MULTIXACT_FLAGBYTES_PER_GROUP       4
                                 71                 :                : #define MULTIXACT_MEMBERS_PER_MEMBERGROUP   \
                                 72                 :                :     (MULTIXACT_FLAGBYTES_PER_GROUP * MXACT_MEMBER_FLAGS_PER_BYTE)
                                 73                 :                : /* size in bytes of a complete group */
                                 74                 :                : #define MULTIXACT_MEMBERGROUP_SIZE \
                                 75                 :                :     (sizeof(TransactionId) * MULTIXACT_MEMBERS_PER_MEMBERGROUP + MULTIXACT_FLAGBYTES_PER_GROUP)
                                 76                 :                : #define MULTIXACT_MEMBERGROUPS_PER_PAGE (BLCKSZ / MULTIXACT_MEMBERGROUP_SIZE)
                                 77                 :                : #define MULTIXACT_MEMBERS_PER_PAGE  \
                                 78                 :                :     (MULTIXACT_MEMBERGROUPS_PER_PAGE * MULTIXACT_MEMBERS_PER_MEMBERGROUP)
                                 79                 :                : 
                                 80                 :                : /* page in which a member is to be found */
                                 81                 :                : static inline int64
   96 heikki.linnakangas@i       82                 :GNC     1832904 : MXOffsetToMemberPage(MultiXactOffset offset)
                                 83                 :                : {
                                 84                 :        1832904 :     return offset / MULTIXACT_MEMBERS_PER_PAGE;
                                 85                 :                : }
                                 86                 :                : 
                                 87                 :                : static inline int64
   96 heikki.linnakangas@i       88                 :UNC           0 : MXOffsetToMemberSegment(MultiXactOffset offset)
                                 89                 :                : {
                                 90                 :              0 :     return MXOffsetToMemberPage(offset) / SLRU_PAGES_PER_SEGMENT;
                                 91                 :                : }
                                 92                 :                : 
                                 93                 :                : /* Location (byte offset within page) of flag word for a given member */
                                 94                 :                : static inline int
   96 heikki.linnakangas@i       95                 :GNC     3668132 : MXOffsetToFlagsOffset(MultiXactOffset offset)
                                 96                 :                : {
                                 97                 :        3668132 :     MultiXactOffset group = offset / MULTIXACT_MEMBERS_PER_MEMBERGROUP;
                                 98                 :        3668132 :     int         grouponpg = group % MULTIXACT_MEMBERGROUPS_PER_PAGE;
                                 99                 :        3668132 :     int         byteoff = grouponpg * MULTIXACT_MEMBERGROUP_SIZE;
                                100                 :                : 
                                101                 :        3668132 :     return byteoff;
                                102                 :                : }
                                103                 :                : 
                                104                 :                : static inline int
                                105                 :        1836268 : MXOffsetToFlagsBitShift(MultiXactOffset offset)
                                106                 :                : {
                                107                 :        1836268 :     int         member_in_group = offset % MULTIXACT_MEMBERS_PER_MEMBERGROUP;
                                108                 :        1836268 :     int         bshift = member_in_group * MXACT_MEMBER_BITS_PER_XACT;
                                109                 :                : 
                                110                 :        1836268 :     return bshift;
                                111                 :                : }
                                112                 :                : 
                                113                 :                : /* Location (byte offset within page) of TransactionId of given member */
                                114                 :                : static inline int
                                115                 :        1830925 : MXOffsetToMemberOffset(MultiXactOffset offset)
                                116                 :                : {
                                117                 :        1830925 :     int         member_in_group = offset % MULTIXACT_MEMBERS_PER_MEMBERGROUP;
                                118                 :                : 
                                119                 :        1830925 :     return MXOffsetToFlagsOffset(offset) +
                                120                 :        1830925 :         MULTIXACT_FLAGBYTES_PER_GROUP +
                                121                 :                :         member_in_group * sizeof(TransactionId);
                                122                 :                : }
                                123                 :                : 
                                124                 :                : /* Storage space consumed by a range of offsets, in bytes */
                                125                 :                : static inline uint64
   75 michael@paquier.xyz       126                 :             12 : MultiXactOffsetStorageSize(MultiXactOffset new_offset,
                                127                 :                :                            MultiXactOffset old_offset)
                                128                 :                : {
                                129         [ -  + ]:             12 :     Assert(new_offset >= old_offset);
                                130                 :             12 :     return (uint64) ((new_offset - old_offset) / MULTIXACT_MEMBERS_PER_MEMBERGROUP) *
                                131                 :                :         MULTIXACT_MEMBERGROUP_SIZE;
                                132                 :                : }
                                133                 :                : 
                                134                 :                : #endif                          /* MULTIXACT_INTERNAL_H */
        

Generated by: LCOV version 2.4-beta