首页 > 其他分享 >CS 551 Systems Programming

CS 551 Systems Programming

时间:2024-10-19 12:43:18浏览次数:8  
标签:Programming 551 batch bitmap list manager memory CS your

CS 551 Systems Programming, Fall 2024 Programming Project 1

Out: 10/13/2024 Sun.

Due: 10/26/2024 Sat. 23:59:59 In this project your are going to implement a custom memory manager that manages heapmemory allocation at program level. Here are the reasons why we need a custom memory managerin C.

  • The C memory allocation functions malloc and free bring performance overhead: thesecalls may lead to a switch between user-space and kernel-space. For programs that do frequent memory allocation/deallocation, using malloc/free will degrade the performance.
  • A custom memory manager allows for detection of memory misuses, such as memory overflow, memory leak and double deallocating a pointer.The goal of this project is to allow students to practice on C programming, especially on bitwiseoperations, pointer operation, linked list, and memory management.User programYour memory manager

(a library)OS kernelUser programOS kernelmalloc/freemalloc/free (interposed version)malloc/free

Figure 1: Overview

1 Overview

Figure 1 depicts where the memory manager locates in a system. The memory manager basicallypreallocates chunks of memory, and performs management on them based on the user programmemory allocation/deallocation requests.

We use an example to illustrate how your memory manager is supposed to work. Supposememory allocations in the memory manager are 16 bytes aligned1 .

  • After the user program starts, the first memory allocation from the program requests 12 bytesof memory (malloc(12)). Prior to this first request, your memory manager is initialized1In other words, the memory manager always allocates memory that is a multiple of 16 bytes. In the base code,this is controlled by the MEM ALIGNMENT BOUNDARY macro defined in memory manager.hwith a batch of memory slots2 , each of which has a size of 16 bytes. Memory manager returnsthe first slot of the batch to the user program.
  • Then the user program makes a second request (malloc(10)). Because the memory allocation is 16 bytes aligned, the memory manager should return a chunk of memory of 16bytes. This time, because there are still available 16-byte-slots in the allocated batch, thememory manager simply return the second slot in the allocated batch to fulfill the requestwithout interacting with the kernel.
  • The user program makes 6 subsequent memory requests, all of which are for memory lessthan 16 bytes. The memory manager simply returns each of the rest 6 free 16-byte-slots tofulfill the requests. And for the implementation of this project, assume youwill only getrequests for less than or equal to 16 bytes memory.
  • The user program makes the 9th request (malloc(7)). Because there is no free slots avail

able, the manager allocates another batch of memory slots of 16 bytes, and returns the first

slot in this batch to the user program.

  • Suppose the 10th memory request from the user program is malloc(28). The managershould return a memory chunk of 32 bytes (remember memory allocation is 16 bytes aligned).Because there is no memory list of 32-byte-slots, the manager has to allocate a batch ofmemory slots of 32 bytes, and returns the first slot to fulfill this request. At this moment,

the memory list of 32-byte-slots has only one memory batch.

  • The memory manager organizes memory batches that have the same slot size using linkedlist, and the resulting list is called a memory batch list, or a memory list.
  • Memory lists are also linked together using linked list. So the default memory list with slotsize of 16 bytes is linked with the newly created 32 bytes slot size memory list.
  • The manager uses a bitmap to track and manage slots allocation/deallocation for eachmemory batch list.

t is easy to see that with such a mechanism, the memory manager not only improves programperformance by reducing the number of kernel/user space switches, utalso tracks all the memoryallocation/deallocation so that it can detect memory misuse such as double freeing. The memory

nager can also add guard bytes at the end of each memory slot to detect memory overflow (just

an example, adding guard bytes is not required by this project.)

2 What to do

2.1 Download the base code Download the base code from Assignments section in the Brightspace. You will need to add yourimplementation into this base code.2In the base code, the number of memory slots in a batch is controlled by the MEM BATCH SLOT COUNT macrodefined in memory manager.h2.2 Complete the bitmap operation functions (25 points)

Complete the implementation of the functions in bitmap.c.

  • int bitmap find first bit(unsigned char * bitmap, int size, int val)This function finds the position (starting from 0) of the first bit whose value is “val” in the

“bitmap”. The val could be either 0 or 1.

Suppose

unsigned char bitmap[] = {0xF7, 0xFF};

Then a call as following

bitmap_find_first_bit(bitmap, sizeof(bitmap), 0);

finds the first bit whose value is 0. The return value should be 3 in this case.

  • int bitmap set bit(unsigned char * bitmap, int size, int target pos)

This function sets the “target pos”-th bit (starting from 0) in the “bitmap” to 1.

Suppose

unsigned char bitmap[] = {0xF7, 0xFF};

Then a call as following

bitmap_set_bit(bitmap, sizeof(bitmap), 3);

sets bit-3 to 1. After the call the content of the bitmap is {0xFF, 0xFF};

  • int bitmap clear bit(unsigned char * bitmap, int size, int target pos)

This function sets the “target pos”-th bit (starting from 0) in the “bitmap” to 0.

  • int bitmap bit is set(unsigned char * bitmap, int size, int pos)

This function tests if the “pos”-th bit (starting from 0) in the “bitmap” is 1.

Suppose

unsigned char bitmap[] = {0xF7, 0xFF};

Then a call as following

bitmap_bit_is_set(bitmap, sizeof(bitmap), 3);

returns 0, because the bit-3 in the bitmap is 0.

  • int bitmap print bitmap(unsigned char * bitmap, int size)

This function prints the content of a bitmap in starting from the first bit, and insert a space

every 4 bits.

Suppose

unsigned char bitmap[] = {0xA7, 0xB5};

Then a call to the function would print the content of the bitmap as

1110 0101 1010 1101

The implementation of this function is given.2.3 Complete the memory manager implementation (70 points) In memory manager.h two important structures are defined:

  • structstru mem batch: structure definition of the a memory batch (of memory slots).
  • structstru mem list: structure definition of a memory list (of memory batches).To better assist you understand how a memory manager is supposed to organize the memoryusing the two data structures, Figure 2 shows an example of a possible snapshot of the memorymanager’s data structures.Figure 2: An example of data structuresBasically there are two kinds of linked list:

A list of memory batches (with a certain slot size): as shown in the previous example, this

ist expands when there is no free slot available. The memory manager adds a new batch atthe end of the list.

  • A list of memory batch list: this list expands when a new slot size comes in.You will need to implement the functions in memory manager.c:
  • void * mem mngr alloc(size t size)This is the memory allocation function of the memory manager. It is used in the same

way as malloc().

Provide your implementation.

The macro MEM ALIGNMENT BOUNDARY (defined in memory manager.h) controlshow memory allocation is aligned. For this project, we use 16 byte aligned.Butyour implementation should be able to handle any alignment. One reason to define the alignment as a macro is to allow for easy configuration. When grading wewill test alignment that is multiples of 16 by changing the definition of the macro

MEM ALIGNMENT BOUNDARY to 8, 32, ....The macro MEM BATCH SLOT COUNT (defined in memory manager.h) controls thenumber of slots in a memory batch. For this project this number is set to 8. But your代 写CS 551 Systems Programming implementation should also work if we change to the macro MEM BATCH SLOT COUNT

to other values. When grading, we will test the cases when MEM BATCH SLOT COUNTis set to multiples of 8 (i.e., 8, 16, 24, ...).

When there are multiple free slots, return the slot using the first-fit policy(i.e, the one

with smallest address).

Remember to clear the corresponding bit in free slots bitmap after a slot is allo

cated to user program.

Do not use array for bitmap, because you never now how many bits you will need. Use

Remember to expand the bitmap when a new batch is added to a list, and keep the oldcontent after expansion.

Create a new memory list to handle the request if none of the existing memory list candeal with the requested size.

Add this memory list into the list of memory lists.

This function should support allocation size up to 5 times the alignment size, e.g., 80bytes for 16 byte alignment.

  • void mem mngr free(void * ptr)

This is the memory free function of the memory manager. It is used in the same wayas free().

Provide your implementation.

The ptr should be a starting address of an assigned slot, report(print out) error if itis not (three possible cases:

1: ptr is the starting address of an unassigned slot - double freeing;

2: ptr is outside of memory managed by the manager;

3: ptr is not the starting address of any slot).

Remeber to set the corresponding bit in free slots bitmap after a slot is freed, so

that it can be used again.

Search through all the memory lists to find out which memory batch the ptr associatedslot belongs to.• void mem mngr init(void)

This function is called by user program when it starts.

Initialize the lists of memory batch list with one default batch list. The slot size of thisdefault batch list is 16 bytes.

Initialize this default list with one batch of memory slots.

Initialize the bitmap of this default list with all bits set to 1, which suggests that allslots in the batch are free to be allocated.

  • void mem mngr leave(void)

This function is called by user program when it quits. It basically frees all the heap

memory allocated.

Provide your implementation.

Don’t forget to free all the memory lists to avoid memory leak.

  • void mem mngr print snapshot(void)

This function has already been implemented. It prints out the current status of the memorymanager. Reading this function may help you understand how the memory manager organizes the memory. Do not change the implementation of this function. It will be used tohelp the grading.

2.4 Writing a makefile (5 points)

Write a makefile to generate

  • memory manager.o
  • bitmap.o
  • a static library memory manager.a, which contains the previous relocatable object files.This library will be linked to our test program for testing.

2.5 Log and submit your work

Log your work: besides the files needed to build your project, you must also include a READMEfile which minimally contains your name and B-number. Additionally, it can contain the following:

  • The status of your program (especially, if not fully complete).
  • Bonus is implemented or not.
  • A description of how your code works, if that is not completely clear by reading the code(note that this should not be necessary, ideally your code should be self-documenting).
  • Possibly a log of test cases which work and which don’t work.
  • Any other material you believe is relevant to the grading of your project.Compress the files: compress the following into a ZIP file:
  • bitmap.c
  • common.h
  • interposition.h
  • memory manager.c
  • memory manager.h
  • Makefile
  • README

Name the ZIP file based on your BU email ID. For example, if your BU email is “[email protected]”,then the zip file should be “proj1 abc.zip”.

Submission: submit the ZIP file to Brightspace before the deadline.

2.6 Grading guidelines

(1) Prepare the ZIP file on a Linux machine. If your zip file cannot be uncompressed, 5 pointsoff.

(2) If the submitted ZIP file/source code files included in the ZIP file are not named as specifiedabove (so that it causes problems for TA’s automated grading scripts), 10 points off.(3) If the submitted code does not compile:

1 TA will try to fix the problem (for no more than 3 minutes);

2 if (problem solved)3 1%-10% points off (based on how complex the fix is, TA’s discretion);4 else

5 TA may contact the student by email or schedule a demo to fix the problem;6 if (problem solved)

7 11%-20% points off (based on how complex the fix is, TA’s discretion);8 else

9 All points off;So in the case that TA contacts you to fix a problem, please respond to TA’s email promptlyor show up at the demo appointment on time; otherwise the line 9 above will be effective.

(4) If the code is not working as required in this spec, the TA should take points based on theassigned full points of the task and the actual problem.

(5) Late penalty: Day1 10%, Day2 20%, Day3 40%, Day4 60%, Day5 80%(6) Lastly but not the least, stick to the collaboration policy stated in the syllabus: you maydiscuss with your fellow students, but code should absolutely be kept private. Any violationto the Academic Honesty Policy and University Academic Policy, will result 0 for the work.

标签:Programming,551,batch,bitmap,list,manager,memory,CS,your
From: https://www.cnblogs.com/goodlunn/p/18475710

相关文章

  • GDPC-CSA::CTF一轮web题目write up-T2 ez http
    首先来看题目先不鸟提示,进去页面逛逛,F12一下,看到如下内容回头来看提示,robots.txt是网页用来告知爬虫允许和禁止访问文件的君子协议,由题我们决定先打开/robots.txt查看一下爬虫被禁止访问哪些文件,其中说不定会有线索如果对robots.txt还不了解的可以看看这里在网站地址框输入......
  • XC6SLX25T-2CSG324C,XC6SLX45T-2FGG484I,XC7K70T-3FBG484E4914, XILINX/赛灵思 嵌入式
    Xilinx是一家总部位于美国的半导体公司,成立于1984年。他们的主要产品是可编程逻辑器件(FPGA和SoC)和相关的开发工具。Xilinx的FPGA产品被广泛应用于各种领域,包括通信、数据中心、工业控制、汽车、物联网等。他们的产品具有灵活性高、性能强大和可定制性强等特点。2018年,Xilinx宣......
  • CSS--固定定位
    固定定位概念固定定位是绝对定位的子类别,一个设置固定定位的元素是相对于视窗固定的,就算页面文档发生了滚动,它也会一直待在相同的地方。固定定位代码添加:position:fixed水平方向:left right垂直方向:top bottom注:1.两个方向各选一个参数即可定位;    2.定......
  • 前端HTML+CSS+JS总结 我的学习笔记
    前端HTMLCSSJS总结一、HTML1.HTML介绍2.基础标签3.图片、音频、视频标签4.超链接标签5.列表标签6.表格标签7.布局标签8.表单标签二、CSS1.CSS概述2.CSS导入方式3.CSS选择器三、JavaScript1.JavaScript简介2.JavaScript引入方式3.JavaScript基础语法书写语法输......
  • 使用AES 128位加解密,加解密模式采用CBC,填充模式采用PKCS5Padding的Java工具方法示例
    importjavax.crypto.Cipher;importjavax.crypto.spec.IvParameterSpec;importjavax.crypto.spec.SecretKeySpec;importjava.util.Base64;publicclassAESUtils{privatestaticfinalStringAES_ALGORITHM="AES/CBC/PKCS5Padding";private......
  • Expression-bodied members (C# programming guide)
    Expressionbodydefinitionsletyouprovideamember'simplementationinaconcise,readableform.Youcanuseanexpressionbodydefinitionwheneverthelogicforanysupportedmember,suchasamethodorproperty,consistsofasingleexpression.A......
  • 536.响应式大鱼海棠电影宣传网页 大学生期末大作业 Web前端网页制作 html+css+js
    目录一、网页概述二、网页文件 三、网页效果四、代码展示1.html2.CSS3.JS五、总结1.简洁实用2.使用方便3.整体性好4.形象突出5.交互式强六、更多推荐欢迎光临仙女的网页世界!这里有各行各业的Web前端网页制作的案例,样式齐全新颖,并持续更新!感谢CSDN,提供了这......
  • 第六章 元素应用CSS
    6.1使用CSS设置字体样式在学习HTML时,通常也会使用HTML,对文本字体进行一些非常简单的样式设置,而使用CSS对字体样式进行设置远比使用HTML灵活、精确得多。CSS样式中有关字体样式的常用属性见下表字体样式的常用属性属性说明属性说明font-family设置字体的类型font-we......
  • 『模拟赛』CSP-S模拟12
    Rank有点烂A.小h的几何虽然但是看起来这就是签。赛时看到计算几何直接润了,没看到送的20pts。主要问题在证一个结论:九点圆圆心位于垂心和外心的中点。几何证法见此,用到的全是初中知识,很好懂。证完就很水了,圆心即为\(\frac{A+B+C}{2}\),随便算个选中的方案数再乘上总概率......
  • csp-s模拟12
    题面首先,这些题目的题意就不太好理解A利用三个中点,暴力就是暴力算斜率暴力算交点圆周率别再写错了constdoublePi=acos(-1);点击查看代码#include<bits/stdc++.h>#definespeed()ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);#definelllonglong#definepb......