CMSC 421 Operating Systems Lecture Notes (c) 1993 Howard E. Motteler 7.5.3 Unix Swapping --------------------- Older Unix had a - swapper (`high level' scheduler) - processes scheduler (`low level' scheduler) Swapping starts when kernel ran out of memory due to: - fork - brk (process asked for more memory) - growing stack Swapping can also start when some other process had been `swapped out' on disk for too long Swapper selects a `victim' to be swapped out: - a process that has been in mem. for at least 2 seconds (to prevent thrashing), and is either - a blocked process (e.g., waiting on i/o) with highest priority + residence time, or - a ready process with highest pri + res time (high number -> low priority in Unix) (sometimes more than one victim is needed, if a lot of memory must be freed up) Swapped-out processes are checked every few sec's to see if they are ready to run: = Swapper choses oldest ready process and does - an `easy swap' if there is enough free memory - a `hard swap' of some other process has to be swapped out first = This is repeated until - no other swapped out processes are ready, or - there is no more room for `new' processes (just brought in or less than 2 sec old) Free memory and swap space is kept on linked lists, using first fit