Calculate the required block size

Assignment Help Operating System
Reference no: EM132785039

Goals

Learn about how Malloc works under the hood

Get used to systems programming environment

Introduction

As you no doubt know by now, a major part of C programming is the management of memory. You have used malloc() and its kin before, but now it is time to delve into how malloc() works.

In this lab, you will implement a memory allocator, which allows users to malloc() and free() memory as needed.

Your allocator will request large chunks of memory from the OS, and manage all the bookkeeping and memory efficiently.

The allocator you will implement is inspired by the DLMalloc allocator designed by Doug Lea. Also inspired by the DLMalloc allocator is the PTMalloc allocator, which is currently used by GLibC. Our allocator is a simplified version, but if you look through the approach taken by DLMalloc you will notice many similarities.

Task 1: Allocation

1. Calculate the required block size (actual request size) by adding the size of the required metadata and rounding the allocation size up to the next 8-byte modulo. The actual request size is either the size calculated in this step or the size of the header struct, whichever is larger.
2. Find the appropriate free list to look for a block to allocate (recall that the block size per each list is based on the rounded request size, not including the metadata)
1. As long as there are no blocks in the current list, check the next list until there is a block, which can satisfy the request
2. When checking the final list, instead of just checking if the list is empty, iterate over all blocks and check if any is large enough to satisfy the request.
3. Depending on the size of the block, either allocate the full block or split the block and allocate the right (higher in memory) portion to the user.
1. When splitting, the size and left_size fields maintained in the neighboring blocks will need to be updated.
4. When allocating a block, update its allocation status to ALLOCATED
5. Finally, return to the user a pointer to the data field of the header.

Task 2: Deallocation (Freeing)
1. Free is called on the same pointer that malloc returned, which means we must calculate the location of the header by pointer arithmetic.
2. Once we have the header of the block being freed we must calculate the locations of its right and left neighbors, also using pointer arithmetic and the block's size fields.
3. Based on the allocation status of the neighboring blocks, we must either insert the block or coalesce with one or both of the neighboring blocks

Task 3: Managing Additional Chunks
Above we don't specify how to handle the case where the user's request cannot be fulfilled by any of the available blocks.
1. If no available block can satisfy an allocation request then we must allocate more memory from the OS. To do this we must call sbrk() again.
2. Two consecutive calls to sbrk() should allocate contiguous regions in memory, therefore when we allocate another chunk we can coalesce it with the most recently allocated chunk. Unfortunately, the user of our library could have called sbrk() between our calls and thus we must check that our two chunks are in fact contiguous in memory.

3. There are a few cases for managing adding a new chunk to the free lists:
1. If the new chunk is not adjacent to the previous chunk, then it can simply be inserted into the appropriate free list like any other block.
2. If the new chunk is adjacent to the previous chunk, then the fence posts between the two chunks should be removed and the chunk should be coalesced with any unallocated memory at the end of the previous chunk.

4. This process may need to be repeated multiple times to get enough memory to satisfy a user's requests.

1. Example: Say a user makes a malloc request for 1000 bytes of memory, but our arena size is 400 bytes. To satisfy the request, we must make 2 consecutive calls to sbrk, leaving us with a total of 1200 bytes in a single contiguous block, from which we can then allocate the necessary 1000 bytes. All new chunks must be the arena size. It is important for you to manage additional chunks this way, as this is how the tests expect you to handle new chunks

Attachment:- Systems Programming.rar

Reference no: EM132785039

Questions Cloud

What role can we play in assuring the best outcomes : Think about the moment in which you became aware of your sexual orientation. Do you recall making a conscious choice to be gay or straight?
Provide the journal entry to admit Roberts : Prior to the investment, land was revalued to a market value of $130,000 from a book value of $80,000. Provide the journal entry to admit Roberts
Economic challenges of working in environment : What are some cultural, political, and economic challenges of working in this environment?
Prepare the journal entry for carla vista growth at april : Prepare the journal entry for Carla Vista Growth at April 2, 2020, assuming Carla Vista Growth estimates returns of 20% based on prior experience
Calculate the required block size : Calculate the required block size (actual request size) by adding the size of the required metadata and rounding the allocation size up to the next 8-byte
Calculate the total remittance due to the canada revenue : Calculate the total remittance due to the Canada Revenue Agency where the total employee contributions to Canada Pension Plan were $15,200.00
Major universities are currently revisiting : Major universities are currently revisiting their affirmative action policies. Discuss the pros and cons of these policies.
Explain what has been done with regard to mitigation : Explain what has been done with regard to mitigation, recovery, and/or response efforts within your community or the community you researched.
Provide the journal entry for Renfro contribution : The partnership also assumed a $14,000 account payable owed to a Renfro supplier. Provide the journal entry for Renfro's contribution to the partnership

Reviews

len2785039

2/3/2021 11:30:25 PM

Need to write 2 functions for allocating and deallocating functions of malloc, i have given the c file and header file

Write a Review

Operating System Questions & Answers

  Write a non-threaded program to simulation heat dissipation

CSC314 Operating Systems - Write a non-threaded program to simulation heat dissipation on the surface of a cylinder. You can model a cylinder using a 2D HxC array of cells - Implement a multithreaded version of the Sieve of Eratosthenes.

  What procedures would you take to fulfill the order

What procedures would you take to fulfill the order? Create short guide to keep business going if power is disrupted again in the future due to hurricane

  Explain scanner and the scanning process

COM 414 -COMPILER CONSTRUCTION- Explain scanner and the scanning process.Discuss storage allocating techniques and storage requirements.

  Simulate fdisk command for allocating partitioning on a disk

To simulate the FDISK command for allocating partitioning on a disk. Output text file consisting of disk allocation information (device, starting location, ending location, block size, id, file system).

  Describe the concept of a signal, and indicate configuration

When a child process is fork()ed, a parent may wait for the successful completion of the child via the wait() service (or one of its variants) so that the return result of that application can be read from the process descriptor block.

  Calculate cocomo effort

Calculate COCOMO effort, TDEV, average sta?ng, and productivity for an organic project that is estimated to be 39,800 lines of code.11. Calculate the unadjusted function points for the problem description of Problem 2.

  What do you think are the major aspects of operating systems

What are the three different vantage points for considering operating systems and what services are designed for performance, and what services are designed for usability?

  Relational database architecture from a network

Determine what would make a corporation or organization migrate to a relational database architecture from a network or hierarchical architecture?

  Use the definition of big-o to prove that 3n+2logn = o(n)

Use the definition of big-O to prove that 3n+2logn = O(n) . Provide the appropriate C & K Contants.

  What does the imply about input validation checks used

What does this imply about input validation checks used to prevent command injection attacks?

  Develop a user mode command interpreter

Develop a user mode command interpreter which support list-short.

  Detennine the transition width in hz

1. A rectangular window with 25 terms is used to design a low pass FIR filter. The pass band edge is located at 2 kHz and the pass band gain is about 0 dB. For a samplin frequency of 20 kHz:

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd