Skip to contentSkip to conversation

After swapout/swapin private dirty mappings become clean

PATCH In review Nikanth Karthikesan 7 participants 44 messages Sep 14, 2010 – Sep 20, 2010

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 After swapout/swapin private dirty mappings become clean

/proc/$pid/smaps broken: After swapout/swapin private dirty mappings become clean.

When a page with private file mapping becomes dirty, the vma will be in both i_mmap tree and anon_vma list. The /proc/$pid/smaps will account these pages as dirty and backed by the file.

But when those dirty pages gets swapped out, and when they are read back from swap, they would be marked as clean, as it should be, as they are part of swap cache now.

But the /proc/$pid/smaps would report the vma as a mapping of a file and it is clean. The pages are actually in same state i.e., dirty with respect to file still, but which was once reported as dirty is now being reported as clean to user-space.

This confuses tools like gdb which uses this information. Those tools think that those pages were never modified and it creates problem when they create dumps.

The file mapping of the vma also cannot be broken as pages never read earlier, will still have to come from the file. Just that those dirty pages have become clean anonymous pages.

During swaping in, restoring the exact state as dirty file-backed pages before swapout would be useless, as there in no real bug. Breaking the vma with only anonymous pages as seperate vmas unnecessary may not be a good thing as well. So let us just export the information that a file-backed vma has anonymous dirty pages.

Export this information in smaps by prepending file-names with "[anon]+", when some of the pages in a file backed vma become anonymous.

---

fs/proc/task_mmu.c +2 -0
index 439fc1f..68f9806 100644
@@ -242,6 +242,8 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
 	 */
 	if (file) {
 		pad_len_spaces(m, len);
+		if (vma->anon_vma)
+			seq_puts(m, "[anon]+");
 		seq_path(m, &file->f_path, "\n");
 	} else {
 		const char *name = arch_vma_name(vma);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw
Quoted 24 lines · Nikanth Karthikesan

/proc/$pid/smaps broken: After swapout/swapin private dirty mappings become clean.

When a page with private file mapping becomes dirty, the vma will be in both i_mmap tree and anon_vma list. The /proc/$pid/smaps will account these pages as dirty and backed by the file.

But when those dirty pages gets swapped out, and when they are read back from swap, they would be marked as clean, as it should be, as they are part of swap cache now.

But the /proc/$pid/smaps would report the vma as a mapping of a file and it is clean. The pages are actually in same state i.e., dirty with respect to file still, but which was once reported as dirty is now being reported as clean to user-space.

This confuses tools like gdb which uses this information. Those tools think that those pages were never modified and it creates problem when they create dumps.

The file mapping of the vma also cannot be broken as pages never read earlier, will still have to come from the file. Just that those dirty pages have become clean anonymous pages.

Quoted 8 lines

During swaping in, restoring the exact state as dirty file-backed pages before swapout would be useless, as there in no real bug. Breaking the vma with only anonymous pages as seperate vmas unnecessary may not be a good thing as well. So let us just export the information that a file-backed vma has anonymous dirty pages.

Export this information in smaps by prepending file-names with "[anon]+", when some of the pages in a file backed vma become anonymous.

For the sake of not breaking existing tools I'd prefer appending " [anon]" instead.

Though a much simpler thing would be to account
the clean anon pages as Private_Dirty (with respect to the backing file displayed). Anonymous vmas in /proc/smaps seem to contain Private_Dirty pages as well. So I still don't understand why this isn't just an accounting bug.

Thanks,
Richard.

Quoted 20 lines

---

fs/proc/task_mmu.c +2 -0
index 439fc1f..68f9806 100644
@@ -242,6 +242,8 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
 	 */
 	if (file) {
 		pad_len_spaces(m, len);
+		if (vma->anon_vma)
+			seq_puts(m, "[anon]+");
 		seq_path(m, &file->f_path, "\n");
 	} else {
 		const char *name = arch_vma_name(vma);
Signature · 9 lines
Richard Guenther <[email protected]>
Novell / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746 - GF: Markus Rex

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw
Quoted 31 lines · On Tuesday 14 September 2010 17:03:59 Richard Guenther wrote:
Quoted 30 lines · Nikanth Karthikesan

/proc/$pid/smaps broken: After swapout/swapin private dirty mappings become clean.

When a page with private file mapping becomes dirty, the vma will be in both i_mmap tree and anon_vma list. The /proc/$pid/smaps will account these pages as dirty and backed by the file.

But when those dirty pages gets swapped out, and when they are read back from swap, they would be marked as clean, as it should be, as they are part of swap cache now.

But the /proc/$pid/smaps would report the vma as a mapping of a file and it is clean. The pages are actually in same state i.e., dirty with respect to file still, but which was once reported as dirty is now being reported as clean to user-space.

This confuses tools like gdb which uses this information. Those tools think that those pages were never modified and it creates problem when they create dumps.

The file mapping of the vma also cannot be broken as pages never read earlier, will still have to come from the file. Just that those dirty pages have become clean anonymous pages.

During swaping in, restoring the exact state as dirty file-backed pages before swapout would be useless, as there in no real bug. Breaking the vma with only anonymous pages as seperate vmas unnecessary may not be a good thing as well. So let us just export the information that a file-backed vma has anonymous dirty pages.

Quoted 6 lines
Quoted 2 lines

Export this information in smaps by prepending file-names with "[anon]+", when some of the pages in a file backed vma become anonymous.

For the sake of not breaking existing tools I'd prefer appending " [anon]" instead.

A filename might have it as suffix!

Quoted 3 lines

Though a much simpler thing would be to account
the clean anon pages as Private_Dirty (with respect to the backing file displayed).

Agreed.

Quoted 4 lines

Anonymous vmas in /proc/smaps seem to contain Private_Dirty pages as well. So I still don't understand why this isn't just an accounting bug.

anonymous pages can be dirty as well. Even these pages now marked as clean would be marked as dirty again, if they are re-dirtied.

Thanks
Nikanth

Quoted 21 lines

Thanks,
Richard.

Quoted 17 lines

---

fs/proc/task_mmu.c +0 -0
index 439fc1f..68f9806 100644
@@ -242,6 +242,8 @@ static void show_map_vma(struct seq_file *m, struct

vm_area_struct *vma) */

fs/proc/task_mmu.c +2 -0
 	if (file) {
 		pad_len_spaces(m, len);
+		if (vma->anon_vma)
+			seq_puts(m, "[anon]+");
 		seq_path(m, &file->f_path, "\n");
 	} else {
 		const char *name = arch_vma_name(vma);
#3 lore raw

PATCH v2 1/1 After swapout/swapin private dirty mappings are reported clean in smaps

/proc/$pid/smaps broken: After swapout/swapin private dirty mappings become clean.

When a page with private file mapping becomes dirty, the vma will be in both i_mmap tree and anon_vma list. The /proc/$pid/smaps will account these pages as dirty and backed by the file.

But when those dirty pages gets swapped out, and when they are read back from swap, they would be marked as clean, as it should be, as they are part of swap cache now.

But the /proc/$pid/smaps would report the vma as a mapping of a file and it is clean. The pages are actually in same state i.e., dirty with respect to file still, but which was once reported as dirty is now being reported as clean to user-space.

This confuses tools like gdb which uses this information. Those tools think that those pages were never modified and it creates problem when they create dumps.

The file mapping of the vma also cannot be broken as pages never read earlier, will still have to come from the file. Just that those dirty pages have become clean anonymous pages.

So instead when a file backed vma has anonymous pages report them as dirty pages. As those pages are dirty with respect to the backing file.

---

fs/proc/task_mmu.c +5 -1
index 439fc1f..06fc468 100644
@@ -368,7 +368,11 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
 				mss->shared_clean += PAGE_SIZE;
 			mss->pss += (PAGE_SIZE << PSS_SHIFT) / mapcount;
 		} else {
-			if (pte_dirty(ptent))
+			/*
+			 * File-backed pages, now anonymous are dirty
+			 * with respect to the file.
+			 */
+			if (pte_dirty(ptent) || (vma->vm_file && PageAnon(page)))
 				mss->private_dirty += PAGE_SIZE;
 			else
 				mss->private_clean += PAGE_SIZE;
#4 lore raw

Re: [PATCH v2] After swapout/swapin private dirty mappings are reported clean in smaps

Quoted 7 lines
fs/proc/task_mmu.c +0 -0
index 439fc1f..06fc468 100644
@@ -368,7 +368,11 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
 				mss->shared_clean += PAGE_SIZE;
 			mss->pss += (PAGE_SIZE << PSS_SHIFT) / mapcount;

fs/proc/task_mmu.c static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, · line 378

Quoted 10 lines
fs/proc/task_mmu.c +5 -1
 		} else {
-			if (pte_dirty(ptent))
+			/*
+			 * File-backed pages, now anonymous are dirty
+			 * with respect to the file.
+			 */
+			if (pte_dirty(ptent) || (vma->vm_file && PageAnon(page)))
 				mss->private_dirty += PAGE_SIZE;
 			else
 				mss->private_clean += PAGE_SIZE;

This is risky than v1. number of dirties are used a lot of application.

#5 lore raw

Re: [PATCH v2] After swapout/swapin private dirty mappings are reported clean in smaps

Quoted 11 lines · On Wednesday 15 September 2010 05:56:36 KOSAKI Motohiro wrote:
Quoted 11 lines
fs/proc/task_mmu.c +2 -1
index 439fc1f..06fc468 100644
@@ -368,7 +368,11 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long
 addr, unsigned long end, mss->shared_clean += PAGE_SIZE;
 			mss->pss += (PAGE_SIZE << PSS_SHIFT) / mapcount;
 		} else {
-			if (pte_dirty(ptent))
+			/*
+			 * File-backed pages, now anonymous are dirty
Quoted 9 lines

fs/proc/task_mmu.c static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, · line 378

Quoted 6 lines
fs/proc/task_mmu.c +3 -0
+			 * with respect to the file.
+			 */
+			if (pte_dirty(ptent) || (vma->vm_file && PageAnon(page)))
 				mss->private_dirty += PAGE_SIZE;
 			else
 				mss->private_clean += PAGE_SIZE;

This is risky than v1. number of dirties are used a lot of application.

This is exactly to help those applications, as currently after swap-out and swap-in, the same pages are accounted as "Private_Clean:" instead of "Private_Dirty:".

Thanks
Nikanth

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw

Re: [PATCH v2] After swapout/swapin private dirty mappings are reported clean in smaps

Quoted 22 lines · On Wednesday 15 September 2010 05:56:36 KOSAKI Motohiro wrote:
Quoted 11 lines
Quoted 11 lines
fs/proc/task_mmu.c +2 -1
index 439fc1f..06fc468 100644
@@ -368,7 +368,11 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long
 addr, unsigned long end, mss->shared_clean += PAGE_SIZE;
 			mss->pss += (PAGE_SIZE << PSS_SHIFT) / mapcount;
 		} else {
-			if (pte_dirty(ptent))
+			/*
+			 * File-backed pages, now anonymous are dirty
Quoted 9 lines

fs/proc/task_mmu.c static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, · line 378

Quoted 6 lines
fs/proc/task_mmu.c +3 -0
+			 * with respect to the file.
+			 */
+			if (pte_dirty(ptent) || (vma->vm_file && PageAnon(page)))
 				mss->private_dirty += PAGE_SIZE;
 			else
 				mss->private_clean += PAGE_SIZE;

This is risky than v1. number of dirties are used a lot of application.

Quoted 3 lines

This is exactly to help those applications, as currently after swap-out and swap-in, the same pages are accounted as "Private_Clean:" instead of "Private_Dirty:".

I don't think so. incorrect infomation bring a lot of confusion rather than its worth.

#7 lore raw

Re: [PATCH v2] After swapout/swapin private dirty mappings are reported clean in smaps

Quoted 21 lines · On Wednesday 15 September 2010 10:18:11 KOSAKI Motohiro wrote:
Quoted 21 lines · On Wednesday 15 September 2010 05:56:36 KOSAKI Motohiro wrote:
Quoted 19 lines
Quoted 7 lines
fs/proc/task_mmu.c +0 -0
index 439fc1f..06fc468 100644
@@ -368,7 +368,11 @@ static int smaps_pte_range(pmd_t *pmd, unsigned
 long addr, unsigned long end, mss->shared_clean += PAGE_SIZE;
 			mss->pss += (PAGE_SIZE << PSS_SHIFT) / mapcount;

fs/proc/task_mmu.c static int smaps_pte_range(pmd_t *pmd, unsigned · line 378

Quoted 10 lines
fs/proc/task_mmu.c +5 -1
 		} else {
-			if (pte_dirty(ptent))
+			/*
+			 * File-backed pages, now anonymous are dirty
+			 * with respect to the file.
+			 */
+			if (pte_dirty(ptent) || (vma->vm_file && PageAnon(page)))
 				mss->private_dirty += PAGE_SIZE;
 			else
 				mss->private_clean += PAGE_SIZE;

This is risky than v1. number of dirties are used a lot of application.

Quoted 5 lines
Quoted 3 lines

This is exactly to help those applications, as currently after swap-out and swap-in, the same pages are accounted as "Private_Clean:" instead of "Private_Dirty:".

I don't think so.

Actually this behaviour is observed. With a simple memhog, you can see pages which are "Private_Dirty:", become "Swap:" and then to "Private_Clean:". And that confused GDB.

Thanks
Nikanth

Quoted 3 lines

incorrect infomation bring a lot of confusion rather than
its worth.

#8 lore raw

Re: [PATCH v2] After swapout/swapin private dirty mappings are reported clean in smaps

Quoted 26 lines · On Wednesday 15 September 2010 10:18:11 KOSAKI Motohiro wrote:
Quoted 25 lines
Quoted 24 lines · On Wednesday 15 September 2010 05:56:36 KOSAKI Motohiro wrote:
Quoted 11 lines
Quoted 11 lines
fs/proc/task_mmu.c +2 -1
index 439fc1f..06fc468 100644
@@ -368,7 +368,11 @@ static int smaps_pte_range(pmd_t *pmd, unsigned
 long addr, unsigned long end, mss->shared_clean += PAGE_SIZE;
 			mss->pss += (PAGE_SIZE << PSS_SHIFT) / mapcount;
 		} else {
-			if (pte_dirty(ptent))
+			/*
+			 * File-backed pages, now anonymous are dirty
Quoted 8 lines

fs/proc/task_mmu.c static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, · line 378

Quoted 6 lines
fs/proc/task_mmu.c +3 -0
+			 * with respect to the file.
+			 */
+			if (pte_dirty(ptent) || (vma->vm_file && PageAnon(page)))
 				mss->private_dirty += PAGE_SIZE;
 			else
 				mss->private_clean += PAGE_SIZE;

This is risky than v1. number of dirties are used a lot of application.

This is exactly to help those applications, as currently after swap-out and swap-in, the same pages are accounted as "Private_Clean:" instead of "Private_Dirty:".

Quoted 5 lines
Quoted 1 line

I don't think so.

Actually this behaviour is observed. With a simple memhog, you can see pages which are "Private_Dirty:", become "Swap:" and then to "Private_Clean:". And that confused GDB.

As I said, incorrect information is always no good solustion. We should concern how to provide good and enough information, but not how to lie.
If currect gdb is crappy, it should fix.

Quoted 2 lines
Quoted 2 lines

incorrect infomation bring a lot of confusion rather than
its worth.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#9 lore raw

Re: [PATCH v2] After swapout/swapin private dirty mappings are reported clean in smaps

Quoted 29 lines · On Wednesday 15 September 2010 10:50:25 KOSAKI Motohiro wrote:
Quoted 29 lines · On Wednesday 15 September 2010 10:18:11 KOSAKI Motohiro wrote:
Quoted 27 lines
Quoted 22 lines · On Wednesday 15 September 2010 05:56:36 KOSAKI Motohiro wrote:
Quoted 12 lines
Quoted 12 lines
fs/proc/task_mmu.c +0 -0
index 439fc1f..06fc468 100644
@@ -368,7 +368,11 @@ static int smaps_pte_range(pmd_t *pmd,

unsigned long addr, unsigned long end, mss->shared_clean += PAGE_SIZE; mss->pss += (PAGE_SIZE << PSS_SHIFT) / mapcount;

fs/proc/task_mmu.c +3 -1
 		} else {
-			if (pte_dirty(ptent))
+			/*
+			 * File-backed pages, now anonymous are dirty
+			 * with respect to the file.
Quoted 8 lines

fs/proc/task_mmu.c static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, · line 378

Quoted 5 lines
fs/proc/task_mmu.c +2 -0
+			 */
+			if (pte_dirty(ptent) || (vma->vm_file && PageAnon(page)))
 				mss->private_dirty += PAGE_SIZE;
 			else
 				mss->private_clean += PAGE_SIZE;

This is risky than v1. number of dirties are used a lot of application.

Quoted 3 lines

This is exactly to help those applications, as currently after swap-out and swap-in, the same pages are accounted as "Private_Clean:" instead of "Private_Dirty:".

I don't think so.

Quoted 8 lines
Quoted 3 lines

Actually this behaviour is observed. With a simple memhog, you can see pages which are "Private_Dirty:", become "Swap:" and then to "Private_Clean:". And that confused GDB.

As I said, incorrect information is always no good solustion. We should
concern how to provide good and enough information, but not how to lie.
If currect gdb is crappy, it should fix.

How? Current smaps information without this patch provides incorrect information. Just because a private dirty page became part of swap cache, it shown as clean and backed by a file. If it is shown as clean and backed by swap then it is fine.

Thanks
Nikanth

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

incorrect infomation bring a lot of confusion rather than
its worth.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#10 lore raw

Re: [PATCH v2] After swapout/swapin private dirty mappings are reported clean in smaps

Quoted 5 lines · Nikanth Karthikesan

How? Current smaps information without this patch provides incorrect information. Just because a private dirty page became part of swap cache, it shown as clean and backed by a file. If it is shown as clean and backed by swap then it is fine.

How is GDB using this information?

Signature · 2 lines
	Three Cheers,
	Balbir
#11 lore raw

Re: [PATCH v2] After swapout/swapin private dirty mappings are reported clean in smaps

Quoted 9 lines · Balbir Singh
Quoted 5 lines · Nikanth Karthikesan

How? Current smaps information without this patch provides incorrect information. Just because a private dirty page became part of swap cache, it shown as clean and backed by a file. If it is shown as clean and backed by swap then it is fine.

How is GDB using this information?

GDB counts the number of dirty and swapped pages in a private mapping and based on that decides whether it needs to dump it to a core file or not. If there are no dirty or swapped pages gdb assumes it can reconstruct the mapping from the original backing file. This way for example shared libraries do not end up in the core file.

Richard.

#12 lore raw

Re: [PATCH v2] After swapout/swapin private dirty mappings are reported clean in smaps

Quoted 10 lines · Richard Guenther
Quoted 8 lines · Balbir Singh
Quoted 5 lines · Nikanth Karthikesan

How? Current smaps information without this patch provides incorrect information. Just because a private dirty page became part of swap cache, it shown as clean and backed by a file. If it is shown as clean and backed by swap then it is fine.

Quoted 7 lines
Quoted 1 line

How is GDB using this information?

GDB counts the number of dirty and swapped pages in a private mapping and based on that decides whether it needs to dump it to a core file or not. If there are no dirty or swapped pages gdb assumes it can reconstruct the mapping from the original backing file. This way for example shared libraries do not end up in the core file.

This whole discussion is a little disturbing.

The page is being reported clean as per the kernel's definition of clean, full stop.

So either there's a latent bug/inconsistency in the kernel VM or external tools are misinterpreting this data. But smaps is just reporting what's there, the fault doesn't lie in smaps. So fixing smaps just hides the problem, wherever it is.

Richard's report that the page is still clean after swapoff suggests the inconsistency lies in the VM.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#13 lore raw

Re: [PATCH v2] After swapout/swapin private dirty mappings are reported clean in smaps

Quoted 24 lines · Matt Mackall
Quoted 10 lines · Richard Guenther
Quoted 8 lines · Balbir Singh
Quoted 5 lines · Nikanth Karthikesan

How? Current smaps information without this patch provides incorrect information. Just because a private dirty page became part of swap cache, it shown as clean and backed by a file. If it is shown as clean and backed by swap then it is fine.

Quoted 7 lines
Quoted 1 line

How is GDB using this information?

GDB counts the number of dirty and swapped pages in a private mapping and based on that decides whether it needs to dump it to a core file or not. If there are no dirty or swapped pages gdb assumes it can reconstruct the mapping from the original backing file. This way for example shared libraries do not end up in the core file.

This whole discussion is a little disturbing.

The page is being reported clean as per the kernel's definition of clean, full stop.

Quoted 7 lines

So either there's a latent bug/inconsistency in the kernel VM or external tools are misinterpreting this data. But smaps is just reporting what's there, the fault doesn't lie in smaps. So fixing smaps just hides the problem, wherever it is.

Richard's report that the page is still clean after swapoff suggests the inconsistency lies in the VM.

Well - the discussion is about the /proc/smaps interface and inconsistencies in what it reports. In particular the interface does not have the capability of reporting all details the kernel has, so it might make sense to not "report a page clean as per the kernel's definition of clean", but only in a /proc/smaps context definition of clean that makes sense.

So, for

7ffff81ff000-7ffff8201000 r--p 000a8000 08:01 16376 /bin/bash

Size:                  8 kB
Rss:                   8 kB
Pss:                   8 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         8 kB
Private_Dirty:         0 kB
Referenced:            4 kB
Swap:                  0 kB

I expect both pages of that mapping to be file-backed by /bin/bash. But surprisingly one page is actually backed by anonymous memory (it was changed, then mapped readonly, swapped out and swapped in again).

Thus, the bug is the above inconsistency in /proc/smaps. Whether there are internal kernel inconsistencies as well doesn't really matter to this problem (as there is no way to distinguish pages that are now backed by anonymous memory in that interface).

Richard.

#14 lore raw

Re: [PATCH v2] After swapout/swapin private dirty mappings are reported clean in smaps

[adding Hugh]

Quoted 54 lines · Richard Guenther
Quoted 24 lines · Matt Mackall
Quoted 10 lines · Richard Guenther
Quoted 8 lines · Balbir Singh
Quoted 5 lines · Nikanth Karthikesan

How? Current smaps information without this patch provides incorrect information. Just because a private dirty page became part of swap cache, it shown as clean and backed by a file. If it is shown as clean and backed by swap then it is fine.

Quoted 7 lines
Quoted 1 line

How is GDB using this information?

GDB counts the number of dirty and swapped pages in a private mapping and based on that decides whether it needs to dump it to a core file or not. If there are no dirty or swapped pages gdb assumes it can reconstruct the mapping from the original backing file. This way for example shared libraries do not end up in the core file.

This whole discussion is a little disturbing.

The page is being reported clean as per the kernel's definition of clean, full stop.

Quoted 7 lines

So either there's a latent bug/inconsistency in the kernel VM or external tools are misinterpreting this data. But smaps is just reporting what's there, the fault doesn't lie in smaps. So fixing smaps just hides the problem, wherever it is.

Richard's report that the page is still clean after swapoff suggests the inconsistency lies in the VM.

Well - the discussion is about the /proc/smaps interface and inconsistencies in what it reports. In particular the interface does not have the capability of reporting all details the kernel has, so it might make sense to not "report a page clean as per the kernel's definition of clean", but only in a /proc/smaps context definition of clean that makes sense.

So, for

7ffff81ff000-7ffff8201000 r--p 000a8000 08:01 16376 /bin/bash

Size:                  8 kB
Rss:                   8 kB
Pss:                   8 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         8 kB
Private_Dirty:         0 kB
Referenced:            4 kB
Swap:                  0 kB
Quoted 6 lines

I expect both pages of that mapping to be file-backed by /bin/bash. But surprisingly one page is actually backed by anonymous memory (it was changed, then mapped readonly, swapped out and swapped in again).

Thus, the bug is the above inconsistency in /proc/smaps.

But that's my point: the consistency problem is NOT in smaps. The page is NOT marked dirty, ergo smaps doesn't report it as dirty. Whether or not there is MORE information smaps could be reporting is irrelevant, the information it IS reporting is consistent with the underlying VM data. If there's an inconsistency about what it means to be clean, it's either in the VM or in your head.

And I frankly think it's in the VM.

In any case, I don't think Nikanth's fix is the right fix, as it basically says "you can't trust any of this". Either swap should return the pages to their pre-swap dirty state in the VM, or we should add another field here:

Weird_Anon_Page_You_Should_Pretend_Is_Private_Dirty: 8 kB

See?

Signature · 8 lines
Mathematics is the supreme nostalgia of our time.


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#15 lore raw

Re: [PATCH v2] After swapout/swapin private dirty mappings are reported clean in smaps

Quoted 73 lines · Matt Mackall

[adding Hugh]

Quoted 54 lines · Richard Guenther
Quoted 24 lines · Matt Mackall
Quoted 10 lines · Richard Guenther
Quoted 8 lines · Balbir Singh
Quoted 5 lines · Nikanth Karthikesan

How? Current smaps information without this patch provides incorrect information. Just because a private dirty page became part of swap cache, it shown as clean and backed by a file. If it is shown as clean and backed by swap then it is fine.

Quoted 7 lines
Quoted 1 line

How is GDB using this information?

GDB counts the number of dirty and swapped pages in a private mapping and based on that decides whether it needs to dump it to a core file or not. If there are no dirty or swapped pages gdb assumes it can reconstruct the mapping from the original backing file. This way for example shared libraries do not end up in the core file.

This whole discussion is a little disturbing.

The page is being reported clean as per the kernel's definition of clean, full stop.

Quoted 7 lines

So either there's a latent bug/inconsistency in the kernel VM or external tools are misinterpreting this data. But smaps is just reporting what's there, the fault doesn't lie in smaps. So fixing smaps just hides the problem, wherever it is.

Richard's report that the page is still clean after swapoff suggests the inconsistency lies in the VM.

Well - the discussion is about the /proc/smaps interface and inconsistencies in what it reports. In particular the interface does not have the capability of reporting all details the kernel has, so it might make sense to not "report a page clean as per the kernel's definition of clean", but only in a /proc/smaps context definition of clean that makes sense.

So, for

7ffff81ff000-7ffff8201000 r--p 000a8000 08:01 16376 /bin/bash

Size:                  8 kB
Rss:                   8 kB
Pss:                   8 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         8 kB
Private_Dirty:         0 kB
Referenced:            4 kB
Swap:                  0 kB
Quoted 6 lines

I expect both pages of that mapping to be file-backed by /bin/bash. But surprisingly one page is actually backed by anonymous memory (it was changed, then mapped readonly, swapped out and swapped in again).

Thus, the bug is the above inconsistency in /proc/smaps.

But that's my point: the consistency problem is NOT in smaps. The page is NOT marked dirty, ergo smaps doesn't report it as dirty. Whether or not there is MORE information smaps could be reporting is irrelevant, the information it IS reporting is consistent with the underlying VM data. If there's an inconsistency about what it means to be clean, it's either in the VM or in your head.

And I frankly think it's in the VM.

Quoted 8 lines

In any case, I don't think Nikanth's fix is the right fix, as it basically says "you can't trust any of this". Either swap should return the pages to their pre-swap dirty state in the VM, or we should add another field here:

Weird_Anon_Page_You_Should_Pretend_Is_Private_Dirty: 8 kB

See?

Well. There is also the case where the page is swapped in again but still allocated in the swap cache. So it's swap-backed, private and clean (because the copy in swap is still valid). But in that case it's not accounted to "Swap:" (presumably because Rss + Swap wouldn't add to the mappings size).

I only care about consistency in /proc/smaps, but agree that an anonymous page that is not backed by swap-cache should always be dirty (in case it was cowed from the zero page at any point of course). Probably that inconsistency doesn't matter, as if it isn't swap-backed even a clean anonmous page can't be simply thrown away (in fact, "clean" or "dirty" doesn't have a meaningful semantics for anonymous memory IMHO).

Richard.

#16 lore raw

Re: [PATCH v2] After swapout/swapin private dirty mappings are reported clean in smaps

In reply to Matt Mackall
Quoted 8 lines · Matt Mackall

But that's my point: the consistency problem is NOT in smaps. The page is NOT marked dirty, ergo smaps doesn't report it as dirty. Whether or not there is MORE information smaps could be reporting is irrelevant, the information it IS reporting is consistent with the underlying VM data. If there's an inconsistency about what it means to be clean, it's either in the VM or in your head.

And I frankly think it's in the VM.

I don't believe there's any problem in the VM here, we'd be having SIGSEGVs all over if there were.

The problem is that /proc/pid/smaps exports a simplified view of the VM, and Richard and Nikanth were hoping that it gave them some info which it has never pretended to give them,

It happens to use a pte_dirty(ptent) test: you could argue that that should be pte_dirty(ptent) || PageDirty(page) (which would then "fix the issue" which Richard sees with swapoff/swapon), or you could argue that it should be pte_dirty(ptent) || PageDirty(page) || PageSwapCache(page) (which would then note clean copies of swap cache as dirty in the sense which Richard and Nikanth are interested in).

But after these years, we should probably assume that most users of /proc/pid/smaps are used to the existing pte_dirty(ptent) test, and would be troubled by a departure from it.

Quoted 7 lines

In any case, I don't think Nikanth's fix is the right fix, as it basically says "you can't trust any of this". Either swap should return the pages to their pre-swap dirty state in the VM, or we should add another field here:

Weird_Anon_Page_You_Should_Pretend_Is_Private_Dirty: 8 kB

I think that the most widely useful but simple extension of /proc/pid/smaps, that would give them the info they want, would indeed be to counts ptes pointing to PageAnon pages and report that total on an additional line (say, just before "Swap:"); but there's no need for the derogatory name you propose there, "Anon:" would suit fine!

The original idea of testing for vma->anon_vma was a good one, but it doesn't fit so well into the /proc/pid/smaps layout; and showing the actual count of Anon pages could be useful to others (though generally it would be Anon+Swap they'd be interested in).

Hugh

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#17 lore raw

Re: [PATCH v2] After swapout/swapin private dirty mappings are reported clean in smaps

Quoted 9 lines · Hugh Dickins
Quoted 7 lines · Matt Mackall

But that's my point: the consistency problem is NOT in smaps. The page is NOT marked dirty, ergo smaps doesn't report it as dirty. Whether or not there is MORE information smaps could be reporting is irrelevant, the information it IS reporting is consistent with the underlying VM data. If there's an inconsistency about what it means to be clean, it's either in the VM or in your head.

Quoted 4 lines
Quoted 1 line

And I frankly think it's in the VM.

I don't believe there's any problem in the VM here, we'd be having SIGSEGVs all over if there were.

Of course it works. It's just not as orthogonal (aka consistent) as it could be in this case: it's not actually reflecting any of the usual meanings of dirtiness here.

Quoted 7 lines

The problem is that /proc/pid/smaps exports a simplified view of the VM, and Richard and Nikanth were hoping that it gave them some info which it has never pretended to give them,

It happens to use a pte_dirty(ptent) test: you could argue that that should be pte_dirty(ptent) || PageDirty(page) (which would then "fix the issue" which Richard sees with swapoff/swapon),

That might be interesting. Are there any other notable cases where pte_dirty() differs from PageDirty()?

Quoted 8 lines

or you could argue
that it should be pte_dirty(ptent) || PageDirty(page) || PageSwapCache(page) (which would then note clean copies of swap cache as dirty in the sense which Richard and Nikanth are interested in).

But after these years, we should probably assume that most users of /proc/pid/smaps are used to the existing pte_dirty(ptent) test, and would be troubled by a departure from it.

Dunno, my smem tool[1] is probably also expecting too much here and I should know better!

Quoted 5 lines
Quoted 5 lines

In any case, I don't think Nikanth's fix is the right fix, as it basically says "you can't trust any of this". Either swap should return the pages to their pre-swap dirty state in the VM, or we should add another field here:

Quoted 7 lines
Quoted 1 line

Weird_Anon_Page_You_Should_Pretend_Is_Private_Dirty: 8 kB

I think that the most widely useful but simple extension of /proc/pid/smaps, that would give them the info they want, would indeed be to counts ptes pointing to PageAnon pages and report that total on an additional line (say, just before "Swap:"); but there's no need for the derogatory name you propose there, "Anon:" would suit fine!

Yes, that wasn't a serious suggestion.

[1] http://www.selenic.com/smem/

Signature · 8 lines
Mathematics is the supreme nostalgia of our time.


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#18 lore raw

Re: [PATCH v2] After swapout/swapin private dirty mappings are reported clean in smaps

Quoted 35 lines · Matt Mackall
Quoted 9 lines · Hugh Dickins
Quoted 7 lines · Matt Mackall

But that's my point: the consistency problem is NOT in smaps. The page is NOT marked dirty, ergo smaps doesn't report it as dirty. Whether or not there is MORE information smaps could be reporting is irrelevant, the information it IS reporting is consistent with the underlying VM data. If there's an inconsistency about what it means to be clean, it's either in the VM or in your head.

Quoted 4 lines
Quoted 1 line

And I frankly think it's in the VM.

I don't believe there's any problem in the VM here, we'd be having SIGSEGVs all over if there were.

Of course it works. It's just not as orthogonal (aka consistent) as it could be in this case: it's not actually reflecting any of the usual meanings of dirtiness here.

Quoted 7 lines

The problem is that /proc/pid/smaps exports a simplified view of the VM, and Richard and Nikanth were hoping that it gave them some info which it has never pretended to give them,

It happens to use a pte_dirty(ptent) test: you could argue that that should be pte_dirty(ptent) || PageDirty(page) (which would then "fix the issue" which Richard sees with swapoff/swapon),

That might be interesting. Are there any other notable cases where pte_dirty() differs from PageDirty()?

Quoted 5 lines

or you could argue
that it should be pte_dirty(ptent) || PageDirty(page) || PageSwapCache(page) (which would then note clean copies of swap cache as dirty in the sense which Richard and Nikanth are interested in).

Quoted 6 lines
Quoted 3 lines

But after these years, we should probably assume that most users of /proc/pid/smaps are used to the existing pte_dirty(ptent) test, and would be troubled by a departure from it.

Dunno, my smem tool[1] is probably also expecting too much here and I should know better!

The question is also what smaps is supposed to deliver (I guess the only documentation as of that respect is the kernel source ...).

The appearantly incomplete information isn't too useful at the moment (apart from displaying the numbers in some form). So changing the semantics of the numbers in a slight way shouldn't cause regressions in tools that formerly worked correct in all cases.

Unfortunately gdb needs some reliable way of checking whether the mappings content in memory is still equal to that of the backing file (best without actually carrying out that comparison ...). /proc/pid/smaps looked like the most precise interface for that - now unfortunately it's not usable for this. Is there any other way?

Richard.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#19 lore raw

Re: [PATCH v2] After swapout/swapin private dirty mappings are reported clean in smaps

In reply to Matt Mackall
Quoted 11 lines · Matt Mackall
Quoted 7 lines · Hugh Dickins

The problem is that /proc/pid/smaps exports a simplified view of the VM, and Richard and Nikanth were hoping that it gave them some info which it has never pretended to give them,

It happens to use a pte_dirty(ptent) test: you could argue that that should be pte_dirty(ptent) || PageDirty(page) (which would then "fix the issue" which Richard sees with swapoff/swapon),

That might be interesting. Are there any other notable cases where pte_dirty() differs from PageDirty()?

I don't know about "other notable". A page may very well be PageDirty (e.g. modified by a write system call) without any of the ptes pointing to it (if there even are any) marked as pte_dirty. A page may very well not be marked PageDirty yet, though one or more of the ptes pointing to it have been marked pte_dirty when userspace made a
write access to the page via that pte. Traditionally (when
/proc/pid/smaps was first reporting dirty versus clean ptes) the pte dirtiness would later be found and propagated through to PageDirtiness (clearing the pte dirtiness), which would later be cleaned when the page was written out to backing store (file or swap).

PeterZ's writeback work in 2.6.19 (set_page_dirty_balance, clear_page_dirty_for_io etc.) tightened up writeback from (most: tmpfs is one exception) shared file mmaps, synchronizing the PageDirty more carefully with the pte_dirty; and perhaps there is some inconsistency there, that we never felt compelled to keep pte and Page so tightly in synch in the anonymous/Swap case - it would have been unnecessary overhead (though I repeatedly forget the essence of why not - file syncing, and pdflush activity, were relevant considerations; but I cannot now put my finger on precisely why shared file writing needed to be fixed, but anonymous dirtying could be left unchanged).

But even if you replace smaps's pte_dirty(ptent) tests by pte_dirty(ptent) || PageDirty(page) tests, it wouldn't be doing what Richard and Nikanth want - they want clean ptes of clean PageSwapCache to be reported as dirty, despite being clean copies of backing store; and I can understand your reluctance to go that far. I think reporting "Anon:" pages is more useful - in part because we have no counts of Anon+Swap, yet that's the quantity which vm_enough_memory may place a limit upon (but beware, it does of course get more
complicated: tmpfs files come out of that tally too, but would not show up in this way).

Hugh

#20 lore raw

PATCH 1/1 Export amount of anonymous memory in a mapping via smaps

Export the number of anonymous pages in a mapping via smaps.

Even the private pages in a mapping backed by a file, would be marked as anonymous, when they are modified. Export this information to user-space via smaps.

---

fs/proc/task_mmu.c +6 -0
index 439fc1f..3c18fc8 100644
@@ -326,6 +326,7 @@ struct mem_size_stats {
 	unsigned long private_clean;
 	unsigned long private_dirty;
 	unsigned long referenced;
+	unsigned long anonymous;
 	unsigned long swap;
 	u64 pss;
 };
@@ -356,6 +357,9 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
 		if (!page)
 			continue;
 
+		if (PageAnon(page))
+			mss->anonymous += PAGE_SIZE;
+
 		mss->resident += PAGE_SIZE;
 		/* Accumulate the size in pages that have been accessed. */
 		if (pte_young(ptent) || PageReferenced(page))
@@ -409,6 +413,7 @@ static int show_smap(struct seq_file *m, void *v)
 		   "Private_Clean:  %8lu kB\n"
 		   "Private_Dirty:  %8lu kB\n"
 		   "Referenced:     %8lu kB\n"
+		   "Anonymous:      %8lu kB\n"
 		   "Swap:           %8lu kB\n"
 		   "KernelPageSize: %8lu kB\n"
 		   "MMUPageSize:    %8lu kB\n",
@@ -420,6 +425,7 @@ static int show_smap(struct seq_file *m, void *v)
 		   mss.private_clean >> 10,
 		   mss.private_dirty >> 10,
 		   mss.referenced >> 10,
+		   mss.anonymous >> 10,
 		   mss.swap >> 10,
 		   vma_kernel_pagesize(vma) >> 10,
 		   vma_mmu_pagesize(vma) >> 10);
Reviewed-by on v1 1/1
#21 lore raw

Re: [PATCH] Export amount of anonymous memory in a mapping via smaps

Quoted 7 lines

Export the number of anonymous pages in a mapping via smaps.

Even the private pages in a mapping backed by a file, would be marked as anonymous, when they are modified. Export this information to user-space via smaps.

Looks good.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#22 lore raw

PATCH 1/1 Document the new Anonymous field in smaps.

Sorry, I missed to add documentation, when I sent the patch. This depends on the patch titled, "[PATCH] Export amount of anonymous memory in a mapping via smaps".

Thanks
Nikanth

Document the new Anonymous field in smaps.

---

Documentation/filesystems/proc.txt +5 -1
index a6aca87..75c7368 100644
@@ -370,6 +370,7 @@ Shared_Dirty:          0 kB
 Private_Clean:         0 kB
 Private_Dirty:         0 kB
 Referenced:          892 kB
+Anonymous:             0 kB
 Swap:                  0 kB
 KernelPageSize:        4 kB
 MMUPageSize:           4 kB
@@ -380,7 +381,10 @@ the amount of the mapping that is currently resident in RAM, the "proportional
 set size” (divide each shared page by the number of processes sharing it), the
 number of clean and dirty shared pages in the mapping, and the number of clean
 and dirty private pages in the mapping.  The "Referenced" indicates the amount
-of memory currently marked as referenced or accessed.
+of memory currently marked as referenced or accessed. The "Anonymous" shows
+the amount of mapping that is not associated with a file. Even the private
+pages in a mapping associated with a file, would become anonymous, when they
+are modified.
 
 This file is only present if the CONFIG_MMU kernel configuration option is
 enabled.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#23 lore raw

PATCH 1/1 smaps: fix dirty pages accounting

Currently, /proc/<pid>/smaps have wrong dirty pages accounting. Shared_Dirty and Private_Dirty output only pte dirty pages and ignore PG_dirty page flag. It is difference against documentation, but also inconsistent against Referenced field. (Referenced checks both pte and page flags)

This patch fixes it.

Test program:

large-array.c
---------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

char array[1*1024*1024*1024L];

int main(void)

 {
         memset(array, 1, sizeof(array));
         pause();

         return 0;

}
---------------------------------------------------

Test case:
1. run ./large-array
2. cat /proc/pidof large-array/smaps
3. swapoff -a
4. cat /proc/pidof large-array/smaps again

Test result:
<before patch>

00601000-40601000 rw-p 00000000 00:00 0

Size:            1048576 kB
Rss:             1048576 kB
Pss:             1048576 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:    218992 kB   <-- showed pages as clean incorrectly
Private_Dirty:    829584 kB
Referenced:       388364 kB
Swap:                  0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB

<after patch>

00601000-40601000 rw-p 00000000 00:00 0

Size:            1048576 kB
Rss:             1048576 kB
Pss:             1048576 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:   1048576 kB  <-- fixed
Referenced:       388480 kB
Swap:                  0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
---
 fs/proc/task_mmu.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
fs/proc/task_mmu.c +2 -2
index 439fc1f..7415f13 100644
@@ -362,13 +362,13 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
 			mss->referenced += PAGE_SIZE;
 		mapcount = page_mapcount(page);
 		if (mapcount >= 2) {
-			if (pte_dirty(ptent))
+			if (pte_dirty(ptent) || PageDirty(page))
 				mss->shared_dirty += PAGE_SIZE;
 			else
 				mss->shared_clean += PAGE_SIZE;
 			mss->pss += (PAGE_SIZE << PSS_SHIFT) / mapcount;
 		} else {
-			if (pte_dirty(ptent))
+			if (pte_dirty(ptent) || PageDirty(page))
 				mss->private_dirty += PAGE_SIZE;
 			else
 				mss->private_clean += PAGE_SIZE;
Signature · 1 line
1.6.5.2
Acked-by on v1 1/1
#24 lore raw

Re: [PATCH] smaps: fix dirty pages accounting

Quoted 65 lines · KOSAKI Motohiro

Currently, /proc/<pid>/smaps have wrong dirty pages accounting. Shared_Dirty and Private_Dirty output only pte dirty pages and ignore PG_dirty page flag. It is difference against documentation, but also inconsistent against Referenced field. (Referenced checks both pte and page flags)

This patch fixes it.

Test program:

large-array.c
---------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

char array[1*1024*1024*1024L];

int main(void)

 {
         memset(array, 1, sizeof(array));
         pause();

         return 0;

}
---------------------------------------------------

Test case:
1. run ./large-array
2. cat /proc/pidof large-array/smaps
3. swapoff -a
4. cat /proc/pidof large-array/smaps again

Test result:
<before patch>

00601000-40601000 rw-p 00000000 00:00 0

Size:            1048576 kB
Rss:             1048576 kB
Pss:             1048576 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:    218992 kB   <-- showed pages as clean incorrectly
Private_Dirty:    829584 kB
Referenced:       388364 kB
Swap:                  0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB

<after patch>

00601000-40601000 rw-p 00000000 00:00 0

Size:            1048576 kB
Rss:             1048576 kB
Pss:             1048576 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:   1048576 kB  <-- fixed
Referenced:       388480 kB
Swap:                  0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Quoted 1 line

Certainly you can have my

but I think it's for Matt to decide what he's wanting to show there, and whether it's safe to change after all this time. I hadn't noticed the descrepancy between "dirty" and "referenced", that certainly argues for your patch.

Quoted 26 lines
---
 fs/proc/task_mmu.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
fs/proc/task_mmu.c +2 -2
index 439fc1f..7415f13 100644
@@ -362,13 +362,13 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
 			mss->referenced += PAGE_SIZE;
 		mapcount = page_mapcount(page);
 		if (mapcount >= 2) {
-			if (pte_dirty(ptent))
+			if (pte_dirty(ptent) || PageDirty(page))
 				mss->shared_dirty += PAGE_SIZE;
 			else
 				mss->shared_clean += PAGE_SIZE;
 			mss->pss += (PAGE_SIZE << PSS_SHIFT) / mapcount;
 		} else {
-			if (pte_dirty(ptent))
+			if (pte_dirty(ptent) || PageDirty(page))
 				mss->private_dirty += PAGE_SIZE;
 			else
 				mss->private_clean += PAGE_SIZE;
Signature · 1 line
1.6.5.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#25 lore raw

Re: [PATCH] Document the new Anonymous field in smaps.

In reply to Nikanth Karthikesan
Quoted 11 lines · Nikanth Karthikesan

Sorry, I missed to add documentation, when I sent the patch. This depends on the patch titled, "[PATCH] Export amount of anonymous memory in a mapping via smaps".

Thanks
Nikanth

Document the new Anonymous field in smaps.

Thanks for adding this, but...

Quoted 16 lines

---

Documentation/filesystems/proc.txt +1 -0
index a6aca87..75c7368 100644
@@ -370,6 +370,7 @@ Shared_Dirty:          0 kB
 Private_Clean:         0 kB
 Private_Dirty:         0 kB
 Referenced:          892 kB
+Anonymous:             0 kB
 Swap:                  0 kB
 KernelPageSize:        4 kB
 MMUPageSize:           4 kB

Documentation/filesystems/proc.txt the amount of the mapping that is currently resident in RAM, the "proportional · line 387

Quoted 8 lines
Documentation/filesystems/proc.txt +4 -1
@@ -380,7 +381,10 @@ the amount of the mapping that is currently resident in RAM, the "proportional
 set size” (divide each shared page by the number of processes sharing it), the
 number of clean and dirty shared pages in the mapping, and the number of clean
 and dirty private pages in the mapping.  The "Referenced" indicates the amount
-of memory currently marked as referenced or accessed.
+of memory currently marked as referenced or accessed. The "Anonymous" shows
+the amount of mapping that is not associated with a file. Even the private
+pages in a mapping associated with a file, would become anonymous, when they
+are modified.

... unfortunately it needs rewording, because you're describing it well with respect to MAP_SHARED versus MAP_PRIVATE, but /proc/pid/smaps has a different definition of whether pages are shared or private, just depending on their mapcount at the instant.

Indeed, adding a comment on that would be helpful too, if you've time.

Quoted 3 lines
Documentation/filesystems/proc.txt +0 -0
 This file is only present if the CONFIG_MMU kernel configuration option is
 enabled.
#26 lore raw

PATCH v2 1/1 Document the new Anonymous field in smaps.

Document the new Anonymous field in smaps.

---

Documentation/filesystems/proc.txt +11 -4
index a6aca87..b430576 100644
@@ -370,17 +370,24 @@ Shared_Dirty:          0 kB
 Private_Clean:         0 kB
 Private_Dirty:         0 kB
 Referenced:          892 kB
+Anonymous:             0 kB
 Swap:                  0 kB
 KernelPageSize:        4 kB
 MMUPageSize:           4 kB
 
-The first  of these lines shows  the same information  as is displayed for the
-mapping in /proc/PID/maps.  The remaining lines show  the size of the mapping,
+The first of these lines shows the same information as is displayed for the
+mapping in /proc/PID/maps. The remaining lines show the size of the mapping,
 the amount of the mapping that is currently resident in RAM, the "proportional
 set size” (divide each shared page by the number of processes sharing it), the
 number of clean and dirty shared pages in the mapping, and the number of clean
-and dirty private pages in the mapping.  The "Referenced" indicates the amount
-of memory currently marked as referenced or accessed.
+and dirty private pages in the mapping. Even pages which are part of
+MAP_SHARED mappings, but has only a single pte mapped i.e., used exclusively
+by a process is accounted as private and not as shared. The "Referenced"
+indicates the amount of memory currently marked as referenced or accessed. The
+"Anonymous" shows the number of pages that is not associated with a file. Even
+mappings associated with a file can have anonymous pages. When the mapping is
+MAP_PRIVATE and its pages are modified, the pages are COWed and marked as
+anonymous.
 
 This file is only present if the CONFIG_MMU kernel configuration option is
 enabled.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#27 lore raw

Re: [PATCH v2] Document the new Anonymous field in smaps.

Quoted 1 line · Nikanth Karthikesan

Document the new Anonymous field in smaps.

Thanks for doing that, good effort, but your shifts between singular and plural rather jarred on my ear, so I've rewritten it a little below. Also added a sentence on "Swap"; but gave up when it came to KernelPageSize and MMUPageSize, let someone else clarify those later.

[PATCH v3] Document the new Anonymous field in smaps.

From: Nikanth Karthikesan <[email protected]>

Document the new Anonymous field in smaps, and also the Swap field. Explain what smaps means by shared and private, which differs from MAP_SHARED and MAP_PRIVATE.

---

 Documentation/filesystems/proc.txt |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
Documentation/filesystems/proc.txt +11 -4
@@ -370,17 +370,24 @@ Shared_Dirty:          0 kB
 Private_Clean:         0 kB
 Private_Dirty:         0 kB
 Referenced:          892 kB
+Anonymous:             0 kB
 Swap:                  0 kB
 KernelPageSize:        4 kB
 MMUPageSize:           4 kB
 
-The first  of these lines shows  the same information  as is displayed for the
-mapping in /proc/PID/maps.  The remaining lines show  the size of the mapping,
+The first of these lines shows the same information as is displayed for the
+mapping in /proc/PID/maps. The remaining lines show the size of the mapping,
 the amount of the mapping that is currently resident in RAM, the "proportional
 set size” (divide each shared page by the number of processes sharing it), the
 number of clean and dirty shared pages in the mapping, and the number of clean
-and dirty private pages in the mapping.  The "Referenced" indicates the amount
-of memory currently marked as referenced or accessed.
+and dirty private pages in the mapping. Note that even a page which is part of
+a MAP_SHARED mapping, but has only a single pte mapped, i.e. is currently used
+by only one process, is accounted as private and not as shared. "Referenced"
+indicates the amount of memory currently marked as referenced or accessed.
+"Anonymous" shows the amount of memory that does not belong to any file. Even
+a mapping associated with a file may contain anonymous pages: when MAP_PRIVATE
+and a page is modified, the file page is replaced by a private anonymous copy.
+"Swap" shows how much would-be-anonymous memory is also used, but out on swap.
 
 This file is only present if the CONFIG_MMU kernel configuration option is
 enabled.
Acked-by
#28 lore raw

Re: [PATCH v2] Document the new Anonymous field in smaps.

Quoted 11 lines · Hugh Dickins
Quoted 1 line · Nikanth Karthikesan

Document the new Anonymous field in smaps.

Thanks for doing that, good effort, but your shifts between singular and plural rather jarred on my ear, so I've rewritten it a little below. Also added a sentence on "Swap"; but gave up when it came to KernelPageSize and MMUPageSize, let someone else clarify those later.

[PATCH v3] Document the new Anonymous field in smaps.

Quoted 8 lines

From: Nikanth Karthikesan <[email protected]>

Document the new Anonymous field in smaps, and also the Swap field. Explain what smaps means by shared and private, which differs from MAP_SHARED and MAP_PRIVATE.

Looks good,

Quoted 36 lines

---

 Documentation/filesystems/proc.txt |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
Documentation/filesystems/proc.txt +11 -4
@@ -370,17 +370,24 @@ Shared_Dirty:          0 kB
 Private_Clean:         0 kB
 Private_Dirty:         0 kB
 Referenced:          892 kB
+Anonymous:             0 kB
 Swap:                  0 kB
 KernelPageSize:        4 kB
 MMUPageSize:           4 kB
 
-The first  of these lines shows  the same information  as is displayed for the
-mapping in /proc/PID/maps.  The remaining lines show  the size of the mapping,
+The first of these lines shows the same information as is displayed for the
+mapping in /proc/PID/maps. The remaining lines show the size of the mapping,
 the amount of the mapping that is currently resident in RAM, the "proportional
 set sizea?? (divide each shared page by the number of processes sharing it), the
 number of clean and dirty shared pages in the mapping, and the number of clean
-and dirty private pages in the mapping.  The "Referenced" indicates the amount
-of memory currently marked as referenced or accessed.
+and dirty private pages in the mapping. Note that even a page which is part of
+a MAP_SHARED mapping, but has only a single pte mapped, i.e. is currently used
+by only one process, is accounted as private and not as shared. "Referenced"
+indicates the amount of memory currently marked as referenced or accessed.
+"Anonymous" shows the amount of memory that does not belong to any file. Even
+a mapping associated with a file may contain anonymous pages: when MAP_PRIVATE
+and a page is modified, the file page is replaced by a private anonymous copy.
+"Swap" shows how much would-be-anonymous memory is also used, but out on swap.
 
 This file is only present if the CONFIG_MMU kernel configuration option is
 enabled.
Signature · 8 lines
Mathematics is the supreme nostalgia of our time.


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on v1 1/1
#29 lore raw

Re: [PATCH] Export amount of anonymous memory in a mapping via smaps

In reply to Nikanth Karthikesan
Quoted 7 lines · Nikanth Karthikesan

Export the number of anonymous pages in a mapping via smaps.

Even the private pages in a mapping backed by a file, would be marked as anonymous, when they are modified. Export this information to user-space via smaps.

but I'd prefer if we added a little more justification, such as:

Exporting this count will help gdb to make a better decision on which areas need to be dumped in its coredump; and should be useful to others studying the memory usage of a process.

Quoted 43 lines

---

fs/proc/task_mmu.c +6 -1
index 439fc1f..3c18fc8 100644
@@ -326,6 +326,7 @@ struct mem_size_stats {
 	unsigned long private_clean;
 	unsigned long private_dirty;
 	unsigned long referenced;
+	unsigned long anonymous;
 	unsigned long swap;
 	u64 pss;
 };
@@ -356,6 +357,9 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
 		if (!page)
 			continue;
 
+		if (PageAnon(page))
+			mss->anonymous += PAGE_SIZE;
+
 		mss->resident += PAGE_SIZE;
 		/* Accumulate the size in pages that have been accessed. */
 		if (pte_young(ptent) || PageReferenced(page))
@@ -409,6 +413,7 @@ static int show_smap(struct seq_file *m, void *v)
 		   "Private_Clean:  %8lu kB\n"
 		   "Private_Dirty:  %8lu kB\n"
 		   "Referenced:     %8lu kB\n"
+		   "Anonymous:      %8lu kB\n"
 		   "Swap:           %8lu kB\n"
 		   "KernelPageSize: %8lu kB\n"
 		   "MMUPageSize:    %8lu kB\n",
@@ -420,6 +425,7 @@ static int show_smap(struct seq_file *m, void *v)
 		   mss.private_clean >> 10,
 		   mss.private_dirty >> 10,
 		   mss.referenced >> 10,
+		   mss.anonymous >> 10,
 		   mss.swap >> 10,
 		   vma_kernel_pagesize(vma) >> 10,
 		   vma_mmu_pagesize(vma) >> 10);
 
--
Quoted 6 lines

To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#30 lore raw

Re: [PATCH v2] After swapout/swapin private dirty mappings are reported clean in smaps

In reply to Richard Guenther
Quoted 10 lines · Richard Guenther
Quoted 8 lines · Balbir Singh
Quoted 5 lines · Nikanth Karthikesan

How? Current smaps information without this patch provides incorrect information. Just because a private dirty page became part of swap cache, it shown as clean and backed by a file. If it is shown as clean and backed by swap then it is fine.

Quoted 8 lines
Quoted 1 line

How is GDB using this information?

GDB counts the number of dirty and swapped pages in a private mapping and based on that decides whether it needs to dump it to a core file or not. If there are no dirty or swapped pages gdb assumes it can reconstruct the mapping from the original backing file. This way for example shared libraries do not end up in the core file.

Thanks for clarifying

Signature · 8 lines
	Three Cheers,
	Balbir

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#31 lore raw

Re: [PATCH v2] After swapout/swapin private dirty mappings are reported clean in smaps

In reply to Richard Guenther
Quoted 7 lines · On Wednesday 15 September 2010 19:44:17 Richard Guenther wrote:
Quoted 6 lines · Balbir Singh
Quoted 4 lines · Nikanth Karthikesan

How? Current smaps information without this patch provides incorrect information. Just because a private dirty page became part of swap cache, it shown as clean and backed by a file. If it is shown as clean and backed by swap then it is fine.

Quoted 8 lines
Quoted 1 line

How is GDB using this information?

GDB counts the number of dirty and swapped pages in a private mapping and based on that decides whether it needs to dump it to a core file or not. If there are no dirty or swapped pages gdb assumes it can reconstruct the mapping from the original backing file. This way for example shared libraries do not end up in the core file.

Well, may be /proc/pid/pagemap + /proc/kpageflags is enough for this! One can get the pageflags using these interfaces. See Documentation/vm/pagemap.txt for the explanation on how to do it. There is also a sample program that prints page flags using this interface in Documentation/vm/page-types.c.

It is bad that /proc/pid/pagemap is never mentioned in Documentation/filesystems/proc.txt. I will send a patch to rectify this.

Thanks
Nikanth

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#32 lore raw

PATCH 1/1 Document /proc/pid/pagemap in Documentation/filesystems/proc.txt

Document /proc/pid/pagemap in Documentation/filesystems/proc.txt

---

Documentation/filesystems/proc.txt +4 -0
index a6aca87..a9c85a6 100644
@@ -136,6 +136,7 @@ Table 1-1: Process specific entries in /proc
  statm		Process memory status information
  status		Process status in human readable form
  wchan		If CONFIG_KALLSYMS is set, a pre-decoded wchan
+ pagemap	Page table
  stack		Report full stack trace, enable via CONFIG_STACKTRACE
  smaps		a extension based on maps, showing the memory consumption of
 		each mapping
@@ -397,6 +398,9 @@ To clear the bits for the file mapped pages associated with the process
     > echo 3 > /proc/PID/clear_refs
 Any other value written to /proc/PID/clear_refs will have no effect.
 
+The /proc/pid/pagemap gives the PFN, which can be used to find the pageflags
+using /proc/kpageflags and number of times a page is mapped using
+/proc/kpagecount. For detailed explanation, see Documentation/vm/pagemap.txt.
 
 1.2 Kernel data
 ---------------

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Acked-by on v1 1/1
#33 lore raw

Re: [PATCH] Document /proc/pid/pagemap in Documentation/filesystems/proc.txt

Quoted 3 lines · Nikanth Karthikesan

Document /proc/pid/pagemap in Documentation/filesystems/proc.txt

Signature · 8 lines
Mathematics is the supreme nostalgia of our time.


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#34 lore raw

Re: [PATCH v2] After swapout/swapin private dirty mappings are reported clean in smaps

In reply to Nikanth Karthikesan
Quoted 16 lines · On Sunday 19 September 2010 23:07:09 Nikanth Karthikesan wrote:
Quoted 7 lines · On Wednesday 15 September 2010 19:44:17 Richard Guenther wrote:
Quoted 6 lines · Balbir Singh
Quoted 4 lines · Nikanth Karthikesan

How? Current smaps information without this patch provides incorrect information. Just because a private dirty page became part of swap cache, it shown as clean and backed by a file. If it is shown as clean and backed by swap then it is fine.

Quoted 7 lines
Quoted 1 line

How is GDB using this information?

GDB counts the number of dirty and swapped pages in a private mapping and based on that decides whether it needs to dump it to a core file or not. If there are no dirty or swapped pages gdb assumes it can reconstruct the mapping from the original backing file. This way for example shared libraries do not end up in the core file.

Quoted 8 lines

Well, may be /proc/pid/pagemap + /proc/kpageflags is enough for this! One
can get the pageflags using these interfaces. See Documentation/vm/pagemap.txt for the explanation on how to do it. There is also a sample program that prints page flags using this interface in Documentation/vm/page-types.c.

It is bad that /proc/pid/pagemap is never mentioned in Documentation/filesystems/proc.txt. I will send a patch to rectify this.

Or even simpler, /proc/pid/numa_maps already exports the number of anonymous pages in a mapping, if you have CONFIG_NUMA=y! Again not documented in Documentation/filesystems/proc.txt

Thanks
Nikanth

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#35 lore raw

Re: [PATCH v2] After swapout/swapin private dirty mappings are reported clean in smaps

In reply to Nikanth Karthikesan
Quoted 17 lines · Nikanth Karthikesan
Quoted 7 lines · On Wednesday 15 September 2010 19:44:17 Richard Guenther wrote:
Quoted 6 lines · Balbir Singh
Quoted 4 lines · Nikanth Karthikesan

How? Current smaps information without this patch provides incorrect information. Just because a private dirty page became part of swap cache, it shown as clean and backed by a file. If it is shown as clean and backed by swap then it is fine.

Quoted 8 lines
Quoted 1 line

How is GDB using this information?

GDB counts the number of dirty and swapped pages in a private mapping and based on that decides whether it needs to dump it to a core file or not. If there are no dirty or swapped pages gdb assumes it can reconstruct the mapping from the original backing file. This way for example shared libraries do not end up in the core file.

Quoted 7 lines

Well, may be /proc/pid/pagemap + /proc/kpageflags is enough for this! One can get the pageflags using these interfaces. See Documentation/vm/pagemap.txt for the explanation on how to do it. There is also a sample program that prints page flags using this interface in Documentation/vm/page-types.c.

It is bad that /proc/pid/pagemap is never mentioned in Documentation/filesystems/proc.txt. I will send a patch to rectify this.

Looks like /proc/kpageflags is root-only, so not a solution for gdb.

Richard.

#36 lore raw
In reply to Nikanth Karthikesan
Quoted 24 lines

/proc/$pid/smaps broken: After swapout/swapin private dirty mappings become clean.

When a page with private file mapping becomes dirty, the vma will be in both i_mmap tree and anon_vma list. The /proc/$pid/smaps will account these pages as dirty and backed by the file.

But when those dirty pages gets swapped out, and when they are read back from swap, they would be marked as clean, as it should be, as they are part of swap cache now.

But the /proc/$pid/smaps would report the vma as a mapping of a file and it is clean. The pages are actually in same state i.e., dirty with respect to file still, but which was once reported as dirty is now being reported as clean to user-space.

This confuses tools like gdb which uses this information. Those tools think that those pages were never modified and it creates problem when they create dumps.

The file mapping of the vma also cannot be broken as pages never read earlier, will still have to come from the file. Just that those dirty pages have become clean anonymous pages.

Quoted 5 lines

During swaping in, restoring the exact state as dirty file-backed pages before swapout would be useless, as there in no real bug. Breaking the vma with only anonymous pages as seperate vmas unnecessary may not be a good thing as well. So let us just export the information that a file-backed vma has anonymous dirty pages.

Why can't gdb check Swap: field in smaps? I think Swap!=0 mean we need dump out.

Am I missing anything?

- kosaki

Quoted 24 lines

Export this information in smaps by prepending file-names with "[anon]+", when some of the pages in a file backed vma become anonymous.

---

fs/proc/task_mmu.c +2 -1
index 439fc1f..68f9806 100644
@@ -242,6 +242,8 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
 	 */
 	if (file) {
 		pad_len_spaces(m, len);
+		if (vma->anon_vma)
+			seq_puts(m, "[anon]+");
 		seq_path(m, &file->f_path, "\n");
 	} else {
 		const char *name = arch_vma_name(vma);
 
 
--
Quoted 5 lines

To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#37 lore raw
Quoted 24 lines · On Wednesday 15 September 2010 05:54:31 KOSAKI Motohiro wrote:
Quoted 24 lines

/proc/$pid/smaps broken: After swapout/swapin private dirty mappings become clean.

When a page with private file mapping becomes dirty, the vma will be in both i_mmap tree and anon_vma list. The /proc/$pid/smaps will account these pages as dirty and backed by the file.

But when those dirty pages gets swapped out, and when they are read back from swap, they would be marked as clean, as it should be, as they are part of swap cache now.

But the /proc/$pid/smaps would report the vma as a mapping of a file and it is clean. The pages are actually in same state i.e., dirty with respect to file still, but which was once reported as dirty is now being reported as clean to user-space.

This confuses tools like gdb which uses this information. Those tools think that those pages were never modified and it creates problem when they create dumps.

The file mapping of the vma also cannot be broken as pages never read earlier, will still have to come from the file. Just that those dirty pages have become clean anonymous pages.

Quoted 9 lines
Quoted 5 lines

During swaping in, restoring the exact state as dirty file-backed pages before swapout would be useless, as there in no real bug. Breaking the vma with only anonymous pages as seperate vmas unnecessary may not be a good thing as well. So let us just export the information that a file-backed vma has anonymous dirty pages.

Why can't gdb check Swap: field in smaps? I think Swap!=0 mean we need dump
out.

Yes. When the page is swapped out it is accounted in "Swap:".

Quoted 2 lines

Am I missing anything?

But when it gets swapped in back to memory, it is removed from "Swap:" and added to "Private_Clean:" instead of "Private_Dirty:".

Thanks
Nikanth

Quoted 24 lines

- kosaki

Quoted 22 lines

Export this information in smaps by prepending file-names with "[anon]+", when some of the pages in a file backed vma become anonymous.

---

fs/proc/task_mmu.c +0 -0
index 439fc1f..68f9806 100644
@@ -242,6 +242,8 @@ static void show_map_vma(struct seq_file *m, struct

vm_area_struct *vma) */

fs/proc/task_mmu.c +2 -0
 	if (file) {
 		pad_len_spaces(m, len);
+		if (vma->anon_vma)
+			seq_puts(m, "[anon]+");
 		seq_path(m, &file->f_path, "\n");
 	} else {
 		const char *name = arch_vma_name(vma);
Quoted 6 lines
Quoted 5 lines

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#38 lore raw
Quoted 35 lines · On Wednesday 15 September 2010 05:54:31 KOSAKI Motohiro wrote:
Quoted 24 lines
Quoted 24 lines

/proc/$pid/smaps broken: After swapout/swapin private dirty mappings become clean.

When a page with private file mapping becomes dirty, the vma will be in both i_mmap tree and anon_vma list. The /proc/$pid/smaps will account these pages as dirty and backed by the file.

But when those dirty pages gets swapped out, and when they are read back from swap, they would be marked as clean, as it should be, as they are part of swap cache now.

But the /proc/$pid/smaps would report the vma as a mapping of a file and it is clean. The pages are actually in same state i.e., dirty with respect to file still, but which was once reported as dirty is now being reported as clean to user-space.

This confuses tools like gdb which uses this information. Those tools think that those pages were never modified and it creates problem when they create dumps.

The file mapping of the vma also cannot be broken as pages never read earlier, will still have to come from the file. Just that those dirty pages have become clean anonymous pages.

Quoted 9 lines
Quoted 5 lines

During swaping in, restoring the exact state as dirty file-backed pages before swapout would be useless, as there in no real bug. Breaking the vma with only anonymous pages as seperate vmas unnecessary may not be a good thing as well. So let us just export the information that a file-backed vma has anonymous dirty pages.

Why can't gdb check Swap: field in smaps? I think Swap!=0 mean we need dump
out.

Quoted 7 lines

Yes. When the page is swapped out it is accounted in "Swap:".

Quoted 2 lines

Am I missing anything?

But when it gets swapped in back to memory, it is removed from "Swap:" and added to "Private_Clean:" instead of "Private_Dirty:".

Here is the code.
I think the page will become dirty, again.

--------------------------------------------------------------
int try_to_free_swap(struct page *page)

{
        VM_BUG_ON(!PageLocked(page));

        if (!PageSwapCache(page))
                return 0;
        if (PageWriteback(page))
                return 0;
        if (page_swapcount(page))
                return 0;

        delete_from_swap_cache(page);
        SetPageDirty(page);
        return 1;
}
#39 lore raw
Quoted 46 lines · On Wednesday 15 September 2010 10:16:36 KOSAKI Motohiro wrote:
Quoted 34 lines · On Wednesday 15 September 2010 05:54:31 KOSAKI Motohiro wrote:
Quoted 24 lines
Quoted 24 lines

/proc/$pid/smaps broken: After swapout/swapin private dirty mappings become clean.

When a page with private file mapping becomes dirty, the vma will be in both i_mmap tree and anon_vma list. The /proc/$pid/smaps will account these pages as dirty and backed by the file.

But when those dirty pages gets swapped out, and when they are read back from swap, they would be marked as clean, as it should be, as they are part of swap cache now.

But the /proc/$pid/smaps would report the vma as a mapping of a file and it is clean. The pages are actually in same state i.e., dirty with respect to file still, but which was once reported as dirty is now being reported as clean to user-space.

This confuses tools like gdb which uses this information. Those tools think that those pages were never modified and it creates problem when they create dumps.

The file mapping of the vma also cannot be broken as pages never read earlier, will still have to come from the file. Just that those dirty pages have become clean anonymous pages.

Quoted 8 lines
Quoted 5 lines

During swaping in, restoring the exact state as dirty file-backed pages before swapout would be useless, as there in no real bug. Breaking the vma with only anonymous pages as seperate vmas unnecessary may not be a good thing as well. So let us just export the information that a file-backed vma has anonymous dirty pages.

Why can't gdb check Swap: field in smaps? I think Swap!=0 mean we need dump out.

Quoted 6 lines

Yes. When the page is swapped out it is accounted in "Swap:".

Quoted 1 line

Am I missing anything?

But when it gets swapped in back to memory, it is removed from "Swap:" and added to "Private_Clean:" instead of "Private_Dirty:".

Here is the code.
I think the page will become dirty, again.

--------------------------------------------------------------
int try_to_free_swap(struct page *page)

Quoted 15 lines
{
        VM_BUG_ON(!PageLocked(page));

        if (!PageSwapCache(page))
                return 0;
        if (PageWriteback(page))
                return 0;
        if (page_swapcount(page))
                return 0;

        delete_from_swap_cache(page);
        SetPageDirty(page);
        return 1;
}

I think this gets called only when the swap space gets freed. But when the page is just swapped out and swapped in, and the page is still part of SwapCache, it will be marked as clean, when the I/O read from swap completes.

Thanks
Nikanth

#40 lore raw
Quoted 57 lines · On Wednesday 15 September 2010 10:16:36 KOSAKI Motohiro wrote:
Quoted 56 lines
Quoted 34 lines · On Wednesday 15 September 2010 05:54:31 KOSAKI Motohiro wrote:
Quoted 24 lines
Quoted 24 lines

/proc/$pid/smaps broken: After swapout/swapin private dirty mappings become clean.

When a page with private file mapping becomes dirty, the vma will be in both i_mmap tree and anon_vma list. The /proc/$pid/smaps will account these pages as dirty and backed by the file.

But when those dirty pages gets swapped out, and when they are read back from swap, they would be marked as clean, as it should be, as they are part of swap cache now.

But the /proc/$pid/smaps would report the vma as a mapping of a file and it is clean. The pages are actually in same state i.e., dirty with respect to file still, but which was once reported as dirty is now being reported as clean to user-space.

This confuses tools like gdb which uses this information. Those tools think that those pages were never modified and it creates problem when they create dumps.

The file mapping of the vma also cannot be broken as pages never read earlier, will still have to come from the file. Just that those dirty pages have become clean anonymous pages.

Quoted 8 lines
Quoted 5 lines

During swaping in, restoring the exact state as dirty file-backed pages before swapout would be useless, as there in no real bug. Breaking the vma with only anonymous pages as seperate vmas unnecessary may not be a good thing as well. So let us just export the information that a file-backed vma has anonymous dirty pages.

Why can't gdb check Swap: field in smaps? I think Swap!=0 mean we need dump out.

Quoted 6 lines

Yes. When the page is swapped out it is accounted in "Swap:".

Quoted 1 line

Am I missing anything?

But when it gets swapped in back to memory, it is removed from "Swap:" and added to "Private_Clean:" instead of "Private_Dirty:".

Here is the code.
I think the page will become dirty, again.

--------------------------------------------------------------
int try_to_free_swap(struct page *page)

{
        VM_BUG_ON(!PageLocked(page));

        if (!PageSwapCache(page))
                return 0;
        if (PageWriteback(page))
                return 0;
        if (page_swapcount(page))
                return 0;
Quoted 7 lines
Quoted 5 lines
        delete_from_swap_cache(page);
        SetPageDirty(page);
        return 1;
}

I think this gets called only when the swap space gets freed.

this is try-to-free-swap-space.
delete_from_swap_cache() does actual free.

Quoted 3 lines

But when the
page is just swapped out and swapped in, and the page is still part of SwapCache, it will be marked as clean, when the I/O read from swap completes.

Because in this case, the swap entry is not freed yet. Then the page is still clean and swap field is still !0.

PageSwapCache == the page has backend swap entry == the page may be clean. But, When the swap entry is removed, page will become dirty again.

As I said, following is incorrect. In almost case, swap entry is not removed at swap-in. Please grep try_to_free_swap() callers and

Quoted 1 line
Quoted 1 line
Quoted 1 line

But when it gets swapped in back to memory, it is removed from "Swap:"

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#41 lore raw
Quoted 73 lines · On Wednesday 15 September 2010 10:45:28 KOSAKI Motohiro wrote:
Quoted 58 lines · On Wednesday 15 September 2010 10:16:36 KOSAKI Motohiro wrote:
Quoted 57 lines
Quoted 35 lines · On Wednesday 15 September 2010 05:54:31 KOSAKI Motohiro wrote:
Quoted 31 lines
Quoted 24 lines

/proc/$pid/smaps broken: After swapout/swapin private dirty mappings become clean.

When a page with private file mapping becomes dirty, the vma will be in both i_mmap tree and anon_vma list. The /proc/$pid/smaps will account these pages as dirty and backed by the file.

But when those dirty pages gets swapped out, and when they are read back from swap, they would be marked as clean, as it should be, as they are part of swap cache now.

But the /proc/$pid/smaps would report the vma as a mapping of a file and it is clean. The pages are actually in same state i.e., dirty with respect to file still, but which was once reported as dirty is now being reported as clean to user-space.

This confuses tools like gdb which uses this information. Those tools think that those pages were never modified and it creates problem when they create dumps.

The file mapping of the vma also cannot be broken as pages never read earlier, will still have to come from the file. Just that those dirty pages have become clean anonymous pages.

Quoted 6 lines

During swaping in, restoring the exact state as dirty file-backed pages before swapout would be useless, as there in no real bug. Breaking the vma with only anonymous pages as seperate vmas unnecessary may not be a good thing as well. So let us just export the information that a file-backed vma has anonymous dirty pages.

Quoted 2 lines

Why can't gdb check Swap: field in smaps? I think Swap!=0 mean we need dump out.

Quoted 6 lines

Yes. When the page is swapped out it is accounted in "Swap:".

Quoted 1 line

Am I missing anything?

But when it gets swapped in back to memory, it is removed from "Swap:" and added to "Private_Clean:" instead of "Private_Dirty:".

Here is the code.
I think the page will become dirty, again.

--------------------------------------------------------------
int try_to_free_swap(struct page *page)

{
        VM_BUG_ON(!PageLocked(page));

        if (!PageSwapCache(page))
                return 0;
        if (PageWriteback(page))
                return 0;
        if (page_swapcount(page))
                return 0;
Quoted 6 lines
Quoted 4 lines
        delete_from_swap_cache(page);
        SetPageDirty(page);
        return 1;
}

I think this gets called only when the swap space gets freed.

this is try-to-free-swap-space.
delete_from_swap_cache() does actual free.

Quoted 4 lines

But when the
page is just swapped out and swapped in, and the page is still part of SwapCache, it will be marked as clean, when the I/O read from swap completes.

Quoted 6 lines

Because in this case, the swap entry is not freed yet. Then the page is
still clean and swap field is still !0.

PageSwapCache == the page has backend swap entry == the page may be clean. But, When the swap entry is removed, page will become dirty again.

Correct.

Quoted 1 line

As I said, following is incorrect.

No.

Quoted 3 lines

In almost case, swap entry is not
removed at swap-in. Please grep try_to_free_swap() callers and

Correct

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

But when it gets swapped in back to memory, it is removed from "Swap:"

I mean the "Swap:" field in smaps file here, not the swapcache.

Thanks
Nikanth

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#42 lore raw
In reply to Nikanth Karthikesan
Quoted 63 lines · Nikanth Karthikesan
Quoted 46 lines · On Wednesday 15 September 2010 10:16:36 KOSAKI Motohiro wrote:
Quoted 34 lines · On Wednesday 15 September 2010 05:54:31 KOSAKI Motohiro wrote:
Quoted 24 lines
Quoted 24 lines

/proc/$pid/smaps broken: After swapout/swapin private dirty mappings become clean.

When a page with private file mapping becomes dirty, the vma will be in both i_mmap tree and anon_vma list. The /proc/$pid/smaps will account these pages as dirty and backed by the file.

But when those dirty pages gets swapped out, and when they are read back from swap, they would be marked as clean, as it should be, as they are part of swap cache now.

But the /proc/$pid/smaps would report the vma as a mapping of a file and it is clean. The pages are actually in same state i.e., dirty with respect to file still, but which was once reported as dirty is now being reported as clean to user-space.

This confuses tools like gdb which uses this information. Those tools think that those pages were never modified and it creates problem when they create dumps.

The file mapping of the vma also cannot be broken as pages never read earlier, will still have to come from the file. Just that those dirty pages have become clean anonymous pages.

Quoted 8 lines
Quoted 5 lines

During swaping in, restoring the exact state as dirty file-backed pages before swapout would be useless, as there in no real bug. Breaking the vma with only anonymous pages as seperate vmas unnecessary may not be a good thing as well. So let us just export the information that a file-backed vma has anonymous dirty pages.

Why can't gdb check Swap: field in smaps? I think Swap!=0 mean we need dump out.

Quoted 6 lines

Yes. When the page is swapped out it is accounted in "Swap:".

Quoted 1 line

Am I missing anything?

But when it gets swapped in back to memory, it is removed from "Swap:" and added to "Private_Clean:" instead of "Private_Dirty:".

Here is the code.
I think the page will become dirty, again.

--------------------------------------------------------------
int try_to_free_swap(struct page *page)

Quoted 15 lines
{
        VM_BUG_ON(!PageLocked(page));

        if (!PageSwapCache(page))
                return 0;
        if (PageWriteback(page))
                return 0;
        if (page_swapcount(page))
                return 0;

        delete_from_swap_cache(page);
        SetPageDirty(page);
        return 1;
}
Quoted 3 lines

I think this gets called only when the swap space gets freed. But when the page is just swapped out and swapped in, and the page is still part of SwapCache, it will be marked as clean, when the I/O read from swap completes.

And it will be still marked clean if I do a swapoff -a after it has been swapped in again. Thus /proc/smaps shows it as file-backed, private, clean and not swapped. Which is wrong.

Richard.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#43 lore raw
Quoted 65 lines · Nikanth Karthikesan
Quoted 64 lines · On Wednesday 15 September 2010 10:16:36 KOSAKI Motohiro wrote:
Quoted 61 lines
Quoted 34 lines · On Wednesday 15 September 2010 05:54:31 KOSAKI Motohiro wrote:
Quoted 24 lines
Quoted 24 lines

/proc/$pid/smaps broken: After swapout/swapin private dirty mappings become clean.

When a page with private file mapping becomes dirty, the vma will be in both i_mmap tree and anon_vma list. The /proc/$pid/smaps will account these pages as dirty and backed by the file.

But when those dirty pages gets swapped out, and when they are read back from swap, they would be marked as clean, as it should be, as they are part of swap cache now.

But the /proc/$pid/smaps would report the vma as a mapping of a file and it is clean. The pages are actually in same state i.e., dirty with respect to file still, but which was once reported as dirty is now being reported as clean to user-space.

This confuses tools like gdb which uses this information. Those tools think that those pages were never modified and it creates problem when they create dumps.

The file mapping of the vma also cannot be broken as pages never read earlier, will still have to come from the file. Just that those dirty pages have become clean anonymous pages.

Quoted 8 lines
Quoted 5 lines

During swaping in, restoring the exact state as dirty file-backed pages before swapout would be useless, as there in no real bug. Breaking the vma with only anonymous pages as seperate vmas unnecessary may not be a good thing as well. So let us just export the information that a file-backed vma has anonymous dirty pages.

Why can't gdb check Swap: field in smaps? I think Swap!=0 mean we need dump out.

Quoted 6 lines

Yes. When the page is swapped out it is accounted in "Swap:".

Quoted 1 line

Am I missing anything?

But when it gets swapped in back to memory, it is removed from "Swap:" and added to "Private_Clean:" instead of "Private_Dirty:".

Here is the code.
I think the page will become dirty, again.

--------------------------------------------------------------
int try_to_free_swap(struct page *page)

{
        VM_BUG_ON(!PageLocked(page));

        if (!PageSwapCache(page))
                return 0;
        if (PageWriteback(page))
                return 0;
        if (page_swapcount(page))
                return 0;

        delete_from_swap_cache(page);
        SetPageDirty(page);
        return 1;
}
Quoted 7 lines
Quoted 3 lines

I think this gets called only when the swap space gets freed. But when the page is just swapped out and swapped in, and the page is still part of SwapCache, it will be marked as clean, when the I/O read from swap completes.

And it will be still marked clean if I do a swapoff -a after it has been swapped in again. Thus /proc/smaps shows it as file-backed, private, clean and not swapped. Which is wrong.

Ahh, my fault.

As Hugh explained, current smaps's Private_Dirty is buggy. If it's not bug, at minimum it's not straight implement. the VM has two dirty flags
1) pte dirty 2) page dirty, but smaps only show (1). then, gdb was confused.

Side note: SetPageDirty() turn on (2).

As I said, the VM doesn't have for file and for anon dirty. but it has another different dirty flags.

And, Dirty is not suitable gdb at all (this also was pointed out by hugh). Because Dirty mean "The page need writeback", but swapcache doesn't need. actual data is in swap already.

So, I vote Hugh's Anon field idea.

Thanks.