Skip to content

Commit

Permalink
Implemented CORE-1751. The changes include:
Browse files Browse the repository at this point in the history
1) Make memory counters aggregated.
2) Add attachment pool and allocate appropriate resources out of this pool.
3) Always release attachments explicitly (via destructor).
4) Always delete user requests prior to attachment deletion.
5) Introduce memory usage counters per every monitoring object.
6) Misc refactoring.
Some pieces are still incomplete (although everything basically works), but I'd like to get feedback and testing sooner rather than later.
  • Loading branch information
dyemanov committed May 6, 2008
1 parent 1485094 commit 6a593ec
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
28 changes: 20 additions & 8 deletions src/common/classes/alloc.cpp
Expand Up @@ -213,29 +213,41 @@ static void print_block(FILE *file, MemoryBlock *blk, bool used_only,

inline void MemoryPool::increment_usage(size_t size)
{
size_t temp = stats->mst_usage += size;
if (temp > stats->mst_max_usage)
stats->mst_max_usage = temp;
for (MemoryStats* statistics = stats; statistics; statistics = statistics->mst_parent)
{
size_t temp = statistics->mst_usage += size;
if (temp > statistics->mst_max_usage)
statistics->mst_max_usage = temp;
}
used_memory += size;
}

inline void MemoryPool::decrement_usage(size_t size)
{
stats->mst_usage -= size;
for (MemoryStats* statistics = stats; statistics; statistics = statistics->mst_parent)
{
statistics->mst_usage -= size;
}
used_memory -= size;
}

inline void MemoryPool::increment_mapping(size_t size)
{
size_t temp = stats->mst_mapped += size;
if (temp > stats->mst_max_mapped)
stats->mst_max_mapped = temp;
for (MemoryStats* statistics = stats; statistics; statistics = statistics->mst_parent)
{
size_t temp = statistics->mst_mapped += size;
if (temp > statistics->mst_max_mapped)
statistics->mst_max_mapped = temp;
}
mapped_memory += size;
}

inline void MemoryPool::decrement_mapping(size_t size)
{
stats->mst_mapped -= size;
for (MemoryStats* statistics = stats; statistics; statistics = statistics->mst_parent)
{
statistics->mst_mapped -= size;
}
mapped_memory -= size;
}

Expand Down
29 changes: 19 additions & 10 deletions src/common/classes/alloc.h
Expand Up @@ -170,28 +170,37 @@ struct PendingFreeBlock
class MemoryStats
{
public:
MemoryStats() : mst_usage(0), mst_mapped(0), mst_max_usage(0), mst_max_mapped(0) {}
~MemoryStats() {}
size_t get_current_usage() const { return mst_usage.value(); }
size_t get_maximum_usage() const { return mst_max_usage; }
size_t get_current_mapping() const { return mst_mapped.value(); }
size_t get_maximum_mapping() const { return mst_max_mapped; }
explicit MemoryStats(MemoryStats* parent = NULL)
: mst_parent(parent), mst_usage(0), mst_mapped(0), mst_max_usage(0), mst_max_mapped(0)
{}

~MemoryStats()
{}

size_t getCurrentUsage() const { return mst_usage.value(); }
size_t getMaximumUsage() const { return mst_max_usage; }
size_t getCurrentMapping() const { return mst_mapped.value(); }
size_t getMaximumMapping() const { return mst_max_mapped; }

private:
// Forbid copy constructor
MemoryStats(const MemoryStats& object) {}
// Forbid copying/assignment
MemoryStats(const MemoryStats&);
MemoryStats& operator=(const MemoryStats&);

MemoryStats* mst_parent;

// Currently allocated memory (without allocator overhead)
// Useful for monitoring engine memory leaks
AtomicCounter mst_usage;
// Amount of memory mapped (including all overheads)
// Useful for monitoring OS memory consumption
AtomicCounter mst_mapped;

// We don't particularily care about extreme precision of these max values,
// this is why we don't synchronize them on Windows
size_t mst_max_usage;
size_t mst_max_mapped;

friend class MemoryPool;
};

Expand Down

0 comments on commit 6a593ec

Please sign in to comment.