Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of framagit.org:simgrid/simgrid
[simgrid.git] / src / xbt / mmalloc / mm_interface.c
1 /* External interface to a mmap'd malloc managed region. */
2
3 /* Copyright (c) 2012-2023. The SimGrid Team. All rights reserved.          */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 /* Copyright 1992, 2000 Free Software Foundation, Inc.
9
10    Contributed by Fred Fish at Cygnus Support.   fnf@cygnus.com
11
12    This file is part of the GNU C Library.
13
14    The GNU C Library is free software; you can redistribute it and/or
15    modify it under the terms of the GNU Library General Public License as
16    published by the Free Software Foundation; either version 2 of the
17    License, or (at your option) any later version.
18
19    The GNU C Library is distributed in the hope that it will be useful,
20    but WITHOUT ANY WARRANTY; without even the implied warranty of
21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22    Library General Public License for more details.
23
24    You should have received a copy of the GNU Library General Public
25    License along with the GNU C Library; see the file COPYING.LIB.  If
26    not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27    Boston, MA 02111-1307, USA.  */
28
29 #include <fcntl.h> /* After sys/types.h, at least for dpx/2.  */
30 #include <string.h>
31 #include <sys/stat.h>
32 #include <sys/types.h>
33
34 #include "mmprivate.h"
35
36 // This is the underlying implementation of mmalloc_get_bytes_used_remote.
37 // Is it used directly to evaluate the bytes used from a different process.
38 size_t mmalloc_get_bytes_used_remote(size_t heaplimit, const malloc_info* heapinfo)
39 {
40   int bytes = 0;
41   for (size_t i = 0; i < heaplimit; ++i) {
42     if (heapinfo[i].type == MMALLOC_TYPE_UNFRAGMENTED) {
43       if (heapinfo[i].busy_block.busy_size > 0)
44         bytes += heapinfo[i].busy_block.busy_size;
45     } else if (heapinfo[i].type > 0) {
46       for (size_t j = 0; j < (size_t)(BLOCKSIZE >> heapinfo[i].type); j++) {
47         if (heapinfo[i].busy_frag.frag_size[j] > 0)
48           bytes += heapinfo[i].busy_frag.frag_size[j];
49       }
50     }
51   }
52   return bytes;
53 }