Exemple #1
0
void
erts_cleanup_messages(ErtsMessage *msgp)
{
    ErtsMessage *mp = msgp;
    while (mp) {
	ErtsMessage *fmp;
	ErlHeapFragment *bp;
	if (ERTS_SIG_IS_EXTERNAL_MSG(mp)) {
	    if (is_not_immed(ERL_MESSAGE_TOKEN(mp))) {
		bp = (ErlHeapFragment *) mp->data.dist_ext->ext_endp;
		erts_cleanup_offheap(&bp->off_heap);
	    }
	    if (mp->data.dist_ext)
		erts_free_dist_ext_copy(mp->data.dist_ext);
	}
        else {
	    if (ERTS_SIG_IS_INTERNAL_MSG(mp)
                && mp->data.attached != ERTS_MSG_COMBINED_HFRAG) {
		bp = mp->data.heap_frag;
            }
	    else {
                mp->data.attached = ERTS_MSG_COMBINED_HFRAG;
		bp = mp->hfrag.next;
		erts_cleanup_offheap(&mp->hfrag.off_heap);
	    }
	    if (bp)
		free_message_buffer(bp);
	}
	fmp = mp;
	mp = mp->next;
	erts_free_message(fmp);
    }
}
Exemple #2
0
Sint
erts_move_messages_off_heap(Process *c_p)
{
    int reds = 1;
    int i;
    ErtsMessage *msgq[] = {c_p->sig_qs.first, c_p->sig_qs.cont};
    /*
     * Move all messages off heap. This *only* occurs when the
     * process had off heap message disabled and just enabled
     * it...
     */

    reds += erts_proc_sig_privqs_len(c_p) / 10;

    ASSERT(erts_atomic32_read_nob(&c_p->state)
	   & ERTS_PSFLG_OFF_HEAP_MSGQ);
    ASSERT(c_p->flags & F_OFF_HEAP_MSGQ_CHNG);

    for (i = 0; i < sizeof(msgq)/sizeof(msgq[0]); i++) {
        ErtsMessage *mp;
        for (mp = msgq[i]; mp; mp = mp->next) {
            Uint msg_sz, token_sz;
#ifdef USE_VM_PROBES
            Uint utag_sz;
#endif
            Eterm *hp;
            ErlHeapFragment *hfrag;

            if (!ERTS_SIG_IS_INTERNAL_MSG(mp))
                continue;

            if (mp->data.attached)
                continue;

            if (is_immed(ERL_MESSAGE_TERM(mp))
#ifdef USE_VM_PROBES
                && is_immed(ERL_MESSAGE_DT_UTAG(mp))
#endif
                && is_not_immed(ERL_MESSAGE_TOKEN(mp)))
                continue;

            /*
             * The message refers into the heap. Copy the message
             * from the heap into a heap fragment and attach
             * it to the message...
             */
            msg_sz = size_object(ERL_MESSAGE_TERM(mp));
#ifdef USE_VM_PROBES
            utag_sz = size_object(ERL_MESSAGE_DT_UTAG(mp));
#endif
            token_sz = size_object(ERL_MESSAGE_TOKEN(mp));

            hfrag = new_message_buffer(msg_sz
#ifdef USE_VM_PROBES
                                       + utag_sz
#endif
                                       + token_sz);
            hp = hfrag->mem;
            if (is_not_immed(ERL_MESSAGE_TERM(mp)))
                ERL_MESSAGE_TERM(mp) = copy_struct(ERL_MESSAGE_TERM(mp),
                                                   msg_sz, &hp,
                                                   &hfrag->off_heap);
            if (is_not_immed(ERL_MESSAGE_TOKEN(mp)))
                ERL_MESSAGE_TOKEN(mp) = copy_struct(ERL_MESSAGE_TOKEN(mp),
                                                    token_sz, &hp,
                                                    &hfrag->off_heap);
#ifdef USE_VM_PROBES
            if (is_not_immed(ERL_MESSAGE_DT_UTAG(mp)))
                ERL_MESSAGE_DT_UTAG(mp) = copy_struct(ERL_MESSAGE_DT_UTAG(mp),
                                                      utag_sz, &hp,
                                                      &hfrag->off_heap);
#endif
            mp->data.heap_frag = hfrag;
            reds += 1;
        }
    }

    return reds;
}