View topic - Resource Manager: Avoid extra copy in io_write

Resource Manager: Avoid extra copy in io_write

For discussion of realtime and/or embedded programming.

Resource Manager: Avoid extra copy in io_write

Postby garg.vineet1 » Tue Oct 12, 2010 4:38 am

Hi All

I am using a resource manager to feed packets to my network driver. However, in transmit side I am having to perform a
full extra copy of the frame due to problem mentioned below. Please help me in understanding this situation better.

QNX documentation mentions following about handling io_write message while writing a resource manager:

buf = (char *) malloc(msg->i.nbytes + 1);
if (buf == NULL)

* Reread the data from the sender's message buffer.
* We're not assuming that all of the data fit into the
* resource manager library's receive buffer.

resmgr_msgread(ctp, buf, msg->i.nbytes, sizeof(msg->i));
buf [msg->i.nbytes] = '\0'; /* just in case the text is not NULL terminated */
printf ("Received %d bytes = '%s'\n", msg -> i.nbytes, buf);

I want to understant the importance of resmgr_msgread API here and the comment above it.

I need to write the packet to the SRAM of a device which is memory mapped into my process (resource manager). However,
If I pass the pointer to mapped memory directly into resmgr_msgread, it fails with errno ESRVRFAULT.

This now requires me to pass a local buffer to get the data from client and then copy it again into memory mapped space
in device SRAM causing performance issues under load.

Please help me optimize performance of my system by removing this additional copy.

New Member
Posts: 1
Joined: Fri Apr 24, 2009 12:16 pm

RE: Resource Manager: Avoid extra copy in io_write

Postby mario » Tue Oct 12, 2010 11:44 am

The extra copy is probably not the issue here, it`s the malloc. If possible try to optimize that by reusing the same memory space and only growing it if needed.

That being said if you get an ESRVFAULT when callsing resmgr_msgread it`s because your pointer is not pointing to valide memory, or that the size specified is too small for the specified memory block. It`s basically a SIGSEGV.
Last edited by mario on Tue Oct 12, 2010 1:08 pm, edited 1 time in total.
QNX Master
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

RE: Resource Manager: Avoid extra copy in io_write

Postby maschoen » Tue Oct 12, 2010 1:08 pm

It sounds like (maybe, the original question is very unclear) you want to know why you can't move data between two processes using a pointer, but instead have to copy the data itself?

If so, you should understand that in most circumstances, a pointer in one process is meaningless in another. There are two exceptions I can think of. 1) You are passing data between two threads in the same process. 2) The data is in shared memory that you have requested be mapped to the same location.

If you really need this type of performance, I recommend using offsets into a shared memory segment.
However, unless you are using a Gigabit network, you might want to do a little order of magnitude calculation as to whether eliminating a copy will help all that much.
QNX Master
Posts: 2681
Joined: Wed Jun 25, 2003 5:18 pm

Return to Realtime and Embedded

Who is online

Users browsing this forum: No registered users and 4 guests