Typical Memory Layout sysPhysMemTop() sysMemTop() FREE_RAM_ADRS

Slides:



Advertisements
Similar presentations
Pointers.
Advertisements

Dynamic Allocation and Linked Lists. Dynamic memory allocation in C C uses the functions malloc() and free() to implement dynamic allocation. malloc is.
Dynamic memory allocation
Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
Carnegie Mellon 1 Dynamic Memory Allocation: Basic Concepts : Introduction to Computer Systems 17 th Lecture, Oct. 21, 2010 Instructors: Randy Bryant.
R4 Dynamically loading processes. Overview R4 is closely related to R3, much of what you have written for R3 applies to R4 In R3, we executed procedures.
CS 450 Module R4. R4 Overview Due on March 11 th along with R3. R4 is a small yet critical part of the MPX system. In this module, you will add the functionality.
Dynamic Memory Allocation I Topics Simple explicit allocators Data structures Mechanisms Policies CS 105 Tour of the Black Holes of Computing.
Dynamic Memory Allocation I Topics Basic representation and alignment (mainly for static memory allocation, main concepts carry over to dynamic memory.
Unions The storage referenced by a union variable can hold data of different types subject to the restriction that at any one time, the storage holds data.
Copyright © 2000, Daniel W. Lewis. All Rights Reserved. CHAPTER 9 MEMORY MANAGEMENT.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Note on malloc() and slab allocation CS-502 (EMC) Fall A Note on malloc() and Slab Allocation CS-502, Operating Systems Fall 2009 (EMC) (Slides include.
KERNEL MEMORY ALLOCATION Unix Internals, Uresh Vahalia Sowmya Ponugoti CMSC 691X.
CS1061: C Programming Lecture 21: Dynamic Memory Allocation and Variations on struct A. O’Riordan, 2004, 2007 updated.
COMP 1402 Winter 2009 Tutorial #8 malloc / calloc / realloc.
Managing Memory Static and Dynamic Memory Type Casts Allocating Arrays of Dynamic Size Resizing Block of Memory Returning Memory from a Function Avoiding.
CSCI 171 Presentation 11 Pointers. Pointer Basics.
Growing Arrays in C By: Victoria Tielebein CS 265- Spring 2011.
1 Memory Allocation Professor Jennifer Rexford COS 217.
User-Level Memory Management in Linux Programming
Agenda  Review: pointer & array  Relationship between pointer & array  Dynamic memory allocation.
 Wind River Systems, Inc Chapter - 8 Memory.
CP104 Introduction to Programming Structure II Lecture 32 __ 1 Data Type planet_t and Basic Operations Abstract Data Type (ADT) is a data type combined.
1 Objectives ❏ To understand the relationship between arrays and pointers ❏ To understand the design and concepts behind pointer arithmetic ❏ To write.
Engineering Problem Solving with C Fundamental Concepts Chapter 6 Pointers.
Memory Allocation. Memory A memory or store is required in a computer to store programs (or information or data). Data used by the variables in a program.
Memory allocation CSE 2451 Matt Boggus. sizeof The sizeof unary operator will return the number of bytes reserved for a variable or data type. Determine:
Discussion: Week 3/26. Structs: Used to hold associated data together Used to group together different types of variables under the same name struct Telephone{
The Environment of a UNIX Process. Introduction How is main() called? How are arguments passed? Memory layout? Memory allocation? Environment variables.
Dynamic memory allocation. The process of allocating memory at run time is known as dynamic memory allocation. C have four library functions for allocating.
1 1 Lecture 4 Structure – Array, Records and Alignment Memory- How to allocate memory to speed up operation Structure – Array, Records and Alignment Memory-
Memory Management Memory Areas and their use Memory Manager Tasks:
Unix Process Environment. main Function A C program starts execution with a function called main. The prototype for the main function is: int main (int.
1 Inner Workings of Malloc and Free Professor Jennifer Rexford COS 217.
Pointers Applications
Real-Time Concepts for Embedded Systems Author: Qing Li with Caroline Yao ISBN: CMPBooks.
VxWorks & Memory Management
Pointers and Arrays Beyond Chapter Pointers and Arrays What are the real differences? Pointer Holds the address of a variable Can be pointed.
7. Pointers, Dynamic Memory 20 th September IIT Kanpur 1C Course, Programming club, Fall 2008.
Stack and Heap Memory Stack resident variables include:
Dynamic Memory Allocation The process of allocating memory at run time is known as dynamic memory allocation. C does not Inherently have this facility,
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
© 2004 OPNET Technologies, Inc. All rights reserved. OPNET and OPNET product names are trademarks of OPNET Technologies, Inc. ARMing Apache David Carter.
Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy.
19&20-2 Know how to declare pointer variables. Understand the & (address) and *(indirection) operators. Dynamic Memory Allocation Related Chapter: ABC.
CS 241 Discussion Section (11/17/2011). Outline Review of MP7 MP8 Overview Simple Code Examples (Bad before the Good) Theory behind MP8.
® 14-2 Optional Products 14.1Overview Shared Memory Objects (VxMP) Virtual Memory (VxVMI)
+ Dynamic memory allocation. + Introduction We often face situations in programming where the data is dynamics in nature. Consider a list of customers.
© Oxford University Press All rights reserved. CHAPTER 7 POINTERS.
12/22/ Thread Model for Realizing Concurrency B. Ramamurthy.
 Wind River Systems, Inc Chapter - 7 Intertask Communication.
CNG 140 C Programming (Lecture set 12) Spring Chapter 13 Dynamic Data Structures.
1 Dynamic Memory Allocation. 2 In everything we have done so far, our variables have been declared at compile time. In these slides, we will see how to.
MORE POINTERS Plus: Memory Allocation Heap versus Stack.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Linked Lists Outline Introduction Self-Referential Structures.
 Wind River Systems, Inc Chapter - 15 Optional Products.
DYNAMIC MEMORY ALLOCATION. Disadvantages of ARRAYS MEMORY ALLOCATION OF ARRAY IS STATIC: Less resource utilization. For example: If the maximum elements.
Arrays and Pointers (part 1) CSE 2031 Fall July 2016.
Embedded Real-Time Systems
Checking Memory Management
Dynamic Memory Allocation
CSC215 Lecture Memory Management.
Dynamic Memory Allocation
Memory Allocation CS 217.
Review & Lab assignments
Pointers The C programming language gives us the ability to directly manipulate the contents of memory addresses via pointers. Unfortunately, this power.
C Programming Lecture-8 Pointers and Memory Management
Chapter 10-1: Dynamic Memory Allocation
Chapter 9: Pointers and String
Presentation transcript:

Typical Memory Layout sysPhysMemTop() sysMemTop() FREE_RAM_ADRS RAM_LOW_ADRS LOCAL_MEM_LOCAL_ADRS Many of the above macros are parameters for the component /hardware/memory/BSP Memory Configuration. The macro LOCAL_MEM_LOCAL_ADRS is the address of the start of RAM on your board. It is typically equal to 0. The macro RAM_LOW_ADRS is the address where VxWorks is loaded. FREE_RAM_ADRS is the address of the end of the VxWorks system image. Most BSP’s define sysPhysMemTop( ) as the top of physical RAM; sysMemTop( ) is always the top of the system memory pool. The difference is the configurable constant USER_RESERVED_MEM. Low memory often contains the interrupt vector table, and space for the boot line and an exception message. More detailed memory maps are available in the Programmer’s Guide appendix for your CPU architecture.

Target Server Memory Pool A pool of memory on the target reserved for use by the Tornado tools: Dynamic loading of object modules. Passing string arguments to tasks spawned on target. Creation of variables from WindSh. The target server manages the pool, keeping overhead such as block lists on the host. The initial size of the target server memory pool is configured by WDB_POOL_SIZE. The default is 1/16 of sysMemTop( ) - FREE_RAM_ADRS. Additional memory is silently allocated from the system memory pool if needed. The target server memory pool helps to reduce memory fragmentation on the target. WDB_POOL_SIZE is not a component parameter, but can be configured .../target/config/comps/src/configAll.h.

System Memory Pool Used for dynamic memory allocation in programs: malloc( ). Creating tasks (stack and TCB). VxWorks memory requests. Initialized at system start-up. Can modify USER_RESERVED_MEM to reserve memory for application-specific use. May need to modify sysPhysMemTop( ) (or just LOCAL_MEM_SIZE) when adding memory to your board. Check your BSP documentation. To add off-board memory: void memAddToPool (pPool, poolSize) pPool must be the local address of the memory. USER_RESERVED_MEM, a parameter for the component /hardware/memory/BSP Memory Configuration, specifies how many bytes below the top of physical RAM the system memory pool ends. The default value is 0. The local address of off-board memory on a VME bus can be computed as follows: Read hardware doc to find the VMEbus address of the memory. Use sysBusToLocalAdrs( ) to compute the local address corresponding to the VMEbus address. Adding off-board memory to the system memory pool is usually a bad idea. A subsequent call to malloc() will give you a block of either on- board or off-board memory, leaving uncertainty about the worst-case access time to this block. Instead, consider creating a separate partition for this off-board memory.

Allocating/Releasing Memory To dynamically allocate memory: void *malloc (nBytes) Returns a pointer to the newly allocated memory or NULL on error. Uses first-fit algorithm. Free memory is stored in a linked list. Some (small) overhead for each malloc( ). To release allocated memory: void free (ptr) Adjacent blocks are coalesced. For 68k boards the overhead for malloc( ) is: 8 byte header per malloc( ). Always rounds up to a 4 byte boundary. When block is free, 8 bytes within body may be used for free list links. Minimum block size is 8 bytes (header) + 8 bytes (free list links) = 16 bytes. See the memPartLib man page for more information about the overhead for your architecture.

void memOptionsSet (options) Debugging Options Default malloc( ) debugging: If request too large, log an error message. Default free( ) debugging: Check block for consistency. If corrupted: suspend task, log error message. Can change default debugging options with: void memOptionsSet (options) Options can be: + MEM_ALLOC_ERROR_LOG_FLAG - MEM_ALLOC_ERROR_SUSPEND_FLAG + MEM_BLOCK_CHECK + MEM_BLOCK_ERROR_LOG_FLAG + MEM_BLOCK_ERROR_SUSPEND_FLAG Bitwise OR options together to get more than one. Setting any MEM_BLOCK_XXX option automatically causes the MEM_BLOCK_CHECK option to be set.

Examining Memory Use the Browser. Enter the memory partition ID in the Show box. System Memory Pool Size Currently Allocated Free Blocks Total Free List The VxWorks system memory partition ID is memSysPartId. Total target memory usage within both the target server pool and the system memory pool is displayed with bar graphs in the browser.

Additional System Memory Management Routines void * calloc (nElems, size) Allocate zeroed memory for an array. void * realloc (ptr, newSize) Resize an allocated block. The block may be moved. int memFindMax( ) Returns the size of the largest free block in system memory. A possible race condition can arise between calls to memFindMax( ) and malloc( ).

Fine Tuning For fast, deterministic allocation of fixed size buffers, use message queues instead of malloc( ). Create a library “bufferLib” of routines for managing your buffers. For example: /* pBlock points to memory for array of buffers (NULL => malloc) */ /* Put addresses of buffers in a message queue */ /* Returned BUF_ID contains the newly created msgQId */ BUF_ID bufCreate (pBlock, numBufs, bufSize); /* Calls msgQReceive() to get next buffer */ void *bufGet (bufId); /* Calls msgQSend() to return the buffer */ void bufReturn (bufId, ptr); Alternative: Implement your own fixed-size block allocator, guarding the block free-list with a mutex, taskLock(), or intLock().

Generic Partition Manager VxWorks provides low-level routines to create and manipulate alternate memory pools. High-level routines like malloc( ) and free( ) call these lower level routines, specifying the system memory pool. Application may use alternate memory partitions to reduce fragmentation. Application may use alternate memory partitions to manage memory with different properties.

Creating a Memory Partition PART_ID memPartCreate (pPool, size) pPool Pointer to memory for this partition. size Size of memory partition in bytes. Returns a partition id (PART_ID), or NULL on error. The memory for this partition (pPool) may be taken from: A separate memory board. A block allocated from the system memory partition. The top of the CPU board’s RAM. PART_ID, defined in memLib.h, is a handle to the memory partition being created. Specify nonzero USER_RESERVED_MEM to reserve memory at the top of RAM for your application’s exclusive use.

Managing Memory Partitions System partition management routines call routines listed below, specifying the PART_ID as memSysPartId. Generic System Memory Pool memPartAlloc( ) malloc( ) memPartFree( ) free( ) memPartShow( ) memShow( ) memPartAddToPool( ) memAddToPool( ) memPartOptionsSet( ) memOptionsSet( ) memPartRealloc( ) realloc( ) memPartFindMax( ) memFindMax( )

Example Creating a Memory Partition ->partId =memPartCreate(pMemory,100000) new symbol “partId” added to symbol table. partId = 0x23ff318: value = 37745448 = 0x23ff328 = partId + 0x10 ->ptr=memPartAlloc(partId,200) new symbol “ptr” added to symbol table. ptr = 0x23ff2ec: value = 37652632 = 0x23e8898 ->show partId status bytes blocks ave block max block ------ ------ ------- --------- ----------- current free 99776 1 99776 99776 alloc 208 1 208 - cumulative alloc 208 1 208 - Partition information can also be obtained using the memory-partition browser.

Summary Standard C routines are used for dynamic memory allocation. To configure the system memory pool: Modify sysPhysMemTop( ). Specify USER_RESERVED_MEM. Call memAddToPool( ). For fast, deterministic allocation of fixed size buffers, use message queues instead of malloc( ). Create separate memory partition for off-board memory, or to help reduce fragmentation.