extern void *mvalloc(void *md, size_t size);
-/* Pick up the current statistics. (see FIXME elsewhere) */
-
-extern struct mstats mmstats(void *md);
-
extern void *mmalloc_attach(int fd, void *baseaddr);
extern void mmalloc_pre_detach(void *md);
extern void *mmalloc_getkey(void *md, int keynum);
-// FIXME: this function is not implemented anymore?
-//extern int mmalloc_errno (void* md);
-
/* return the heap used when NULL is passed as first argument to any mm* function */
extern void *mmalloc_get_default_md(void);
type = mdp->heapinfo[block].busy.type;
switch (type) {
case 0:
- /* Get as many statistics as early as we can. */
- mdp->heapstats.chunks_used--;
- mdp->heapstats.bytes_used -=
- mdp->heapinfo[block].busy.info.block.size * BLOCKSIZE;
- mdp->heapstats.bytes_free +=
- mdp->heapinfo[block].busy.info.block.size * BLOCKSIZE;
-
/* Find the free cluster previous to this one in the free list.
Start searching at the last block referenced; this may benefit
programs with locality of allocation. */
mdp->heapinfo[block].free.prev = i;
mdp->heapinfo[i].free.next = block;
mdp->heapinfo[mdp->heapinfo[block].free.next].free.prev = block;
- mdp->heapstats.chunks_free++;
}
/* Now that the block is linked in, see if we can coalesce it
mdp->heapinfo[block].free.next
= mdp->heapinfo[mdp->heapinfo[block].free.next].free.next;
mdp->heapinfo[mdp->heapinfo[block].free.next].free.prev = block;
- mdp->heapstats.chunks_free--;
}
/* Now see if we can return stuff to the system. */
break;
default:
- /* Do some of the statistics. */
- mdp->heapstats.chunks_used--;
- mdp->heapstats.bytes_used -= 1 << type;
- mdp->heapstats.chunks_free++;
- mdp->heapstats.bytes_free += 1 << type;
-
/* Get the address of the first free fragment in this block. */
prev = (struct list *)
((char *) ADDRESS(block) +
mdp->heapinfo[block].busy.info.block.size = 1;
mdp->heapinfo[block].busy.info.block.busy_size = 0;
- /* Keep the statistics accurate. */
- mdp->heapstats.chunks_used++;
- mdp->heapstats.bytes_used += BLOCKSIZE;
- mdp->heapstats.chunks_free -= BLOCKSIZE >> type;
- mdp->heapstats.bytes_free -= BLOCKSIZE;
-
mfree((void *) mdp, (void *) ADDRESS(block));
} else if (mdp->heapinfo[block].busy.info.frag.nfree != 0) {
/* If some fragments of this block are free, link this
#include "mfree.c"
#include "mmalloc.c"
#include "mmemalign.c"
-#include "mmstats.c"
#include "mrealloc.c"
#include "mvalloc.c"
#include "mmorecore.c"
/* Heapstats */
- int errors = 0;
-
- struct mstats ms1 = mmstats(h1);
- struct mstats ms2 = mmstats(h2);
-
- if(ms1.chunks_used != ms2.chunks_used){
- if(XBT_LOG_ISENABLED(xbt_mm_legacy, xbt_log_priority_debug)){
- XBT_DEBUG("Different chunks allocated by the user : %zu - %zu", ms1.chunks_used, ms2.chunks_used);
- errors++;
- }else{
- return 1;
- }
- }
-
- if(ms1.bytes_used != ms2.bytes_used){
- if(XBT_LOG_ISENABLED(xbt_mm_legacy, xbt_log_priority_debug)){
- XBT_DEBUG("Different byte total of user-allocated chunks : %zu - %zu", ms1.bytes_used, ms2.bytes_used);
- errors++;
- }else{
- return 1;
- }
- }
-
- if(ms1.bytes_free != ms2.bytes_free){
- if(XBT_LOG_ISENABLED(xbt_mm_legacy, xbt_log_priority_debug)){
- XBT_DEBUG("Different byte total of chunks in the free list : %zu - %zu", ms1.bytes_free, ms2.bytes_free);
- errors++;
- }else{
- return 1;
- }
- }
-
- if(ms1.chunks_free != ms2.chunks_free){
- if(XBT_LOG_ISENABLED(xbt_mm_legacy, xbt_log_priority_debug)){
- XBT_DEBUG("Different chunks in the free list : %zu - %zu", ms1.chunks_free, ms2.chunks_free);
- errors++;
- }else{
- return 1;
- }
- }
-
struct mdesc *mdp1, *mdp2;
mdp1 = MD_TO_MDP(h1);
mdp2 = MD_TO_MDP(h2);
- int res = mmalloc_compare_mdesc(mdp1, mdp2, std_heap_addr);
+ int errors = mmalloc_compare_mdesc(mdp1, mdp2, std_heap_addr);
- return ((errors + res ) > 0);
+ return (errors > 0);
}
RESIDUAL(next->next, BLOCKSIZE) >> log;
}
- /* Update the statistics. */
- mdp->heapstats.chunks_used++;
- mdp->heapstats.bytes_used += 1 << log;
- mdp->heapstats.chunks_free--;
- mdp->heapstats.bytes_free -= 1 << log;
} else {
/* No free fragments of the desired size, so get a new block
and break it into fragments, returning the first. */
mdp->heapinfo[block].busy.type = log;
mdp->heapinfo[block].busy.info.frag.nfree = i - 1;
mdp->heapinfo[block].busy.info.frag.first = i - 1;
-
- mdp->heapstats.chunks_free += (BLOCKSIZE >> log) - 1;
- mdp->heapstats.bytes_free += BLOCKSIZE - (1 << log);
- mdp->heapstats.bytes_used -= BLOCKSIZE - (1 << log);
}
} else {
/* Large allocation to receive one or more blocks.
block = mdp->heapinfo[0].free.prev;
mdp->heapinfo[block].free.size += (blocks - lastblocks);
- mdp->heapstats.bytes_free += (blocks - lastblocks) * BLOCKSIZE;
continue;
}
result = morecore(mdp, blocks * BLOCKSIZE);
mdp->heapinfo[block].busy.type = 0;
mdp->heapinfo[block].busy.info.block.size = blocks;
mdp->heapinfo[block].busy.info.block.busy_size = size;
- mdp->heapstats.chunks_used++;
- mdp->heapstats.bytes_used += blocks * BLOCKSIZE;
return (result);
}
}
= mdp->heapinfo[block].free.prev;
mdp->heapinfo[mdp->heapinfo[block].free.prev].free.next
= mdp->heapindex = mdp->heapinfo[block].free.next;
- mdp->heapstats.chunks_free--;
}
mdp->heapinfo[block].busy.type = 0;
mdp->heapinfo[block].busy.info.block.size = blocks;
mdp->heapinfo[block].busy.info.block.busy_size = size;
- mdp->heapstats.chunks_used++;
- mdp->heapstats.bytes_used += blocks * BLOCKSIZE;
- mdp->heapstats.bytes_free -= blocks * BLOCKSIZE;
}
//printf("(%s) Done mallocing. Result is %p\n",xbt_thread_self_name(),result);fflush(stdout);
return (result);
struct list *prev;
};
-/* Statistics available to the user.
- FIXME: By design, the internals of the malloc package are no longer
- exported to the user via an include file, so access to this data needs
- to be via some other mechanism, such as mmstat_<something> where the
- return value is the <something> the user is interested in. */
-
-struct mstats {
- size_t bytes_total; /* Total size of the heap. */
- size_t chunks_used; /* Chunks allocated by the user. */
- size_t bytes_used; /* Byte total of user-allocated chunks. */
- size_t chunks_free; /* Chunks in the free list. */
- size_t bytes_free; /* Byte total of chunks in the free list. */
-};
-
/* Internal structure that defines the format of the malloc-descriptor.
This gets written to the base address of the region that mmalloc is
managing, and thus also becomes the file header for the mapped file,
malloc_info *heapinfo;
- /* Instrumentation. */
-
- struct mstats heapstats;
-
/* Free list headers for each fragment size. */
/* Free lists for each fragment size. */
+++ /dev/null
-/* Access the statistics maintained by `mmalloc'.
- Copyright 1990, 1991, 1992 Free Software Foundation
-
- Written May 1989 by Mike Haertel.
- Modified Mar 1992 by Fred Fish. (fnf@cygnus.com) */
-
-/* Copyright (c) 2010. The SimGrid Team.
- * All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "mmprivate.h"
-
-/* FIXME: See the comment in mmprivate.h where struct mstats is defined.
- None of the internal mmalloc structures should be externally visible
- outside the library. */
-
-struct mstats mmstats(void *md)
-{
- struct mstats result;
- struct mdesc *mdp;
-
- mdp = MD_TO_MDP(md);
- result.bytes_total = (char *) mdp->top - (char *) mdp;
- result.chunks_used = mdp->heapstats.chunks_used;
- result.bytes_used = mdp->heapstats.bytes_used;
- result.chunks_free = mdp->heapstats.chunks_free;
- result.bytes_free = mdp->heapstats.bytes_free;
- return (result);
-}