Skip to content

Commit

Permalink
Columns free their data buffer at destruction if self-managed memory …
Browse files Browse the repository at this point in the history
…is turned off.

- This is important now, since we need to free memory for running non-trivial tests and micro-benchmarks.
- This works only when not using MorphStore's own memory manager, since it does not fully support freeing yet.
- The solution still contains some workarounds, see issue #19.
  • Loading branch information
pdamme committed Apr 16, 2019
1 parent 14dd49a commit 6403407
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ if ( DEFINED QMMMES )
set( ignoreMe ${QMMMES} )
else ( DEFINED QMMMES )
set( MorphStoreProjectConf "${MorphStoreProjectConf}\tQMMMES defaults to 128M.\n" )
morph_flag("-UMSV_NO_SELFMANAGED_MEMORY")
morph_flag("-UMSV_QUERY_MEMORY_MANAGER_MINIMUM_EXPAND_SIZE")
endif ( DEFINED QMMMES )

if ( DEFINED ENABLE_MONITORING )
Expand Down
2 changes: 2 additions & 0 deletions include/core/memory/management/utils/alignment_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#ifndef MORPHSTORE_CORE_MEMORY_MANAGEMENT_UTILS_ALIGNMENT_HELPER_H
#define MORPHSTORE_CORE_MEMORY_MANAGEMENT_UTILS_ALIGNMENT_HELPER_H

#include <core/utils/preprocessor.h>

#ifndef MSV_MEMORY_MANAGER_ALIGNMENT_BYTE
# define MSV_MEMORY_MANAGER_ALIGNMENT_BYTE 64_B
#endif
Expand Down
7 changes: 7 additions & 0 deletions include/core/memory/stl_wrapper/ostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,25 @@
#ifndef MORPHSTORE_CORE_MEMORY_STL_WRAPPER_OSTREAM_H
#define MORPHSTORE_CORE_MEMORY_STL_WRAPPER_OSTREAM_H

#ifndef MSV_NO_SELFMANAGED_MEMORY
#ifndef MORPHSTORE_CORE_MEMORY_MANAGEMENT_ALLOCATORS_GLOBAL_SCOPE_ALLOCATOR_H
# error "Perpetual (global scoped) allocator ( allocators/global_scope_allocator.h ) has to be included before all stl_wrapper."
#endif
#endif

#include <sstream>
#include <fstream>
#include <unistd.h>

namespace morphstore {

#ifndef MSV_NO_SELFMANAGED_MEMORY
using ostring_stream = std::basic_ostringstream< char, std::char_traits< char >, global_scope_stdlib_allocator< char > >;
using basic_stringbuf = std::basic_stringbuf< char, std::char_traits< char >, global_scope_stdlib_allocator< char > >;
#else
using ostring_stream = std::basic_ostringstream< char, std::char_traits< char > >;
using basic_stringbuf = std::basic_stringbuf< char, std::char_traits< char > >;
#endif
using basic_filebuf = std::basic_filebuf< char, std::char_traits< char > >;

class outbuf : public morphstore::basic_stringbuf {
Expand Down
29 changes: 23 additions & 6 deletions include/core/storage/column.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
*/

#include <core/storage/column_helper.h>
#ifdef MSV_NO_SELFMANAGED_MEMORY
#include <core/memory/management/utils/alignment_helper.h>
#endif
#include <core/morphing/format.h>
#include <core/utils/basic_types.h>
#include <core/utils/helper_types.h>
Expand Down Expand Up @@ -59,32 +62,42 @@ class column {
column< F > & operator= ( column< F > && ) = delete;

virtual ~column( ) {
// debug( "Uncompressed Storage Container - dtor( ): Freeing", m_Data );
// free( const_cast< void * >( static_cast< void const * const >( m_Data ) ) );
#ifdef MSV_NO_SELFMANAGED_MEMORY
free( m_DataUnaligned );
#else
if( m_PersistenceType == storage_persistence_type::globalScope ) {
general_memory_manager::get_instance( ).deallocate( m_Data );
}
#endif
}

private:
column_meta_data m_MetaData;
#ifdef MSV_NO_SELFMANAGED_MEMORY
void * m_DataUnaligned;
#endif
voidptr_t m_Data;
// @todo Actually, the persistence type only makes sense if we use our
// own memory manager.
storage_persistence_type m_PersistenceType;

column(
storage_persistence_type p_PersistenceType,
size_t p_SizeAllocatedByte
) :
m_MetaData{ 0, 0, p_SizeAllocatedByte },
#ifdef MSV_NO_SELFMANAGED_MEMORY
m_DataUnaligned{
malloc( get_size_with_alignment_padding( p_SizeAllocatedByte ) )
},
m_Data{ create_aligned_ptr( m_DataUnaligned ) },
#else
m_Data{
#ifndef MSV_NO_SELFMANAGED_MEMORY
( p_PersistenceType == storage_persistence_type::globalScope )
? general_memory_manager::get_instance( ).allocate( p_SizeAllocatedByte )
: malloc( p_SizeAllocatedByte )
#else
malloc( p_SizeAllocatedByte );
#endif
},
#endif
m_PersistenceType{ p_PersistenceType }
{
//
Expand Down Expand Up @@ -115,9 +128,13 @@ class column {
static column< F > * create_global_column(size_t p_SizeAllocByte) {
return new
(
#ifdef MSV_NO_SELFMANAGED_MEMORY
malloc( sizeof( column< F > ) )
#else
general_memory_manager::get_instance( ).allocate(
sizeof( column< F > )
)
#endif
)
column(
storage_persistence_type::globalScope,
Expand Down

0 comments on commit 6403407

Please sign in to comment.