- An advantage of paging is the possibility of sharing common code. This consideration is particularly important in a time-sharing environment.
Sharing of code in a paging environment.
- Consider a system that supports 40 users, each of whom executes a text editor (see Fig. 8.12).
- If the text editor consists of 150 KB of code and 50 KB of data space, we need 8,000 KB to support the 40 users (
- If the code is reentrant code (or pure code), it can be shared (to be shareable, the code must be reentrant). Here we see a three-page editor -each page 50 KB in size- being shared among three processes. Each process has its own data page.
- Reentrant code is non-self-modifying code; it never changes during execution. Thus, two or more processes can execute the same code at the same time.
- Each process has its own copy of registers and data storage to hold the data for the process's execution. The data for two different processes will, of course, be different.
- Only one copy of the editor need be kept in physical memory. Each user's page table maps onto the same physical copy of the editor, but data pages are mapped onto different frames.
- Thus, to support 40 users, we need only one copy of the editor (150 KB), plus 40 copies of the 50 KB of data space per user.
The total space required is now 2,150 KB instead of 8,000 KB-a significant savings.
- Organizing memory according to pages provides numerous benefits in addition to allowing several processes to share the same physical pages.