Code Monkey home page Code Monkey logo

malloc_lib's Introduction

Malloc Library with Buddy System

The malloc library using buddy system to maintain a group of free lists to manage the memory heap. The buddy system supports seven APIs, including malloc, realloc, calloc, free, memalign, posix_memalign and reallocarray. This malloc library is thread safty, and using per-core arena algorithm to maintain multi thread when allocating memory.

Data Structure

Schema

    buddy_util.c
        |
        |
        |
     buddy.c  ma_util.c
        |         |
        |         |
        |         |
        |---------|                     |----calloc.c
                  |     |----malloc.c---|----memalign.c
                  |     |               |----posixmemalign.c
                  |     |
                  |-----|----realloc.c---reallocarray.c
                        |
                        |
                        |----free.c

Buddy System

The buddy system has two different kind of data structure. "f_header" is double linked list struct to maintain a couple of free lists, and "m_header" is the header of the allocated block, which contains a varible to store the block size. Both f_header and m_header have a pointer varible that point to themselves, which is used to check the validation of the header. The design idea of keeping two kinds of data structures is to reduce the header size.

The buddy system only handles the block whose size below half page size. If the requirement size bigger than half page size, the system calls mmap and munmap.

Per-Core Arena

The arena system has two different kind of data structure. Structure "arena" is used to store the infomation of an arena, including its id, used size and free size. Structure "pthread" is a linked list used to reference each thread to its own arena.

The number of arena is the same as the number of the processor that the computer have. If the number of the threads less than the number of the processor, each thread runs in its own arena. If the number of the threads greater than the number of the process, some threads will share the same arena. After a thread being assigned to an arena, that thread won't try to go to another arena.

Getting Start

Installing

Download from the website and unzip using the code

tar -xzf hw3.tar.gz

Testing

To test the malloc library, please run

make check1

To clean the object file, please run

make clean

To debug the program, please run

make debug

Author

  • Kevin Ming Feb, 18, 2018

malloc_lib's People

Contributors

yuchongming avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.