SHARING

A Virtual Fantasy

	Once upon a time, a VERY long time ago as computers count time, there was a (human) virus that forced all children to stay home from school.  In our special family, there were four children: Alyssa, Barbara, Cassandra, and Deidre.  All of them wanted to attend Very Terrific College (VTC) part of the Very Special Colleges network (VSC) deep in Maple Syrup Land, and study computers.  Alas, their father (Dear Old Dad), who had great respect for VTC, still only had one little computer that had only 64K of memory, a PDP11/45 he had from the truely olden times.  It had one CPU and 4 terminals. Fortunately for our story, he had taken an Operating Systems course back in the day, from the professor they all called Jack Of All Trades, at good old VTC.
	All went to their father.  Alyssa said, “FATHER, I have a very LARGE program I am writing, and so I need ALL 64K of the computer memory.  Her father said, “The computer will take care of your needs.”
Alyssa said, “FATHER, I have a very LARGE program I am writing, and so I need ALL 64K of the computer memory.”  Her father said, “The computer will take care of your needs.”
	Barbara said, “FATHER, I have a very LARGE amount of data for the program I am writing, and so I need ALL 64K of the computer memory.”  Her father said, “The computer will take care of your needs.”
	Cassandra said, “FATHER, I have a LOT of computations in the program I am writing, and so I cannot have other programs slowing the computer down.”  Her father said, “The computer will take care of your needs.”
	Deidra said, “FATHER, I have a very LARGE matrix in the program I am writing, and so I need ALL 64K of the computer memory.  Her father said, “The computer will take care of your needs.”
	They all said, “The computer cannot POSSIBLY take care of ALL of us. It only has one CPU and a mere 64 K of memory. It is practically a DINOSAUR among computers.” And of course, they all wanted to have first priority.  The father smiled, and waved at the CPU, and said, “This is a MAGIC CPU.  Trust me, it can take care of ALL of you.
	Alyssa happened to log in first.  She was pleased when it said her CPU memory was allocated for CPU memory blocks 0 thru 63, 1024words each. She was not worried about the others, she was happy that she had what she needed.
	Barbara logged in next, at almost the same time.  She was a little puzzled when it said her CPU memory was allocated for CPU memory blocks 64 thru 127, 1024 words each. 'Funny numbering', she thought to herself.  She was not worried about the others, she was happy that she had what she needed.
	Cassandra was granted blocks 128 through 191, and Deidra was granted blocks 192 through 255. All four felt a little guilty that the whole computer memory was at their command, but none felt guilty enough to offer to share.
	Process A(Alyssa's program) requested to load her whole program code into memory, and she was astonished at how quickly it was done.  (She did not understand until later that all the computer did was mark 64 BYTES in the virtual memory table as hers; nothing was actually loaded yet.)    She ran her program.  In her mind, the whole program was in memory; but actually, it only loaded the first chunk of her program into virtual memory block 9, which was physical memory block 0.
	Process B(Barbara's program) was equally fast, loading the first block of her program into virtual memory block 64, physical memory block 1.  Cassandra thought her program was loaded into memory beginning in memory 128, but it actually went into VIRTUAL memory block 128, PHYSICAL memory block 2.  And you guessed it, Deidre's code went into VIRTUAL memory 192, the first block going into PHYSICAL memory 3.  

	Then their programs began to execute.  Due to natural locality, all of their programs executed in the first block for at least a few instructions, and so no further loads were needed immediately.  Barbara's program was the first to load data.  Her program data was in virtual memory 84, but went into physical memory 4.  Cassandra was next, her program asked for virtual memory 158, which went into physical memory 5.  Deidra's request was loaded into virtual memory 232, physical memory 6, and Alyssa's request was for virtual memory 40, which went into physical memory 7. (See later for diagrams of memory after each had done two memory references.)
	All of them were happy, because it took so little time to load ONE block into memory, they were not delayed at all.  They didn't even realize the computer was loading blocks for the other sisters, as well.
	Eventually, the computer physical memory filled.  Each of them THOUGHT they had only filled (on the average) ¼ of the computer memory, when for the first time, there was no available physical memory to load the requested memory into.  Fortunately, the operating system had been programmed for the Least Recently Used algorithm.  It picked the block that had been left alone for the longest time.  (Fortunately, computer blocks do not get lonely when they are left alone, unlike people in social isolation trying to avoid a dreaded global pandemic.)  Because the users had already finished using those blocks, they did not notice a difference in computer response time.  Their programs continued running, (usually) swapping out blocks that had been finished with, and their programs finished executing.
	They all ran to their Dear Old Dad, and thanked him for letting them have the computer all to themselves.  But then they heard each other, and wondered.  “How can we all think we had the computer to ourselves, and it ran so fast?”
	Dear Old Dad smiled at them.  “That is due to a magic called Virtual Memory. You see, you were all ACTUALLY sharing, but by the magic, none of you even noticed.  Now we have to teach you how to CHOOSE to share and work together, or you will never be successful working on group projects at VTC.  

Please note:
	Each thought they had 64 blocks of memory available just for them, but when they had each only referenced TWO blocks, , only EIGHT total blocks were loaded into (physical) memory.
0A
1B
2C
3D
4B
5C
6D
7A
(The rest of physical memory was available for use at that time.)

	Even after all of (physical) memory filled, the computer response time was SO fast, they never even realized that they were actually SHARING the computer four ways.  And so they programmed happily ever after.

IN YOUR SMALL GROUPS:
Prepare a PAGE TABLE for this story.
(One possibility: use EXCEL to list the virtual memory spaces;
As each memory request occurs, update what physical memory spaces are referred to by virtual memory.)

Note that in real operating systems, care must be taken that the virtual memory table does not take up a huge portion of the physical memory.