The Profession of IT Multitasking Without Thrashing Lessons from Operating Systems Teach How to Do Multitasking Without Thrashing
Total Page:16
File Type:pdf, Size:1020Kb
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 interrupts 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 context switch 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 operating system 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 Atlas 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 process 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.