PostgreSQL Source Code  git master
datapagemap.h File Reference
#include "storage/relfilenode.h"
#include "storage/block.h"
Include dependency graph for datapagemap.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  datapagemap
 

Typedefs

typedef struct datapagemap datapagemap_t
 
typedef struct datapagemap_iterator datapagemap_iterator_t
 

Functions

void datapagemap_add (datapagemap_t *map, BlockNumber blkno)
 
datapagemap_iterator_tdatapagemap_iterate (datapagemap_t *map)
 
bool datapagemap_next (datapagemap_iterator_t *iter, BlockNumber *blkno)
 
void datapagemap_print (datapagemap_t *map)
 

Typedef Documentation

◆ datapagemap_iterator_t

Definition at line 23 of file datapagemap.h.

◆ datapagemap_t

typedef struct datapagemap datapagemap_t

Definition at line 22 of file datapagemap.h.

Function Documentation

◆ datapagemap_add()

void datapagemap_add ( datapagemap_t map,
BlockNumber  blkno 
)

Definition at line 33 of file datapagemap.c.

References datapagemap::bitmap, datapagemap::bitmapsize, and pg_realloc().

Referenced by process_block_change().

34 {
35  int offset;
36  int bitno;
37 
38  offset = blkno / 8;
39  bitno = blkno % 8;
40 
41  /* enlarge or create bitmap if needed */
42  if (map->bitmapsize <= offset)
43  {
44  int oldsize = map->bitmapsize;
45  int newsize;
46 
47  /*
48  * The minimum to hold the new bit is offset + 1. But add some
49  * headroom, so that we don't need to repeatedly enlarge the bitmap in
50  * the common case that blocks are modified in order, from beginning
51  * of a relation to the end.
52  */
53  newsize = offset + 1;
54  newsize += 10;
55 
56  map->bitmap = pg_realloc(map->bitmap, newsize);
57 
58  /* zero out the newly allocated region */
59  memset(&map->bitmap[oldsize], 0, newsize - oldsize);
60 
61  map->bitmapsize = newsize;
62  }
63 
64  /* Set the bit */
65  map->bitmap[offset] |= (1 << bitno);
66 }
char * bitmap
Definition: datapagemap.h:18
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
int bitmapsize
Definition: datapagemap.h:19

◆ datapagemap_iterate()

datapagemap_iterator_t* datapagemap_iterate ( datapagemap_t map)

Definition at line 76 of file datapagemap.c.

References datapagemap_iterator::map, datapagemap_iterator::nextblkno, and pg_malloc().

Referenced by calculate_totals(), datapagemap_print(), and execute_pagemap().

77 {
79 
80  iter = pg_malloc(sizeof(datapagemap_iterator_t));
81  iter->map = map;
82  iter->nextblkno = 0;
83 
84  return iter;
85 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
BlockNumber nextblkno
Definition: datapagemap.c:22
datapagemap_t * map
Definition: datapagemap.c:21

◆ datapagemap_next()

bool datapagemap_next ( datapagemap_iterator_t iter,
BlockNumber blkno 
)

Definition at line 88 of file datapagemap.c.

References datapagemap::bitmap, datapagemap::bitmapsize, datapagemap_iterator::map, and datapagemap_iterator::nextblkno.

Referenced by calculate_totals(), datapagemap_print(), and execute_pagemap().

89 {
90  datapagemap_t *map = iter->map;
91 
92  for (;;)
93  {
94  BlockNumber blk = iter->nextblkno;
95  int nextoff = blk / 8;
96  int bitno = blk % 8;
97 
98  if (nextoff >= map->bitmapsize)
99  break;
100 
101  iter->nextblkno++;
102 
103  if (map->bitmap[nextoff] & (1 << bitno))
104  {
105  *blkno = blk;
106  return true;
107  }
108  }
109 
110  /* no more set bits in this bitmap. */
111  return false;
112 }
char * bitmap
Definition: datapagemap.h:18
uint32 BlockNumber
Definition: block.h:31
int bitmapsize
Definition: datapagemap.h:19
BlockNumber nextblkno
Definition: datapagemap.c:22
datapagemap_t * map
Definition: datapagemap.c:21

◆ datapagemap_print()

void datapagemap_print ( datapagemap_t map)

Definition at line 118 of file datapagemap.c.

References datapagemap_iterate(), datapagemap_next(), pg_free(), and pg_log_debug.

Referenced by print_filemap().

119 {
121  BlockNumber blocknum;
122 
123  iter = datapagemap_iterate(map);
124  while (datapagemap_next(iter, &blocknum))
125  pg_log_debug("block %u", blocknum);
126 
127  pg_free(iter);
128 }
uint32 BlockNumber
Definition: block.h:31
bool datapagemap_next(datapagemap_iterator_t *iter, BlockNumber *blkno)
Definition: datapagemap.c:88
#define pg_log_debug(...)
Definition: logging.h:91
datapagemap_iterator_t * datapagemap_iterate(datapagemap_t *map)
Definition: datapagemap.c:76
void pg_free(void *ptr)
Definition: fe_memutils.c:105