• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Embedded Software » Linux » Linux forum » CMEM memory fragmentation with heap allocation - is it an issue, if all memory gets freed ?
Share
Linux
  • Forum
Options
  • Subscribe via RSS

Forums

CMEM memory fragmentation with heap allocation - is it an issue, if all memory gets freed ?

This question is answered
Mike Whittaker
Posted by Mike Whittaker
on May 18 2012 04:26 AM
Intellectual410 points

The documentation advocates pool allocation for production systems to avoid fragmentation.

However, if using Heap allocation (ie. no pools) if all the memory allocations are performed by just one process, which gets restarted (and hence all buffers automatically freed) - is fragmentation a problem, since CMEM gets all its memory back each time ?

It would be more flexible to omit pool definitions and just let the application request what it needed each time.

But if Heap-based usage always gave rise to fragmentation despite all the CMEM meory being freed from time to time, then it would be necessary to continue to use Pools.

cmem pool heap
Report Abuse
  • Reply
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
All Replies
  • Robert Tivy
    Posted by Robert Tivy
    on May 18 2012 15:46 PM
    Verified Answer
    Verified by Mike Whittaker
    Genius11090 points

    If all CMEM heap memory allocations are freed (either directly, or indirectly as a result of process exit) then there will be no fragmentation.  The CMEM heap allocator coalesces (joins) free blocks as you free them.  For a fresh system, CMEM's heap starts with one big free block, and after all allocated blocks are freed back to the system, there will once again be one big free block.

    CMEM's heap is essentially a port of SysBios's HeapMem module, but without all the configurability or general usage, so documentation about the dynamics of the HeapMem module also apply to CMEM's implementation.

    Regards,

    - Rob

     

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Mike Whittaker
    Posted by Mike Whittaker
    on May 22 2012 05:44 AM
    Intellectual410 points

    Well, having dropped the pools definitions from the previously working insmod, we now see:

    CMEM Error: getPool: failed to get a pool fitting a size xxxx

    which suggests that making all CMEM allocations from the heap is not working as expected ...

    [Edit]

    OK, I now need to use useHeapIfPoolUnavailable=[0|1] !!

    Still getting CMEM Error: allocPool: ioctl CMEM_IOCALLOC failed from pool 0: -1

    from my BufTab_create()

    and CMEMK Error: ALLOC: invalid pool (0) passed.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Robert Tivy
    Posted by Robert Tivy
    on May 22 2012 13:42 PM
    Genius11090 points

    Mike Whittaker

    OK, I now need to use useHeapIfPoolUnavailable=[0|1] !!

    That's right.

    Mike Whittaker

    Still getting CMEM Error: allocPool: ioctl CMEM_IOCALLOC failed from pool 0: -1

    from my BufTab_create()

    and CMEMK Error: ALLOC: invalid pool (0) passed.

    The only way I can see the above situation happening is if the code (BufTab_create()) is explicitly calling CMEM_allocPool() (or CMEM_allocPool2()).  The "heap fallback" feature is available only when CMEM_alloc() (or CMEM_alloc2()) is called with params->type == CMEM_POOL.

    I'm not sure if you can confirm this or not, you'd need to know the internals of BufTab_create(), but if you do have access to the source code, check if it is calling CMEM_allocPool().  Or, you could enable user-level debug and see for yourself, by putting this in your .cfg file:
        var CMEM = xdc.useModule('ti.sdo.linuxutils.cmem.CMEM');
        CMEM.debug = true;

    Also, enabling debug for the kernel module will allow useful info to be printed on the console.  To do so, rebuild cmemk.ko for "debug":
        % cd <linuxutils>/packages/ti/sdo/linuxutils/cmem/src/module
        % make debug

    Regards,

    - Rob

     

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Mike Whittaker
    Posted by Mike Whittaker
    on May 23 2012 05:01 AM
    Intellectual410 points

    Hmm, that's a bit of a pain - stop using the Pool feature explicitly only to find that the standard API forces its use in any case -  seems to defeat the object a bit :-(

    Could do with a NoReallyUseHeapIfPoolUnavailableIDoMeanThatSoDoItThanks=1

    Looks like the real flag doesn't actually do what it says on the tin.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Chris Richardson77843
    Posted by Chris Richardson77843
    on May 23 2012 10:55 AM
    Intellectual315 points

    Hi Mike,

    I'm not sure what platform you are using, or what version of the DVSDK, but on DM36x using DVSDK 4.02.00.06 (linuxutils 2.26.01.02) we are using the CMEM heap without issue.  We use it to allocate video buffers with BufTab_create, as well as other buffers we use for DMA transfers.  I can attest that the heap flag really does work in this environment.  Have you set the memory params on the buffer attributes passed to BufTab_create to the defaults or have you set them explicitly?

    Chris

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Robert Tivy
    Posted by Robert Tivy
    on May 23 2012 15:27 PM
    Genius11090 points

    Mike Whittaker

    Hmm, that's a bit of a pain - stop using the Pool feature explicitly only to find that the standard API forces its use in any case -  seems to defeat the object a bit :-(

    Could do with a NoReallyUseHeapIfPoolUnavailableIDoMeanThatSoDoItThanks=1

    Looks like the real flag doesn't actually do what it says on the tin.

    :) That must be part of the Siri API set?

    I believe that the CMEM_allocPool() API has been deprecated, and was deprecated before this "heap fallback" feature was implemented, so it didn't get enhanced with the feature.

    If you, or code that you call, calls CMEM_alloc() (or CMEM_alloc2(), the block-based version) then this heap fallback feature does work.

    Were you able to see CMEM debug output at all?  Since I don't know your code I'm still actually guessing as to the root cause of your issue.  If your issue is not due to explicit calls to CMEM_allocPool() then I would need to investigate elsewhere.

    Regards,

    - Rob

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Mike Whittaker
    Posted by Mike Whittaker
    on May 25 2012 05:21 AM
    Intellectual410 points

    Thanks for your responses chaps - will update this when this issue gets another time-slice for investigation, until when the pools will remain ...

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use