Tuesday, December 10, 2013

Best Fit Memory Management

I'm currently in an operating systems class right now. I feel like I'm failing miserably but who knows until the grades come out. Anyway, the following information may give away who I am and where I go to school but I'm going to go for it. I feel like this nugget of late information needs to be shared. 
So we're working with Minix and learning about paging, memory management and whatnot. To cement the knowledge into our brains, the teacher decided to tell us to change the memory management algorithm from first fit, which finds the first hole in memory which fits the memory space that the current process needs, to best fit. So in best fit, the operating system finds the smallest memory hole that matches or is larger than the memory needed by the process/program. One of the hardest parts of the assignment is finding the file and portion of code to modify. And I have finally found it. According to the minix book and the minix 3.1.1 source code I'm using on a website, the file is src/servers/pm/alloc.c and it's the part involving the alloc_mem function which is lines 58 to 100. Happy editing since I don't want to think about how to change the algorithm and code to best fit. Maybe one day when I look back I'll figure it out. Until then, happy deep night coding.