viewpoints

VDOI:10.1145/3126494 Peter J. Denning The Profession of IT Multitasking Without Thrashing Lessons from operating systems teach how to do multitasking without thrashing.

UR INDIVIDUAL ABILITY to The first four destinations basi- mercial world with its OS 360 in 1965. be productive has been cally remove incoming tasks from your Operating systems implement mul- hard stressed by the sheer workspace, the fifth closes quick loops, titasking by cycling a CPU through a load of task requests we and the sixth holds your incomplete list of all incomplete tasks, giving each receive via the Internet. In loops. GTD helps you keep track of one a time slice on the CPU. If the task 2001, David Allen published Getting these unfinished loops. does not complete by the end of its O 1 Things Done, a best-selling book about The idea of tasks being closed loops time slice, the OS it and puts a system for managing all our tasks to of a conversation between a requester it on the end of the list. To switch the eliminate stress and increase produc- and a perform was first proposed in CPU context, the OS saves all the CPU tivity. Allen claims that a considerable 1979 by Fernando Flores.5 The “condi- registers of the current task and loads amount of stress comes our way when tions of satisfaction” that are produced the registers of the new task. The de- we have too many incomplete tasks. by the performer define loop comple- signers set the time slice length long He views tasks as loops connecting tion and allow tracking the movement enough to keep the total someone making a request and you of the conversation toward completion. time insignificant. However, if the time as the performer who must deliver the Incomplete loops have many negative slice is too short, the system can signif- requested results. Getting systematic consequences including accumulations icantly slow down due to rapidly accu- about completing loops dramatically of dissatisfaction, stress, and distrust. mulating context-switching time. reduces stress. Many people have found the GTD When main memory was small, mul- Allen says that operating systems are to be very helpful at titasking was implemented by loading designed to get tasks done efficiently completing their loops, maintaining only one task at a time. Thus, each con- on computers. Why not export key ideas satisfaction with work, and reducing text switch forced a memory swap: the about task management into a person- stress. It is a fine example of us taking pages of the running task were saved to al operating system? He calls his oper- lessons from technology to improve disk, and then the pages of the new task ating system GTD, for Getting Things our lives. loaded. Page swapping is extremely ex- Done. The GTD system supports you in pensive. The 1965 era OSs eliminated tracking open loops and moving them Multitasking this problem by combining multitask- toward completion. It routes incoming Unfortunately, GTD does not eliminate ing with multiprogramming: the pages requests to one of these destinations in another source of stress that was much of all active tasks stay loaded in main your filing system: less of a problem in 2001 than today. memory and context switching involves ˲˲ Trash This is the problem of thrashing when no swapping. However, if too many tasks ˲˲ Tasks that might one day turn out you have too many tasks in progress at were activated, their allocations would to be worth doing the same time.2 be too small and they would page exces- ˲˲ Tasks that serve as potential future The term multitasking is used in op- sively, causing system throughput to col- reference points erating systems to mean executing mul- lapse. Engineers called this thrashing, a ˲˲ Tasks delegated to someone else, tiple computational processes simulta- shorthand for “paging to death.” awaiting their response neously. The very first operating system Eventually researchers discovered ˲˲ Tasks that can be completed im- do this was the supervisor, running the root cause of thrashing and built mediately in under two minutes at the University of Manchester, U.K., in control systems to eliminate it—I will ˲˲ Tasks accepted for processing 1959. IBM brought the idea to the com- return to this shortly.

32 COMMUNICATIONS OF THE ACM | SEPTEMBER 2017 | VOL. 60 | NO. 9 viewpoints viewpoints

Figure 1. In this memory map of a Firefox Browser in Linux, the colored pixels indicate that a page (vertical axis) is used during a fixed size execution interval (horizontal axis). The locality sets (pages used) are small compared to the whole address space and their use persists over extended intervals.

Instructions Modify Load Store html V 7bb0

6cc4

5dd8 PAGES

4eec

4000

0 75341312 150682624 226023936 301365249 INSTRUCTIONS (376706 per pixel) Page size: 4096: 0 to 2% memory

Human Multitasking numerals. With fewer context switches, decision that can take quite a Humans multitask too by juggling sev- time-slicing is faster than fine-grained long time to decide—a situation known eral incomplete tasks at once. Cogni- multitasking but still slower than one- as the choice uncertainty problem.4 tive scientists and psychologists have at-a-time processing. A third factor that slows human multi- studied human multitasking for almost Human context switching is more tasking is gathering the resources neces- two decades. Their main finding is that complicated than computer context sary to continue with a task. Some resourc- humans do not switch tasks well. Psy- switching. Whereas the computer con- es are physical such as books, equipment, chologist Nancy Napier illustrates with text switch replaces a fixed number of and tools. Some are digital such as files, a simple do-it-yourself test.7 Write “I am bytes in a few CPU registers, the human images, sounds, Web pages, and remote a great multitasker” on line 1 and the has to recall what was “on the mind” at databases. And some are mental, things series of numbers 1, 2, 3, …, 20 on line the time of the switch and, if the human you have to remember about where you 2. Time how long it takes to do this. Now was interrupted with no opportunity to were in the task and what approach you do it again, alternating one letter from choose a “clean break,” the human has were taking to perform it. All these re- line 1 and one numeral from line 2. to reconstruct lost short term memory. sources must be close at hand so that you Time how long it takes. For most people, Context switching is not the only can access them quickly. the fine-grained multitasking in the sec- problem. Whereas a computer picks These three problems plague multi- ond run takes over twice as long as the the next task from the head of a queue, taskers of all age groups. Many studies one-task-at-a-time first run. Moreover, your brain has to consider all the tasks report considerable evidence of nega- you are likely to make more errors while and select one, such as the most urgent tive effects—multitasking seems to multitasking. This test reveals just how or the most important. The time to reduce productivity, increase errors, slow our brains are at context switching. choose a next task goes up faster than increase stress, and exhaust us. Some You can try the test a third time using linear with the number of tasks. More- researchers report that multitaskers are time-slicing, for example writing five over, if you have several urgent impor- less likely to develop expertise in a topic

FIGURE 1 COURTESY OF ANDRIAN MCMENAMIN FIGURE 1 COURTESY letters and then switching to write five tant tasks, your brain can get stuck in a because they do not get enough inten-

SEPTEMBER 2017 | VOL. 60 | NO. 9 | COMMUNICATIONS OF THE ACM 33 viewpoints

Figure 2. OS control system to maximize throughput with variable partition of main time needed for a task. memory determined by task working sets. ˲˲ Some tasks need to be held aside in an inactive status until you have the

main memory (active tasks) capacity to deal with them. Analog: the tasks awaiting waiting tasks queue. activation accepted ˲˲ When a task’s working set is in tasks free WS1 WS1 WS3 WS4 your workspace, protect it from being completed incoming tasks unloaded as long as the task is active. requests tasks put Analog: protect working sets of active aside by OS open valve when tasks and do not steal from other tasks. first waiting task’s ˲˲ WS fits into free You will thrash if you activate too many tasks so that the total demand is beyond your capacity. Analog: insuffi- cient CPU and memory for active tasks. sive focused practice with it. Some fret susceptible to thrashing as the num- ˲˲ If you are able to choose moments that if we do not learn to manage our ber of tasks sharing memory increases of context switch, select a moment of multitasking well, we may wind up be- because each gets a smaller workspace “clean break” that requires little men- coming a world of dilettantes with few and, when the workspaces are smaller tal reacquisition time when you return experts to keep our technology running. than the working sets, every task is to the task. If you cannot defer an in- Thrashing happens to human mul- quickly interrupted by a page fault. terruption to such a moment, you will titaskers when they have too many in- Under working-set partitioning need more reacquisition time because complete tasks. They fall into a mood the OS sizes the workspaces to hold you will have to reconstruct short-term of “overwhelm” in which they expe- each task’s measured working set. As memory lost at the interruption. Ana- rience considerable stress, cannot shown in Figure 2, it loads tasks into log: ill-timed interrupts can cause loss choose a next task to work on, and can- memory until the unused free space is of part of a working set. not stay focused on the chosen task. It too small to hold the next task’s work- You are likely to find that you can- can be a difficult state to recover from. ing set; the remaining tasks are held not accommodate more than a few Let us now take a look at what OSs aside in a queue until there is room for active tasks at once without thrash- do to avoid thrashing and see what les- their working sets. When a task has a ing. However, with the precautions sons we can take to avoid it ourselves. page fault, the new page is added to its described here, thrashing is unlikely. workspace by taking a free page; when If it does occur you will feel over- Locality, Working Sets, and Thrashing any page has not been used for T mem- whelmed and your processing effi- The OS seeks to allocate memory ory references, it is evicted from the ciency will be badly impaired. To exit among multiple tasks so as to maxi- task’s workspace and placed in the free the thrashing state, you need to reduce mize system throughput—the number space. Thus, the OS divides the memory demand or increase your capacity. You of completed tasks per second.3 among the active tasks such that each can do this by reaching out to other The accompanying Figure 1 is strong task’s workspace tracks its locality sets. people—making requests for help, re- graphical evidence of the principle of lo- Page faults do not steal pages from oth- negotiating deadlines, acquiring more cality—computations concentrate their er working sets. This strategy automati- resources, and in some cases cancel- memory accesses to relatively small lo- cally adjusts the load (number of active ing less important tasks. cality sets over extended intervals. Local- tasks) to keep throughput near its maxi- ity should be no surprise—it reflects the mum and to avoid thrashing. References 1. Allen, D. Getting Things Done. Penguin. 2001. way human designers approach tasks. Context switching is not the cause of 2. Christian, B. and Griffiths. T.Algorithms to Live By: The We use the term working set for OS’s thrashing. The cause of thrashing is the Computer Science of Human Decisions. Henry Holt and Company, 2016. estimate of a task’s locality set. The for- failure to give every active task enough 3. Denning, P. Working sets past and present. IEEE Trans mal definition is that working set is space for its working set, thereby caus- Software Engineering SE-6, 1 (Jan. 1980), 64–84. 4. Denning, P. and Martell, C. Great Principles of the pages used in a backward-looking ing excessive movement of pages be- Computing. MIT Press, 2015. 5. Flores, F. Conversations for Action and Collected window of a fixed sizeT memory refer- tween secondary and main memory. Essays. CreateSpace Independent Publishing ences. In Figure 1, T is the length of the Platform, 2012. Translation to Human Multitasking 6. McMenamin, A. Applying working set heuristics to sampling interval and the working set the Linux kernel. Masters Thesis, Birkbeck College, equals the locality set 97% of the time. Although the analogy with OSs is not University of London, 2011; http://bit.ly/2vFSgY8 7. Napier, N. The myth of multitasking, 2014; http://bit. Each task needs a workspace—its perfect, there are some lessons: ly/1vuBGcC own area of memory in which to load its ˲˲ Recognize that each task needs a pages. There are at least two ways to di- variable working set of resources (phys- Peter J. Denning ([email protected]) is Distinguished vide the total memory among the active ical, digital, and mental), which must Professor of Computer Science and Director of the Cebrowski Institute for information innovation at tasks. In fixed partitioning, the OS gives be easily accessible in your workspace. the Naval Postgraduate School in Monterey, CA, each task a fixed workspace. In work- Analog: the working set of pages. is Editor of ACM Ubiquity, and is a past president of ACM. The author’s views expressed here are not necessarily ing-set partitioning, the OS gives each ˲˲ Your capacity to deal with a task is those of his employer or the U.S. federal government. task a variable workspace that tracks the resources and time needed to get its locality sets. Fixed partitioning is it done. Analog: the memory and CPU Copyright held by author.

34 COMMUNICATIONS OF THE ACM | SEPTEMBER 2017 | VOL. 60 | NO. 9