cosc038@csc.canterbury.ac.nz (04/18/91)
I have a problem that someone with SunOS 4.1.1 sources may be able to help me with. I have written a program to print out a summary of address space information for a given (SunOS) process. The example below shows its output for a very small, statically linked, program. kahu has: a sun4c kernel architecture; a page size of 4096 2048 memory pages present; 2035 usable by the system; 1760 pageable Address space summary for process 16027 p_tsize = 4 p_dsize = 2 p_ssize = 2 p_rssize = 6 p_maxrss = 524287 p_swrss = 4 Segment 0: 0x2000 -> 0x5fff type = 02 prot = 015 maxprot = 017 Page details Address 0x2000: vp 0xff022774 offset 0x94c000 page# 0x4ee Address 0x3000: vp 0xff06de64 offset 0x1000 page# 0x3c1 Address 0x4000: vp 0xff06de64 offset 0x2000 page# 0x6af Address 0x5000: vp 0xff06de64 offset 0x3000 page# 0x612 Segment 1: 0x6000 -> 0x7fff type = 02 prot = 017 maxprot = 017 Page details Address 0x6000: vp 0xff022774 offset 0x98f000 page# 0x636 Address 0x7000: vp 0xff06de64 offset 0x5000 page# 0x3c3 Segment 2: 0xf7ffe000 -> 0xf7ffffff type = 02 prot = 017 maxprot = 017 Page details Address 0xf7ffe000: Not in use Address 0xf7fff000: vp 0xff022774 offset 0x7db000 page# 0x4e4 The program was originally written for SunOS 4.0, and as we have SunOS 4.0 source, finding out all of the information wasn't too hard. Now I've ported it to SunOS 4.1.1 (no kernel source here), and I've encountered some problems in determining the physical page numbers. The method I used in the SunOS 4.0 version was as follows. 1. Extract the array of page strcutures (whose start is pointed at by _pages). 2. Look for the page - if found note the index in the array of the page structure, if not found then page not present in physical memory. 3. Add the index from 2. to the value of _pages_base - the sum is the physical page # (ppn). If you then od /dev/mem ppn*PAGESIZE you sould see the contents of the particular page from the process address space. Now, in 4.1.1 things are a bit different. The _pages variable still points to the array of page structs. There is a variable _epages which points to the page struct BEYOND the end of the page struct array - which means there are (_epages - _pages) / sizeof(struct page) structures in the array - i.e. the number of pages available for paging. This value is equal to that of _total_pages (1760 in the example). So far so good - we can still work out the index into the pages array as before. Now - the problem is to translate this index to a physical page number. The _pages_base variable is not in 4.1.1! The value of variable _physmem seems to hold the number of memory pages available to the kernel (2035 above - minor question - this is always a few less than the memory size - what are the other pages used for - the monitor? mapped to devices?). Anyway if you set pages_base to be _physmem - #pages available for paging, and compute physical page numbers by adding pages_base + array index you get pretty close to the physical page number (OK on a sparc 2, off by 2 on sparc 1s, off by about 17 on a sparcserver 490). So can anyone tell me how I can compute the value of _pages_base, on 4.1.1 so that when I add the page array index I to pages_base I get the physical page number? -- Paul Ashton Email(internet): paul@cosc.canterbury.ac.nz NZ Telecom: Office: +64 3 667 001 x6350 NZ Post: Dept of Computer Science University of Canterbury, Christchurch, New Zealand