Hello Thomas,
      
            Thank you for your suggestions, needless to say it helped a lot. As 
you suggested, I have created an initial dsm segment and used it create dsa 
area as well as to detach dsm. Thus, it helped me in using 'on_dsm_detach' 
callback. I have tested the code and it works well. I did post a code snippet, 
just verify if I have missed anything.

CREATE DSA:

      old_context = MemoryContextSwitchTo(TopMemoryContext);



      segment = dsm_create(DSA_INITIAL_SEGMENT_SIZE, 0); /* Initial segment 
size 1mb */

      dsm_pin_segment(segment);



      area = dsa_create_in_place(dsm_segment_address(segment), 
DSA_INITIAL_SEGMENT_SIZE, GraphIndex_tranche_id(), segment);

      on_dsm_detach(segment, &detach_func, 
PointerGetDatum(dsm_segment_address(segment)));



      MemoryContextSwitchTo(old_context);

      

      dsa_pin(area);

      dsm_pin_mapping(segment);

      dsa_pin_mapping(area);



      /* Saving dsa_handle in shmem for serving other processes */

      GraphIndexShmem->graphindex_dsa_handle = dsm_segment_handle(segment);



      PROC_DSA_AREA = area;





ATTACH DSA:



      old_context = MemoryContextSwitchTo(TopMemoryContext);



      segment = dsm_attach(GraphIndexShmem->graphindex_dsa_handle);

      area = dsa_attach_in_place(dsm_segment_address(segment), segment);



      on_dsm_detach(segment, &detach_func, 
PointerGetDatum(dsm_segment_address(segment)));



      MemoryContextSwitchTo(old_context);



      dsm_pin_mapping(segment);

      dsa_pin_mapping(area);



      PROC_DSA_AREA = area;



Thank you,
G. Sai Ram







---- On Wed, 24 Jan 2018 13:53:52 +0530 Thomas Munro 
<thomas.mu...@enterprisedb.com> wrote ----




On Wed, Jan 24, 2018 at 8:37 PM, Gaddam Sai Ram 

<gaddamsaira...@zohocorp.com> wrote: 

> Found that there is a callback for dsa detach but that function requires 

> segment pointer as an argument, Should be as below: 

> 

> on_dsm_detach(PROC_DSA_AREA->segment_maps[0].segment, detach_func); 

> ... 

> But i couldn't access that segment, as DSA_AREA struct is defined in 
dsa.c, 

> so I am unable to include. 

> 

> Any other ways to get dsa detach event, or to access DSA Segment pointer? 

 

There are two ways to create DSA areas: dsa_create() and 

dsa_create_in_place(). In all existing in-core uses of DSA areas, 

they are created "in place". That means that you have to supply the 

initial DSM segment and then they live inside that, and they will 

quietly create more DSM segments as needed if they run out of space. 

If you do it that way you get to install detach hooks for that root 

DSM segment because you have your hands on it. Maybe you should do 

that too? Basically just replace your current DSA creation, handle 

sharing and attaching code with the DSM equivalents (make it, say, 1MB 

in size), and then use dsa_{create,attach}_in_place() in the space 

inside it. The easiest way would be to give *all* the space in this 

root DSM segment using dsm_segment_address() to get the "place" to put 

the DSA area, or you could use a shm_toc to put that + other fixed 

size stuff inside it (the way execParallel.c does). 

 

It probably seems a bit weird and circular that DSA areas manage a set 

of DSM segments, but can themselves live in a user-supplied DSM 

segment. DSM segments have two roles: they are shared memory, and in 

this capacity a DSA area owns and uses them as raw storage, but they 

are also a kind of general shared resource ownership/management 

mechanism that comes with some free shared space, and in this capacity 

they can be used to own a DSA area (or shared files, or interprocess 

queues, or ..). 

 

Hope that helps. 

 

-- 

Thomas Munro 

http://www.enterprisedb.com 






Reply via email to