Skip to content

Fix shared resources allocation #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions dsm_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ typedef BlockHeader* BlockHeaderPtr;
#define set_length(header, length) \
((length) | ((*header) & FREE_BIT))

/*
* Amount of memory that need to be requested in shared memory to store dsm
* config
*/
Size
get_dsm_shared_size()
{
return (Size) MAXALIGN(sizeof(DsmConfig));
}

/*
* Initialize dsm config for arrays
*/
Expand Down
11 changes: 10 additions & 1 deletion init.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ static bool validate_range_constraint(Expr *, PartRelationInfo *, Datum *, Datum
static bool validate_hash_constraint(Expr *expr, PartRelationInfo *prel, int *hash);
static int cmp_range_entries(const void *p1, const void *p2);

Size
pathman_memsize()
{
Size size;

size = get_dsm_shared_size() + MAXALIGN(sizeof(PathmanState));
return size;
}

void
init_shmem_config()
{
Expand Down Expand Up @@ -596,4 +605,4 @@ remove_relation_info(Oid relid)
}
prel->children_count = 0;
hash_search(relations, (const void *) &key, HASH_REMOVE, 0);
}
}
2 changes: 2 additions & 0 deletions pathman.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ int irange_list_length(List *rangeset);
bool irange_list_find(List *rangeset, int index, bool *lossy);

/* Dynamic shared memory functions */
Size get_dsm_shared_size(void);
void init_dsm_config(void);
bool init_dsm_segment(size_t blocks_count, size_t block_size);
void init_dsm_table(size_t block_size, size_t start, size_t end);
Expand All @@ -171,6 +172,7 @@ HTAB *range_restrictions;
bool initialization_needed;

/* initialization functions */
Size pathman_memsize(void);
void init_shmem_config(void);
void load_config(void);
void create_relations_hashtable(void);
Expand Down
6 changes: 4 additions & 2 deletions pg_pathman.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ _PG_init(void)
}
#endif

/* Request additional shared resources */
RequestAddinShmemSpace(pathman_memsize());
RequestAddinLWLocks(3);

set_rel_pathlist_hook_original = set_rel_pathlist_hook;
set_rel_pathlist_hook = pathman_set_rel_pathlist_hook;
shmem_startup_hook_original = shmem_startup_hook;
Expand Down Expand Up @@ -325,8 +329,6 @@ handle_modification_query(Query *parse)
static void
pathman_shmem_startup(void)
{
/* Initialize locks */
RequestAddinLWLocks(3);

/* Allocate shared memory objects */
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
Expand Down