Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: IOMalloc question



Hi, Garth:

Thanks for your help. I checked all the interface supported by IOMemoryDescriptor
but I cannot find one that can work for me. I think I need to give you more details.


I am writing a filter driver. In the read/write routines, I got a IOMemoryDescriptor
as input but I really need another buffer of the same size to do some processing.


So this is what I do roughly:

read(client, byteStart, buffer, completion)
{
IOByteCount n = buffer->getLength();
void *mem = IOMalloc(n);
IOMemoryDescriptor *myBuffer = IOMemoryDescriptor::withAddress(mem, n, ....);



I can understand that IOMalloc can fail so I add some code like this:

if <failed> queue the request ....

Then in the IO completion code, I added:

.....
   IOFree(mem);
  <process the queue - try IOMalloc again ...>

However, even right after the memory is freed, the IOMalloc still fails (not 100%)!!!
After some time (real quick), I have no more outstanding IO but I still have some
queued request waiting for memory. The calling process (XTune) is now hung,
waiting for IO completion. I even add a polling thread to wake up the request
queue and try IOMalloc but it will still fail. Who is to blame?


I thought about reusing the memory buffer but I cannot assume that the sizes are all the same
and it will be hard to manage them this way. It is the kernel's job to manage memory.


I do not know if returning kIOReturnNoMemory immediately (the first failure)
is a good idea??   That might break many things or even panic if the caller
cannot handle IO error.

Please give me you suggestion.


Tony




From: Garth Cummings <email@hidden>
Reply-To: Darwin Drivers Mailing List <email@hidden>
To: Tony Wong <email@hidden>
CC: Darwin Drivers Mailing List <email@hidden>
Subject: Re: IOMalloc question
Date: Tue, 8 May 2007 15:39:44 -0700

Hi Tony,

On Apr 30, 2007, at 11:58 AM, Tony Wong wrote:


I am using IOMalloc in a media filter driver to allocate buffer for each read, write request.
Data is copied around.


Everything works fine until I ran a heavy read test. After a few fairly large read requests
(512K size), IOMalloc fails. That's fine. I queue the request up and then the driver retries
the IOMalloc in the IOCompletion routine when some previous IOMalloc'ed buffer is freed.
It works a couple times and then it gets stuck. Then I added some timeout events to
do the IOMalloc periodically but it just fails. The test hangs.


I also have the impression that IOMalloc() will block until memory is available. When does it
ever return NULL? What does that mean?


Is there other way to allocate memory (I am assuming that IOMalloc has a limited pool??)?

IOMalloc is only for small temporary allocations. Otherwise try IOBufferMemoryDescriptor.


--gc
____________________________________________________________________
Garth Cummings					 email@hidden
Sr. Software Engineer
Apple Developer Technical Support

<http://developer.apple.com/technicalsupport>

WWDC 2007 ?June 11-15 ?Moscone West ?San Francisco, CA
<http://developer.apple.com/wwdc/>



_________________________________________________________________
Like the way Microsoft Office Outlook works? You’ll love Windows Live Hotmail. http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_outlook_0507


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-drivers mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-drivers/email@hidden

This email sent to email@hidden
References: 
 >Re: IOMalloc question (From: Garth Cummings <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.