Skip to content

Commit

Permalink
Hook up OS.MM.Heap_pages.{total,used}
Browse files Browse the repository at this point in the history
The total number of heap pages is computed from the Solo5 heap size
(si->heap_size) and the number of used pages is computed from the
result returned by dlmalloc's malloc_footprint().

Note that mallinfo() is deliberately not used in the latter case as that
call is expensive and existing unikernels rely on this interface being
cheap to call.
  • Loading branch information
mato committed Oct 7, 2020
1 parent 94372da commit ab32449
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
20 changes: 20 additions & 0 deletions lib/bindings/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "hypercall.h"
#include "xen/hvm/params.h"

#include <stdlib.h>

#define CAML_NAME_SPACE
#include <caml/mlvalues.h>
#include <caml/memory.h>
Expand All @@ -29,6 +31,7 @@

static char *unused_argv[] = { "mirage", NULL };
static const char *solo5_cmdline = "";
static size_t solo5_heap_size;

CAMLprim value
mirage_xen_get_cmdline(value v_unit)
Expand Down Expand Up @@ -104,11 +107,28 @@ mirage_xen_get_xenstore_page(value v_unit)
(void *)(raw_pfn << PAGE_SHIFT), PAGE_SIZE));
}

/* @@noalloc */
CAMLprim value
mirage_xen_heap_get_pages_total(value v_unit)
{
return Val_long(solo5_heap_size / PAGE_SIZE);
}

extern size_t malloc_footprint(void);

/* @@noalloc */
CAMLprim value
mirage_xen_heap_get_pages_used(value v_unit)
{
return Val_long(malloc_footprint() / PAGE_SIZE);
}

extern void _nolibc_init(uintptr_t, size_t);

int solo5_app_main(const struct solo5_start_info *si)
{
solo5_cmdline = si->cmdline;
solo5_heap_size = si->heap_size;
_nolibc_init(si->heap_start, si->heap_size);
gnttab_init();
caml_startup(unused_argv);
Expand Down
12 changes: 0 additions & 12 deletions lib/bindings/mm_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@
#include <caml/alloc.h>
#include <caml/memory.h>

CAMLprim value
stub_heap_get_pages_total(value unit) // noalloc
{
return Val_long(0);
}

CAMLprim value
stub_heap_get_pages_used(value unit) // noalloc
{
return Val_long(0);
}

/* expose the virt_to_mfn macro for converting a "virtual address number"
* (AKA "a pointer") to a machine frame number
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/mM.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Heap_pages = struct
external total: unit -> int = "stub_heap_get_pages_total" [@@noalloc]
external used: unit -> int = "stub_heap_get_pages_used" [@@noalloc]
external total: unit -> int = "mirage_xen_heap_get_pages_total" [@@noalloc]
external used: unit -> int = "mirage_xen_heap_get_pages_used" [@@noalloc]
end

0 comments on commit ab32449

Please sign in to comment.