src/backend/storage/freespace/freespace.c
static void
fsm_extend(Relation rel, BlockNumber fsm_nblocks)
{
	BlockNumber fsm_nblocks_now;
	PGAlignedBlock pg;
	SMgrRelation reln;

	PageInit((Page) pg.data, BLCKSZ, 0);

	/*
	 * We use the relation extension lock to lock out other backends trying to
	 * extend the FSM at the same time. It also locks out extension of the
	 * main fork, unnecessarily, but extending the FSM happens seldom enough
	 * that it doesn't seem worthwhile to have a separate lock tag type for
	 * it.
	 *
	 * Note that another backend might have extended or created the relation
	 * by the time we get the lock.
	 */
	LockRelationForExtension(rel, ExclusiveLock);

	/*
	 * Caution: re-using this smgr pointer could fail if the relcache entry
	 * gets closed.  It's safe as long as we only do smgr-level operations
	 * between here and the last use of the pointer.
	 */
	reln = RelationGetSmgr(rel);

	/*
	 * Create the FSM file first if it doesn't exist.  If
	 * smgr_cached_nblocks[FSM_FORKNUM] is positive then it must exist, no
	 * need for an smgrexists call.
	 */
	if ((reln->smgr_cached_nblocks[FSM_FORKNUM] == 0 ||
		 reln->smgr_cached_nblocks[FSM_FORKNUM] == InvalidBlockNumber) &&
		!smgrexists(reln, FSM_FORKNUM))
		smgrcreate(reln, FSM_FORKNUM, false);

	/* Invalidate cache so that smgrnblocks() asks the kernel. */
	reln->smgr_cached_nblocks[FSM_FORKNUM] = InvalidBlockNumber;
	fsm_nblocks_now = smgrnblocks(reln, FSM_FORKNUM);

	/* Extend as needed. */
	while (fsm_nblocks_now < fsm_nblocks)
	{
		PageSetChecksumInplace((Page) pg.data, fsm_nblocks_now);

		smgrextend(reln, FSM_FORKNUM, fsm_nblocks_now,
				   pg.data, false);
		fsm_nblocks_now++;
	}

	UnlockRelationForExtension(rel, ExclusiveLock);
}
/*
 * Ensure that the FSM fork is at least fsm_nblocks long, extending
 * it if necessary with empty pages. And by empty, I mean pages filled
 * with zeros, meaning there's no free space.
 */
Ensure that the FSM fork is at least fsm_nblocks long, extending
it if necessary with empty pages. And by empty, I mean pages filled
with zeros, meaning there's no free space.
Ensure that the FSM fork is at least fsm_nblocks long extending it if necessary with empty pages . And by empty I mean pages filled with zeros meaning there ' s no free space .
static void
fsm_extend(Relation rel, BlockNumber fsm_nblocks)
{
	BlockNumber fsm_nblocks_now;
	PGAlignedBlock pg;
	SMgrRelation reln;
	PageInit((Page) pg.data, BLCKSZ, 0);
	LockRelationForExtension(rel, ExclusiveLock);
	reln = RelationGetSmgr(rel);
	if ((reln->smgr_cached_nblocks[FSM_FORKNUM] == 0 ||
		 reln->smgr_cached_nblocks[FSM_FORKNUM] == InvalidBlockNumber) &&
		!smgrexists(reln, FSM_FORKNUM))
		smgrcreate(reln, FSM_FORKNUM, false);
	reln->smgr_cached_nblocks[FSM_FORKNUM] = InvalidBlockNumber;
	fsm_nblocks_now = smgrnblocks(reln, FSM_FORKNUM);
	while (fsm_nblocks_now < fsm_nblocks)
	{
		PageSetChecksumInplace((Page) pg.data, fsm_nblocks_now);
		smgrextend(reln, FSM_FORKNUM, fsm_nblocks_now,
				   pg.data, false);
		fsm_nblocks_now++;
	}
	UnlockRelationForExtension(rel, ExclusiveLock);
}
static void fsm_extend ( Relation rel , BlockNumber fsm_nblocks ) { BlockNumber fsm_nblocks_now ; PGAlignedBlock pg ; SMgrRelation reln ; PageInit ( ( Page ) pg . data , BLCKSZ , 0 ) ; LockRelationForExtension ( rel , ExclusiveLock ) ; reln = RelationGetSmgr ( rel ) ; if ( ( reln -> smgr_cached_nblocks [ FSM_FORKNUM ] == 0 || reln -> smgr_cached_nblocks [ FSM_FORKNUM ] == InvalidBlockNumber ) && ! smgrexists ( reln , FSM_FORKNUM ) ) smgrcreate ( reln , FSM_FORKNUM , false ) ; reln -> smgr_cached_nblocks [ FSM_FORKNUM ] = InvalidBlockNumber ; fsm_nblocks_now = smgrnblocks ( reln , FSM_FORKNUM ) ; while ( fsm_nblocks_now < fsm_nblocks ) { PageSetChecksumInplace ( ( Page ) pg . data , fsm_nblocks_now ) ; smgrextend ( reln , FSM_FORKNUM , fsm_nblocks_now , pg . data , false ) ; fsm_nblocks_now ++ ; } UnlockRelationForExtension ( rel , ExclusiveLock ) ; }
Ensure that the FSM fork is at least fsm_nblocks long, extending
 it if necessary with empty pages.
Ensure that the FSM fork is at least fsm_nblocks long extending it if necessary with empty pages .
/*
	 * We use the relation extension lock to lock out other backends trying to
	 * extend the FSM at the same time. It also locks out extension of the
	 * main fork, unnecessarily, but extending the FSM happens seldom enough
	 * that it doesn't seem worthwhile to have a separate lock tag type for
	 * it.
	 *
	 * Note that another backend might have extended or created the relation
	 * by the time we get the lock.
	 */ /*
	 * Caution: re-using this smgr pointer could fail if the relcache entry
	 * gets closed.  It's safe as long as we only do smgr-level operations
	 * between here and the last use of the pointer.
	 */ /*
	 * Create the FSM file first if it doesn't exist.  If
	 * smgr_cached_nblocks[FSM_FORKNUM] is positive then it must exist, no
	 * need for an smgrexists call.
	 */ /* Invalidate cache so that smgrnblocks() asks the kernel. */ /* Extend as needed. */