filename, MSG_storage_get_used_size(st), MSG_storage_get_size(st));
if (MSG_process_self_PID() == 1){
- XBT_INFO("\tUnlink file '%s'",MSG_file_get_name(file));
+ XBT_INFO("\tUnlink file '%s'", MSG_file_get_name(file));
MSG_file_unlink(file);
} else {
- XBT_INFO("\tClose file '%s'",filename);
+ XBT_INFO("\tClose file '%s'", filename);
MSG_file_close(file);
}
return 0;
msg_storage_t storage_src = simgrid::s4u::Storage::byName(fd->storageId);
msg_host_t attached_host = storage_src->host();
fd->unlink(attached_host);
+ delete fd;
return MSG_OK;
}
if (host->isOff())
THROWF(host_error, 0, "Host %s failed, you cannot call this function", host->cname());
- int res = surf_host_unlink(host, fd->surf_file);
- xbt_free(fd);
- return res;
+ return surf_host_unlink(host, fd->surf_file);
}
sg_size_t simcall_HANDLER_file_get_size(smx_simcall_t simcall, smx_file_t fd)
#define HUGE_PAGE_SIZE 1<<21
-/*
- * Similar to smpi_shared_malloc, but only sharing the blocks described by shared_block_offsets.
+/* Similar to smpi_shared_malloc, but only sharing the blocks described by shared_block_offsets.
* This array contains the offsets (in bytes) of the block to share.
* Even indices are the start offsets (included), odd indices are the stop offsets (excluded).
- * For instance, if shared_block_offsets == {27, 42}, then the elements mem[27], mem[28], ..., mem[41] are shared. The others are not.
+ * For instance, if shared_block_offsets == {27, 42}, then the elements mem[27], mem[28], ..., mem[41] are shared.
+ * The others are not.
*/
+
void* smpi_shared_malloc_partial(size_t size, size_t* shared_block_offsets, int nb_shared_blocks)
{
char *huge_page_mount_point = xbt_cfg_get_string("smpi/shared-malloc-hugepage");
use_huge_page = 0;
#endif
smpi_shared_malloc_blocksize = static_cast<unsigned long>(xbt_cfg_get_double("smpi/shared-malloc-blocksize"));
- void *mem, *allocated_ptr;
+ void* mem;
size_t allocated_size;
if(use_huge_page) {
xbt_assert(smpi_shared_malloc_blocksize == HUGE_PAGE_SIZE, "the block size of shared malloc should be equal to the size of a huge page.");
/* First reserve memory area */
- allocated_ptr = mmap(NULL, allocated_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
-
+ void* allocated_ptr = mmap(NULL, allocated_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
xbt_assert(allocated_ptr != MAP_FAILED, "Failed to allocate %zuMiB of memory. Run \"sysctl vm.overcommit_memory=1\" as root "
"to allow big allocations.\n",
// Remove the file from storage
st->content_->erase(fd->name);
- xbt_free(fd->name);
- xbt_free(fd->mount);
- xbt_free(fd);
return 0;
}
}
void *mmorecore(struct mdesc *mdp, ssize_t size)
{
ssize_t test = 0;
- void *result; // please keep it uninitialized to track issues
+ void* result; // please keep it uninitialized to track issues
off_t foffset; /* File offset at which new mapping will start */
size_t mapbytes; /* Number of bytes to map */
- void *moveto; /* Address where we wish to move "break value" to */
- void *mapto; /* Address we actually mapped to */
+ void* moveto; /* Address where we wish to move "break value" to */
+ void* mapto; /* Address we actually mapped to */
char buf = 0; /* Single byte to write to extend mapped file */
if (size == 0) {
/* Just return the current "break" value. */
- result = mdp->breakval;
-
- } else if (size < 0) {
- /* We are deallocating memory. If the amount requested would cause
- us to try to deallocate back past the base of the mmap'd region
- then die verbosely. Otherwise, deallocate the memory and return
- the old break value. */
- if (((char *) mdp->breakval) + size >= (char *) mdp->base) {
- result = (void *) mdp->breakval;
- mdp->breakval = (char *) mdp->breakval + size;
+ return mdp->breakval;
+ }
+
+ if (size < 0) {
+ /* We are deallocating memory. If the amount requested would cause us to try to deallocate back past the base of
+ * the mmap'd region then die verbosely. Otherwise, deallocate the memory and return the old break value. */
+ if (((char*)mdp->breakval) + size >= (char*)mdp->base) {
+ result = (void*)mdp->breakval;
+ mdp->breakval = (char*)mdp->breakval + size;
moveto = PAGE_ALIGN(mdp->breakval);
- munmap(moveto,
- (size_t) (((char *) mdp->top) - ((char *) moveto)) - 1);
+ munmap(moveto, (size_t)(((char*)mdp->top) - ((char*)moveto)) - 1);
mdp->top = moveto;
} else {
fprintf(stderr,"Internal error: mmap was asked to deallocate more memory than it previously allocated. Bailling out now!\n");
abort();
}
} else {
- /* We are allocating memory. Make sure we have an open file
- descriptor if not working with anonymous memory. */
+ /* We are allocating memory. Make sure we have an open file descriptor if not working with anonymous memory. */
if (!(mdp->flags & MMALLOC_ANONYMOUS) && mdp->fd < 0) {
fprintf(stderr,"Internal error: mmap file descriptor <0 (%d), without MMALLOC_ANONYMOUS being in the flags.\n",mdp->fd);
abort();
- } else if ((char *) mdp->breakval + size > (char *) mdp->top) {
- /* The request would move us past the end of the currently
- mapped memory, so map in enough more memory to satisfy
- the request. This means we also have to grow the mapped-to
- file by an appropriate amount, since mmap cannot be used
- to extend a file. */
- moveto = PAGE_ALIGN((char *) mdp->breakval + size);
- mapbytes = (char *) moveto - (char *) mdp->top;
- foffset = (char *) mdp->top - (char *) mdp->base;
+ } else if ((char*)mdp->breakval + size > (char*)mdp->top) {
+ /* The request would move us past the end of the currently mapped memory, so map in enough more memory to satisfy
+ the request. This means we also have to grow the mapped-to file by an appropriate amount, since mmap cannot
+ be used to extend a file. */
+ moveto = PAGE_ALIGN((char*)mdp->breakval + size);
+ mapbytes = (char*)moveto - (char*)mdp->top;
+ foffset = (char*)mdp->top - (char*)mdp->base;
if (mdp->fd > 0) {
/* FIXME: Test results of lseek() */
}
}
- /* Let's call mmap. Note that it is possible that mdp->top
- is 0. In this case mmap will choose the address for us.
- This call might very well overwrite an already existing memory mapping
- (leading to weird bugs).
+ /* Let's call mmap. Note that it is possible that mdp->top is 0. In this case mmap will choose the address for us.
+ This call might very well overwrite an already existing memory mapping (leading to weird bugs).
*/
mapto = mmap(mdp->top, mapbytes, PROT_READ | PROT_WRITE,
MAP_PRIVATE_OR_SHARED(mdp) | MAP_IS_ANONYMOUS(mdp) |
if (mdp->top == 0)
mdp->base = mdp->breakval = mapto;
- mdp->top = PAGE_ALIGN((char *) mdp->breakval + size);
+ mdp->top = PAGE_ALIGN((char*)mdp->breakval + size);
result = (void *) mdp->breakval;
- mdp->breakval = (char *) mdp->breakval + size;
+ mdp->breakval = (char*)mdp->breakval + size;
} else {
/* Memory is already mapped, we only need to increase the breakval: */
result = (void *) mdp->breakval;
- mdp->breakval = (char *) mdp->breakval + size;
+ mdp->breakval = (char*)mdp->breakval + size;
}
}
return (result);
#include "mmprivate.h"
-/* Resize the given region to the new size, returning a pointer
- to the (possibly moved) region. This is optimized for speed;
- some benchmarks seem to indicate that greater compactness is
- achieved by unconditionally allocating and copying to a
- new region. This module has incestuous knowledge of the
- internals of both mfree and mmalloc. */
+/* Resize the given region to the new size, returning a pointer to the (possibly moved) region. This is optimized for
+ * speed; some benchmarks seem to indicate that greater compactness is achieved by unconditionally allocating and
+ * copying to a new region. This module has incestuous knowledge of the internals of both mfree and mmalloc. */
void *mrealloc(xbt_mheap_t mdp, void *ptr, size_t size)
{
void *result;
- int type;
- size_t block, blocks, oldlimit;
+ size_t blocks;
+ size_t oldlimit;
/* Only keep real realloc, and reroute hidden malloc and free to the relevant functions */
if (size == 0) {
//printf("(%s)realloc %p to %d...",xbt_thread_self_name(),ptr,(int)size);
if ((char *) ptr < (char *) mdp->heapbase || BLOCK(ptr) > mdp->heapsize) {
- printf
- ("FIXME. Ouch, this pointer is not mine, refusing to proceed (another solution would be to malloc it instead of reallocing it, see source code)\n");
+ printf("FIXME. Ouch, this pointer is not mine, refusing to proceed (another solution would be to malloc "
+ "it instead of reallocing it, see source code)\n");
result = mmalloc(mdp, size);
abort();
return result;
if (size < SMALLEST_POSSIBLE_MALLOC)
size = SMALLEST_POSSIBLE_MALLOC;
- block = BLOCK(ptr);
+ size_t block = BLOCK(ptr);
- type = mdp->heapinfo[block].type;
+ int type = mdp->heapinfo[block].type;
switch (type) {
case MMALLOC_TYPE_HEAPINFO: