CS318 - Pintos
Pintos source browser for JHU CS318 course
Enumerations | Functions | Variables
multi-oom.c File Reference
#include <debug.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <syscall.h>
#include <random.h>
#include "tests/lib.h"
Include dependency graph for multi-oom.c:

Go to the source code of this file.

Enumerations

enum  child_termination_mode { RECURSE, CRASH }
 

Functions

static pid_t spawn_child (int c, enum child_termination_mode mode)
 Spawn a recursive copy of ourselves, passing along instructions for the child. More...
 
static void consume_some_resources (void)
 Open a number of files (and fail to close them). More...
 
static int NO_INLINE consume_some_resources_and_die (int seed)
 Consume some resources, then terminate this process in some abnormal way. More...
 
int main (int argc, char *argv[])
 The first copy is invoked without command line arguments. More...
 

Variables

static const int EXPECTED_DEPTH_TO_PASS = 30
 Recursively executes itself until the child fails to execute. More...
 
static const int EXPECTED_REPETITIONS = 10
 
const char * test_name = "multi-oom"
 Child process for syn-read test. More...
 

Enumeration Type Documentation

◆ child_termination_mode

Enumerator
RECURSE 
CRASH 

Definition at line 32 of file multi-oom.c.

Function Documentation

◆ consume_some_resources()

static void consume_some_resources ( void  )
static

Open a number of files (and fail to close them).

The kernel must free any kernel resources associated with these file descriptors.

Definition at line 49 of file multi-oom.c.

References open(), and test_name.

Referenced by consume_some_resources_and_die(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ consume_some_resources_and_die()

static int NO_INLINE consume_some_resources_and_die ( int  seed)
static

Consume some resources, then terminate this process in some abnormal way.


Definition at line 66 of file multi-oom.c.

References consume_some_resources(), exit(), NOT_REACHED, NULL, open(), PHYS_BASE, random_init(), and random_ulong().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int argc   ,
char *  argv[] 
)

The first copy is invoked without command line arguments.

Subsequent copies are invoked with a parameter 'depth' that describes how many parent processes preceded them. Each process spawns one or multiple recursive copies of itself, passing 'depth+1' as depth.

Some children are started with the '-k' flag, which will result in abnormal termination.

Definition at line 106 of file multi-oom.c.

References ASSERT, atoi(), consume_some_resources(), consume_some_resources_and_die(), CRASH, EXPECTED_DEPTH_TO_PASS, EXPECTED_REPETITIONS, fail(), msg(), NOT_REACHED, RECURSE, spawn_child(), strcmp(), and wait().

Here is the call graph for this function:

◆ spawn_child()

static pid_t spawn_child ( int  c,
enum child_termination_mode  mode 
)
static

Spawn a recursive copy of ourselves, passing along instructions for the child.

Definition at line 37 of file multi-oom.c.

References CRASH, exec(), mode, snprintf(), and test_name.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ EXPECTED_DEPTH_TO_PASS

const int EXPECTED_DEPTH_TO_PASS = 30
static

Recursively executes itself until the child fails to execute.

We expect that at least 30 copies can run.

We count how many children your kernel was able to execute before it fails to start a new process. We require that, if a process doesn't actually get to start, exec() must return -1, not a valid PID.

We repeat this process 10 times, checking that your kernel allows for the same level of depth every time.

In addition, some processes will spawn children that terminate abnormally after allocating some resources.

Written by Godmar Back godma.nosp@m.r@gm.nosp@m.ail.c.nosp@m.om

Definition at line 27 of file multi-oom.c.

Referenced by main().

◆ EXPECTED_REPETITIONS

const int EXPECTED_REPETITIONS = 10
static

Definition at line 28 of file multi-oom.c.

Referenced by main().

◆ test_name

const char* test_name = "multi-oom"

Child process for syn-read test.

Reads the contents of a test file a byte at a time, in the hope that this will take long enough that we can get a significant amount of contention in the kernel file system code.

Child process for syn-read test.

Reads from a file created by our parent process, which is growing it. We loop until we've read the whole file successfully. Many iterations through the loop will return 0 bytes, because the file has not grown in the meantime. That is, we are "busy waiting" for the file to grow. (This test could be improved by adding a "yield" system call and calling yield whenever we receive a 0-byte read.)

Child process for syn-read test.

Attempts to close the file descriptor passed as the first command-line argument. This is invalid, because file descriptors are not inherited in Pintos. Two results are allowed: either the system call should return without taking any action, or the kernel should terminate the process with a -1 exit code.

Child process for syn-read test.

Opens and tries to write to its own executable, verifying that that is disallowed. Then recursively executes itself to the depth indicated by the first command-line argument.

Child process for syn-read test.

Just prints a single message and terminates.

Child process for syn-read test.

Definition at line 30 of file multi-oom.c.

Referenced by consume_some_resources(), and spawn_child().