Skip to content

Commit

Permalink
Memory Zone: Removed the fast malloc mode
Browse files Browse the repository at this point in the history
The fast mode was originally implemented to overcome slow
malloc performance when allocating lots of data, but it never
worked quite right.
  • Loading branch information
skyjake committed Feb 23, 2012
1 parent 76d3ce4 commit d81c798
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 56 deletions.
2 changes: 0 additions & 2 deletions doomsday/engine/portable/include/dd_zone.h
Expand Up @@ -49,8 +49,6 @@ boolean Z_IsInited(void);
int Z_Init(void);

void Z_Shutdown(void);
void Z_EnableFastMalloc(boolean isEnabled);
//void Z_PrintStatus(void);
void* Z_Malloc(size_t size, int tag, void* ptr);
void Z_Free(void* ptr);
void Z_FreeTags(int lowTag, int highTag);
Expand Down
49 changes: 5 additions & 44 deletions doomsday/engine/portable/src/dd_zone.c
Expand Up @@ -12,12 +12,6 @@
* It is of no value to free a cachable block, because it will get
* overwritten automatically if needed.
*
* When fast malloc mode is enabled, memory volumes aren't checked for purgable
* blocks. If the rover block isn't suitable, a new empty volume is created
* without further checking. This is suitable for cases where lots of blocks
* are being allocated in a rapid sequence, with no frees in between (e.g.,
* map setup).
*
* @par Block Sequences
* The PU_MAPSTATIC purge tag has a special purpose.
* It works like PU_MAP so that it is purged on a per map basis, but
Expand Down Expand Up @@ -101,16 +95,6 @@ typedef struct zblockset_block_s {
static memvolume_t *volumeRoot;
static memvolume_t *volumeLast;

/**
* If false, Z_Malloc will free purgable blocks and aggressively look for
* free memory blocks inside each memory volume before creating new volumes.
* This leads to slower mallocing performance, but reduces memory fragmentation
* as free and purgable blocks are utilized within the volumes. Fast mode is
* enabled during map setup because a large number of mallocs will occur
* during setup.
*/
static boolean fastMalloc = false;

static mutex_t zoneMutex = 0;

static __inline void lockZone(void)
Expand Down Expand Up @@ -139,22 +123,6 @@ long superatol(char *s)
return val;
}

/**
* Enables or disables fast malloc mode. Enable for added performance during
* map setup. Disable fast mode during other times to save memory and reduce
* fragmentation.
*
* @param isEnabled true or false.
*/
void Z_EnableFastMalloc(boolean isEnabled)
{
lockZone();

fastMalloc = isEnabled;

unlockZone();
}

/**
* Create a new memory volume. The new volume is added to the list of
* memory volumes.
Expand Down Expand Up @@ -412,6 +380,11 @@ static __inline boolean isVolumeTooFull(memvolume_t* vol)
return vol->allocatedBytes > vol->size * .95f;
}

/**
* The static rovers should be rewound back near the beginning of the volume
* periodically. Currently this is done whenever tag ranges are purged (e.g.,
* before map changes).
*/
static void rewindStaticRovers(void)
{
memvolume_t* volume;
Expand Down Expand Up @@ -513,18 +486,6 @@ void *Z_Malloc(size_t size, int tag, void *user)

gotoNextVolume = false;

/*
if(fastMalloc)
{
// In fast malloc mode, if the rover block isn't large enough,
// just give up and move to the next volume right away.
if(base->user || base->size < size)
{
gotoNextVolume = true;
}
}
*/

numChecked = 0;

// 'base' is the block that we'll end up using.
Expand Down
10 changes: 0 additions & 10 deletions doomsday/engine/portable/src/r_world.c
Expand Up @@ -1355,12 +1355,6 @@ void R_SetupMap(int mode, int flags)
switch(mode)
{
case DDSMM_INITIALIZE:
// Switch to fast malloc mode in the zone. This is intended for large
// numbers of mallocs with no frees in between.
/// @todo Fast mallocs are broken; they end up reserving more and more
/// new volumes as the old ones get "dirty".
Z_EnableFastMalloc(false /*true*/);

#ifdef _DEBUG
Con_Message("R_SetupMap: ddMapSetup begins (fast mallocs).\n");
#endif
Expand Down Expand Up @@ -1475,10 +1469,6 @@ void R_SetupMap(int mode, int flags)
// Inform the timing system to suspend the starting of the clock.
firstFrameAfterLoad = true;

// Switch back to normal malloc mode in the zone. Z_Malloc will look
// for free blocks in the entire zone and purge purgable blocks.
Z_EnableFastMalloc(false);

Z_PrintStatus();
return;
}
Expand Down

0 comments on commit d81c798

Please sign in to comment.