Skip to content

Commit

Permalink
Add comments for pagemap functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dipinhora committed Jul 27, 2023
1 parent d1ae054 commit 889df0a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/libponyrt/mem/pagemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ chunk_t* ponyint_pagemap_get_chunk(const void* addr)
return chunk;
}

/* This function looks up the chunk_t* to returns it and also looks
* up the pony_actor_t* to return in the out paramter `actor`. This
* is done in order to avoid allocating a struct to return as a single
* return value while minimizing the need to traverse the pagemap multiple
* times in order to retrieve both the chunk_t* and the pony_actor_t*.
*
* NOTE: the multiple atomic instructions to retrieve the chunk_t* followed
* by the pony_actor_t* should be safe because the only time the pagemap
* is updated is when a chunk_t is first allocated by an actor or when the
* chunk_t is deallocated/freed by GC and in both scenarios the only actor
* with a reference to memory that would resolve to that pagemap entry is
* the owning actor of the chunk_t.
*/
chunk_t* ponyint_pagemap_get(const void* addr, pony_actor_t** actor)
{
PONY_ATOMIC(void*)* next_node = &root;
Expand Down Expand Up @@ -163,6 +176,16 @@ chunk_t* ponyint_pagemap_get(const void* addr, pony_actor_t** actor)
return chunk;
}

/* This function sets the chunk_t* and the pony_actor_t* in the pagemap for
* a small chunk_t (exactly one pagemap entry).
*
* NOTE: the multiple atomic instructions to set the chunk_t* followed
* by the pony_actor_t* should be safe because the only time the pagemap
* is updated is when a chunk_t is first allocated by an actor or when the
* chunk_t is deallocated/freed by GC and in both scenarios the only actor
* with a reference to memory that would resolve to that pagemap entry is
* the owning actor of the chunk_t.
*/
void ponyint_pagemap_set(const void* addr, chunk_t* chunk, pony_actor_t* actor)
{
PONY_ATOMIC(void*)* next_node = &root;
Expand Down Expand Up @@ -229,6 +252,16 @@ void ponyint_pagemap_set(const void* addr, chunk_t* chunk, pony_actor_t* actor)
atomic_store_explicit(next_node, actor, memory_order_release);
}

/* This function sets the chunk_t* and the pony_actor_t* in the pagemap for
* a large chunk_t's (more than one pagemap entry required).
*
* NOTE: the multiple atomic instructions to set the chunk_t* followed
* by the pony_actor_t* should be safe because the only time the pagemap
* is updated is when a chunk_t is first allocated by an actor or when the
* chunk_t is deallocated/freed by GC and in both scenarios the only actor
* with a reference to memory that would resolve to that pagemap entry is
* the owning actor of the chunk_t.
*/
void ponyint_pagemap_set_bulk(const void* addr, chunk_t* chunk, pony_actor_t* actor, size_t size)
{
PONY_ATOMIC(void*)* next_node = NULL;
Expand Down

0 comments on commit 889df0a

Please sign in to comment.