[Barrelfish-users] Fwd: How to reclaim the memory allocated by frame_alloc?

Shi Jinghao (史经浩) jhshi at cs.hku.hk
Tue Mar 27 15:27:47 CEST 2012


Just realize that I sent the mail using gmail, which seems be filtered by
this maillist. Please ignore this
if you've seen it.

Regards,
Jinghao

---------- Forwarded message ----------
From: Shi Jinghao <jhshi89 at gmail.com>
Date: Tue, Mar 27, 2012 at 9:23 PM
Subject: How to reclaim the memory allocated by frame_alloc?
To: barrelfish-users at lists.inf.ethz.ch


Hi,

I need to send message between cores in barrelfish (X86_32). And somehow I
decide to send the capability
of a frame that contains the message, since the message will have variable
size. And I was wondering what's
the proper way to reclaim the message frame when it's useless.

I create a message frame like this (details like error checking
are omitted, also for simplicity, assume message
size is fixed (MSG_SIZE)):

    // allocate a frame capability
    struct capref* msgcap = (struct capref*) malloc (sizeof(struct capref));
    frame_alloc(msgcap, MSG_SIZE, NULL);

    // map to my address space so I can fill the message body
    struct my_message* msg;
    vspace_map_one_frame_attr((void**)&msg, MSG_SIZE, *msgcap,
VREGION_FLAGS_READ_WRITE, NULL, NULL);

Then I send the frame cap to another process (on a different core).

On receiver side, I get the message like this:

    struct my_message* msg;
    vspace_map_one_frame_attr(&msg, MSG_SIZE, msgcap,
VREGION_FLAGS_READ_WRITE, NULL, NULL);

However, how am I supposed to reclaim the message? Based on my
understanding, my current try is:

    // on sender side
    cap_revoke(*msgcap);
    cap_destroy(*msgcap);
    free(msgcap);  // msgcap is allocated by malloc
    vspace_unmap(msg);

    // on receiver side
    vspace_unmap(msg);

But I don't know if this is the right way to do it. (Though no explicit
problem occurs until now). Any suggestions on this?

PS: on receiver side, vspace_map_on_frame_attr won't allocate any new
memory, right? So after this, sender and receiver
will share the same physical memory. Please clarify if my understanding is
right.

Thanks for your reading.

Regards,
Jinghao
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.inf.ethz.ch/pipermail/barrelfish-users/attachments/20120327/77f13d84/attachment.html 


More information about the Barrelfish-users mailing list