Yet Another Memory Manager

Slides:



Advertisements
Similar presentations
KERNEL MEMORY ALLOCATION Unix Internals, Uresh Vahalia Sowmya Ponugoti CMSC 691X.
Advertisements

Unconstrained UVM SystemVerilog Performance You may add your company logo to this page, ONLY Presented by Wes Queen Verifcation Manager IBM.
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
Memory Management Memory Areas and their use Memory Manager Tasks:
Memory Management A memory manager should take care of allocating memory when needed by programs release memory that is no longer used to the heap. Memory.
Harvard University Oracle Database Administration Session 5 Data Storage.
1 Data Structures Data Structures Topic #2. 2 Today’s Agenda Data Abstraction –Given what we talked about last time, we need to step through an example.
E.G.M. PetrakisHashing1 Hashing on the Disk  Keys are stored in “disk pages” (“buckets”)  several records fit within one page  Retrieval:  find address.
Memory Allocation CS Introduction to Operating Systems.
Real-Time Concepts for Embedded Systems Author: Qing Li with Caroline Yao ISBN: CMPBooks.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Purpose  This training course describes how to configure the the C/C++ compiler options.
Dynamic Partition Allocation Allocate memory depending on requirements Partitions adjust depending on memory size Requires relocatable code –Works best.
EE4E. C++ Programming Lecture 1 From C to C++. Contents Introduction Introduction Variables Variables Pointers and references Pointers and references.
C++ for Engineers and Scientists Second Edition Chapter 6 Modularity Using Functions.
Chapter 6: User-Defined Functions
ICS 145B -- L. Bic1 Project: Main Memory Management Textbook: pages ICS 145B L. Bic.
Optimization of Verification Effort using Reusable Sequence Collection Dipesh Handa Gaurav Chugh Gaurav Minda Kumar Rajeev Ranjan.
Copyright © Curt Hill Generic Classes Template Classes or Container Classes.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
1 Advanced Memory Management Techniques  static vs. dynamic kernel memory allocation  resource map allocation  power-of-two free list allocation  buddy.
CE Operating Systems Lecture 17 File systems – interface and implementation.
SVA Encapsulation in UVM enabling phase and configuration aware assertions by Mark Litterick Verification Consultant Verilab GmbH, Munich, Germany.
Chapter 7 - Functions. Functions u Code group that performs single task u Specification refers to what goes into and out of function u Design refers to.
LINKED LISTS.
DYNAMIC MEMORY ALLOCATION. Disadvantages of ARRAYS MEMORY ALLOCATION OF ARRAY IS STATIC: Less resource utilization. For example: If the maximum elements.
Procedures Procedures are very important for writing reusable and maintainable code in assembly and high-level languages. How are they implemented? Application.
Disk Cache Main memory buffer contains most recently accessed disk sectors Cache is organized by blocks, block size = sector’s A hash table is used to.
CS212: Object Oriented Analysis and Design
Chapter 9: Value-Returning Functions
Inheritance Chapter 7 Inheritance Basics Programming with Inheritance
Working with Data Blocks and Frames
Memory Management Memory Areas and their use Memory Manager Tasks:
Virtual memory.
Programming with ANSI C ++
User-Written Functions
Chapter 2 Memory and process management
Chapter 7: User-Defined Functions II
Programming with ANSI C ++
CS 215 Final Review Ismail abumuhfouz Fall 2014.
Partitioned Memory Allocation
Chapter 3: Using Methods, Classes, and Objects
Memory Management Memory Areas and their use Memory Manager Tasks:
Word Processing.
Introduction to Computers
Krishnan Balakrishnan, Courtney Fricano, and Kaushal Modi
Main Memory Management
This pointer, Dynamic memory allocation, Constructors and Destructor
– Introduction to Object Technology
C++ for Engineers and Scientists Second Edition
Introduction to Linked Lists
Optimizing Malloc and Free
CS Introduction to Operating Systems
Object Oriented Programming COP3330 / CGS5409
Introduction to Abstract Data Types
Machine Independent Features
Yet Another Memory Manager
6 Chapter Functions.
Dr. Bhargavi Dept of CS CHRIST
Classes and Objects.
Selection Insertion and Merge
Effective and Efficient memory Protection Using Dynamic Tainting
Linked Lists Chapter 4.
Chapter 14: Protection.
Data Structures & Algorithms
Standard Template Library
Memory Management Memory Areas and their use Memory Manager Tasks:
Standard Template Library
SPL – PS3 C++ Classes.
Presentation transcript:

Yet Another Memory Manager YAMM Yet Another Memory Manager Ionut Tolea AMIQ Consulting June 23, 2016 Munich, Germany

Agenda Theory Comparison with UVM_MAM Examples Memory Management Introduction YAMM Overview: Features, Algorithm, Data types, API Comparison with UVM_MAM Feature-wise Performance-wise Examples

Memory Management Introduction

Memory Management – What is it?

Memory Management Requirements Real Life Verification Provide memory buffers to programs Support real life use cases Prevent memory corruption Provide randomization support Reduce fragmentation Provide debug support Not necessarily a memory model

YAMM Overview

YAMM Features (1) Everything is a buffer, either it’s a free one or a user defined one YAMM provides API for retrieval of allocated buffers Buffers can be allocated using a specific allocation mode User can set different granularities and address alignments YAMM has the ability to store contents or generate random contents inside used buffers Memory Map The memory is initialized after reset as a free buffer containing the entire memory space. Memory allocation is done by splitting and moving space from the free buffer to new occupied buffers Every buffer allocated in memory is responsible for it’s address space. Contents can be allocated directly in the buffer or other buffers can be allocated for that address space. The memory can be segmented in as many pieces and on as many levels as the user want limited only by the memory size. As was described earlier there are 4 ways of reserving buffers in memory and 6 allocation modes. This way YAMM can be suitable for any type of project. Both insertion and allocation have 2 ways of usage Giving a buffer as an argument, which was prior created by the user An easy mode that takes a starting address and a size through an access (insert), or just a size as argument (allocate) and returns the created buffer.

YAMM Features (2) Buffers represent address spaces themselves Memory can be dumped to file or can be returned in a readable form as a string It provides functions to check the statistics of a specific memory space Can be extended for specific use cases

YAMM Data Types yamm_buffer yamm yamm_access Contains all data and functions yamm Top level class in the hierarchy Inherits from yamm_buffer and implements specific functionality required for top level yamm_access Optional usage Used to model a basic access (start address, size) YAMM After instantiation memory can be built with a specific size and name. After building the memory, before calling reset() static buffers can be allocated Calling reset creates the free buffer for the entire memory span and allocates the static buffers Calling reset a second time brings the memory to the initial state (After static buffers allocation) YAMM BUFFER There are functions for allocating, deallocating, searching, setting and reading content Any buffer can act the same way as the entire memory. It’s memory span becomes accessible as a free buffer inside which you can allocate other buffers. This also works for static buffers to which the user possesses a reference..

YAMM Overview Algorithm After initialization the memory map will contain a single free buffer All buffers in a memory map are chained in a double linked list

YAMM Overview API Allocation Deallocation Manual allocation: insertion Automatic allocation rules: RANDOM_FIT FIRST_FIT (and FIRST_FIT_RND) BEST_FIT (and BEST_FIT_RND) UNIFORM_FIT Deallocation It can be done on a specific buffer or address

YAMM Overview API - Allocation/Deallocation After a build was done the parameters for the memory are set but the free buffer is not yet created, the memory can’t yet be used for normal allocations. At this time, before reset static buffers can be allocated. This is the first step. Initially, after a reset is done the memory will look as it is pictured in the rightmost memory space. After the reset buffers can be allocated and deallocated normally. Between the 2nd and 3rd memory spaces you can see how a deallocation takes place. The buffers is replaced by a free buffer that is merged with the adjacent free buffers. Doing another reset afterwards will result in the memory being returned to the state it was after allocating the static buffers.

YAMM Overview API Search functions Debug functions Retrieve buffers by name Retrieve buffer by address Retrieve buffers in address range Retrieve buffers by access Debug functions Return the memory map allocation as a string Dump memory map to file Provide usage and fragmentation statistics Get_all_buffers_by_type User can assign names to specific buffers using set_name() function A queue with said buffers can be returned calling the get_all_buffer_by_type() function using the name set to those buffers as an argument. Get_buffer Using an address as an argument get_buffer() function return the buffer that contain that address Get_buffers_in_range Specifying a start and end address get_buffers_in_range() will return a queue with all buffers in that memory region Get_buffers_by_access Same as the previous, it actually does a call to get_buffers_in_range() but it gets its region from an access instead of it being specified by the user.

Comparison with UVM MAM

MAM UVM solution The solution is oriented more towards memory modeling than memory management MAM plays a small role and is used with uvm_mem to reserve specific memory regions Supports only “greedy” allocation mode Specific regions can be freed or entire memory can be wiped Memory state can be returned as a string Complex and general solution It’s composed of a large number of objects, each with a specific use Organized hierarchically, many of the features are hard to access Massive overhead, not useful for cases in which memory management is solely required It prioritizes complexity and reusability rather than performance or ease of use Coverage support!

MAM vs YAMM Feature wise (1) MAM YAMM Memory Allocation Deallocation uvm_mam is linked to uvm_mem which provides the mam memory locations used for storing data Allocation Can only allocate on previously unallocated memory Has only 2 allocation modes Deallocation Releases the specific region YAMM Memory YAMM top level as well as every individual buffer contains a memory map composed of multiple buffers that can store simple data Allocation Permits allocation in previously unallocated memory or inside an already allocated buffer Has 6 allocation modes Deallocation Can display a warning if said buffer contains other buffers

MAM vs YAMM Feature wise (2) MAM YAMM Finding buffers Ease of use Provides an iterator that user must use for any needs Ease of use It’s complex and rather hard to use For features beyond reserving and freeing regions user has to go to objects higher in the hierarchy YAMM Finding buffers Provides support for finding and modifying buffers by different criteria Ease of use Has a more user friendly API Memory map can be accessed by calling functions on the top level Specific regions can be accessed by calling same functions on the chosen buffers

Performance test Parameters Memory space of 1G Allocate 5000 buffers of size 100 Measure the time taken for allocation every 100 allocations For MAM, request_region() with default policy was used (it will randomly allocate only memory that wasn’t previously allocated) For YAMM, allocate_by_size() with RANDOM_FIT allocation mode was used

Performance - MAM vs YAMM more than 200x speed

Examples

Examples Configuration Example yamm new_memory; yamm_size_width memory_size = 10000; new_memory = new; new_memory.build(“memory_name”, memory_size); // Now you can allocate static buffers. The memory was created but buffers // can't be allocated yet. After reset(), normal buffers can be allocated but static // buffers can't. new_memory.reset();

Examples Sequence Example class user_sequence extends uvm_sequence; rand int unsigned access_size; ... task body(); yamm_buffer buffer = p_sequencer.user_memory.allocate_by_size(access_size); `uvm_do_with(user_item, { address == buffer.start_addr; size == buffer.size;//or access_size data == buffer.get_contents(); }) endtask endclass

Examples Scoreboard Example class user_scoreboard; yamm user_memory; ... //function checks if the current access is done to a previously allocated address function void check_access(user_item item); if(user_memory.get_buffer(item.addr) == null) `uvm_error(get_name(), "Access detected to a non-allocated memory address!") endfunction endclass

YAMM Availability Free under Apache 2.0 license Available after SNUG conferences Blog: www.amiq.com/consulting/blog Github: github.com/amiq-consulting

Questions?