mm: dirty page problem
I wrote a test program. It mmap a file and do some write, so some pages become dirty.
and then I do "cat /proc/meminfo", so I get dirty pages that I have written. this happened in my home
computer with debian, self compiled kernel 2.6.18-5 installed.
but in my company, on the servers (suse kernel 2.6.16.54), after the test program have written the data, there was no change in dirty pages column of "cat /proc/meminfo" 's output. after I killed the test program, the dirty pages changed immediately.
I dont know why such different behavior, can you help me?
becauce we want a program mmap some files, and after the files' contents were changed, the OS can write out these dirty data back to disk periodly.
Best regards!
I did some search in the changlogs between 2..6.16 adn 2.6.19.
I found this in http://www.kernel.org/pub/linux/kernel/v2.6/ChangeLog-2.6.19
and I concluded that the kernel below 2.6.19 can't tracking shared dirty pages, am I right?
commit edc79b2a46ed854595e40edcf3f8b37f9f14aa3f
Author: Peter Zijlstra <[email protected]> Date: Mon Sep 25 23:30:58 2006 -0700
[PATCH] mm: balance dirty pages
Now that we can detect writers of shared mappings, throttle them.
Avoids OOM
by surprise.
commit d08b3851da41d0ee60851f2c75b118e1f7a5fc89
Author: Peter Zijlstra <[email protected]> Date: Mon Sep 25 23:30:57 2006 -0700
[PATCH] mm: tracking shared dirty pages
Tracking of dirty pages in shared writeable mmap()s.
The idea is simple: write protect clean shared writeable pages, catch the write-fault, make writeable and set dirty. On page write-back clean all the PTE dirty bits and write protect them once again.
The implementation is a tad harder, mainly because the default backing_dev_info capabilities were too loosely maintained. Hence it is not enough to test the backing_dev_info for cap_account_dirty.
The current heuristic is as follows, a VMA is eligible when:
- its shared writeable
(vm_flags & (VM_WRITE|VM_SHARED)) == (VM_WRITE|VM_SHARED)
- it is not a 'special' mapping
(vm_flags & (VM_PFNMAP|VM_INSERTPAGE)) == 0
- the backing_dev_info is cap_account_dirty mapping_cap_account_dirty(vma->vm_file->f_mapping)
- f_op->mmap() didn't change the default page protection
Page from remap_pfn_range() are explicitly excluded because their COW semantics are already horrid enough (see vm_normal_page() indo_wp_page()) and
because they don't have a backing store anyway.
mprotect() is taught about the new behaviour as well. However it overrides the last condition.
Cleaning the pages on write-back is done with page_mkclean() a new
rmap call.
It can be called on any page, but is currently only implemented for mapped pages, if the page is found the be of a VMA that accounts dirty
pages it will
also wrprotect the PTE.
Finally, in fs/buffers.c:try_to_free_buffers(); removeclear_page_dirty() from
under ->private_lock. This seems to be safe, since ->private_lock
is used to
serialize access to the buffers, not the page itself. This is
needed because
clear_page_dirty() will call into page_mkclean() and would thereby violate locking order.
Quoted 25 lines · xue yong
I wrote a test program. It mmap a file and do some write, so some pages become dirty.
and then I do "cat/proc/meminfo", so I get dirty pages that I have written. this happened in my home
computer with debian, self compiled kernel 2.6.18-5 installed.but in my company, on the servers (suse kernel 2.6.16.54), after the test program have written the data, there was no change in dirty pages column of "cat
/proc/meminfo" 's output. after I killed the test program, the dirty pages changed immediately.I dont know why such different behavior, can you help me?
becauce we want a program mmap some files, and after the files' contents were changed, the OS can write out these dirty data back to disk periodly.
Best regards!
Quoted 10 lines · xue yong
I did some search in the changlogs between 2..6.16 adn 2.6.19.
I found this in http://www.kernel.org/pub/linux/kernel/v2.6/ChangeLog-2.6.19and I concluded that the kernel below 2.6.19 can't tracking shared dirty pages, am I right?
commit
edc79b2a46ed854595e40edcf3f8b37f9f14aa3fAuthor: Peter Zijlstra <[email protected]> Date: Mon Sep 25 23:30:58 2006 -0700
Quoted 7 lines
[PATCH] mm: balance dirty pages
commit
d08b3851da41d0ee60851f2c75b118e1f7a5fc89Author: Peter Zijlstra <[email protected]> Date: Mon Sep 25 23:30:57 2006 -0700[PATCH] mm: tracking shared dirty pages
Correct, prior to .19 we didn't have effective tracking of dirty pages. munmap() and msync() would walk the page tables and collect dirty pages, but without explicit action these pages would stay hidden.
These patches you found change that by mapping clean shared pages RO and taking a fault on the dirtying write. We once again map then RO when they'd be written out to disk.
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): 1245757970.19816.1675.camel@twins
Quoted 9 lines · Peter Zijlstra
Quoted 7 lines · xue yong
Thanks a lot, Peter.
Your reply resolved my doubt.we have a service program (just say A) running with about 14G mmaped data. and there is another daemon (just say B) do msync( SYNC) periodically.
so I want to know in this pattern, was the data flushed to disk?
Quoted 9 lines
I don't think so.
The problem is that
msync()only scans the current process' page tables, which would be clean since B doesn't write, only A does.So you'd have to modify your program, A, to do the
msync()itself -- possibly from a thread (threads share the vm context and thus page tables).
:) I did have this thought, because there was littile bo(block out), and pmap showed that
the dirty pages belong to a process was always growing.
I believe you are the authority. Your confirmation matters.
In "Understanding the Linux® Virtual Memory Manager" page 163, Mel Gorman said that
Process-mapped pages are not easily swappable because there is no way to map struct pages to PTEs except to search every page table, which is far too expensive.
So neither kswapd nor other kernel daemons do the scan job. Without explicit action these pages would stay hidden.
Quoted 10 lines
Quoted 7 lines
and we have the problem, after we stoped/restarted A, many ditry pages emerged,
about 4G data was flushed out in the following time.Thanks for your advice on these patches. I understand it now. So if we change the kernel to a higher version, can we solve the problem I mentioned above.
Yes, I would recommend running a more recent kernel.
Quoted 21 lines · xue yong
Quoted 9 lines · Peter Zijlstra
Quoted 7 lines · xue yong
Thanks a lot, Peter.
Your reply resolved my doubt.we have a service program (just say A) running with about 14G mmaped data. and there is another daemon (just say B) do msync( SYNC) periodically.
so I want to know in this pattern, was the data flushed to disk?
Quoted 9 lines
I don't think so.
The problem is that
msync()only scans the current process' page tables, which would be clean since B doesn't write, only A does.So you'd have to modify your program, A, to do the
msync()itself -- possibly from a thread (threads share the vm context and thus page tables).
Quoted 5 lines
:) I did have this thought, because there was littile bo(block out), and pmap showed that
the dirty pages belong to a process was always growing.I believe you are the authority. Your confirmation matters.
I'm one of the people who knows this code rather well, yes ;-)
Quoted 7 lines
In "Understanding the Linux® Virtual Memory Manager" page 163, Mel Gorman said that
Process-mapped pages are not easily swappable because there is no way to map struct pages to PTEs except to search every page table, which is far too expensive.
So neither kswapd nor other kernel daemons do the scan job. Without explicit action these pages would stay hidden.
While a great book to learn some of the basics from, it is severely out-dated. I think in his 2.6 chapter he does mention something about reverse map, or rmap as its called.
These days we do keep a data structure whereby it is easier to find all ptes for a particular mapping (mm/rmap.c).
In particular try_to_unmap() is the routine used to remove all ptes in order to swap a page.