Skip to contentSkip to conversation

vmscan: protect exectuable page from inactive list scan

PATCH In review Shaohua Li 4 participants 11 messages Sep 29, 2010 – Sep 30, 2010

Subsystems (3)
lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH 1/1 vmscan: protect exectuable page from inactive list scan

With commit 645747462435, pte referenced file page isn't activated in inactive list scan. For VM_EXEC page, if it can't get a chance to active list, the executable page protect loses its effect. We protect such page in inactive scan here, now such page will be guaranteed cached in a full scan of active and inactive list, which restores previous behavior.

mm/vmscan.c +9 -2
index c5dfabf..b973048 100644
@@ -608,8 +608,15 @@ static enum page_references page_check_references(struct page *page,
 		 * quickly recovered.
 		 */
 		SetPageReferenced(page);
-
-		if (referenced_page)
+		/*
+		 * Identify pte referenced and file-backed pages and give them
+		 * one trip around the active list. So that executable code get
+		 * better chances to stay in memory under moderate memory
+		 * pressure. JVM can create lots of anon VM_EXEC pages, so we
+		 * ignore them here.
+		 */
+		if (referenced_page || ((vm_flags & VM_EXEC) &&
+		    page_is_file_cache(page)))
 			return PAGEREF_ACTIVATE;
 
 		return PAGEREF_KEEP;

--
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>

maintainer
#1 lore raw
Quoted 5 lines · Shaohua Li

With commit 645747462435, pte referenced file page isn't activated in inactive list scan. For VM_EXEC page, if it can't get a chance to active list, the executable page protect loses its effect. We protect such page in inactive scan here, now such page will be guaranteed cached in a full scan of active and inactive list, which restores previous behavior.

This change was in the back of my head since the used-once detection was merged but there were never any regressions reported that would indicate a requirement for it.

Does this patch fix a problem you observed?

Quoted 4 lines
mm/vmscan.c +0 -0
@@ -608,8 +608,15 @@ static enum page_references page_check_references(struct page *page,
 		 * quickly recovered.

mm/vmscan.c static enum page_references page_check_references(struct page *page, · line 616

Quoted 10 lines
mm/vmscan.c +6 -2
 		 */
 		SetPageReferenced(page);
-
-		if (referenced_page)
+		/*
+		 * Identify pte referenced and file-backed pages and give them
+		 * one trip around the active list. So that executable code get
+		 * better chances to stay in memory under moderate memory
+		 * pressure. JVM can create lots of anon VM_EXEC pages, so we
+		 * ignore them here.

PTE-referenced PageAnon() pages are activated unconditionally a few lines further up, so the page_is_file_cache() check filters only shmem pages. I doubt this was your intention...?

mm/vmscan.c static enum page_references page_check_references(struct page *page, · line 622

Quoted 6 lines
mm/vmscan.c +3 -0
+		 */
+		if (referenced_page || ((vm_flags & VM_EXEC) &&
+		    page_is_file_cache(page)))
 			return PAGEREF_ACTIVATE;
 
 		return PAGEREF_KEEP;

--
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>

author
#2 lore raw
Quoted 10 lines · Johannes Weiner
Quoted 5 lines · Shaohua Li

With commit 645747462435, pte referenced file page isn't activated in inactive list scan. For VM_EXEC page, if it can't get a chance to active list, the executable page protect loses its effect. We protect such page in inactive scan here, now such page will be guaranteed cached in a full scan of active and inactive list, which restores previous behavior.

This change was in the back of my head since the used-once detection was merged but there were never any regressions reported that would indicate a requirement for it.

The executable page protect is to improve responsibility. I would expect it's hard for user to report such regression.

Quoted 1 line

Does this patch fix a problem you observed?

No, I haven't done test where Fengguang does in commit 8cab4754d24a0f.

Quoted 10 lines
Quoted 10 lines
mm/vmscan.c +2 -2
@@ -608,8 +608,15 @@ static enum page_references page_check_references(struct page *page,
 		 * quickly recovered.
 		 */
 		SetPageReferenced(page);
-
-		if (referenced_page)
+		/*
+		 * Identify pte referenced and file-backed pages and give them
Quoted 8 lines

mm/vmscan.c static enum page_references page_check_references(struct page *page, · line 616

Quoted 4 lines
mm/vmscan.c +4 -0
+		 * one trip around the active list. So that executable code get
+		 * better chances to stay in memory under moderate memory
+		 * pressure. JVM can create lots of anon VM_EXEC pages, so we
+		 * ignore them here.

PTE-referenced PageAnon() pages are activated unconditionally a few lines further up, so the page_is_file_cache() check filters only shmem pages. I doubt this was your intention...?

This is intented. the executable page protect is just to protect executable file pages. please see 8cab4754d24a0f.

--
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>

#3 lore raw
Quoted 8 lines · Johannes Weiner
Quoted 7 lines · Shaohua Li
Quoted 5 lines

With commit 645747462435, pte referenced file page isn't activated in inactive list scan. For VM_EXEC page, if it can't get a chance to active list, the executable page protect loses its effect. We protect such page in inactive scan here, now such page will be guaranteed cached in a full scan of active and inactive list, which restores previous behavior.

Quoted 5 lines
Quoted 3 lines

This change was in the back of my head since the used-once detection was merged but there were never any regressions reported that would indicate a requirement for it.

The executable page protect is to improve responsibility. I would expect it's hard for user to report such regression.

Seems strange. 8cab4754d24a0f was introduced for fixing real world problem. So, I wonder why current people can't feel the same lag if it is.

Quoted 2 lines
Quoted 1 line

Does this patch fix a problem you observed?

No, I haven't done test where Fengguang does in commit 8cab4754d24a0f.

But, I am usually not against a number. If you will finished to test them I'm happy :)

Quoted 19 lines
Quoted 11 lines
Quoted 11 lines
mm/vmscan.c +2 -2
@@ -608,8 +608,15 @@ static enum page_references page_check_references(struct page *page,
 		 * quickly recovered.
 		 */
 		SetPageReferenced(page);
-
-		if (referenced_page)
+		/*
+		 * Identify pte referenced and file-backed pages and give them
Quoted 8 lines

mm/vmscan.c static enum page_references page_check_references(struct page *page, · line 616

Quoted 4 lines
mm/vmscan.c +4 -0
+		 * one trip around the active list. So that executable code get
+		 * better chances to stay in memory under moderate memory
+		 * pressure. JVM can create lots of anon VM_EXEC pages, so we
+		 * ignore them here.

PTE-referenced PageAnon() pages are activated unconditionally a few lines further up, so the page_is_file_cache() check filters only shmem pages. I doubt this was your intention...?

Quoted 2 lines

This is intented. the executable page protect is just to protect executable file pages. please see 8cab4754d24a0f.

8cab4754d24a0f was using !PageAnon() but your one are using page_is_file_cache. 8cab4754d24a0f doesn't tell us the reason of the change, no?

--
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>

#4 lore raw
Quoted 14 lines · KOSAKI Motohiro
Quoted 8 lines · Johannes Weiner
Quoted 7 lines · Shaohua Li
Quoted 5 lines

With commit 645747462435, pte referenced file page isn't activated in inactive list scan. For VM_EXEC page, if it can't get a chance to active list, the executable page protect loses its effect. We protect such page in inactive scan here, now such page will be guaranteed cached in a full scan of active and inactive list, which restores previous behavior.

Quoted 5 lines
Quoted 3 lines

This change was in the back of my head since the used-once detection was merged but there were never any regressions reported that would indicate a requirement for it.

The executable page protect is to improve responsibility. I would expect it's hard for user to report such regression.

Quoted 8 lines

Seems strange. 8cab4754d24a0f was introduced for fixing real world problem. So, I wonder why current people can't feel the same lag if it is.

Quoted 2 lines
Quoted 1 line

Does this patch fix a problem you observed?

No, I haven't done test where Fengguang does in commit 8cab4754d24a0f.

But, I am usually not against a number. If you will finished to test them I'm happy :)

Yeah, it needs good numbers for adding such special case code. I attached the scripts used for 8cab4754d24a0f, hope this helps.

Note that the test-mmap-exec-prot.sh used /proc/sys/fs/suid_dumpable as an indicator whether the extra logic is enabled. This is a convenient trick I sometimes play with new code:

+ extern int suid_dumpable;
+ if (suid_dumpable)

                        if ((vm_flags & VM_EXEC) && !PageAnon(page)) {
                                list_add(&page->lru, &l_active);
                                continue;
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 8 lines
mm/vmscan.c +0 -1
@@ -608,8 +608,15 @@ static enum page_references page_check_references(struct page *page,
 		 * quickly recovered.
 		 */
 		SetPageReferenced(page);
-

mm/vmscan.c static enum page_references page_check_references(struct page *page, · line 619

Quoted 10 lines
mm/vmscan.c +8 -1
-		if (referenced_page)
+		/*
+		 * Identify pte referenced and file-backed pages and give them
+		 * one trip around the active list. So that executable code get
+		 * better chances to stay in memory under moderate memory
+		 * pressure. JVM can create lots of anon VM_EXEC pages, so we
+		 * ignore them here.
+               if (referenced_page || ((vm_flags & VM_EXEC) &&
+                   page_is_file_cache(page)))
                        return PAGEREF_ACTIVATE;

PTE-referenced PageAnon() pages are activated unconditionally a few lines further up, so the page_is_file_cache() check filters only shmem pages. I doubt this was your intention...?

Quoted 5 lines
Quoted 2 lines

This is intented. the executable page protect is just to protect executable file pages. please see 8cab4754d24a0f.

8cab4754d24a0f was using !PageAnon() but your one are using page_is_file_cache. 8cab4754d24a0f doesn't tell us the reason of the change, no?

What if the executable file happen to be on tmpfs? The !PageAnon() test also covers that case. The page_is_file_cache() test here seems unnecessary. And it looks better to move the VM_EXEC test above the SetPageReferenced() line to avoid possible side effects.

Thanks,
Fengguang

#5 lore raw
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

PTE-referenced PageAnon() pages are activated unconditionally a few lines further up, so the page_is_file_cache() check filters only shmem pages. I doubt this was your intention...?

This is intented. the executable page protect is just to protect executable file pages. please see 8cab4754d24a0f.

Quoted 7 lines
Quoted 2 lines

8cab4754d24a0f was using !PageAnon() but your one are using page_is_file_cache. 8cab4754d24a0f doesn't tell us the reason of the change, no?

What if the executable file happen to be on tmpfs? The !PageAnon() test also covers that case. The page_is_file_cache() test here seems unnecessary. And it looks better to move the VM_EXEC test above the SetPageReferenced() line to avoid possible side effects.

Both agree :)

--
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>

author
#6 lore raw
In reply to Wu Fengguang
Quoted 31 lines · Fengguang
Quoted 14 lines · KOSAKI Motohiro
Quoted 8 lines · Johannes Weiner
Quoted 7 lines · Shaohua Li
Quoted 5 lines

With commit 645747462435, pte referenced file page isn't activated in inactive list scan. For VM_EXEC page, if it can't get a chance to active list, the executable page protect loses its effect. We protect such page in inactive scan here, now such page will be guaranteed cached in a full scan of active and inactive list, which restores previous behavior.

Quoted 5 lines
Quoted 3 lines

This change was in the back of my head since the used-once detection was merged but there were never any regressions reported that would indicate a requirement for it.

The executable page protect is to improve responsibility. I would expect it's hard for user to report such regression.

Quoted 8 lines

Seems strange. 8cab4754d24a0f was introduced for fixing real world problem. So, I wonder why current people can't feel the same lag if it is.

Quoted 2 lines
Quoted 1 line

Does this patch fix a problem you observed?

No, I haven't done test where Fengguang does in commit 8cab4754d24a0f.

But, I am usually not against a number. If you will finished to test them I'm happy :)

Yeah, it needs good numbers for adding such special case code. I attached the scripts used for 8cab4754d24a0f, hope this helps.

Note that the test-mmap-exec-prot.sh used /proc/sys/fs/suid_dumpable as an indicator whether the extra logic is enabled. This is a convenient trick I sometimes play with new code:

Review

Quoted 5 lines
(quoted diff) +2 -0
+                       extern int suid_dumpable;
+                       if (suid_dumpable)
                        if ((vm_flags & VM_EXEC) && !PageAnon(page)) {
                                list_add(&page->lru, &l_active);
                                continue;

ok, I'll test them, but might a little later, after a 7-day holiday.

Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 15 lines
Quoted 15 lines
mm/vmscan.c +6 -2
@@ -608,8 +608,15 @@ static enum page_references page_check_references(struct page *page,
 		 * quickly recovered.
 		 */
 		SetPageReferenced(page);
-
-		if (referenced_page)
+		/*
+		 * Identify pte referenced and file-backed pages and give them
+		 * one trip around the active list. So that executable code get
+		 * better chances to stay in memory under moderate memory
+		 * pressure. JVM can create lots of anon VM_EXEC pages, so we
+		 * ignore them here.
Quoted 8 lines

mm/vmscan.c static enum page_references page_check_references(struct page *page, · line 620

Quoted 3 lines
mm/vmscan.c +2 -0
+               if (referenced_page || ((vm_flags & VM_EXEC) &&
+                   page_is_file_cache(page)))
                        return PAGEREF_ACTIVATE;

PTE-referenced PageAnon() pages are activated unconditionally a few lines further up, so the page_is_file_cache() check filters only shmem pages. I doubt this was your intention...?

This is intented. the executable page protect is just to protect executable file pages. please see 8cab4754d24a0f.

Quoted 7 lines
Quoted 2 lines

8cab4754d24a0f was using !PageAnon() but your one are using page_is_file_cache. 8cab4754d24a0f doesn't tell us the reason of the change, no?

What if the executable file happen to be on tmpfs? The !PageAnon() test also covers that case. The page_is_file_cache() test here seems unnecessary. And it looks better to move the VM_EXEC test above the SetPageReferenced() line to avoid possible side effects.

oops, I should mention this commit 41e20983fe553 here. That commit changes it to page_is_file_cache()

--
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>

#7 lore raw
Quoted 32 lines · Shaohua
Quoted 31 lines · Fengguang
Quoted 14 lines · KOSAKI Motohiro
Quoted 8 lines · Johannes Weiner
Quoted 7 lines · Shaohua Li
Quoted 5 lines

With commit 645747462435, pte referenced file page isn't activated in inactive list scan. For VM_EXEC page, if it can't get a chance to active list, the executable page protect loses its effect. We protect such page in inactive scan here, now such page will be guaranteed cached in a full scan of active and inactive list, which restores previous behavior.

Quoted 5 lines
Quoted 3 lines

This change was in the back of my head since the used-once detection was merged but there were never any regressions reported that would indicate a requirement for it.

The executable page protect is to improve responsibility. I would expect it's hard for user to report such regression.

Quoted 8 lines

Seems strange. 8cab4754d24a0f was introduced for fixing real world problem. So, I wonder why current people can't feel the same lag if it is.

Quoted 2 lines
Quoted 1 line

Does this patch fix a problem you observed?

No, I haven't done test where Fengguang does in commit 8cab4754d24a0f.

But, I am usually not against a number. If you will finished to test them I'm happy :)

Yeah, it needs good numbers for adding such special case code. I attached the scripts used for 8cab4754d24a0f, hope this helps.

Note that the test-mmap-exec-prot.sh used /proc/sys/fs/suid_dumpable as an indicator whether the extra logic is enabled. This is a convenient trick I sometimes play with new code:

Quoted 6 lines

Review

Quoted 5 lines
(quoted diff) +2 -0
+                       extern int suid_dumpable;
+                       if (suid_dumpable)
                        if ((vm_flags & VM_EXEC) && !PageAnon(page)) {
                                list_add(&page->lru, &l_active);
                                continue;

ok, I'll test them, but might a little later, after a 7-day holiday.

Have a good time :)

Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
Quoted 23 lines
Quoted 15 lines
Quoted 15 lines
mm/vmscan.c +6 -2
@@ -608,8 +608,15 @@ static enum page_references page_check_references(struct page *page,
 		 * quickly recovered.
 		 */
 		SetPageReferenced(page);
-
-		if (referenced_page)
+		/*
+		 * Identify pte referenced and file-backed pages and give them
+		 * one trip around the active list. So that executable code get
+		 * better chances to stay in memory under moderate memory
+		 * pressure. JVM can create lots of anon VM_EXEC pages, so we
+		 * ignore them here.
Quoted 8 lines

mm/vmscan.c static enum page_references page_check_references(struct page *page, · line 620

Quoted 3 lines
mm/vmscan.c +2 -0
+               if (referenced_page || ((vm_flags & VM_EXEC) &&
+                   page_is_file_cache(page)))
                        return PAGEREF_ACTIVATE;

PTE-referenced PageAnon() pages are activated unconditionally a few lines further up, so the page_is_file_cache() check filters only shmem pages. I doubt this was your intention...?

Quoted 2 lines

This is intented. the executable page protect is just to protect executable file pages. please see 8cab4754d24a0f.

8cab4754d24a0f was using !PageAnon() but your one are using page_is_file_cache. 8cab4754d24a0f doesn't tell us the reason of the change, no?

Quoted 6 lines
Quoted 4 lines

What if the executable file happen to be on tmpfs? The !PageAnon() test also covers that case. The page_is_file_cache() test here seems unnecessary. And it looks better to move the VM_EXEC test above the SetPageReferenced() line to avoid possible side effects.

oops, I should mention this commit 41e20983fe553 here. That commit changes it to page_is_file_cache()

Oops, forgot about that "real but beyond my imagination" corner case..

Thanks,
Fengguang

--
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>

#8 lore raw
In reply to Shaohua Li
Quoted 68 lines · Fengguang
Quoted 31 lines · KOSAKI Motohiro
Quoted 14 lines
Quoted 8 lines · Johannes Weiner
Quoted 7 lines · Shaohua Li
Quoted 5 lines

With commit 645747462435, pte referenced file page isn't activated in inactive list scan. For VM_EXEC page, if it can't get a chance to active list, the executable page protect loses its effect. We protect such page in inactive scan here, now such page will be guaranteed cached in a full scan of active and inactive list, which restores previous behavior.

Quoted 5 lines
Quoted 3 lines

This change was in the back of my head since the used-once detection was merged but there were never any regressions reported that would indicate a requirement for it.

The executable page protect is to improve responsibility. I would expect it's hard for user to report such regression.

Quoted 8 lines

Seems strange. 8cab4754d24a0f was introduced for fixing real world problem. So, I wonder why current people can't feel the same lag if it is.

Quoted 2 lines
Quoted 1 line

Does this patch fix a problem you observed?

No, I haven't done test where Fengguang does in commit 8cab4754d24a0f.

But, I am usually not against a number. If you will finished to test them I'm happy :)

Yeah, it needs good numbers for adding such special case code. I attached the scripts used for 8cab4754d24a0f, hope this helps.

Note that the test-mmap-exec-prot.sh used /proc/sys/fs/suid_dumpable as an indicator whether the extra logic is enabled. This is a convenient trick I sometimes play with new code:

Review

Quoted 5 lines
(quoted diff) +2 -0
+                       extern int suid_dumpable;
+                       if (suid_dumpable)
                        if ((vm_flags & VM_EXEC) && !PageAnon(page)) {
                                list_add(&page->lru, &l_active);
                                continue;

ok, I'll test them, but might a little later, after a 7-day holiday.

Quoted 29 lines
Quoted 28 lines
Quoted 23 lines
Quoted 15 lines
Quoted 15 lines
mm/vmscan.c +6 -2
@@ -608,8 +608,15 @@ static enum page_references page_check_references(struct page *page,
 		 * quickly recovered.
 		 */
 		SetPageReferenced(page);
-
-		if (referenced_page)
+		/*
+		 * Identify pte referenced and file-backed pages and give them
+		 * one trip around the active list. So that executable code get
+		 * better chances to stay in memory under moderate memory
+		 * pressure. JVM can create lots of anon VM_EXEC pages, so we
+		 * ignore them here.
Quoted 8 lines

mm/vmscan.c static enum page_references page_check_references(struct page *page, · line 620

Quoted 3 lines
mm/vmscan.c +2 -0
+               if (referenced_page || ((vm_flags & VM_EXEC) &&
+                   page_is_file_cache(page)))
                        return PAGEREF_ACTIVATE;

PTE-referenced PageAnon() pages are activated unconditionally a few lines further up, so the page_is_file_cache() check filters only shmem pages. I doubt this was your intention...?

Quoted 2 lines

This is intented. the executable page protect is just to protect executable file pages. please see 8cab4754d24a0f.

8cab4754d24a0f was using !PageAnon() but your one are using page_is_file_cache. 8cab4754d24a0f doesn't tell us the reason of the change, no?

Quoted 6 lines
Quoted 4 lines

What if the executable file happen to be on tmpfs? The !PageAnon() test also covers that case. The page_is_file_cache() test here seems unnecessary. And it looks better to move the VM_EXEC test above the SetPageReferenced() line to avoid possible side effects.

oops, I should mention this commit 41e20983fe553 here. That commit changes it to page_is_file_cache()

Hmmm...

I think 41e20983fe553 is red herring fix. because 1) Even if all pages are VM_EXEC, we don't have to make OOM anyway. tmpfs or not is not good decision source. (note: On embedded, regular file-system can be smaller than tmpfs)
2) We've already fixed tmpfs used once page issue. (e9d6c15738 and vmscantmpfs-treat-used-once-pages-on-tmpfs-as-used-once.patch in -mm)

Is the issue still exist?

--
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>

author
#9 lore raw
Quoted 75 lines · KOSAKI Motohiro
Quoted 68 lines · Fengguang
Quoted 31 lines · KOSAKI Motohiro
Quoted 14 lines
Quoted 8 lines · Johannes Weiner
Quoted 7 lines · Shaohua Li
Quoted 5 lines

With commit 645747462435, pte referenced file page isn't activated in inactive list scan. For VM_EXEC page, if it can't get a chance to active list, the executable page protect loses its effect. We protect such page in inactive scan here, now such page will be guaranteed cached in a full scan of active and inactive list, which restores previous behavior.

Quoted 5 lines
Quoted 3 lines

This change was in the back of my head since the used-once detection was merged but there were never any regressions reported that would indicate a requirement for it.

The executable page protect is to improve responsibility. I would expect it's hard for user to report such regression.

Quoted 8 lines

Seems strange. 8cab4754d24a0f was introduced for fixing real world problem. So, I wonder why current people can't feel the same lag if it is.

Quoted 2 lines
Quoted 1 line

Does this patch fix a problem you observed?

No, I haven't done test where Fengguang does in commit 8cab4754d24a0f.

But, I am usually not against a number. If you will finished to test them I'm happy :)

Yeah, it needs good numbers for adding such special case code. I attached the scripts used for 8cab4754d24a0f, hope this helps.

Note that the test-mmap-exec-prot.sh used /proc/sys/fs/suid_dumpable as an indicator whether the extra logic is enabled. This is a convenient trick I sometimes play with new code:

Review

Quoted 5 lines
(quoted diff) +2 -0
+                       extern int suid_dumpable;
+                       if (suid_dumpable)
                        if ((vm_flags & VM_EXEC) && !PageAnon(page)) {
                                list_add(&page->lru, &l_active);
                                continue;

ok, I'll test them, but might a little later, after a 7-day holiday.

Quoted 29 lines
Quoted 28 lines
Quoted 23 lines
Quoted 15 lines
Quoted 15 lines
mm/vmscan.c +6 -2
@@ -608,8 +608,15 @@ static enum page_references page_check_references(struct page *page,
 		 * quickly recovered.
 		 */
 		SetPageReferenced(page);
-
-		if (referenced_page)
+		/*
+		 * Identify pte referenced and file-backed pages and give them
+		 * one trip around the active list. So that executable code get
+		 * better chances to stay in memory under moderate memory
+		 * pressure. JVM can create lots of anon VM_EXEC pages, so we
+		 * ignore them here.
Quoted 8 lines

mm/vmscan.c static enum page_references page_check_references(struct page *page, · line 619

Quoted 3 lines
mm/vmscan.c +2 -0
+               if (referenced_page || ((vm_flags & VM_EXEC) &&
+                   page_is_file_cache(page)))
                        return PAGEREF_ACTIVATE;

PTE-referenced PageAnon() pages are activated unconditionally a few lines further up, so the page_is_file_cache() check filters only shmem pages. I doubt this was your intention...?

Quoted 2 lines

This is intented. the executable page protect is just to protect executable file pages. please see 8cab4754d24a0f.

8cab4754d24a0f was using !PageAnon() but your one are using page_is_file_cache. 8cab4754d24a0f doesn't tell us the reason of the change, no?

Quoted 6 lines
Quoted 4 lines

What if the executable file happen to be on tmpfs? The !PageAnon() test also covers that case. The page_is_file_cache() test here seems unnecessary. And it looks better to move the VM_EXEC test above the SetPageReferenced() line to avoid possible side effects.

oops, I should mention this commit 41e20983fe553 here. That commit changes it to page_is_file_cache()

Quoted 7 lines

Hmmm...

I think 41e20983fe553 is red herring fix. because 1) Even if all pages are VM_EXEC, we don't have to make OOM anyway. tmpfs or not is not good decision source. (note: On embedded, regular file-system can be smaller than tmpfs)
2) We've already fixed tmpfs used once page issue. (e9d6c15738 and vmscantmpfs-treat-used-once-pages-on-tmpfs-as-used-once.patch in -mm)

IIRC, e9d6c15738 solved the used once issue at the time when the page is added to lru list at the first time. while this issue is moving a page from inactive list to active list or give the page another around to active list. if we have no the filter, moving vast executable tmpfs pages to activate list can still increasing anon list rotate rate and cause more file pages scan and oom killer.

--
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
Quoted 83 lines · KOSAKI Motohiro
Quoted 75 lines
Quoted 68 lines · Fengguang
Quoted 31 lines · KOSAKI Motohiro
Quoted 14 lines
Quoted 8 lines · Johannes Weiner
Quoted 7 lines · Shaohua Li
Quoted 5 lines

With commit 645747462435, pte referenced file page isn't activated in inactive list scan. For VM_EXEC page, if it can't get a chance to active list, the executable page protect loses its effect. We protect such page in inactive scan here, now such page will be guaranteed cached in a full scan of active and inactive list, which restores previous behavior.

Quoted 5 lines
Quoted 3 lines

This change was in the back of my head since the used-once detection was merged but there were never any regressions reported that would indicate a requirement for it.

The executable page protect is to improve responsibility. I would expect it's hard for user to report such regression.

Quoted 8 lines

Seems strange. 8cab4754d24a0f was introduced for fixing real world problem. So, I wonder why current people can't feel the same lag if it is.

Quoted 2 lines
Quoted 1 line

Does this patch fix a problem you observed?

No, I haven't done test where Fengguang does in commit 8cab4754d24a0f.

But, I am usually not against a number. If you will finished to test them I'm happy :)

Yeah, it needs good numbers for adding such special case code. I attached the scripts used for 8cab4754d24a0f, hope this helps.

Note that the test-mmap-exec-prot.sh used /proc/sys/fs/suid_dumpable as an indicator whether the extra logic is enabled. This is a convenient trick I sometimes play with new code:

Review

Quoted 5 lines
(quoted diff) +2 -0
+                       extern int suid_dumpable;
+                       if (suid_dumpable)
                        if ((vm_flags & VM_EXEC) && !PageAnon(page)) {
                                list_add(&page->lru, &l_active);
                                continue;

ok, I'll test them, but might a little later, after a 7-day holiday.

Quoted 29 lines
Quoted 28 lines
Quoted 23 lines
Quoted 15 lines
Quoted 15 lines
mm/vmscan.c +6 -2
@@ -608,8 +608,15 @@ static enum page_references page_check_references(struct page *page,
 		 * quickly recovered.
 		 */
 		SetPageReferenced(page);
-
-		if (referenced_page)
+		/*
+		 * Identify pte referenced and file-backed pages and give them
+		 * one trip around the active list. So that executable code get
+		 * better chances to stay in memory under moderate memory
+		 * pressure. JVM can create lots of anon VM_EXEC pages, so we
+		 * ignore them here.
Quoted 8 lines

mm/vmscan.c static enum page_references page_check_references(struct page *page, · line 619

Quoted 3 lines
mm/vmscan.c +2 -0
+               if (referenced_page || ((vm_flags & VM_EXEC) &&
+                   page_is_file_cache(page)))
                        return PAGEREF_ACTIVATE;

PTE-referenced PageAnon() pages are activated unconditionally a few lines further up, so the page_is_file_cache() check filters only shmem pages. I doubt this was your intention...?

Quoted 2 lines

This is intented. the executable page protect is just to protect executable file pages. please see 8cab4754d24a0f.

8cab4754d24a0f was using !PageAnon() but your one are using page_is_file_cache. 8cab4754d24a0f doesn't tell us the reason of the change, no?

Quoted 6 lines
Quoted 4 lines

What if the executable file happen to be on tmpfs? The !PageAnon() test also covers that case. The page_is_file_cache() test here seems unnecessary. And it looks better to move the VM_EXEC test above the SetPageReferenced() line to avoid possible side effects.

oops, I should mention this commit 41e20983fe553 here. That commit changes it to page_is_file_cache()

Quoted 7 lines

Hmmm...

I think 41e20983fe553 is red herring fix. because 1) Even if all pages are VM_EXEC, we don't have to make OOM anyway. tmpfs or not is not good decision source. (note: On embedded, regular file-system can be smaller than tmpfs)
2) We've already fixed tmpfs used once page issue. (e9d6c15738 and vmscantmpfs-treat-used-once-pages-on-tmpfs-as-used-once.patch in -mm)

Quoted 6 lines

IIRC, e9d6c15738 solved the used once issue at the time when the page is added to lru list at the first time. while this issue is moving a page from inactive list to active list or give the page another around to active list. if we have no the filter, moving vast executable tmpfs pages to activate list can still increasing anon list rotate rate and cause more file pages scan and oom killer.

before invoking OOM, we scan pages about two times between priority-12 and priority-0. then, one time activation is harmless. but two times activation and/or another rotate factor can be made trouble.

before vmscantmpfs-treat-used-once-pages-on-tmpfs-as-used-once.patch, tmpfs pages are always rotated at least once. and VM_EXEC add +1 time. Thus, two times rotate occur and bring to trouble. I think.

If this is not enough solution, of cource we need additional fix. but tmpfs is not special. It's fs independent issue.

However I agree page_is_file_cache() check is harmless because typical guys don't put executable into tmpfs. So, If you can't agree me, I can accept your one.

Thanks.

--
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>