mirror of
https://github.com/caperren/school_archives.git
synced 2025-11-09 21:51:15 +00:00
Added OS II assignments
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,38 @@
|
||||
\section{Design}
|
||||
In order to implement a best-fit version of the slob, we're going to need to modify the functions slob\_alloc and slob\_page\_alloc in "slob.c". From a high level, the biggest change that needs to be made is for slob\_alloc to have an understanding of which of its pages have a block that is best sized for the allocation that is requested. This will involve not only finding a page with free blocks available, but going through all pages with free blocks available, and then choosing the page and block that is larger than, but closest to the size of the requested allocation. If along the way, we encounter a page with a block that is exactly the size we need, we can immediately choose that as the allocation point as you can't get better than perfectly sized. In the event that there are no pages with blocks available to store the requested size of allocation, the default creation of a new page will occur, providing an empty chunk of memory that will have enough space.
|
||||
|
||||
Changes to slob\_alloc:
|
||||
\begin{lstlisting}[lineskip=3pt,keywords={if,else,while,for}]
|
||||
for each page
|
||||
//section "Enough room on this page?"
|
||||
check size of all blocks on current page
|
||||
|
||||
if (no space large enough on this page) {
|
||||
continue
|
||||
}
|
||||
if (any block has a perfect fit) {
|
||||
store page
|
||||
break
|
||||
}
|
||||
else if (any block has a fit better than current best fit) {
|
||||
store page
|
||||
}
|
||||
|
||||
if (found page with block with space) {
|
||||
allocate the space
|
||||
} else {
|
||||
create a new page
|
||||
}
|
||||
|
||||
\end{lstlisting}
|
||||
|
||||
Changes to slob\_page\_alloc:
|
||||
\begin{itemize}
|
||||
\item Separate the original function so that it finds the best block (using same logic as find\_closest\_block\_size\_in\_page) and then allocates that block
|
||||
\item Take out "room enough" section because we already know there is room
|
||||
\end{itemize}
|
||||
|
||||
find\_closest\_block\_size\_in\_page:
|
||||
\begin{itemize}
|
||||
\item Uses same logic as original slob\_page\_alloc to go through each block, but searches for the best instead of the first
|
||||
\end{itemize}
|
||||
@@ -0,0 +1,18 @@
|
||||
#include <stdio.h>
|
||||
#include <linux/unistd.h>
|
||||
|
||||
#define __sys_slob_free 400
|
||||
#define __sys_slob_used 401
|
||||
|
||||
int main (void){
|
||||
float fragmentation_percent;
|
||||
long used = syscall(__sys_slob_used);
|
||||
long free = syscall(__sys_slob_free);
|
||||
|
||||
fragmentation_percent = (float) free / (float) used;
|
||||
printf("Amount free: %ld.\n", free);
|
||||
printf("Amount used: %ld.\n", used);
|
||||
printf("Amount frag: %.2f%%.\n", fragmentation_percent);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,410 @@
|
||||
diff -Naur -x '*.o' -x '*.ko' -x '*.order' -x '*.builtin' -x '*.cmd' -x '*.mod.c' linux-yocto-3.19.2_untouched/mm/slob.c linux-yocto-3.19.2/mm/slob.c
|
||||
--- linux-yocto-3.19.2_untouched/mm/slob.c 2018-05-04 15:15:00.445347537 -0700
|
||||
+++ linux-yocto-3.19.2/mm/slob.c 2018-06-06 17:07:53.244403545 -0700
|
||||
@@ -68,6 +68,9 @@
|
||||
#include <linux/list.h>
|
||||
#include <linux/kmemleak.h>
|
||||
|
||||
+#include <linux/linkage.h>
|
||||
+#include <linux/syscalls.h>
|
||||
+
|
||||
#include <trace/events/kmem.h>
|
||||
|
||||
#include <linux/atomic.h>
|
||||
@@ -101,6 +104,8 @@
|
||||
static LIST_HEAD(free_slob_medium);
|
||||
static LIST_HEAD(free_slob_large);
|
||||
|
||||
+size_t num_pages = 0;
|
||||
+
|
||||
/*
|
||||
* slob_page_free: true for pages on free_slob_pages list.
|
||||
*/
|
||||
@@ -211,55 +216,117 @@
|
||||
free_pages((unsigned long)b, order);
|
||||
}
|
||||
|
||||
-/*
|
||||
- * Allocate a slob block within a given slob_page sp.
|
||||
- */
|
||||
static void *slob_page_alloc(struct page *sp, size_t size, int align)
|
||||
{
|
||||
- slob_t *prev, *cur, *aligned = NULL;
|
||||
- int delta = 0, units = SLOB_UNITS(size);
|
||||
+ slob_t *prev, *cur, *aligned = NULL, *best = NULL, *best_prev = NULL;
|
||||
+ int delta = 0;
|
||||
+ int units = SLOB_UNITS(size);
|
||||
+ slobidx_t avail;
|
||||
|
||||
+ /* Find best fit block on page that can fit what needs to be allocated */
|
||||
for (prev = NULL, cur = sp->freelist; ; prev = cur, cur = slob_next(cur)) {
|
||||
- slobidx_t avail = slob_units(cur);
|
||||
+ avail = slob_units(cur);
|
||||
|
||||
+ /* Use aligned blocks if requested */
|
||||
if (align) {
|
||||
aligned = (slob_t *)ALIGN((unsigned long)cur, align);
|
||||
delta = aligned - cur;
|
||||
}
|
||||
- if (avail >= units + delta) { /* room enough? */
|
||||
- slob_t *next;
|
||||
+
|
||||
+ /* If the current block is the best option seen yet, store it */
|
||||
+ if(avail >= units + delta && (!best || avail < slob_units(best))) {
|
||||
+ best = cur;
|
||||
+ best_prev = prev;
|
||||
+ }
|
||||
+
|
||||
+ /* If this is the last block, exit loop */
|
||||
+ if (slob_last(cur)) {
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ }
|
||||
+
|
||||
+ /* Allocate the best block found above, if found */
|
||||
+ if (best != NULL){
|
||||
+ slob_t *next;
|
||||
|
||||
- if (delta) { /* need to fragment head to align? */
|
||||
- next = slob_next(cur);
|
||||
- set_slob(aligned, avail - delta, next);
|
||||
- set_slob(cur, delta, aligned);
|
||||
- prev = cur;
|
||||
- cur = aligned;
|
||||
- avail = slob_units(cur);
|
||||
- }
|
||||
+ /* Align if necessary */
|
||||
+ if (align) {
|
||||
+ aligned = (slob_t *)ALIGN((unsigned long)best, align);
|
||||
+ delta = aligned - best;
|
||||
+ }
|
||||
+
|
||||
+ /* Get the amount of space available */
|
||||
+ avail = slob_units(best);
|
||||
|
||||
- next = slob_next(cur);
|
||||
- if (avail == units) { /* exact fit? unlink. */
|
||||
- if (prev)
|
||||
- set_slob(prev, slob_units(prev), next);
|
||||
- else
|
||||
- sp->freelist = next;
|
||||
- } else { /* fragment */
|
||||
- if (prev)
|
||||
- set_slob(prev, slob_units(prev), cur + units);
|
||||
- else
|
||||
- sp->freelist = cur + units;
|
||||
- set_slob(cur + units, avail - units, next);
|
||||
+
|
||||
+ if (delta) { /* need to fragment head to align? */
|
||||
+ next = slob_next(best);
|
||||
+ set_slob(aligned, (avail - delta), next);
|
||||
+ set_slob(best, delta, aligned);
|
||||
+ best_prev = best;
|
||||
+ best = aligned;
|
||||
+ avail = slob_units(best);
|
||||
+ }
|
||||
+
|
||||
+ next = slob_next(best);
|
||||
+
|
||||
+ /* exact fit? unlink. */
|
||||
+ if (avail == units) {
|
||||
+ if (best_prev)
|
||||
+ set_slob(best_prev, slob_units(best_prev), next);
|
||||
+ else
|
||||
+ sp->freelist = next;
|
||||
+ } else { /* fragment */
|
||||
+ if (best_prev){
|
||||
+ set_slob(best_prev, slob_units(best_prev), best + units);
|
||||
}
|
||||
+ else{
|
||||
+ sp->freelist = best + units;
|
||||
+ }
|
||||
+ set_slob(best + units, avail - units, next);
|
||||
+ }
|
||||
+
|
||||
+ sp->units -= units;
|
||||
+ if (!sp->units)
|
||||
+ clear_slob_page_free(sp);
|
||||
+ return best;
|
||||
+ }
|
||||
+
|
||||
+ return NULL;
|
||||
+}
|
||||
+
|
||||
+
|
||||
+static int find_closest_block_size_in_page(struct page *sp, size_t size, int align)
|
||||
+{
|
||||
+ slob_t *prev, *cur, *aligned = NULL, *best = NULL;
|
||||
+ int delta = 0, units = SLOB_UNITS(size);
|
||||
|
||||
- sp->units -= units;
|
||||
- if (!sp->units)
|
||||
- clear_slob_page_free(sp);
|
||||
- return cur;
|
||||
+ for (prev = NULL, cur = sp->freelist; ; prev = cur, cur = slob_next(cur)) {
|
||||
+ slobidx_t avail = slob_units(cur);
|
||||
+
|
||||
+ /* Align if necessary */
|
||||
+ if (align) {
|
||||
+ aligned = (slob_t *)ALIGN((unsigned long)cur, align);
|
||||
+ delta = aligned - cur;
|
||||
}
|
||||
- if (slob_last(cur))
|
||||
- return NULL;
|
||||
+
|
||||
+ /* Keep track of the better block if we've found one */
|
||||
+ if(avail >= units + delta && (!best || avail < slob_units(best))){
|
||||
+ best = cur;
|
||||
+ }
|
||||
+
|
||||
+ /* If we're at the end, return the best block, or -1 if not found*/
|
||||
+ if (slob_last(cur)) {
|
||||
+ if(best){
|
||||
+ return slob_units(best);
|
||||
+ }else{
|
||||
+ return -1;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
}
|
||||
+ return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -267,11 +334,12 @@
|
||||
*/
|
||||
static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
|
||||
{
|
||||
- struct page *sp;
|
||||
- struct list_head *prev;
|
||||
- struct list_head *slob_list;
|
||||
+ struct page *sp = NULL, *best_pg = NULL;
|
||||
+ struct list_head *slob_list = NULL;
|
||||
slob_t *b = NULL;
|
||||
unsigned long flags;
|
||||
+ slobidx_t best_fit = 0;
|
||||
+ slobidx_t cur_fit;
|
||||
|
||||
if (size < SLOB_BREAK1)
|
||||
slob_list = &free_slob_small;
|
||||
@@ -281,53 +349,67 @@
|
||||
slob_list = &free_slob_large;
|
||||
|
||||
spin_lock_irqsave(&slob_lock, flags);
|
||||
- /* Iterate through each partially free page, try to find room */
|
||||
+
|
||||
+ /* Iterate through each page for find a spot if possible */
|
||||
list_for_each_entry(sp, slob_list, lru) {
|
||||
#ifdef CONFIG_NUMA
|
||||
- /*
|
||||
- * If there's a node specification, search for a partial
|
||||
- * page with a matching node id in the freelist.
|
||||
- */
|
||||
- if (node != NUMA_NO_NODE && page_to_nid(sp) != node)
|
||||
- continue;
|
||||
+ /*
|
||||
+ * If there's a node specification, search for a partial
|
||||
+ * page with a matching node id in the freelist.
|
||||
+ */
|
||||
+ if (node != NUMA_NO_NODE && page_to_nid(sp) != node)
|
||||
+ continue;
|
||||
#endif
|
||||
- /* Enough room on this page? */
|
||||
- if (sp->units < SLOB_UNITS(size))
|
||||
- continue;
|
||||
-
|
||||
- /* Attempt to alloc */
|
||||
- prev = sp->lru.prev;
|
||||
- b = slob_page_alloc(sp, size, align);
|
||||
- if (!b)
|
||||
- continue;
|
||||
-
|
||||
- /* Improve fragment distribution and reduce our average
|
||||
- * search time by starting our next search here. (see
|
||||
- * Knuth vol 1, sec 2.5, pg 449) */
|
||||
- if (prev != slob_list->prev &&
|
||||
- slob_list->next != prev->next)
|
||||
- list_move_tail(slob_list, prev->next);
|
||||
- break;
|
||||
+ /* Enough room on this page? */
|
||||
+ if (sp->units < SLOB_UNITS(size))
|
||||
+ continue;
|
||||
+
|
||||
+ /* Find out if there's space for this in the current page */
|
||||
+ cur_fit = find_closest_block_size_in_page(sp, size, align);
|
||||
+
|
||||
+ /* If not, continue*/
|
||||
+ if(cur_fit == -1){
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ /* Stop if we've found something that perfectly matches */
|
||||
+ if (cur_fit == SLOB_UNITS(size)) {
|
||||
+ best_pg = sp;
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ /* Store the current best fit block, if it's better than previous */
|
||||
+ if (best_fit > cur_fit || best_pg == NULL) {
|
||||
+ best_pg = sp;
|
||||
+ best_fit = cur_fit;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ /* Attempt to allocate */
|
||||
+ if(best_pg != NULL){
|
||||
+ b = slob_page_alloc(best_pg, size, align);
|
||||
}
|
||||
+
|
||||
spin_unlock_irqrestore(&slob_lock, flags);
|
||||
|
||||
- /* Not enough space: must allocate a new page */
|
||||
+ /* Make a new page if we never found a spot */
|
||||
if (!b) {
|
||||
- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
|
||||
- if (!b)
|
||||
- return NULL;
|
||||
- sp = virt_to_page(b);
|
||||
- __SetPageSlab(sp);
|
||||
-
|
||||
- spin_lock_irqsave(&slob_lock, flags);
|
||||
- sp->units = SLOB_UNITS(PAGE_SIZE);
|
||||
- sp->freelist = b;
|
||||
- INIT_LIST_HEAD(&sp->lru);
|
||||
- set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
|
||||
- set_slob_page_free(sp, slob_list);
|
||||
- b = slob_page_alloc(sp, size, align);
|
||||
- BUG_ON(!b);
|
||||
- spin_unlock_irqrestore(&slob_lock, flags);
|
||||
+ b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
|
||||
+ if (!b)
|
||||
+ return NULL;
|
||||
+ sp = virt_to_page(b);
|
||||
+ __SetPageSlab(sp);
|
||||
+
|
||||
+ spin_lock_irqsave(&slob_lock, flags);
|
||||
+ sp->units = SLOB_UNITS(PAGE_SIZE);
|
||||
+ sp->freelist = b;
|
||||
+ INIT_LIST_HEAD(&sp->lru);
|
||||
+ set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
|
||||
+ set_slob_page_free(sp, slob_list);
|
||||
+ b = slob_page_alloc(sp, size, align);
|
||||
+ BUG_ON(!b);
|
||||
+ spin_unlock_irqrestore(&slob_lock, flags);
|
||||
+ num_pages++;
|
||||
}
|
||||
if (unlikely((gfp & __GFP_ZERO) && b))
|
||||
memset(b, 0, size);
|
||||
@@ -362,6 +444,7 @@
|
||||
__ClearPageSlab(sp);
|
||||
page_mapcount_reset(sp);
|
||||
slob_free_pages(b, 0);
|
||||
+ num_pages--;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -640,3 +723,31 @@
|
||||
{
|
||||
slab_state = FULL;
|
||||
}
|
||||
+
|
||||
+asmlinkage long sys_slob_free(void) {
|
||||
+ struct list_head *temp;
|
||||
+ struct page *sp;
|
||||
+ unsigned long free_units = 0;
|
||||
+
|
||||
+ temp = &free_slob_small;
|
||||
+ list_for_each_entry(sp, temp, lru) {
|
||||
+ free_units += sp->units;
|
||||
+ }
|
||||
+ temp = &free_slob_medium;
|
||||
+ list_for_each_entry(sp, temp, lru) {
|
||||
+ free_units += sp->units;
|
||||
+ }
|
||||
+ temp = &free_slob_large;
|
||||
+ list_for_each_entry(sp, temp, lru) {
|
||||
+ free_units += sp->units;
|
||||
+ }
|
||||
+
|
||||
+ return free_units;
|
||||
+}
|
||||
+
|
||||
+asmlinkage long sys_slob_used(void) {
|
||||
+ long slob_total_used;
|
||||
+
|
||||
+ slob_total_used = SLOB_UNITS(PAGE_SIZE) * num_pages;
|
||||
+ return slob_total_used;
|
||||
+}
|
||||
\ No newline at end of file
|
||||
diff -Naur -x '*.o' -x '*.ko' -x '*.order' -x '*.builtin' -x '*.cmd' -x '*.mod.c' linux-yocto-3.19.2_untouched/include/linux/syscalls.h linux-yocto-3.19.2/include/linux/syscalls.h
|
||||
--- linux-yocto-3.19.2_untouched/include/linux/syscalls.h 2018-05-04 15:14:59.075324834 -0700
|
||||
+++ linux-yocto-3.19.2/include/linux/syscalls.h 2018-06-06 16:32:02.518020727 -0700
|
||||
@@ -882,4 +882,6 @@
|
||||
const char __user *const __user *argv,
|
||||
const char __user *const __user *envp, int flags);
|
||||
|
||||
+asmlinkage long sys_slob_free(void);
|
||||
+asmlinkage long sys_slob_used(void);
|
||||
#endif
|
||||
diff -Naur -x '*.o' -x '*.ko' -x '*.order' -x '*.builtin' -x '*.cmd' -x '*.mod.c' linux-yocto-3.19.2_untouched/arch/x86/syscalls/syscall_32.tbl linux-yocto-3.19.2/arch/x86/syscalls/syscall_32.tbl
|
||||
--- linux-yocto-3.19.2_untouched/arch/x86/syscalls/syscall_32.tbl 2018-05-04 15:14:40.077010007 -0700
|
||||
+++ linux-yocto-3.19.2/arch/x86/syscalls/syscall_32.tbl 2018-06-06 16:31:26.578421117 -0700
|
||||
@@ -365,3 +365,6 @@
|
||||
356 i386 memfd_create sys_memfd_create
|
||||
357 i386 bpf sys_bpf
|
||||
358 i386 execveat sys_execveat stub32_execveat
|
||||
+
|
||||
+400 i386 slob_free sys_slob_free
|
||||
+401 i386 slob_used sys_slob_used
|
||||
\ No newline at end of file
|
||||
--- linux-yocto-3.19.2_untouched/.config 2018-05-04 15:15:03.830403632 -0700
|
||||
+++ linux-yocto-3.19.2/.config 2018-06-05 17:11:02.799939154 -0700
|
||||
@@ -146,7 +146,6 @@
|
||||
CONFIG_MEMCG=y
|
||||
CONFIG_MEMCG_SWAP=y
|
||||
CONFIG_MEMCG_SWAP_ENABLED=y
|
||||
-CONFIG_MEMCG_KMEM=y
|
||||
# CONFIG_CGROUP_PERF is not set
|
||||
CONFIG_CGROUP_SCHED=y
|
||||
CONFIG_FAIR_GROUP_SCHED=y
|
||||
@@ -211,12 +210,10 @@
|
||||
CONFIG_PERF_EVENTS=y
|
||||
# CONFIG_DEBUG_PERF_USE_VMALLOC is not set
|
||||
CONFIG_VM_EVENT_COUNTERS=y
|
||||
-CONFIG_SLUB_DEBUG=y
|
||||
CONFIG_COMPAT_BRK=y
|
||||
# CONFIG_SLAB is not set
|
||||
-CONFIG_SLUB=y
|
||||
-# CONFIG_SLOB is not set
|
||||
-CONFIG_SLUB_CPU_PARTIAL=y
|
||||
+# CONFIG_SLUB is not set
|
||||
+CONFIG_SLOB=y
|
||||
# CONFIG_SYSTEM_TRUSTED_KEYRING is not set
|
||||
CONFIG_PROFILING=y
|
||||
CONFIG_TRACEPOINTS=y
|
||||
@@ -251,7 +248,6 @@
|
||||
CONFIG_HAVE_PERF_USER_STACK_DUMP=y
|
||||
CONFIG_HAVE_ARCH_JUMP_LABEL=y
|
||||
CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG=y
|
||||
-CONFIG_HAVE_ALIGNED_STRUCT_PAGE=y
|
||||
CONFIG_HAVE_CMPXCHG_LOCAL=y
|
||||
CONFIG_HAVE_CMPXCHG_DOUBLE=y
|
||||
CONFIG_ARCH_WANT_IPC_PARSE_VERSION=y
|
||||
@@ -275,7 +271,6 @@
|
||||
# CONFIG_GCOV_KERNEL is not set
|
||||
CONFIG_ARCH_HAS_GCOV_PROFILE_ALL=y
|
||||
CONFIG_HAVE_GENERIC_DMA_COHERENT=y
|
||||
-CONFIG_SLABINFO=y
|
||||
CONFIG_RT_MUTEXES=y
|
||||
CONFIG_BASE_SMALL=0
|
||||
CONFIG_MODULES=y
|
||||
@@ -3787,8 +3782,6 @@
|
||||
# CONFIG_PAGE_EXTENSION is not set
|
||||
# CONFIG_DEBUG_PAGEALLOC is not set
|
||||
# CONFIG_DEBUG_OBJECTS is not set
|
||||
-# CONFIG_SLUB_DEBUG_ON is not set
|
||||
-# CONFIG_SLUB_STATS is not set
|
||||
CONFIG_HAVE_DEBUG_KMEMLEAK=y
|
||||
# CONFIG_DEBUG_KMEMLEAK is not set
|
||||
# CONFIG_DEBUG_STACK_USAGE is not set
|
||||
@@ -0,0 +1,99 @@
|
||||
\documentclass[onecolumn, draftclsnofoot, 10pt, compsoc]{IEEEtran}
|
||||
\usepackage{graphicx}
|
||||
\graphicspath{{./figures/}}
|
||||
|
||||
\usepackage{url}
|
||||
\usepackage{setspace}
|
||||
\usepackage{multicol}
|
||||
\usepackage{pdflscape}
|
||||
\usepackage{pdfpages}
|
||||
\usepackage[british]{babel}
|
||||
\usepackage{listings}
|
||||
\usepackage{xcolor}
|
||||
\usepackage{listings}
|
||||
\usepackage{hyperref}
|
||||
\usepackage{subfig}
|
||||
\usepackage{textcomp}
|
||||
|
||||
\usepackage{geometry}
|
||||
\geometry{textheight=9.5in, textwidth=7in}
|
||||
|
||||
% \overfullrule=2in
|
||||
|
||||
|
||||
%Personal \newcommands
|
||||
|
||||
\definecolor{backcolor}{rgb}{0.95,0.95,0.92}
|
||||
\lstset{basicstyle=\ttfamily,
|
||||
backgroundcolor=\color{backcolor},
|
||||
showstringspaces=false,
|
||||
commentstyle=\color{red},
|
||||
keywordstyle=\color{blue},
|
||||
columns=fullflexible,
|
||||
breaklines=true,
|
||||
postbreak=\mbox{\textcolor{red}{$\hookrightarrow$}\space},
|
||||
}
|
||||
|
||||
\newcommand{\NameSigPair}[1]{
|
||||
\par
|
||||
\makebox[2.75in][r]{#1}
|
||||
\hfill
|
||||
\makebox[3.25in]{
|
||||
\makebox[2.25in]{\hrulefill}
|
||||
\hfill
|
||||
\makebox[.75in]{\hrulefill}
|
||||
}
|
||||
\par\vspace{-12pt}
|
||||
\textit{
|
||||
\tiny\noindent
|
||||
\makebox[2.75in]{}
|
||||
\hfill
|
||||
\makebox[3.25in]{
|
||||
\makebox[2.25in][r]{Signature}
|
||||
\hfill
|
||||
\makebox[.75in][r]{Date}
|
||||
}
|
||||
}
|
||||
}
|
||||
% 3. If the document is not to be signed, uncomment the command below
|
||||
\renewcommand{\NameSigPair}[1]{#1}
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
\begin{document}
|
||||
\begin{titlepage}
|
||||
\pagenumbering{gobble}
|
||||
\begin{singlespace}
|
||||
\par\vspace{2in}
|
||||
\centering
|
||||
\scshape{
|
||||
\huge Operating Systems II Homework 4 \par
|
||||
{\large\today}\par
|
||||
\vspace{.5in}
|
||||
\vfill
|
||||
\vspace{5pt}
|
||||
{\large Prepared by }\par
|
||||
Group 4 \par
|
||||
% 5. comment out the line below this one if you do not wish to name your team
|
||||
\vspace{5pt}
|
||||
{\Large
|
||||
\NameSigPair{Corinna Brown}\par
|
||||
\NameSigPair{Corwin Perren}\par
|
||||
}
|
||||
\vspace{20pt}
|
||||
\begin{abstract}
|
||||
The document is our group's submission for homework four covering the design of our solution, answers to explicit assignment questions, a version control log, and a work log.
|
||||
\end{abstract}
|
||||
}
|
||||
\end{singlespace}
|
||||
\end{titlepage}
|
||||
\newpage
|
||||
\pagenumbering{arabic}
|
||||
\tableofcontents
|
||||
\clearpage
|
||||
|
||||
\input{design}
|
||||
\input{questions}
|
||||
\input{versioncontrollog}
|
||||
\input{worklog}
|
||||
|
||||
\end{document}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,31 @@
|
||||
# This config is copied from overleaf so output there will match compiled output here
|
||||
|
||||
# support for the glossaries package:
|
||||
add_cus_dep('glo', 'gls', 0, 'makeglossaries');
|
||||
add_cus_dep('acn', 'acr', 0, 'makeglossaries');
|
||||
sub makeglossaries {
|
||||
system("makeglossaries \"$_[0]\"");
|
||||
}
|
||||
|
||||
# support for the nomencl package:
|
||||
add_cus_dep('nlo', 'nls', 0, 'makenlo2nls');
|
||||
sub makenlo2nls {
|
||||
system("makeindex -s nomencl.ist -o \"$_[0].nls\" \"$_[0].nlo\"");
|
||||
}
|
||||
|
||||
# from the documentation for V. 2.03 of asymptote:
|
||||
sub asy {return system("asy \"$_[0]\"");}
|
||||
add_cus_dep("asy","eps",0,"asy");
|
||||
add_cus_dep("asy","pdf",0,"asy");
|
||||
add_cus_dep("asy","tex",0,"asy");
|
||||
|
||||
# metapost rule from http://tex.stackexchange.com/questions/37134
|
||||
add_cus_dep('mp', '1', 0, 'mpost');
|
||||
sub mpost {
|
||||
my $file = $_[0];
|
||||
my ($name, $path) = fileparse($file);
|
||||
pushd($path);
|
||||
my $return = system "mpost $name";
|
||||
popd();
|
||||
return $return;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
# Makefile created by Corwin Perren
|
||||
# Generic makefile for all LaTeX projects downloaded from overleaf
|
||||
#
|
||||
# All this makefile does is call perl against latexmkrc, which is
|
||||
# the latex equivalent of make
|
||||
|
||||
LATEXMK_COMPILE_FLAGS = -cd -pdf homework4.tex
|
||||
LATEXMK_CLEAN_FLAGS = -c
|
||||
|
||||
.DEFAULT_GOAL := all
|
||||
|
||||
all: latexmk_output clean
|
||||
|
||||
latexmk_output:
|
||||
perl latexmk.pl $(LATEXMK_COMPILE_FLAGS)
|
||||
mv homework4.pdf CS444_project4_4.pdf
|
||||
|
||||
clean:
|
||||
perl latexmk.pl $(LATEXMK_CLEAN_FLAGS)
|
||||
@@ -0,0 +1,44 @@
|
||||
\section{Questions}
|
||||
\subsection{Point of Assignment}
|
||||
One of the main points of this assignment was to gain experience working with the memory management system in Linux. Working with slob.c requires knowledge of how memory is organized and how to access this memory. Doing this also provides more experience modifying existing kernel code. Finally this assignment also provided an opportunity to create and use a custom system call.
|
||||
|
||||
\subsection{Problem Approach}
|
||||
We approached this problem by first reading the HW4 page on Canvas and reading through the slob.c file in the "mm" folder. After reaching an understanding of how the "slob.c" file works, we set up our kernel to use SLOB instead of SLAB.
|
||||
|
||||
Next we started to create a design for how we would implement the best-fit algorithm. This involved determining which functions were being used to implement first-fit. These functions were found to be "slob\_alloc" and "slob\_page\_alloc". To implement best-fit we modified these and added a helper function "find\_closest\_block\_size\_in\_page". After this was tested and correctly functioning, we added two system call functions that find the amount of free memory and the amount of used memory by finding the number of pages being used and the amount of space on each page that is free. These system calls were also added to a unmodified version of the kernel's slob.c to test the fragmentation of the first-fit algorithm in comparison to the best-fit algorithm. These system calls were added to the system call table, and a program was written to call these system calls in order to test both algorithms. Each algorithm was then tested five times. The results of these tests are in the "Correctness" section below.
|
||||
|
||||
\subsection{Correctness}
|
||||
The test results are shown in Table 1 below. The test was run five different times on each of the two kernels with the different algorithms. To calculate the fragmentation, the following equation was used:
|
||||
\[ \frac{free blocks}{total blocks}*100 = fragmentation \]
|
||||
The average fragmentation over these five tests was then calculated. The average fragmentation was found to be 5.80\% for first-fit and 4.20\% for best-fit.
|
||||
|
||||
\begin{table}[ht]
|
||||
\caption{Fragmentation of First-Fit vs. Best-Fit Algorithms} % title of Table
|
||||
\centering % used for centering table
|
||||
\begin{tabular}{ c | c c c | c c c } % centered columns (7 columns)
|
||||
\hline\hline %inserts double horizontal lines
|
||||
& \multicolumn{3}{| c |}{First-Fit} & \multicolumn{3}{ c }{Best-Fit}\\
|
||||
\hline
|
||||
Trial & Free Blocks & Total Blocks & Fragmentation & Free Blocks & Total Blocks & Fragmentation \\ [0.5ex] % inserts table
|
||||
%heading
|
||||
\hline % inserts single horizontal line
|
||||
1 & 303776 & 5220352 & 5.82\% & 217544 & 5132288 & 4.24\% \\ % inserting body of the table
|
||||
2 & 303032 & 5220352 & 5.80\% & 214686 & 5130240 & 4.18\% \\
|
||||
3 & 304898 & 5220400 & 5.84\% & 215515 & 5130240 & 4.20\% \\
|
||||
4 & 303096 & 5220352 & 5.81\% & 213248 & 5128192 & 4.16\% \\
|
||||
5 & 298986 & 5216256 & 5.73\% & 215862 & 5130240 & 4.21\% \\
|
||||
\hline
|
||||
Average & & & 5.80\% & & & 4.20\% \\
|
||||
\hline %inserts single line
|
||||
\end{tabular}
|
||||
\label{table:nonlin} % is used to refer this table in the text
|
||||
\end{table}
|
||||
|
||||
As can be seen from the table, the fragmentation values fo r the best-fit algorithm are lower than those for the default first-fit one that ships with the kernel. This proves out implementation is correct as the best-fit model, while slower, does use the allocated pages in memory more efficiently than first-fit.
|
||||
|
||||
|
||||
\subsection{What Was Learned}
|
||||
We learned in this lab that the memory management system in linux is large and complex. We also learned that best-fit has less fragmentation than first-fit. However, there is a trade-off as best-fit also causes the kernel to boot significantly slower than with first-fit. Finally we learned how to create a custom system call, how to add it to the system call table, and how to use it.
|
||||
|
||||
\subsection{How to Evaluate}
|
||||
To evaluate this, get a clean version of the linux yocto kernel and copy the patch file into the root of the directory. Run "patch -p1 -t $<$ homework4.patch" to apply the changes to the necessary files. Make the kernel using "make -j4". Boot the kernel and scp the "find\_fragmentation.c" file into the running vm. Run "gcc find\_fragmentation.c -o frag\_check" on the vm's command line to build the fragmentation source into a binary. Run the binary with "./frag\_check". If the program outputs reasonable values for free, used, and fragmentation the kernel was built and is running correctly using the modified slob algorithm. The values on a cleanly booted system should closely match the best-fit table values from above.
|
||||
@@ -0,0 +1,11 @@
|
||||
\section{Version Control Log}
|
||||
\begin{center}
|
||||
\begin{tabular}{l l l l} \textbf{Detail} & \textbf{Author} & \textbf{Date} &\textbf{Description}\\\hline
|
||||
|
||||
\href{.//commit/3b486d3c5ba08b193bc64b47e5cab98ac4cbbafe}{3b486d3} & Corwin Perren & 2018-06-05 18:16:42 -0700 &Clean kernels for homework 4. *Design commited here*\\\hline
|
||||
\href{.//commit/5b7861a5682daf082272f8e0dd24a0174ef70f4b}{5b7861a} & Corwin Perren & 2018-06-05 18:26:26 -0700 &Missed adding updated files from previous commit.\\\hline
|
||||
\href{.//commit/608c1fc75c1be5e2a87a81185c3a09712ca5232f}{608c1fc} & Corwin Perren & 2018-06-06 18:00:36 -0700 &Finished hw4. Patch made. Tested.\\\hline
|
||||
|
||||
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
@@ -0,0 +1,20 @@
|
||||
\section{Work Log}
|
||||
\begin{itemize}
|
||||
\item 06-05-2019
|
||||
\begin{itemize}
|
||||
\item Group met in Valley Library
|
||||
\item Started Latex document for Homework 4
|
||||
\item Read through slob.c
|
||||
\item Created initial design for best-fit algorithm
|
||||
\item Began work modifying slob.c
|
||||
\end{itemize}
|
||||
\item 06-06-2019
|
||||
\begin{itemize}
|
||||
\item Group met in Valley Library
|
||||
\item Made working version of best-fit slob.c
|
||||
\item Ran performance tests between algorithms
|
||||
\item Created patch file
|
||||
\item Finished latex document
|
||||
\item Turned in assignment
|
||||
\end{itemize}
|
||||
\end{itemize}
|
||||
Reference in New Issue
Block a user