From: HENRY::IN%"McGuire_Ed%grinnell.mailnet%MIT-MULTICS.ARPA%SRI-KL.ARPA%relay.cs.net@rca.com" 24-DEC-1986 16:39 To: INFO-VAX@SRI-KL.ARPA Subj: Virtual pages - 126 lines Brian McKeever (MCKEEVER@UMKCVAX1.BITNET) wrote to me the other day asking me how to compute virtual pages in use by a process. He said that he tried subtracting the process parameter FREPTECNT from the SYSBOOT parameter VIRTUALPAGECNT, but it was always 72 pages less than SHOW PROCESS/CONTINUOUS. I'm writing this long note for the following reasons: - In my ignorance, I have been confusing VIRTUALPAGECNT and PGFLQUOTA, and this is reflected in an error in the procedure SWAPFILE.COM which I distributed a while back. - I found the missing 72 pages, and the story is interesting. - Now I have two new questions about virtual page management which I can't answer, and I hope someone on this list can. 1. I thought in my ignorance that the process parameter PGFLQUOTA limited the total size of the process address space. In fact, PGFLQUOTA limits the number of demand-zero pages and copy-on-reference section pages, i.e. pages that might end up in the page file. I got mixed up when I found out that PGFLQUOTA does not limit the al number of pages that are actually IN the page file, only the number of pages that COULD BE PUT IN the page file. So SWAPFILE.COM, the procedure I wrote which displays information about process memory usage, says it reports virtual page count in its output. But what it's really doing is subtracting PAGFILCNT from PGFLQUOTA. This is in fact another useful number, the local writeable page count, alias the page file quota used. I'm going to put the right column titles into SWAPFILE.COM, and add code to correctly compute virtual pages if the numbers are available from DCL. If you want the corrected version, send me a note. 2. Here's what I learned about the parts of the process header that control virtual pages. I had to go all over the internals manual and experiment to get this info. Some of the definitions in the internals manual are wrong. I hope this is all right. DEFINITIONS Item Unit Description ------------------------------------------------------------------------- 2^21 page Number of pages in P0, P1, S0, or S1 space P0BR address Virtual address of the bottom of the P0 page table P0LR page Number of used longwords in the P0 page table (beginning at P0BR); number of pages in P0 space FREP0VA address Virtual address of first nonexistent page in P0 page; always equal to P0LR x 512 P1BR address Virtual address of the first page of the P1 page table (P1 expands from 7FFFFFFF[16] toward smaller addresses, so a longword at this address would describe the page at virtual address 40000000[16]) P1LR page Number of unused longwords in the P1 page table (beginning at P1BR); always equal to 2^21 - number of pages in P1 space FREP1VA address Virtual address of first nonexistent page in P1 space; always equal to (P1LR - 1) x 512 + 40000000[16] FREPTECNT page Number of unused longwords in the page table space (pages available for P0 or P1 space); always equal to (VIRTUALPAGECNT + 127) DIV 128 - P0LR - (2^21 - P1LR) - 1 DISCUSSION A process page table is a database of longwords, each describing one page of virtual address space. There are two page tables, the P0 page table and the P1 page table, that describe virtual address space for a process. These two tables together I'll call the "page table space" for the purposes of this explanation. Virtual address space for the "page table space", which is a part of the process header, is reserved when the process is created. The SYSBOOT parameter VIRTUALPAGECNT sets the maximum virtual size of a process, so a "page table space" is created that is big enough to describe VIRTUALPAGECNT pages. There are 128 longwords in a page. Therefore, each page of the "page table space" describes 128 pages of the process' virtual address space. So, the size of the "page table space" (in pages) is computed by dividing VIRTUALPAGECNT by 128 and rounding up. Let's call this value TABLEPAGES. You can use the following formula to compute TABLEPAGES. (VIRTUALPAGECNT + 127) DIV 128 This means that the number of entries in the "page table space" can be anywhere from VIRTUALPAGECNT to VIRTUALPAGECNT + 127. For example, at Grinnell, VIRTUALPAGECNT is 68536. A 536 page "page table space" is required to describe that many pages. There are actually 536 x 128 = 68608 longwords in this "page table space", which is 72 greater than 68536. The number of longwords in the "page table space" is equal to TABLEPAGES x 128. We can call this TABLESLOTS. To compute the size of a process' current virtual address space, subtract the process header parameter FREPTECNT from TABLESLOTS. This is the value displayed by SHOW PROCESS/CONTINUOUS. 3. This are my mysteries. Can anybody answer them? The size of the process' current virtual address space can also be calculated by the formula P0LR + (2^21 - P1LR). However, this value is always 1 greater than the value shown by SHOW PROCESS/CONTINUOUS. Why is there a difference? Am I just making a silly fencepost error? Is the real limit to a process' virtual address space VIRTUALPAGECNT or TABLESLOTS? The fact that SHOW PROCESS/CONTINUOUS is apparently using TABLESLOTS to compute current virtual address space is evidence that TABLESLOTS is the real limit, but the documentation always says it's VIRTUALPAGECNT. 4. The quotations at the tops of some of the chapters in the internals manual are starting to make a lot of sense to me. Chapter 16, Memory Management System Services: _Confusion now hath made his masterpiece!_ --"Macbeth" 2,3 Chapter 26, Size of System Virtual Address Space: _A little inaccuracy sometimes saves tons of explanation._ --Saki, "The Comments of Moung Ka"