Operating System - HP-UX
1819541 Members
2539 Online
109603 Solutions
New Discussion юеВ

Re: paging in, paging out

 
SOLVED
Go to solution
Geetam
Frequent Advisor

paging in, paging out

I have been told many times that 'paging in' is normal, and 'paging out' is bad. But I do not understand what the terms actually mean. Can anyone explain?

Does 'in' and 'out' refer to a direction: IN to physical memory and OUT to swap?

Thanks
12 REPLIES 12
Rita C Workman
Honored Contributor

Re: paging in, paging out

Theoretically, paging only occurs when there is no more free memory,
and the system needs to swap memory images to disk.

Even though you have free memory, the systems are paging because the
user's applications are using memory mapped files. These files are
created using the mmap(), munmap(), and msync() system calls. These
system calls actually bypass the file system and avoid the buffer cache
to enhance their performance in reading and writing to disk. Normal
calls, such as read() and write(), read and write to the file systems
via the buffers, like the buffer cache. This causes intermediate steps
in the read() (or writing with write()), which are reading from the disk
to the buffer and then writing from the buffer to the memory (reversed
for the write() function).

When writing to the memory mapped files, the virtual memory subsystem
pages them out to disk, which is in effect writing them. This process
resembles swap paging, but is really not due to memory pressure. In
essence, the memory mapped files use the kernel's paging function to
write data to the disk.

Regards
Rita C Workman
Honored Contributor

Re: paging in, paging out

Theoretically, paging only occurs when there is no more free memory,
and the system needs to swap memory images to disk.

Even though you have free memory, the systems are paging because the
user's applications are using memory mapped files. These files are
created using the mmap(), munmap(), and msync() system calls. These
system calls actually bypass the file system and avoid the buffer cache
to enhance their performance in reading and writing to disk. Normal
calls, such as read() and write(), read and write to the file systems
via the buffers, like the buffer cache. This causes intermediate steps
in the read() (or writing with write()), which are reading from the disk
to the buffer and then writing from the buffer to the memory (reversed
for the write() function).

When writing to the memory mapped files, the virtual memory subsystem
pages them out to disk, which is in effect writing them. This process
resembles swap paging, but is really not due to memory pressure. In
essence, the memory mapped files use the kernel's paging function to
write data to the disk.
Anthony deRito
Respected Contributor

Re: paging in, paging out

These terms refer to a activity called "demand paging". Demand paging allows the memory management subsystem to bring into physical memory only the parts of the process that are need to run. This is called pageing in. Pageing out is also part of "demand paging" that kicks in when processes need to be pushed out to virtual memory because of memory pressure (or a physical memory shortage). So the memory management subsystem which is part of the kernel is performing these activities and they happen dynamically.

Tony
CHRIS_ANORUO
Honored Contributor

Re: paging in, paging out

It is better to have a system with large values for page in than page out activities. Memory management uses paging thresholds that tigger various paging activities. Whenever the swapon call is made to a device or filesystem, the amount os swap newly enabled is converted to units of pages and added to the two global swap-reservation counters total enabled swap and available swap space.
The paging thresholds are (lotsfree- 1/8 of freemem; desfree- 1/16 of freemem; and minfree- 1/4 of desfree). Lotsfree and desfree are upper and lower bound free memory. Minfree is minimal amount of free memory tolerable. If free memory drops below this boundary, system is desperate for memory and deactivation processes starts.


Chris
When We Seek To Discover The Best In Others, We Somehow Bring Out The Best In Ourselves.
John Palmer
Honored Contributor

Re: paging in, paging out

More fundamentally, you need to be aware that HP-UX is a 'virtual memory' operating system. Every process has a set of 'segment' types and each segment consists of a number of 'pages'.

Examples of segment types are
'data' (where variables are kept and of course can be altered)
'text' (program code which is read only)
'stack' (a speciaal type of data segment)

Pages are 'paged in' to memory from disk (program file or swap space) when they are required to be executed (text) or read or altered (data). Not all the pages that make up the process need to be in memory at once and indeed process memory can far exceed physical memory.

The pages of a process that are in memory are known as the 'Resident Set' and the whole process is known as the 'Virtual Set'.

When a process is started, a reasonable amount of its text and data pages will be paged into memory. As it runs, further pages will be required. If a page is required that is not in memory, a 'page fault' occurs and HP-UX arranges for that page (and probably others around it) to be paged in. This will continue and if a process continues to do similar things, a stable resident set will tend to remain in memory.

If there is plenty of real memory, all well and good. Resident sets will increase until some sort of stability occurs.

If memory is short, HP-UX has to discard some pages belonging to one process in order to page in those required for another. If these are text (read only) pages then they are simply disacarsded and overwritten - they can be paged in again later from the program file. If data and they have been modified then they have to be paged out to a swap file. This is bad because writes take a long time.

Thus paging in is a normal occurrence of a virtual memory system although obtaining a stable resident set for all processes is desirable and paging out is bad.

I hope this makes some sort of sense and is of some use to you.
James R. Ferguson
Acclaimed Contributor

Re: paging in, paging out

Geetam:

I think the kernel (pun intended) of truth in the "good" vs. "bad" is that to page-ins may first require page-outs to create free memory. Thus to do work (page-in/good) we first need to do other work (page-out)/bad).

...JRF...
Geetam
Frequent Advisor

Re: paging in, paging out

Just to clarify / summarise:

Is 'paging in' ANY reading into memory (eg process starting up), or only SWAP activity reading into memory (including text from program file)?

'Paging out' is moving memory areas belonging to a process to swap space.

Once pages are 'paged out', can they be swapped 'in' multiple times (page out once, page in many)? Of course only if they are not altered.

If you are lucky enough that nothing is 'paged out', there just isn't anything to 'page in', right?

Both 'paging in' and 'paging out' involves disk activity (assuming we are not using pseudo swap yet), so both are slowing the machine down.

'Paging out' is worse because it is a write activity, which takes longer.

It is really bad, if 'paging out' happens because the swapper is trying to page something 'in' and does not have the memory for it. Then 'paging out' would happen frequently, not just once when a process starts up.

Please comment, or correct me if I have got it wrong. Thanks
John Palmer
Honored Contributor
Solution

Re: paging in, paging out

Paging in is ANY reading into memory.

Once paged out, pages can be paged in many times. If they are data pages and have not been amended then they can just be discarded. If modified then they have to be paged out if the mmory that they occupy is required for some other process.

If you have plenty of memory, no swap space will be used (HP-UX will reserve swap space for data segments). You will still get paging in because of processes starting etc.

Paging out only happens when you are short of memory. It doesn't happen as a matter of course when a process starts.
CHRIS_ANORUO
Honored Contributor

Re: paging in, paging out

Hi Geetam,

As I pointed out earlier, if free memory drops below minfree value, that means system is desperate for memory and deactivation processes starts i.e paging out.

Chris
When We Seek To Discover The Best In Others, We Somehow Bring Out The Best In Ourselves.
Anthony deRito
Respected Contributor

Re: paging in, paging out

Geetam, here are my comments:


You wrote:

"Is 'paging in' ANY reading into memory (eg process starting up), or only SWAP activity reading into memory (including text from program file)?"

You must think of the concept of paging from the respect of a facility of the kernel called the Memory Management Subsystem (MMS). I think because you have no reference point, this is confusing to you. The MMS will see ALL memory (physical and virtual) as an entire pool of memory. The MMS decides how to effectively use this pool of memory. To do this it sets up mappings when the program is compiled that map the many parts of a process between physical memory and virtual memory. This mapping gives the MMS everything it needs in order to find the pages a program needs to run.

Now, a program can only run in physical memory and not virtual memory as you know. When a program runs, the kernel will start off in "user" mode and the instructions will start to execute. When the program tries to find a page that is not in physical memory, a "page fault" occurs and the kernel will switch to "system" mode and use the maps I mentioned above to find the page. When it finds it, it looks for a free page in physical memory to load it. (Remember, in physical memory, a page is either free or used. A free page is not mapped to a virtual address and a used page is mapped to a virtual address.) If it does not find a free page in which to load it, kernel will moves used pages out to virtual memory to make room, hence the term "page-out". The kernel then "pages-in" the page needed, switches back to user mode and the process executes again this time finding what it needs. This is all done by the MMS dynamically.

"'Paging out' is moving memory areas belonging to a process to swap space. "

Yes. So that there is room for pages that need to be paged-in.

"Once pages are 'paged out', can they be swapped 'in' multiple times (page out once, page in many)? Of course only if they are not altered."

Remember your reference point - the MMS. The MMS will use this pool of memory as efficiently as possible to keep programs running. Pages are always "out" unless they are needed. They will be paged-in when they are needed. Remember, "demand paging".

"If you are lucky enough that nothing is 'paged out', there just isn't anything to 'page in', right? "

Not true. Unless your physical memory is large enough to have every page of every process in it, the MMS will have to page-in.

"Both 'paging in' and 'paging out' involves disk activity (assuming we are not using pseudo swap yet), so both are slowing the machine down."

UNIX is designed to run many more processes than the system has room to fit into physical memory. This is the beauty of UNIX.

"'Paging out' is worse because it is a write activity, which takes longer."

More acurately, paging out is not good because it is an indication of memory pressure.

"It is really bad, if 'paging out' happens because the swapper is trying to page something 'in' and does not have the memory for it."

Paging out ONLY happens when the MMS is trying to page something 'in' and does not have the physical memory for it.

"Then 'paging out' would happen frequently, not just once when a process starts up. "

Paging out will happen as many times as seen fit by the MMS to keep processes running.


Tony
Don Curtis_1
Advisor

Re: paging in, paging out

Sorry to add this in a reply but the "posting" function is crashing.

I have read a couple of posts concerning memory management and the "variables" LOTSFREE, DESFREE, etc. I am loading 11.0 and get an error during "configurable parameters" that include errors with these settings. My question is, how do you access/change these settings?

Thanks.
Don Morris_1
Honored Contributor

Re: paging in, paging out

LOTSFREE, DESFREE and MINFREE are tunables, so you should be able to change them with kmtune - that should be there on 11.0. Barring that, look in /usr/conf/master.d for them (should be in core-hpux), edit the file to change them and run config or mk_kernel).

Frankly, they _should_ be 0 -- that tells the kernel to just figure out good values based on available physical memory at boot.

What errors are you seeing, by the way? Something like lotsfree greater than freemem? (In other words someone just set it way too high?)

By the way -- regarding an earlier comment, the system does _not_ begin paging out when memory falls below MINFREE - it starts when free physical pages falls below LOTSFREE.

Here's a quick synopsis:
Exactly how the steal hand treats the pages still marked as unused depends on the comparison of free system physical memory and three tunables: LOTSFREE, DESFREE, and MINFREE. If freemem > LOTSFREE, the steal hand actually does nothing. There's lots of memory still available on the system, so why chance moving a page to swap space that might be needed soon? In the more common case, when DESFREE< freemem < LOTSFREE, pages are 'stolen' or moved from physical memory to swap space. When MINFREE < freemem < DESFREE, system memory is getting more critical and the steal hand steals pages and puts low priority processes to sleep, increasing the
likelihood for stealing their pages on the next pass. Finally, when freemem < MINFREE the system memory need is critical and the steal hand begins deactivating processes to completely free their memory.