diff --git a/dsm_array.c b/dsm_array.c index 47647bc8..6464fddf 100644 --- a/dsm_array.c +++ b/dsm_array.c @@ -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 */ diff --git a/init.c b/init.c index 7fca420a..d411e223 100644 --- a/init.c +++ b/init.c @@ -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() { @@ -596,4 +605,4 @@ remove_relation_info(Oid relid) } prel->children_count = 0; hash_search(relations, (const void *) &key, HASH_REMOVE, 0); -} \ No newline at end of file +} diff --git a/pathman.h b/pathman.h index bfb171c6..f658014f 100644 --- a/pathman.h +++ b/pathman.h @@ -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); @@ -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); diff --git a/pg_pathman.c b/pg_pathman.c index 5758ffd0..7f8f7beb 100644 --- a/pg_pathman.c +++ b/pg_pathman.c @@ -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; @@ -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);