Skip to contentSkip to conversation

deactive invalidated pages

RFC In review Minchan Kim 8 participants 54 messages Nov 21, 2010 – Nov 24, 2010

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

RFC 1/2 deactive invalidated pages

Recently, there are reported problem about thrashing.
(http://marc.info/?l=rsync&m=128885034930933&w=2)
It happens by backup workloads(ex, nightly rsync). That's because the workload makes just use-once pages and touches pages twice. It promotes the page into active list so that it results in working set page eviction.

Some app developer want to support POSIX_FADV_NOREUSE. But other OSes don't support it, either.
(http://marc.info/?l=linux-mm&m=128928979512086&w=2)

By Other approach, app developer uses POSIX_FADV_DONTNEED. But it has a problem. If kernel meets page is writing during invalidate_mapping_pages, it can't work.
It is very hard for application programmer to use it. Because they always have to sync data before calling fadivse(..POSIX_FADV_DONTNEED) to make sure the pages could be discardable. At last, they can't use deferred write of kernel so that they could see performance loss.
(http://insights.oetiker.ch/linux/fadvise.html)

In fact, invalidate is very big hint to reclaimer. It means we don't use the page any more. So let's move the writing page into inactive list's head.

If it is real working set, it could have a enough time to activate the page since we always try to keep many pages in inactive list.

I reuse lru_demote of Peter with some change.

Cc Rik van Riel <[email protected]>
Cc KOSAKI Motohiro <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Nick Piggin <[email protected]>

Ben, Remain thing is to modify rsync and use
fadvise(POSIX_FADV_DONTNEED). Could you test it?

---
 include/linux/swap.h |    1 +
 mm/swap.c            |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++
 mm/truncate.c        |   11 +++++---
 3 files changed, 69 insertions(+), 4 deletions(-)
include/linux/swap.h +1 -0
index eba53e7..a3c9248 100644
@@ -213,6 +213,7 @@ extern void mark_page_accessed(struct page *);
 extern void lru_add_drain(void);
 extern int lru_add_drain_all(void);
 extern void rotate_reclaimable_page(struct page *page);
+extern void lru_deactive_page(struct page *page);
 extern void swap_setup(void);
 
 extern void add_page_to_unevictable_list(struct page *page);
mm/swap.c +61 -0

81 lines not on this page · raw message

mm/truncate.c +7 -4
index cd94607..c73fb19 100644
@@ -332,7 +332,8 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
 {
 	struct pagevec pvec;
 	pgoff_t next = start;
-	unsigned long ret = 0;
+	unsigned long ret;
+	unsigned long count = 0;
 	int i;
 
 	pagevec_init(&pvec, 0);
@@ -359,8 +360,10 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
 			if (lock_failed)
 				continue;
 
-			ret += invalidate_inode_page(page);
-
+			ret = invalidate_inode_page(page);
+			if (!ret)
+				lru_deactive_page(page);
+			count += ret;
 			unlock_page(page);
 			if (next > end)
 				break;
@@ -369,7 +372,7 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
 		mem_cgroup_uncharge_end();
 		cond_resched();
 	}
-	return ret;
+	return count;
 }
 EXPORT_SYMBOL(invalidate_mapping_pages);
 
Signature · 8 lines
1.7.0.4

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

RFC 2/2 Prevent promotion of page in madvise_dontneed

Now zap_pte_range alwayas promotes pages which are pte_young && !VM_SequentialReadHint(vma). But in case of calling MADV_DONTNEED, it's unnecessary since the page wouldn't use any more.

If the page is sharred by other processes and it's real working set

Cc Rik van Riel <[email protected]>
Cc KOSAKI Motohiro <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Nick Piggin <[email protected]>
---
 include/linux/mm.h |    4 ++--
 mm/madvise.c       |    4 ++--
 mm/memory.c        |    9 ++++++---
 mm/mmap.c          |    4 ++--
 4 files changed, 12 insertions(+), 9 deletions(-)
include/linux/mm.h +2 -2
index 721f451..1555abe 100644
@@ -778,11 +778,11 @@ struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr,
 int zap_vma_ptes(struct vm_area_struct *vma, unsigned long address,
 		unsigned long size);
 unsigned long zap_page_range(struct vm_area_struct *vma, unsigned long address,
-		unsigned long size, struct zap_details *);
+		unsigned long size, struct zap_details *, int promote);
 unsigned long unmap_vmas(struct mmu_gather **tlb,
 		struct vm_area_struct *start_vma, unsigned long start_addr,
 		unsigned long end_addr, unsigned long *nr_accounted,
-		struct zap_details *);
+		struct zap_details *, int promote);
 
 /**
  * mm_walk - callbacks for walk_page_range
mm/madvise.c +2 -2
index 319528b..247e5fd 100644
@@ -171,9 +171,9 @@ static long madvise_dontneed(struct vm_area_struct * vma,
 			.nonlinear_vma = vma,
 			.last_index = ULONG_MAX,
 		};
-		zap_page_range(vma, start, end - start, &details);
+		zap_page_range(vma, start, end - start, &details, 0);
 	} else
-		zap_page_range(vma, start, end - start, NULL);
+		zap_page_range(vma, start, end - start, NULL, 0);
 	return 0;
 }
 
mm/memory.c +6 -3
index 02e48aa..276abdb 100644
@@ -1075,6 +1075,7 @@ static unsigned long unmap_page_range(struct mmu_gather *tlb,
  * @end_addr: virtual address at which to end unmapping
  * @nr_accounted: Place number of unmapped pages in vm-accountable vma's here
  * @details: details of nonlinear truncation or shared cache invalidation
+ * @promote: whether pages inclued vma would be promoted or not
  *
  * Returns the end address of the unmapping (restart addr if interrupted).
  *
@@ -1096,7 +1097,7 @@ static unsigned long unmap_page_range(struct mmu_gather *tlb,
 unsigned long unmap_vmas(struct mmu_gather **tlbp,
 		struct vm_area_struct *vma, unsigned long start_addr,
 		unsigned long end_addr, unsigned long *nr_accounted,
-		struct zap_details *details)
+		struct zap_details *details, int promote)
 {
 	long zap_work = ZAP_BLOCK_SIZE;
 	unsigned long tlb_start = 0;	/* For tlb_finish_mmu */
@@ -1184,9 +1185,10 @@ out:
  * @address: starting address of pages to zap
  * @size: number of bytes to zap
  * @details: details of nonlinear truncation or shared cache invalidation
+ * @promote: whether the page would be promoted or not
  */
 unsigned long zap_page_range(struct vm_area_struct *vma, unsigned long address,
-		unsigned long size, struct zap_details *details)
+		unsigned long size, struct zap_details *details, int promote)
 {
 	struct mm_struct *mm = vma->vm_mm;
 	struct mmu_gather *tlb;
@@ -1196,7 +1198,8 @@ unsigned long zap_page_range(struct vm_area_struct *vma, unsigned long address,
 	lru_add_drain();
 	tlb = tlb_gather_mmu(mm, 0);
 	update_hiwater_rss(mm);
-	end = unmap_vmas(&tlb, vma, address, end, &nr_accounted, details);
+	end = unmap_vmas(&tlb, vma, address, end,
+			&nr_accounted, details, promote);
 	if (tlb)
 		tlb_finish_mmu(tlb, address, end);
 	return end;
mm/mmap.c +2 -2
index b179abb..0d42c08 100644
@@ -1904,7 +1904,7 @@ static void unmap_region(struct mm_struct *mm,
 	lru_add_drain();
 	tlb = tlb_gather_mmu(mm, 0);
 	update_hiwater_rss(mm);
-	unmap_vmas(&tlb, vma, start, end, &nr_accounted, NULL);
+	unmap_vmas(&tlb, vma, start, end, &nr_accounted, NULL, 1);
 	vm_unacct_memory(nr_accounted);
 	free_pgtables(tlb, vma, prev? prev->vm_end: FIRST_USER_ADDRESS,
 				 next? next->vm_start: 0);
@@ -2278,7 +2278,7 @@ void exit_mmap(struct mm_struct *mm)
 	tlb = tlb_gather_mmu(mm, 1);
 	/* update_hiwater_rss(mm) here? but nobody should be looking */
 	/* Use -1 here to ensure all VMAs in the mm are unmapped */
-	end = unmap_vmas(&tlb, vma, 0, -1, &nr_accounted, NULL);
+	end = unmap_vmas(&tlb, vma, 0, -1, &nr_accounted, NULL, 1);
 	vm_unacct_memory(nr_accounted);
 
 	free_pgtables(tlb, vma, FIRST_USER_ADDRESS, 0);
Signature · 1 line
1.7.0.4
#2 lore raw

Re: [RFC 2/2] Prevent promotion of page in madvise_dontneed

Quoted 1 line · Minchan Kim

If the page is sharred by other processes and it's real working set

Please ignore this last sentense. It's my mistake. I will fix it v2 after some review.

Signature · 9 lines
Kind regards,
Minchan Kim

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw

Re: [RFC 2/2] Prevent promotion of page in madvise_dontneed

In reply to Minchan Kim
Quoted 4 lines · Minchan Kim

Now zap_pte_range alwayas promotes pages which are pte_young && !VM_SequentialReadHint(vma). But in case of calling MADV_DONTNEED, it's unnecessary since the page wouldn't use any more.

Is this not against master? If it is, I think you might have forgotten to update the zap_page_range() reference on mm/memory.c:1226 (in zap_vma_ptes()). Should promote be true or false in this case? Cheers,

- Ben

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw

Re: [RFC 2/2] Prevent promotion of page in madvise_dontneed

Quoted 8 lines · Ben Gamari
Quoted 4 lines · Minchan Kim

Now zap_pte_range alwayas promotes pages which are pte_young && !VM_SequentialReadHint(vma). But in case of calling MADV_DONTNEED, it's unnecessary since the page wouldn't use any more.

Is this not against master? If it is, I think you might have forgotten to update the zap_page_range() reference on mm/memory.c:1226 (in zap_vma_ptes()). Should promote be true or false in this case? Cheers,

Thanks. I missed that. Whatever, It's okay. :) That's because it is used by only VM_PFNMAP.
It means the VMA doesn't have struct page descriptor of pages. So zap_pte_range never promote the page.

Anyway, by semantic, it should be "zero".
Will fix.
Thanks, Ben.

Quoted 3 lines

- Ben

Signature · 9 lines
Kind regards,
Minchan Kim

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#5 lore raw

Re: [RFC 2/2] Prevent promotion of page in madvise_dontneed

In reply to Minchan Kim
Quoted 5 lines · On Sun, 21 Nov 2010 23:30:24 +0900 Minchan Kim <[email protected]> wrote:

Now zap_pte_range alwayas promotes pages which are pte_young && !VM_SequentialReadHint(vma). But in case of calling MADV_DONTNEED, it's unnecessary since the page wouldn't use any more.

If the page is sharred by other processes and it's real working set

This patch doesn't actually do anything. It passes variable `promote' all the way down to unmap_vmas(), but unmap_vmas() doesn't use that new variable.

Have a comment fixlet:

mm/memory.c renamed from mm/memory.c~mm-prevent-promotion-of-page-in-madvise_dontneed-fix +1 -1
@@ -1075,7 +1075,7 @@ static unsigned long unmap_page_range(st
  * @end_addr: virtual address at which to end unmapping
  * @nr_accounted: Place number of unmapped pages in vm-accountable vma's here
  * @details: details of nonlinear truncation or shared cache invalidation
- * @promote: whether pages inclued vma would be promoted or not
+ * @promote: whether pages included in the vma should be promoted or not
  *
  * Returns the end address of the unmapping (restart addr if interrupted).
  *

_

Also, I'd suggest that we avoid introducing the term "promote". It isn't a term which is presently used in Linux MM. Probably "activate" has a better-known meaning.

And `activate' could be a bool if one is in the mood for that.

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw

Re: [RFC 2/2] Prevent promotion of page in madvise_dontneed

Quoted 7 lines · Andrew Morton
Quoted 4 lines · On Sun, 21 Nov 2010 23:30:24 +0900 Minchan Kim <[email protected]> wrote:

Now zap_pte_range alwayas promotes pages which are pte_young && !VM_SequentialReadHint(vma). But in case of calling MADV_DONTNEED, it's unnecessary since the page wouldn't use any more.

Quoted 5 lines
Quoted 1 line

If the page is sharred by other processes and it's real working set

This patch doesn't actually do anything.  It passes variable `promote' all the way down to unmap_vmas(), but unmap_vmas() doesn't use that new variable.

Oops. Sorry for that.
I will resend the patch with your fixlet and Ben's point. Thank you.

Quoted 21 lines

Have a comment fixlet:

mm/memory.c renamed from mm/memory.c~mm-prevent-promotion-of-page-in-madvise_dontneed-fix +1 -1
@@ -1075,7 +1075,7 @@ static unsigned long unmap_page_range(st
  * @end_addr: virtual address at which to end unmapping
  * @nr_accounted: Place number of unmapped pages in vm-accountable vma's here
  * @details: details of nonlinear truncation or shared cache invalidation
- * @promote: whether pages inclued vma would be promoted or not
+ * @promote: whether pages included in the vma should be promoted or not
  *
  * Returns the end address of the unmapping (restart addr if interrupted).
  *

_

Also, I'd suggest that we avoid introducing the term "promote".  It isn't a term which is presently used in Linux MM.  Probably "activate" has a better-known meaning.

And `activate' could be a bool if one is in the mood for that.

Signature · 2 lines
Kind regards,
Minchan Kim
#7 lore raw

Re: [RFC 2/2] Prevent promotion of page in madvise_dontneed

In reply to Andrew Morton
Quoted 28 lines · Andrew Morton
Quoted 5 lines · On Sun, 21 Nov 2010 23:30:24 +0900 Minchan Kim <[email protected]> wrote:

Now zap_pte_range alwayas promotes pages which are pte_young && !VM_SequentialReadHint(vma). But in case of calling MADV_DONTNEED, it's unnecessary since the page wouldn't use any more.

If the page is sharred by other processes and it's real working set

This patch doesn't actually do anything. It passes variable `promote' all the way down to unmap_vmas(), but unmap_vmas() doesn't use that new variable.

Have a comment fixlet:

mm/memory.c renamed from mm/memory.c~mm-prevent-promotion-of-page-in-madvise_dontneed-fix +1 -1
@@ -1075,7 +1075,7 @@ static unsigned long unmap_page_range(st
  * @end_addr: virtual address at which to end unmapping
  * @nr_accounted: Place number of unmapped pages in vm-accountable vma's here
  * @details: details of nonlinear truncation or shared cache invalidation
- * @promote: whether pages inclued vma would be promoted or not
+ * @promote: whether pages included in the vma should be promoted or not
  *
  * Returns the end address of the unmapping (restart addr if interrupted).
  *

_

Quoted 1 line

Also, I'd suggest that we avoid introducing the term "promote".

Promote also has special meaning for huge pages. Demoting or promoting a page refers to changing its size. The same applies to the other patch - s/demote/deactive/ s/promote/activate/ . Currently this is no confusion within the VM but when Andrea's THP patches are merged, it'll become an issue.

Signature · 10 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#8 lore raw

Re: [RFC 2/2] Prevent promotion of page in madvise_dontneed

Quoted 29 lines · Mel Gorman
Quoted 28 lines · Andrew Morton
Quoted 5 lines · On Sun, 21 Nov 2010 23:30:24 +0900 Minchan Kim <[email protected]> wrote:

Now zap_pte_range alwayas promotes pages which are pte_young && !VM_SequentialReadHint(vma). But in case of calling MADV_DONTNEED, it's unnecessary since the page wouldn't use any more.

If the page is sharred by other processes and it's real working set

This patch doesn't actually do anything.  It passes variable `promote' all the way down to unmap_vmas(), but unmap_vmas() doesn't use that new variable.

Have a comment fixlet:

mm/memory.c renamed from mm/memory.c~mm-prevent-promotion-of-page-in-madvise_dontneed-fix +1 -1
@@ -1075,7 +1075,7 @@ static unsigned long unmap_page_range(st
   * @end_addr: virtual address at which to end unmapping
   * @nr_accounted: Place number of unmapped pages in vm-accountable vma's here
   * @details: details of nonlinear truncation or shared cache invalidation
- * @promote: whether pages inclued vma would be promoted or not
+ * @promote: whether pages included in the vma should be promoted or not
   *
   * Returns the end address of the unmapping (restart addr if interrupted).
   *

_

Quoted 7 lines
Quoted 1 line

Also, I'd suggest that we avoid introducing the term "promote".

Promote also has special meaning for huge pages. Demoting or promoting a page refers to changing its size. The same applies to the other patch - s/demote/deactive/ s/promote/activate/ . Currently this is no confusion within the VM but when Andrea's THP patches are merged, it'll become an issue.

Thanks for the information.

Quoted 6 lines

--
Mel Gorman
Part-time Phd Student                          Linux Technology Center University of Limerick                         IBM Dublin Software Lab

Signature · 9 lines
Kind regards,
Minchan Kim

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#9 lore raw
In reply to Minchan Kim
Quoted 3 lines · Minchan Kim

Ben, Remain thing is to modify rsync and use
fadvise(POSIX_FADV_DONTNEED). Could you test it?

Thanks a ton for the patch. Looks good. Testing as we speak.

- Ben

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#10 lore raw
Quoted 6 lines · Minchan Kim
Quoted 3 lines

Ben, Remain thing is to modify rsync and use
fadvise(POSIX_FADV_DONTNEED). Could you test it?

Thanks a ton for the patch. Looks good. Testing as we speak.

If possible, can you please post your rsync patch and your testcase (or your rsync option + system memory size info + data size info)?

#11 lore raw
Quoted 7 lines · KOSAKI Motohiro
Quoted 6 lines · Minchan Kim
Quoted 3 lines

Ben, Remain thing is to modify rsync and use
fadvise(POSIX_FADV_DONTNEED). Could you test it?

Thanks a ton for the patch. Looks good. Testing as we speak.

For the record, this was a little premature. As I spoke the kernel was building but I still haven't had a chance to take any data. Any suggestions for how to determine the effect (or hopefully lack thereof) of rsync on the system's working set?

Quoted 3 lines

If possible, can you please post your rsync patch and your testcase (or your rsync option + system memory size info + data size info)?

Patch coming right up.

The original test case is a backup script for my home directory. rsync is invoked with,

rsync --archive --update --progress --delete --delete-excluded --exclude-from=~/.backup/exclude --log-file=~/.backup/rsync.log -e ssh /home/ben ben@myserver:/mnt/backup/current

My home directory is 120 GB with typical delta sizes of tens of megabytes between backups (although sometimes deltas can be gigabytes, after which the server has severe interactivity issues). The server is unfortunately quite memory constrained with only 1.5GB of memory (old inherited hardware). Given the size of my typical deltas, I'm worried that even simply walking the directory hierarchy might be enough to push out my working set.

Looking at the rsync access pattern with strace it seems that it does a very good job of avoid duplicate reads which is good news for these patches.

Cheers,

- Ben

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#12 lore raw
Quoted 33 lines · Ben Gamari
Quoted 7 lines · KOSAKI Motohiro
Quoted 6 lines · Minchan Kim
Quoted 3 lines

Ben, Remain thing is to modify rsync and use
fadvise(POSIX_FADV_DONTNEED). Could you test it?

Thanks a ton for the patch. Looks good. Testing as we speak.

For the record, this was a little premature. As I spoke the kernel was building but I still haven't had a chance to take any data. Any suggestions for how to determine the effect (or hopefully lack thereof) of rsync on the system's working set?

Quoted 3 lines

If possible, can you please post your rsync patch and your testcase (or your rsync option + system memory size info + data size info)?

Patch coming right up.

The original test case is a backup script for my home directory. rsync is invoked with,

rsync --archive --update --progress --delete --delete-excluded --exclude-from=~/.backup/exclude --log-file=~/.backup/rsync.log -e ssh /home/ben ben@myserver:/mnt/backup/current

My home directory is 120 GB with typical delta sizes of tens of megabytes between backups (although sometimes deltas can be gigabytes, after which the server has severe interactivity issues). The server is unfortunately quite memory constrained with only 1.5GB of memory (old inherited hardware). Given the size of my typical deltas, I'm worried that even simply walking the directory hierarchy might be enough to push out my working set.

Quoted 3 lines

Looking at the rsync access pattern with strace it seems that it does a very good job of avoid duplicate reads which is good news for these patches.

Thanks for the notice. Ben.
FYI, we have a plan to change the policy as you look this thread. Maybe It would be good than my current policy in the page.

Please recognize it. :)

Quoted 7 lines

Cheers,

- Ben

Signature · 9 lines
Kind regards,
Minchan Kim

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#13 lore raw

RFC PATCH 1/1 fadvise support in rsync

In reply to KOSAKI Motohiro

Warning for kernel folks: I'm not much of an mm person; let me know if I got anything horribly wrong.

Many folks use rsync in their nightly backup jobs. In these applications, speed is of minimal concern and should be sacrificed in order to minimize the effect of rsync on the rest of the machine. When rsync is working on a large directory it can quickly fill the page cache with written data, displacing the rest of the system's working set. The solution for this is to inform the kernel that our written pages will no longer be needed and should be expelled to disk. The POSIX interface for this, posix_fadvise, has existed for some time, but there has been no useable implementation in any of the major operating systems.

Attempts have been made in the past[1] to use the fadvise interface, but kernel limitations have made this quite messy. In particular, the kernel supports FADV_DONTNEED as a single-shot hint; i.e. if the page is clean when the hint is given it will be freed, otherwise the hint is ignored. For this reason it is necessary to fdatasync() against dirtied pages before giving the hint. This, however, requires that rsync do some accounting, calling fdatasync() and fadvise() only after giving the kernel an opportunity to flush the data itself.

Moreover, fadvise(DONTNEED) frees pages regardless of whether the hinting process is the only referrer. For this reason, the previous fadvise patch also used mincore to identify which pages are needed by other processes. Altogether, this makes using fadvise very expensive from a complexity standpoint. This is very unfortunately since the interface could be quite usable with a few minor changes.

I recently asked about this on the LKML[2], where Minchan Kim was nice enough to put together a patch improving support for the FADV_DONTNEED hint. His patch adds invalidated flagged pages to the inactive list. This obviates the need for fdatasync() since the page will be reclaimed by the kernel in the standard inactive reclaim path. Moreover, by adding hinted pages to the head of the inactive list, other processes are given ample time to call the pages back to the active list, eliminating the need for the previous mincore() hack.

Here is my attempt at adding fadvise support to rsync (against v3.0.7). I do this in both the sender (hinting after match_sums()) and the receiver (hinting after receive_data()). In principle we could get better granularity if this was hooked up within match_sums() (or even the map_ptr() interface) and the receive loop in receive_data(), but I wanted to keep things simple at first (any comments on these ideas?) . At the moment is for little more than testing. Considering the potential negative effects of using FADV_DONTNEED on older kernels, it is likely we will want this functionality off by default with a command line flag to enable.

Cheers,

- Ben

[1] http://insights.oetiker.ch/linux/fadvise.html
[2] http://lkml.org/lkml/2010/11/21/59

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#14 lore raw

Re: [RFC PATCH] fadvise support in rsync

Quoted 20 lines · Ben Gamari

Warning for kernel folks: I'm not much of an mm person; let me know if I got anything horribly wrong.

Many folks use rsync in their nightly backup jobs. In these applications, speed is of minimal concern and should be sacrificed in order to minimize the effect of rsync on the rest of the machine. When rsync is working on a large directory it can quickly fill the page cache with written data, displacing the rest of the system's working set. The solution for this is to inform the kernel that our written pages will no longer be needed and should be expelled to disk. The POSIX interface for this, posix_fadvise, has existed for some time, but there has been no useable implementation in any of the major operating systems.

Attempts have been made in the past[1] to use the fadvise interface, but kernel limitations have made this quite messy. In particular, the kernel supports FADV_DONTNEED as a single-shot hint; i.e. if the page is clean when the hint is given it will be freed, otherwise the hint is ignored. For this reason it is necessary to fdatasync() against dirtied pages before giving the hint. This, however, requires that rsync do some accounting, calling fdatasync() and fadvise() only after giving the kernel an opportunity to flush the data itself.

Quoted 6 lines

Moreover, fadvise(DONTNEED) frees pages regardless of whether the hinting process is the only referrer. For this reason, the previous fadvise patch also used mincore to identify which pages are needed by other processes. Altogether, this makes using fadvise very expensive from a complexity standpoint. This is very unfortunately since the interface could be quite usable with a few minor changes.

Thanks for the easy to understand summary,
and for working through a solution.

Quoted 11 lines

I recently asked about this on the LKML[2], where Minchan Kim was nice enough to put together a patch improving support for the FADV_DONTNEED hint. His patch adds invalidated flagged pages to the inactive list. This obviates the need for fdatasync() since the page will be reclaimed by the kernel in the standard inactive reclaim path. Moreover, by adding hinted pages to the head of the inactive list, other processes are given ample time to call the pages back to the active list, eliminating the need for the previous mincore() hack.

Here is my attempt at adding fadvise support to rsync (against v3.0.7). I do this in both the sender (hinting after match_sums()) and the receiver (hinting after receive_data()).

So for the moment you still thrash the cache when
backing up large files. Fair enough.

Quoted 4 lines

In principle we could get better granularity if this was
hooked up within match_sums() (or even the map_ptr() interface) and the receive loop in receive_data(), but I wanted to keep things simple at first (any comments on these ideas?) .

I implemented finer grained fadvise(DONTNEED) in dvd-vr1 and noted that I had to be careful not to invalidate read ahead data from the cache. I.E. I had to specify the specific range I had processed.

Quoted 4 lines

At the moment is for little more than testing.
Considering the potential negative effects of using FADV_DONTNEED on older kernels, it is likely we will want this functionality off by default with a command line flag to enable.

The downside being, files opened by other apps may be dropped? Well if you're thrashing the cache anyway I'd just enable by default and get the good behavior on new kernels.

cheers,
Padraig.

[1] http://www.pixelbeat.org/programs/dvd-vr/dvd-vr-0.9.7.tar.gz

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#15 lore raw

Re: [RFC PATCH] fadvise support in rsync

In reply to Ben Gamari
Quoted 9 lines

Here is my attempt at adding fadvise support to rsync (against v3.0.7). I do this in both the sender (hinting after match_sums()) and the receiver (hinting after receive_data()). In principle we could get better granularity if this was hooked up within match_sums() (or even the map_ptr() interface) and the receive loop in receive_data(), but I wanted to keep things simple at first (any comments on these ideas?) . At the moment is for little more than testing. Considering the potential negative effects of using FADV_DONTNEED on older kernels, it is likely we will want this functionality off by default with a command line flag to enable.

Great!

As far as you don't hesitate userland app, we have no reason to hesitate kernel change. We are only worry about to create no user interface. Because it's maintainance nightmare.

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#16 lore raw

PATCH 1/3 Add fadvise interface wrapper

In reply to KOSAKI Motohiro

With recent discussion on the LKML[1], it seems likely that Linux will finally support posix_fadvise in a useful way with the FADV_DONTNEED flag. This should allow us to minimize the effect of rsync on the system's working set. Add the necessary wrapper to syscall.c.

[1] http://lkml.org/lkml/2010/11/21/59

---
 syscall.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
syscall.c +11 -0
index cfabc3e..9f5b1c3 100644
@@ -28,6 +28,7 @@
 #ifdef HAVE_SYS_ATTR_H
 #include <sys/attr.h>
 #endif
+#include <fcntl.h>
 
 extern int dry_run;
 extern int am_root;
@@ -282,3 +283,13 @@ OFF_T do_lseek(int fd, OFF_T offset, int whence)
 	return lseek(fd, offset, whence);
 #endif
 }
+
+#if _XOPEN_SOURCE >= 600
+int do_fadvise(int fd, OFF_T offset, OFF_T len, int advise)
+{
+        return posix_fadvise(fd, offset, len, advise);
+}
+#else
+#define do_fadvise() 
+#endif
+
Signature · 8 lines
1.7.1

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#17 lore raw

PATCH 2/3 Inform kernel of FADV_DONTNEED hint in sender

In reply to KOSAKI Motohiro

Use the FADV_DONTNEED fadvise hint after finishing reading an origin fd in the sender.

---
 sender.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
sender.c +6 -0
index 59dae7d..a934bfe 100644
@@ -338,6 +338,12 @@ void send_files(int f_in, int f_out)
 		if (do_progress)
 			end_progress(st.st_size);
 
+                if (do_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED) != 0) {
+                        rsyserr(FERROR_XFER, errno,
+                                "fadvise failed in sending %s",
+                                full_fname(fname));
+                }
+
 		log_item(log_code, file, &initial_stats, iflags, NULL);
 
 		if (mbuf) {
Signature · 8 lines
1.7.1

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#18 lore raw

PATCH 3/3 Inform kernel of FADV_DONTNEED hint in receiver

In reply to KOSAKI Motohiro

Use the FADV_DONTNEED fadvise hint after finishing writing to a destinataion fd in the receiver.

---
 receiver.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
receiver.c +6 -0
index 39c5e49..33b21fb 100644
@@ -721,6 +721,12 @@ int recv_files(int f_in, char *local_name)
 		recv_ok = receive_data(f_in, fnamecmp, fd1, st.st_size,
 				       fname, fd2, F_LENGTH(file));
 
+                if (do_fadvise(fd2, 0, 0, POSIX_FADV_DONTNEED) != 0) {
+                        rsyserr(FERROR_XFER, errno,
+                                "fadvise failed in writing %s",
+                                full_fname(fname));
+                }
+
 		log_item(log_code, file, &initial_stats, iflags, NULL);
 
 		if (fd1 != -1)
Signature · 8 lines
1.7.1

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on v1 1/2
#19 lore raw
In reply to Minchan Kim
Quoted 11 lines · Minchan Kim

Recently, there are reported problem about thrashing.
(http://marc.info/?l=rsync&m=128885034930933&w=2)
It happens by backup workloads(ex, nightly rsync). That's because the workload makes just use-once pages and touches pages twice. It promotes the page into active list so that it results in working set page eviction.

Some app developer want to support POSIX_FADV_NOREUSE. But other OSes don't support it, either.
(http://marc.info/?l=linux-mm&m=128928979512086&w=2)

Quoted 9 lines

By Other approach, app developer uses POSIX_FADV_DONTNEED. But it has a problem. If kernel meets page is writing during invalidate_mapping_pages, it can't work.
It is very hard for application programmer to use it. Because they always have to sync data before calling fadivse(..POSIX_FADV_DONTNEED) to make sure the pages could be discardable. At last, they can't use deferred write of kernel so that they could see performance loss.
(http://insights.oetiker.ch/linux/fadvise.html)

This looks promising...

Signature · 8 lines
All rights reversed

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#20 lore raw
In reply to Minchan Kim
Quoted 32 lines · On Sun, 21 Nov 2010 23:30:23 +0900 Minchan Kim <[email protected]> wrote:

Recently, there are reported problem about thrashing.
(http://marc.info/?l=rsync&m=128885034930933&w=2)
It happens by backup workloads(ex, nightly rsync). That's because the workload makes just use-once pages and touches pages twice. It promotes the page into active list so that it results in working set page eviction.

Some app developer want to support POSIX_FADV_NOREUSE. But other OSes don't support it, either.
(http://marc.info/?l=linux-mm&m=128928979512086&w=2)

By Other approach, app developer uses POSIX_FADV_DONTNEED. But it has a problem. If kernel meets page is writing during invalidate_mapping_pages, it can't work.
It is very hard for application programmer to use it. Because they always have to sync data before calling fadivse(..POSIX_FADV_DONTNEED) to make sure the pages could be discardable. At last, they can't use deferred write of kernel so that they could see performance loss.
(http://insights.oetiker.ch/linux/fadvise.html)

In fact, invalidate is very big hint to reclaimer. It means we don't use the page any more. So let's move the writing page into inactive list's head.

If it is real working set, it could have a enough time to activate the page since we always try to keep many pages in inactive list.

I reuse lru_demote of Peter with some change.

Quoted 6 lines

...

+/*
+ * Function used to forecefully demote a page to the head of the inactive
+ * list.
+ */

This comment is wrong? The page gets moved to the _tail_ of the inactive list?

Quoted 1 line

+void lru_deactive_page(struct page *page)

Should be "deactivate" throughout the patch. IMO.

Quoted 29 lines
(quoted diff) +9 -0
+{
+	if (likely(get_page_unless_zero(page))) {
+		struct pagevec *pvec = &get_cpu_var(lru_deactive_pvecs);
+
+		if (!pagevec_add(pvec, page))
+			__pagevec_lru_deactive(pvec);
+		put_cpu_var(lru_deactive_pvecs);
+	}
 }
 
+
 void lru_add_drain(void)
 {
 	drain_cpu_pagevecs(get_cpu());
mm/truncate.c +2 -1
index cd94607..c73fb19 100644
@@ -332,7 +332,8 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
 {
 	struct pagevec pvec;
 	pgoff_t next = start;
-	unsigned long ret = 0;
+	unsigned long ret;
+	unsigned long count = 0;
 	int i;
 
 	pagevec_init(&pvec, 0);

mm/truncate.c unsigned long invalidate_mapping_pages(struct address_space *mapping, · line 365

Quoted 8 lines
mm/truncate.c +3 -2
@@ -359,8 +360,10 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
 			if (lock_failed)
 				continue;
 
-			ret += invalidate_inode_page(page);
-
+			ret = invalidate_inode_page(page);
+			if (!ret)
+				lru_deactive_page(page);

This is the core part of the patch and it needs a code comment to explain the reasons for doing this.

I wonder about the page_mapped() case. We were unable to invalidate the page because it was mapped into pagetables. But was it really appropriate to deactivate the page in that case?

mm/truncate.c unsigned long invalidate_mapping_pages(struct address_space *mapping, · line 369

Quoted 4 lines
mm/truncate.c +1 -0
+			count += ret;
 			unlock_page(page);
 			if (next > end)
 				break;

Suggested updates:

 include/linux/swap.h |    2 +-
 mm/swap.c            |   13 ++++++-------
 mm/truncate.c        |    7 ++++++-
 3 files changed, 13 insertions(+), 9 deletions(-)
include/linux/swap.h renamed from include/linux/swap.h~mm-deactivate-invalidated-pages-fix +1 -1
diff -puN include/linux/swap.h~mm-deactivate-invalidated-pages-fix include/linux/swap.h
@@ -213,7 +213,7 @@ extern void mark_page_accessed(struct pa
 extern void lru_add_drain(void);
 extern int lru_add_drain_all(void);
 extern void rotate_reclaimable_page(struct page *page);
-extern void lru_deactive_page(struct page *page);
+extern void lru_deactivate_page(struct page *page);
 extern void swap_setup(void);
 
 extern void add_page_to_unevictable_list(struct page *page);
mm/swap.c renamed from mm/swap.c~mm-deactivate-invalidated-pages-fix +6 -7
diff -puN mm/swap.c~mm-deactivate-invalidated-pages-fix mm/swap.c
@@ -39,7 +39,7 @@ int page_cluster;
 
 static DEFINE_PER_CPU(struct pagevec[NR_LRU_LISTS], lru_add_pvecs);
 static DEFINE_PER_CPU(struct pagevec, lru_rotate_pvecs);
-static DEFINE_PER_CPU(struct pagevec, lru_deactive_pvecs);
+static DEFINE_PER_CPU(struct pagevec, lru_deactivate_pvecs);
 
 
 /*
@@ -334,23 +334,22 @@ static void drain_cpu_pagevecs(int cpu)
 		local_irq_restore(flags);
 	}
 
-	pvec = &per_cpu(lru_deactive_pvecs, cpu);
+	pvec = &per_cpu(lru_deactivate_pvecs, cpu);
 	if (pagevec_count(pvec))
 		__pagevec_lru_deactive(pvec);
 }
 
 /*
- * Function used to forecefully demote a page to the head of the inactive
- * list.
+ * Forecfully demote a page to the tail of the inactive list.
  */
-void lru_deactive_page(struct page *page)
+void lru_deactivate_page(struct page *page)
 {
 	if (likely(get_page_unless_zero(page))) {
-		struct pagevec *pvec = &get_cpu_var(lru_deactive_pvecs);
+		struct pagevec *pvec = &get_cpu_var(lru_deactivate_pvecs);
 
 		if (!pagevec_add(pvec, page))
 			__pagevec_lru_deactive(pvec);
-		put_cpu_var(lru_deactive_pvecs);
+		put_cpu_var(lru_deactivate_pvecs);
 	}
 }
 
mm/truncate.c renamed from mm/truncate.c~mm-deactivate-invalidated-pages-fix +6 -1
diff -puN mm/truncate.c~mm-deactivate-invalidated-pages-fix mm/truncate.c
@@ -361,8 +361,13 @@ unsigned long invalidate_mapping_pages(s
 				continue;
 
 			ret = invalidate_inode_page(page);
+			/*
+			 * If the page was dirty or under writeback we cannot
+			 * invalidate it now.  Move it to the tail of the
+			 * inactive LRU so that reclaim will free it promptly.
+			 */
 			if (!ret)
-				lru_deactive_page(page);
+				lru_deactivate_page(page);
 			count += ret;
 			unlock_page(page);
 			if (next > end)

_

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#21 lore raw
Quoted 37 lines · Andrew Morton
Quoted 34 lines · On Sun, 21 Nov 2010 23:30:23 +0900 Minchan Kim <[email protected]> wrote:

Recently, there are reported problem about thrashing.
(http://marc.info/?l=rsync&m=128885034930933&w=2)
It happens by backup workloads(ex, nightly rsync). That's because the workload makes just use-once pages and touches pages twice. It promotes the page into active list so that it results in working set page eviction.

Some app developer want to support POSIX_FADV_NOREUSE. But other OSes don't support it, either.
(http://marc.info/?l=linux-mm&m=128928979512086&w=2)

By Other approach, app developer uses POSIX_FADV_DONTNEED. But it has a problem. If kernel meets page is writing during invalidate_mapping_pages, it can't work.
It is very hard for application programmer to use it. Because they always have to sync data before calling fadivse(..POSIX_FADV_DONTNEED) to make sure the pages could be discardable. At last, they can't use deferred write of kernel so that they could see performance loss.
(http://insights.oetiker.ch/linux/fadvise.html)

In fact, invalidate is very big hint to reclaimer. It means we don't use the page any more. So let's move the writing page into inactive list's head.

If it is real working set, it could have a enough time to activate the page since we always try to keep many pages in inactive list.

I reuse lru_demote of Peter with some change.

...

Quoted 7 lines
Quoted 4 lines

+/*
+ * Function used to forecefully demote a page to the head of the inactive
+ * list.
+ */

This comment is wrong?  The page gets moved to the _tail_ of the inactive list?

No. I add it in _head_ of the inactive list intentionally. Why I don't add it to _tail_ is that I don't want to be aggressive. The page might be real working set. So I want to give a chance to activate it again.
If it's not working set, it can be reclaimed easily and it can prevent active page demotion since inactive list size would be big enough for not calling shrink_active_list.

Quoted 4 lines
Quoted 2 lines

+void lru_deactive_page(struct page *page)

Should be "deactivate" throughout the patch. IMO.

Thank you.

Quoted 42 lines
Quoted 30 lines
(quoted diff) +8 -0
+{
+     if (likely(get_page_unless_zero(page))) {
+             struct pagevec *pvec = &get_cpu_var(lru_deactive_pvecs);
+
+             if (!pagevec_add(pvec, page))
+                     __pagevec_lru_deactive(pvec);
+             put_cpu_var(lru_deactive_pvecs);
+     }

 }

+
 void lru_add_drain(void)
 {
      drain_cpu_pagevecs(get_cpu());

mm/truncate.c +2 -1
index cd94607..c73fb19 100644
@@ -332,7 +332,8 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
  {
       struct pagevec pvec;
       pgoff_t next = start;
-     unsigned long ret = 0;
+     unsigned long ret;
+     unsigned long count = 0;
       int i;
 
       pagevec_init(&pvec, 0);

mm/truncate.c unsigned long invalidate_mapping_pages(struct address_space *mapping, · line 365

Quoted 8 lines
mm/truncate.c +3 -2
@@ -359,8 +360,10 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
                       if (lock_failed)
                               continue;
 
-                     ret += invalidate_inode_page(page);
-
+                     ret = invalidate_inode_page(page);
+                     if (!ret)
+                             lru_deactive_page(page);

This is the core part of the patch and it needs a code comment to explain the reasons for doing this.

Quoted 3 lines

I wonder about the page_mapped() case.  We were unable to invalidate the page because it was mapped into pagetables.  But was it really appropriate to deactivate the page in that case?

Yes. My assumption is that if it's real working set, it could be activated easily during inactive list moving window time.

Quoted 89 lines

mm/truncate.c unsigned long invalidate_mapping_pages(s

Quoted 6 lines
mm/truncate.c +1 -0
+                     count += ret;
                       unlock_page(page);
                       if (next > end)
                               break;

Suggested updates:

 include/linux/swap.h |    2 +-
 mm/swap.c            |   13 ++++++-------
 mm/truncate.c        |    7 ++++++-

 3 files changed, 13 insertions(+), 9 deletions(-)

diff -puN include/linux/swap.h~mm-deactivate-invalidated-pages-fix include/linux/swap.h

include/linux/swap.h renamed from include/linux/swap.h~mm-deactivate-invalidated-pages-fix +1 -1
@@ -213,7 +213,7 @@ extern void mark_page_accessed(struct pa
  extern void lru_add_drain(void);
  extern int lru_add_drain_all(void);
  extern void rotate_reclaimable_page(struct page *page);
-extern void lru_deactive_page(struct page *page);
+extern void lru_deactivate_page(struct page *page);
  extern void swap_setup(void);
 
  extern void add_page_to_unevictable_list(struct page *page);

diff -puN mm/swap.c~mm-deactivate-invalidated-pages-fix mm/swap.c

mm/swap.c renamed from mm/swap.c~mm-deactivate-invalidated-pages-fix +6 -7
@@ -39,7 +39,7 @@ int page_cluster;
 
  static DEFINE_PER_CPU(struct pagevec[NR_LRU_LISTS], lru_add_pvecs);
  static DEFINE_PER_CPU(struct pagevec, lru_rotate_pvecs);
-static DEFINE_PER_CPU(struct pagevec, lru_deactive_pvecs);
+static DEFINE_PER_CPU(struct pagevec, lru_deactivate_pvecs);
 
 
  /*
@@ -334,23 +334,22 @@ static void drain_cpu_pagevecs(int cpu)
                local_irq_restore(flags);
        }
 
-       pvec = &per_cpu(lru_deactive_pvecs, cpu);
+       pvec = &per_cpu(lru_deactivate_pvecs, cpu);
        if (pagevec_count(pvec))
                __pagevec_lru_deactive(pvec);
  }
 
  /*
- * Function used to forecefully demote a page to the head of the inactive
- * list.
+ * Forecfully demote a page to the tail of the inactive list.
  */
-void lru_deactive_page(struct page *page)
+void lru_deactivate_page(struct page *page)
  {
        if (likely(get_page_unless_zero(page))) {
-               struct pagevec *pvec = &get_cpu_var(lru_deactive_pvecs);
+               struct pagevec *pvec = &get_cpu_var(lru_deactivate_pvecs);
 
                if (!pagevec_add(pvec, page))
                        __pagevec_lru_deactive(pvec);
-               put_cpu_var(lru_deactive_pvecs);
+               put_cpu_var(lru_deactivate_pvecs);
        }
  }
 

diff -puN mm/truncate.c~mm-deactivate-invalidated-pages-fix mm/truncate.c

mm/truncate.c renamed from mm/truncate.c~mm-deactivate-invalidated-pages-fix +6 -1
@@ -361,8 +361,13 @@ unsigned long invalidate_mapping_pages(s
                                continue;
 
                        ret = invalidate_inode_page(page);
+                       /*
+                        * If the page was dirty or under writeback we cannot
+                        * invalidate it now.  Move it to the tail of the
+                        * inactive LRU so that reclaim will free it promptly.
+                        */
                        if (!ret)
-                               lru_deactive_page(page);
+                               lru_deactivate_page(page);
                        count += ret;
                        unlock_page(page);
                        if (next > end)

_

Signature · 9 lines
Kind regards,
Minchan Kim

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#22 lore raw
Quoted 5 lines · On Tue, 23 Nov 2010 13:52:05 +0900 Minchan Kim <[email protected]> wrote:
Quoted 5 lines
Quoted 4 lines

+/*
+ * Function used to forecefully demote a page to the head of the inactive
+ * list.
+ */

Quoted 7 lines
Quoted 2 lines

This comment is wrong? __The page gets moved to the _tail_ of the inactive list?

No. I add it in _head_ of the inactive list intentionally. Why I don't add it to _tail_ is that I don't want to be aggressive. The page might be real working set. So I want to give a chance to activate it again.

Well.. why? The user just tried to toss the page away altogether. If the kernel wasn't able to do that immediately, the best it can do is to toss the page away asap?

Quoted 3 lines

If it's not working set, it can be reclaimed easily and it can prevent active page demotion since inactive list size would be big enough for not calling shrink_active_list.

What is "working set"? Mapped and unmapped pagecache, or are you referring solely to mapped pagecache?

If it's mapped pagecache then the user was being a bit silly (or didn't know that some other process had mapped the file). In which case we need to decide what to do - leave the page alone, deactivate it, or half-deactivate it as this patch does.

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#23 lore raw
Quoted 19 lines · Andrew Morton
Quoted 5 lines · On Tue, 23 Nov 2010 13:52:05 +0900 Minchan Kim <[email protected]> wrote:
Quoted 5 lines
Quoted 4 lines

+/*
+ * Function used to forecefully demote a page to the head of the inactive
+ * list.
+ */

Quoted 7 lines
Quoted 2 lines

This comment is wrong? __The page gets moved to the _tail_ of the inactive list?

No. I add it in _head_ of the inactive list intentionally. Why I don't add it to _tail_ is that I don't want to be aggressive. The page might be real working set. So I want to give a chance to activate it again.

Well..  why?  The user just tried to toss the page away altogether.  If the kernel wasn't able to do that immediately, the best it can do is to toss the page away asap?

Quoted 6 lines
Quoted 3 lines

If it's not working set, it can be reclaimed easily and it can prevent active page demotion since inactive list size would be big enough for not calling shrink_active_list.

What is "working set"?  Mapped and unmapped pagecache, or are you referring solely to mapped pagecache?

I mean it's mapped by other processes.

Quoted 5 lines

If it's mapped pagecache then the user was being a bit silly (or didn't know that some other process had mapped the file).  In which case we need to decide what to do - leave the page alone, deactivate it, or half-deactivate it as this patch does.

What I want is the half-deactivate.

Okay. We will use the result of invalidate_inode_page. If fail happens by page_mapped, we can do half-deactivate. But if fail happens by dirty(ex, writeback), we can add it to tail. Does it make sense?

Signature · 2 lines
Kind regards,
Minchan Kim
maintainer
#24 lore raw
Quoted 37 lines · On Tue, 23 Nov 2010 14:23:33 +0900 Minchan Kim <[email protected]> wrote:
Quoted 19 lines · Andrew Morton
Quoted 5 lines · On Tue, 23 Nov 2010 13:52:05 +0900 Minchan Kim <[email protected]> wrote:
Quoted 5 lines
Quoted 4 lines

+/*
+ * Function used to forecefully demote a page to the head of the inactive
+ * list.
+ */

Quoted 7 lines
Quoted 2 lines

This comment is wrong? __The page gets moved to the _tail_ of the inactive list?

No. I add it in _head_ of the inactive list intentionally. Why I don't add it to _tail_ is that I don't want to be aggressive. The page might be real working set. So I want to give a chance to activate it again.

Well.. __why? __The user just tried to toss the page away altogether. __If the kernel wasn't able to do that immediately, the best it can do is to toss the page away asap?

Quoted 6 lines
Quoted 3 lines

If it's not working set, it can be reclaimed easily and it can prevent active page demotion since inactive list size would be big enough for not calling shrink_active_list.

What is "working set"? __Mapped and unmapped pagecache, or are you referring solely to mapped pagecache?

I mean it's mapped by other processes.

Quoted 5 lines

If it's mapped pagecache then the user was being a bit silly (or didn't know that some other process had mapped the file). __In which case we need to decide what to do - leave the page alone, deactivate it, or half-deactivate it as this patch does.

Quoted 6 lines

What I want is the half-deactivate.

Okay. We will use the result of invalidate_inode_page. If fail happens by page_mapped, we can do half-deactivate. But if fail happens by dirty(ex, writeback), we can add it to tail. Does it make sense?

Spose so. It's unobvious.

If the page is dirty or under writeback then reclaim will immediately move it to the head of the LRU anyway. But given that the user has just freed a bunch of pages with invalidate(), it's unlikely that reclaim will be running soon.

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#25 lore raw
Quoted 46 lines · Andrew Morton
Quoted 37 lines · On Tue, 23 Nov 2010 14:23:33 +0900 Minchan Kim <[email protected]> wrote:
Quoted 19 lines · Andrew Morton
Quoted 5 lines · On Tue, 23 Nov 2010 13:52:05 +0900 Minchan Kim <[email protected]> wrote:
Quoted 5 lines
Quoted 4 lines

+/*
+ * Function used to forecefully demote a page to the head of the inactive
+ * list.
+ */

Quoted 7 lines
Quoted 2 lines

This comment is wrong? __The page gets moved to the _tail_ of the inactive list?

No. I add it in _head_ of the inactive list intentionally. Why I don't add it to _tail_ is that I don't want to be aggressive. The page might be real working set. So I want to give a chance to activate it again.

Well.. __why? __The user just tried to toss the page away altogether. __If the kernel wasn't able to do that immediately, the best it can do is to toss the page away asap?

Quoted 6 lines
Quoted 3 lines

If it's not working set, it can be reclaimed easily and it can prevent active page demotion since inactive list size would be big enough for not calling shrink_active_list.

What is "working set"? __Mapped and unmapped pagecache, or are you referring solely to mapped pagecache?

I mean it's mapped by other processes.

Quoted 5 lines

If it's mapped pagecache then the user was being a bit silly (or didn't know that some other process had mapped the file). __In which case we need to decide what to do - leave the page alone, deactivate it, or half-deactivate it as this patch does.

Quoted 6 lines

What I want is the half-deactivate.

Okay. We will use the result of invalidate_inode_page. If fail happens by page_mapped, we can do half-deactivate. But if fail happens by dirty(ex, writeback), we can add it to tail. Does it make sense?

Quoted 4 lines

Spose so.  It's unobvious.

If the page is dirty or under writeback then reclaim will immediately move it to the head of the LRU anyway.  But given that the user has

Why does it move into head of LRU?
If the page which isn't mapped doesn't have PG_referenced, it would be reclaimed.

Quoted 2 lines

just freed a bunch of pages with invalidate(), it's unlikely that reclaim will be running soon.

If reclaim doesn't start soon, it's good. That's because we have a time to activate it and
when reclaim happens, reclaimer can reclaim pages easily.

If I don't understand your point, could you elaborate on it?

Signature · 9 lines
Kind regards,
Minchan Kim

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#26 lore raw
Quoted 48 lines · On Tue, 23 Nov 2010 14:45:15 +0900 Minchan Kim <[email protected]> wrote:
Quoted 46 lines · Andrew Morton
Quoted 43 lines · On Tue, 23 Nov 2010 14:23:33 +0900 Minchan Kim <[email protected]> wrote:
Quoted 19 lines · Andrew Morton
Quoted 5 lines · On Tue, 23 Nov 2010 13:52:05 +0900 Minchan Kim <[email protected]> wrote:
Quoted 5 lines
Quoted 4 lines

+/*
+ * Function used to forecefully demote a page to the head of the inactive
+ * list.
+ */

Quoted 7 lines
Quoted 2 lines

This comment is wrong? __The page gets moved to the _tail_ of the inactive list?

No. I add it in _head_ of the inactive list intentionally. Why I don't add it to _tail_ is that I don't want to be aggressive. The page might be real working set. So I want to give a chance to activate it again.

Well.. __why? __The user just tried to toss the page away altogether. __If the kernel wasn't able to do that immediately, the best it can do is to toss the page away asap?

Quoted 6 lines
Quoted 3 lines

If it's not working set, it can be reclaimed easily and it can prevent active page demotion since inactive list size would be big enough for not calling shrink_active_list.

What is "working set"? __Mapped and unmapped pagecache, or are you referring solely to mapped pagecache?

I mean it's mapped by other processes.

Quoted 5 lines

If it's mapped pagecache then the user was being a bit silly (or didn't know that some other process had mapped the file). __In which case we need to decide what to do - leave the page alone, deactivate it, or half-deactivate it as this patch does.

What I want is the half-deactivate.

Okay. We will use the result of invalidate_inode_page. If fail happens by page_mapped, we can do half-deactivate. But if fail happens by dirty(ex, writeback), we can add it to tail. Does it make sense?

Quoted 8 lines
Quoted 4 lines

Spose so. __It's unobvious.

If the page is dirty or under writeback then reclaim will immediately move it to the head of the LRU anyway. __But given that the user has

Why does it move into head of LRU?
If the page which isn't mapped doesn't have PG_referenced, it would be reclaimed.

If it's dirty or under writeback it can't be reclaimed!

Quoted 8 lines
Quoted 2 lines

just freed a bunch of pages with invalidate(), it's unlikely that reclaim will be running soon.

If reclaim doesn't start soon, it's good. That's because we have a time to activate it and
when reclaim happens, reclaimer can reclaim pages easily.

If I don't understand your point, could you elaborate on it?

If reclaim doesn't happen soon and the page was dirty or under writeback (and hence unreclaimable) then there's a better chance that it _will_ be reclaimable by the time reclaim comes along and has a look at it. Yes, that's good.

And a note to Mel: this is one way in which we can get significant (perhaps tremendous) numbers of dirty pages coming off the tail of the LRU, and hence eligible for pageout() treatment.

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#27 lore raw
Quoted 52 lines · Andrew Morton
Quoted 50 lines · On Tue, 23 Nov 2010 14:45:15 +0900 Minchan Kim <[email protected]> wrote:
Quoted 48 lines · Andrew Morton
Quoted 37 lines · On Tue, 23 Nov 2010 14:23:33 +0900 Minchan Kim <[email protected]> wrote:
Quoted 19 lines · Andrew Morton
Quoted 5 lines · On Tue, 23 Nov 2010 13:52:05 +0900 Minchan Kim <[email protected]> wrote:
Quoted 5 lines
Quoted 4 lines

+/*
+ * Function used to forecefully demote a page to the head of the inactive
+ * list.
+ */

Quoted 7 lines
Quoted 2 lines

This comment is wrong? __The page gets moved to the _tail_ of the inactive list?

No. I add it in _head_ of the inactive list intentionally. Why I don't add it to _tail_ is that I don't want to be aggressive. The page might be real working set. So I want to give a chance to activate it again.

Well.. __why? __The user just tried to toss the page away altogether. __If the kernel wasn't able to do that immediately, the best it can do is to toss the page away asap?

Quoted 6 lines
Quoted 3 lines

If it's not working set, it can be reclaimed easily and it can prevent active page demotion since inactive list size would be big enough for not calling shrink_active_list.

What is "working set"? __Mapped and unmapped pagecache, or are you referring solely to mapped pagecache?

I mean it's mapped by other processes.

Quoted 5 lines

If it's mapped pagecache then the user was being a bit silly (or didn't know that some other process had mapped the file). __In which case we need to decide what to do - leave the page alone, deactivate it, or half-deactivate it as this patch does.

Quoted 6 lines

What I want is the half-deactivate.

Okay. We will use the result of invalidate_inode_page. If fail happens by page_mapped, we can do half-deactivate. But if fail happens by dirty(ex, writeback), we can add it to tail. Does it make sense?

Spose so. __It's unobvious.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

If the page is dirty or under writeback then reclaim will immediately move it to the head of the LRU anyway. __But given that the user has

Why does it move into head of LRU?
If the page which isn't mapped doesn't have PG_referenced, it would be reclaimed.

If it's dirty or under writeback it can't be reclaimed!

I see your point. And it's why I add it to head of inactive list.

Quoted 10 lines
Quoted 9 lines
Quoted 3 lines

just freed a bunch of pages with invalidate(), it's unlikely that reclaim will be running soon.

If reclaim doesn't start soon, it's good. That's because we have a time to activate it and
when reclaim happens, reclaimer can reclaim pages easily.

If I don't understand your point, could you elaborate on it?

Quoted 9 lines

If reclaim doesn't happen soon and the page was dirty or under writeback (and hence unreclaimable) then there's a better chance that it _will_ be reclaimable by the time reclaim comes along and has a look at it.  Yes, that's good.

And a note to Mel: this is one way in which we can get significant (perhaps tremendous) numbers of dirty pages coming off the tail of the LRU, and hence eligible for pageout() treatment.

I think you agree my as-is approach. Right?
Then, could you revert your fixlet?
I will add additional description with your fix.

Signature · 2 lines
Kind regards,
Minchan Kim
maintainer
#28 lore raw
Quoted 10 lines · On Tue, 23 Nov 2010 15:05:39 +0900 Minchan Kim <[email protected]> wrote:

On Tue, Nov 23, 2010 at 2:48 PM, Andrew Morton

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

move it to the head of the LRU anyway. __But given that the user has

Why does it move into head of LRU?
If the page which isn't mapped doesn't have PG_referenced, it would be reclaimed.

If it's dirty or under writeback it can't be reclaimed!

I see your point. And it's why I add it to head of inactive list.

But that *guarantees* that the page will get a full trip around the inactive list. And this will guarantee that potentially useful pages are reclaimed before the pages which we *know* the user doesn't want! Bad!

Whereas if we queue it to the tail, it will only get that full trip if reclaim happens to run before the page is cleaned. And we just agreed that reclaim isn't likely to run immediately, because pages are being freed.

So we face a choice between guaranteed eviction of potentially-useful pages (which are very expensive to reestablish) versus a *possible* need to move an unreclaimable page to the head of the LRU, which is cheap.

So we need to decide if

(certain * possibly-expensive) is less than (possible * cheap).

So no, it's not obvious to me that this was the correct decision.

One way to help with this guess would be to instrument those pages (would require adding a special page flag to identify them, I expect) and see how many of these pages get immediately reclaimed off the LRU versus how many get recycled. And then run a batch of "typical workloads" under that instrumentation.

Only there aren't any "typical workloads" for fadvise(DONTNEED) :(

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#29 lore raw
Quoted 23 lines · Andrew Morton
Quoted 10 lines · On Tue, 23 Nov 2010 15:05:39 +0900 Minchan Kim <[email protected]> wrote:

On Tue, Nov 23, 2010 at 2:48 PM, Andrew Morton

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

move it to the head of the LRU anyway. __But given that the user has

Why does it move into head of LRU?
If the page which isn't mapped doesn't have PG_referenced, it would be reclaimed.

If it's dirty or under writeback it can't be reclaimed!

I see your point. And it's why I add it to head of inactive list.

But that *guarantees* that the page will get a full trip around the inactive list.  And this will guarantee that potentially useful pages are reclaimed before the pages which we *know* the user doesn't want! Bad!

Whereas if we queue it to the tail, it will only get that full trip if reclaim happens to run before the page is cleaned.  And we just agreed that reclaim isn't likely to run immediately, because pages are being freed.

Quoted 4 lines

So we face a choice between guaranteed eviction of potentially-useful pages (which are very expensive to reestablish) versus a *possible* need to move an unreclaimable page to the head of the LRU, which is cheap.

How about flagging SetPageReclaim when we add it to head of inactive? If page write is complete, end_page_writeback would move it to tail of inactive.

Signature · 9 lines
Kind regards,
Minchan Kim

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#30 lore raw
Quoted 25 lines · On Tue, 23 Nov 2010 16:44:50 +0900 Minchan Kim <[email protected]> wrote:
Quoted 23 lines · Andrew Morton
Quoted 10 lines · On Tue, 23 Nov 2010 15:05:39 +0900 Minchan Kim <[email protected]> wrote:

On Tue, Nov 23, 2010 at 2:48 PM, Andrew Morton

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

move it to the head of the LRU anyway. __But given that the user has

Why does it move into head of LRU?
If the page which isn't mapped doesn't have PG_referenced, it would be reclaimed.

If it's dirty or under writeback it can't be reclaimed!

I see your point. And it's why I add it to head of inactive list.

But that *guarantees* that the page will get a full trip around the inactive list. __And this will guarantee that potentially useful pages are reclaimed before the pages which we *know* the user doesn't want! Bad!

Whereas if we queue it to the tail, it will only get that full trip if reclaim happens to run before the page is cleaned. __And we just agreed that reclaim isn't likely to run immediately, because pages are being freed.

Quoted 8 lines
Quoted 4 lines

So we face a choice between guaranteed eviction of potentially-useful pages (which are very expensive to reestablish) versus a *possible* need to move an unreclaimable page to the head of the LRU, which is cheap.

How about flagging SetPageReclaim when we add it to head of inactive? If page write is complete, end_page_writeback would move it to tail of inactive.

ooh, that sounds clever. We'd want to do that for both PageDirty() and for PageWriteback() pages.

But if we do it for PageDirty() pages, we'd need to clear PageReclaim() if someone reuses the page for some reason. We'll end up with pages all over the place which have PageReclaim set. I guess we could clear PageReclaim() in mark_page_accessed(), but that's hardly going to give us full coverage.

hmm. Maybe just do it for PageWriteback pages. Then userspace can do

	sync_file_range(SYNC_FILE_RANGE_WRITE);
	fadvise(DONTNEED);

and all those pages which now have PageWriteback set will also get PageReclaim set.

But we'd need to avoid races against end_io when setting PageReclaim against the PageWriteback pages - if the interrupt happens while we're setting PageReclaim, it will end up being incorrectly set.

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#31 lore raw
Quoted 50 lines · Andrew Morton
Quoted 25 lines · On Tue, 23 Nov 2010 16:44:50 +0900 Minchan Kim <[email protected]> wrote:
Quoted 23 lines · Andrew Morton
Quoted 10 lines · On Tue, 23 Nov 2010 15:05:39 +0900 Minchan Kim <[email protected]> wrote:

On Tue, Nov 23, 2010 at 2:48 PM, Andrew Morton

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

move it to the head of the LRU anyway. __But given that the user has

Why does it move into head of LRU?
If the page which isn't mapped doesn't have PG_referenced, it would be reclaimed.

If it's dirty or under writeback it can't be reclaimed!

I see your point. And it's why I add it to head of inactive list.

But that *guarantees* that the page will get a full trip around the inactive list. __And this will guarantee that potentially useful pages are reclaimed before the pages which we *know* the user doesn't want! Bad!

Whereas if we queue it to the tail, it will only get that full trip if reclaim happens to run before the page is cleaned. __And we just agreed that reclaim isn't likely to run immediately, because pages are being freed.

Quoted 8 lines
Quoted 4 lines

So we face a choice between guaranteed eviction of potentially-useful pages (which are very expensive to reestablish) versus a *possible* need to move an unreclaimable page to the head of the LRU, which is cheap.

How about flagging SetPageReclaim when we add it to head of inactive? If page write is complete, end_page_writeback would move it to tail of inactive.

ooh, that sounds clever.  We'd want to do that for both PageDirty() and for PageWriteback() pages.

But if we do it for PageDirty() pages, we'd need to clear PageReclaim() if someone reuses the page for some reason.  We'll end up with pages all over the place which have PageReclaim set.  I guess we could clear PageReclaim() in mark_page_accessed(), but that's hardly going to give us full coverage.

hmm.  Maybe just do it for PageWriteback pages.  Then userspace can do

       sync_file_range(SYNC_FILE_RANGE_WRITE);
       fadvise(DONTNEED);

Quoted 7 lines

and all those pages which now have PageWriteback set will also get PageReclaim set.

But we'd need to avoid races against end_io when setting PageReclaim against the PageWriteback pages - if the interrupt happens while we're setting PageReclaim, it will end up being incorrectly set.

Okay. I will see it and resend new version.
Thanks for good comment, Andrew.

Signature · 9 lines
Kind regards,
Minchan Kim

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#32 lore raw
In reply to Andrew Morton
Quoted 70 lines · Andrew Morton
Quoted 48 lines · On Tue, 23 Nov 2010 14:45:15 +0900 Minchan Kim <[email protected]> wrote:
Quoted 46 lines · Andrew Morton
Quoted 43 lines · On Tue, 23 Nov 2010 14:23:33 +0900 Minchan Kim <[email protected]> wrote:
Quoted 19 lines · Andrew Morton
Quoted 5 lines · On Tue, 23 Nov 2010 13:52:05 +0900 Minchan Kim <[email protected]> wrote:
Quoted 5 lines
Quoted 4 lines

+/*
+ * Function used to forecefully demote a page to the head of the inactive
+ * list.
+ */

Quoted 7 lines
Quoted 2 lines

This comment is wrong? __The page gets moved to the _tail_ of the inactive list?

No. I add it in _head_ of the inactive list intentionally. Why I don't add it to _tail_ is that I don't want to be aggressive. The page might be real working set. So I want to give a chance to activate it again.

Well.. __why? __The user just tried to toss the page away altogether. __If the kernel wasn't able to do that immediately, the best it can do is to toss the page away asap?

Quoted 6 lines
Quoted 3 lines

If it's not working set, it can be reclaimed easily and it can prevent active page demotion since inactive list size would be big enough for not calling shrink_active_list.

What is "working set"? __Mapped and unmapped pagecache, or are you referring solely to mapped pagecache?

I mean it's mapped by other processes.

Quoted 5 lines

If it's mapped pagecache then the user was being a bit silly (or didn't know that some other process had mapped the file). __In which case we need to decide what to do - leave the page alone, deactivate it, or half-deactivate it as this patch does.

What I want is the half-deactivate.

Okay. We will use the result of invalidate_inode_page. If fail happens by page_mapped, we can do half-deactivate. But if fail happens by dirty(ex, writeback), we can add it to tail. Does it make sense?

Quoted 8 lines
Quoted 4 lines

Spose so. __It's unobvious.

If the page is dirty or under writeback then reclaim will immediately move it to the head of the LRU anyway. __But given that the user has

Why does it move into head of LRU?
If the page which isn't mapped doesn't have PG_referenced, it would be reclaimed.

If it's dirty or under writeback it can't be reclaimed!

Quoted 8 lines
Quoted 2 lines

just freed a bunch of pages with invalidate(), it's unlikely that reclaim will be running soon.

If reclaim doesn't start soon, it's good. That's because we have a time to activate it and
when reclaim happens, reclaimer can reclaim pages easily.

If I don't understand your point, could you elaborate on it?

Quoted 9 lines

If reclaim doesn't happen soon and the page was dirty or under writeback (and hence unreclaimable) then there's a better chance that it _will_ be reclaimable by the time reclaim comes along and has a look at it. Yes, that's good.

And a note to Mel: this is one way in which we can get significant (perhaps tremendous) numbers of dirty pages coming off the tail of the LRU, and hence eligible for pageout() treatment.

Agreed. This is why I'd be ok with the pages always being added to the head of the inactive list to take into consideration another process might be using the page (via read/write so it's not very obvious) and to give flusher threads a chance to clean the page. Ideally the pages being deactivated would be prioritised for cleaning but I don't think we have a mechanism for it at the moment.

Signature · 3 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab
#33 lore raw
Quoted 81 lines · Mel Gorman
Quoted 70 lines · Andrew Morton
Quoted 48 lines · On Tue, 23 Nov 2010 14:45:15 +0900 Minchan Kim <[email protected]> wrote:
Quoted 46 lines · Andrew Morton
Quoted 43 lines · On Tue, 23 Nov 2010 14:23:33 +0900 Minchan Kim <[email protected]> wrote:
Quoted 19 lines · Andrew Morton
Quoted 5 lines · On Tue, 23 Nov 2010 13:52:05 +0900 Minchan Kim <[email protected]> wrote:
Quoted 5 lines
Quoted 4 lines

+/*
+ * Function used to forecefully demote a page to the head of the inactive
+ * list.
+ */

Quoted 7 lines
Quoted 2 lines

This comment is wrong? __The page gets moved to the _tail_ of the inactive list?

No. I add it in _head_ of the inactive list intentionally. Why I don't add it to _tail_ is that I don't want to be aggressive. The page might be real working set. So I want to give a chance to activate it again.

Well.. __why? __The user just tried to toss the page away altogether. __If the kernel wasn't able to do that immediately, the best it can do is to toss the page away asap?

Quoted 6 lines
Quoted 3 lines

If it's not working set, it can be reclaimed easily and it can prevent active page demotion since inactive list size would be big enough for not calling shrink_active_list.

What is "working set"? __Mapped and unmapped pagecache, or are you referring solely to mapped pagecache?

I mean it's mapped by other processes.

Quoted 5 lines

If it's mapped pagecache then the user was being a bit silly (or didn't know that some other process had mapped the file). __In which case we need to decide what to do - leave the page alone, deactivate it, or half-deactivate it as this patch does.

What I want is the half-deactivate.

Okay. We will use the result of invalidate_inode_page. If fail happens by page_mapped, we can do half-deactivate. But if fail happens by dirty(ex, writeback), we can add it to tail. Does it make sense?

Quoted 8 lines
Quoted 4 lines

Spose so. __It's unobvious.

If the page is dirty or under writeback then reclaim will immediately move it to the head of the LRU anyway. __But given that the user has

Why does it move into head of LRU?
If the page which isn't mapped doesn't have PG_referenced, it would be reclaimed.

If it's dirty or under writeback it can't be reclaimed!

Quoted 8 lines
Quoted 2 lines

just freed a bunch of pages with invalidate(), it's unlikely that reclaim will be running soon.

If reclaim doesn't start soon, it's good. That's because we have a time to activate it and
when reclaim happens, reclaimer can reclaim pages easily.

If I don't understand your point, could you elaborate on it?

Quoted 9 lines

If reclaim doesn't happen soon and the page was dirty or under writeback (and hence unreclaimable) then there's a better chance that it _will_ be reclaimable by the time reclaim comes along and has a look at it.  Yes, that's good.

And a note to Mel: this is one way in which we can get significant (perhaps tremendous) numbers of dirty pages coming off the tail of the LRU, and hence eligible for pageout() treatment.

Quoted 6 lines

Agreed. This is why I'd be ok with the pages always being added to the head of the inactive list to take into consideration another process might be using the page (via read/write so it's not very obvious) and to give flusher threads a chance to clean the page. Ideally the pages being deactivated would be prioritised for cleaning but I don't think we have a mechanism for it at the moment.

In view point of reclaim, it's right. but might not for efficient write. If we have a such mechanism, current pageout effect(random write) could happen still.
I think what we can do is to prevent writeout by pageout. For it, it's good to put the page head of inacitve and as soon as write complete, we move the page to tail of inactive.

Quoted 6 lines

--
Mel Gorman
Part-time Phd Student                          Linux Technology Center University of Limerick                         IBM Dublin Software Lab

Signature · 2 lines
Kind regards,
Minchan Kim
#34 lore raw
In reply to Andrew Morton
Quoted 10 lines · Andrew Morton
Quoted 8 lines · On Tue, 23 Nov 2010 13:52:05 +0900 Minchan Kim <[email protected]> wrote:
Quoted 7 lines
Quoted 4 lines

+/*
+ * Function used to forecefully demote a page to the head of the inactive
+ * list.
+ */

This comment is wrong? __The page gets moved to the _tail_ of the inactive list?

Quoted 9 lines
Quoted 4 lines

No. I add it in _head_ of the inactive list intentionally. Why I don't add it to _tail_ is that I don't want to be aggressive. The page might be real working set. So I want to give a chance to activate it again.

Well.. why? The user just tried to toss the page away altogether. If the kernel wasn't able to do that immediately, the best it can do is to toss the page away asap?

I'm just guessing here on the motivation but maybe it is in case FADV_DONENEED was called on a page in use by another process (via read/write more do than being mapped). Process A says "I don't need this" but by moving it to the head of the list we give Process B a chance to reference it and reactivate without incurring a major fault?

Quoted 4 lines
Quoted 3 lines

If it's not working set, it can be reclaimed easily and it can prevent active page demotion since inactive list size would be big enough for not calling shrink_active_list.

Quoted 8 lines

What is "working set"? Mapped and unmapped pagecache, or are you referring solely to mapped pagecache?

If it's mapped pagecache then the user was being a bit silly (or didn't know that some other process had mapped the file). In which case we need to decide what to do - leave the page alone, deactivate it, or half-deactivate it as this patch does.

What are the odds of an fadvise() user having used mincore() in advance to determine if the page was in use by another process? I would guess "low" so this half-deactivate gives a chance for the page to be promoted again as well as a chance for the flusher threads to clean the page if it really is to be reclaimed.

Signature · 10 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#35 lore raw
Quoted 6 lines · Mel Gorman
Quoted 5 lines

If it's mapped pagecache then the user was being a bit silly (or didn't know that some other process had mapped the file). In which case we need to decide what to do - leave the page alone, deactivate it, or half-deactivate it as this patch does.

Quoted 6 lines

What are the odds of an fadvise() user having used mincore() in advance to determine if the page was in use by another process? I would guess "low" so this half-deactivate gives a chance for the page to be promoted again as well as a chance for the flusher threads to clean the page if it really is to be reclaimed.

Do we really want to make the user jump through such hoops as using mincore() just to get the kernel to handle use-once pages properly? I hope the answer is no. I know that fadvise isn't supposed to be a magic bullet, but it would be nice if more processes would use it to indicate their access patterns and the only way that will happen is if it is reasonably straightforward to use.

- Ben

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#36 lore raw
Quoted 7 lines · Ben Gamari
Quoted 6 lines · Mel Gorman
Quoted 5 lines

If it's mapped pagecache then the user was being a bit silly (or didn't know that some other process had mapped the file). In which case we need to decide what to do - leave the page alone, deactivate it, or half-deactivate it as this patch does.

Quoted 8 lines
Quoted 6 lines

What are the odds of an fadvise() user having used mincore() in advance to determine if the page was in use by another process? I would guess "low" so this half-deactivate gives a chance for the page to be promoted again as well as a chance for the flusher threads to clean the page if it really is to be reclaimed.

Do we really want to make the user jump through such hoops as using mincore() just to get the kernel to handle use-once pages properly?

I would think "no" which is why I support half-deactivating pages so they won't have to. The downside is that it's essentially a race window as another process needs to reactivate the page before it gets reclaimed to avoid a major fault.

Quoted 7 lines

I hope the answer is no. I know that fadvise isn't supposed to be a magic bullet, but it would be nice if more processes would use it to indicate their access patterns and the only way that will happen is if it is reasonably straightforward to use.

- Ben

Signature · 3 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab
maintainer
#37 lore raw
Quoted 14 lines · On Tue, 23 Nov 2010 14:58:56 +0000 Mel Gorman <[email protected]> wrote:
Quoted 13 lines · Ben Gamari
Quoted 12 lines · Mel Gorman
Quoted 5 lines

If it's mapped pagecache then the user was being a bit silly (or didn't know that some other process had mapped the file). In which case we need to decide what to do - leave the page alone, deactivate it, or half-deactivate it as this patch does.

What are the odds of an fadvise() user having used mincore() in advance to determine if the page was in use by another process? I would guess "low" so this half-deactivate gives a chance for the page to be promoted again as well as a chance for the flusher threads to clean the page if it really is to be reclaimed.

Quoted 5 lines
Quoted 2 lines

Do we really want to make the user jump through such hoops as using mincore() just to get the kernel to handle use-once pages properly?

I would think "no" which is why I support half-deactivating pages so they won't have to.

If the page is page_mapped() then we can assume that some other process is using it and we leave it alone *altogether*.

If the page is dirty or under writeback (and !page_mapped()) then we should assume that we should free it asap. The PageReclaim() trick might help with that.

I just don't see any argument for moving the page to the head of the inactive LRU as a matter of policy. We can park it there because we can't think of anythnig else to do with it, but it's the wrong place for it.

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#38 lore raw
Quoted 17 lines · Andrew Morton
Quoted 14 lines · On Tue, 23 Nov 2010 14:58:56 +0000 Mel Gorman <[email protected]> wrote:
Quoted 13 lines · Ben Gamari
Quoted 12 lines · Mel Gorman
Quoted 5 lines

If it's mapped pagecache then the user was being a bit silly (or didn't know that some other process had mapped the file). In which case we need to decide what to do - leave the page alone, deactivate it, or half-deactivate it as this patch does.

What are the odds of an fadvise() user having used mincore() in advance to determine if the page was in use by another process? I would guess "low" so this half-deactivate gives a chance for the page to be promoted again as well as a chance for the flusher threads to clean the page if it really is to be reclaimed.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Do we really want to make the user jump through such hoops as using mincore() just to get the kernel to handle use-once pages properly?

I would think "no" which is why I support half-deactivating pages so they won't have to.

If the page is page_mapped() then we can assume that some other process is using it and we leave it alone *altogether*.

Agreed, that makes perfect sense.

Quoted 4 lines

If the page is dirty or under writeback (and !page_mapped()) then we should assume that we should free it asap. The PageReclaim() trick might help with that.

Again agreed.

Quoted 5 lines

I just don't see any argument for moving the page to the head of the inactive LRU as a matter of policy. We can park it there because we can't think of anythnig else to do with it, but it's the wrong place for it.

Is there a better alternative? One thing that springs to mind is that we are not exactly tracking very well what effect these policy changes have. The analysis scripts I have do a reasonable job on tracking reclaim activity (although only as part of the mmtests tarball, I should split them out as a standalone tool) but not the impact - namely minor and major faults. I should sort that out so we can put better reclaim analysis in place.

Signature · 10 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#39 lore raw
Quoted 43 lines · Mel Gorman
Quoted 17 lines · Andrew Morton
Quoted 14 lines · On Tue, 23 Nov 2010 14:58:56 +0000 Mel Gorman <[email protected]> wrote:
Quoted 13 lines · Ben Gamari
Quoted 12 lines · Mel Gorman
Quoted 5 lines

If it's mapped pagecache then the user was being a bit silly (or didn't know that some other process had mapped the file).  In which case we need to decide what to do - leave the page alone, deactivate it, or half-deactivate it as this patch does.

What are the odds of an fadvise() user having used mincore() in advance to determine if the page was in use by another process? I would guess "low" so this half-deactivate gives a chance for the page to be promoted again as well as a chance for the flusher threads to clean the page if it really is to be reclaimed.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Do we really want to make the user jump through such hoops as using mincore() just to get the kernel to handle use-once pages properly?

I would think "no" which is why I support half-deactivating pages so they won't have to.

If the page is page_mapped() then we can assume that some other process is using it and we leave it alone *altogether*.

Agreed, that makes perfect sense.

Quoted 4 lines

If the page is dirty or under writeback (and !page_mapped()) then we should assume that we should free it asap.  The PageReclaim() trick might help with that.

Again agreed.

Quoted 5 lines

I just don't see any argument for moving the page to the head of the inactive LRU as a matter of policy.  We can park it there because we can't think of anythnig else to do with it, but it's the wrong place for it.

Quoted 6 lines

Is there a better alternative? One thing that springs to mind is that we are not exactly tracking very well what effect these policy changes have. The analysis scripts I have do a reasonable job on tracking reclaim activity (although only as part of the mmtests tarball, I should split them out as a standalone tool) but not the impact - namely minor and major faults. I should sort that out so we can put better reclaim analysis in place.

It can help very much. :)

Also, I need time since I am so busy.

Quoted 6 lines

--
Mel Gorman
Part-time Phd Student                          Linux Technology Center University of Limerick                         IBM Dublin Software Lab

Signature · 9 lines
Kind regards,
Minchan Kim

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#40 lore raw
Quoted 14 lines · Minchan Kim
Quoted 7 lines
Quoted 6 lines

I just don't see any argument for moving the page to the head of the inactive LRU as a matter of policy.  We can park it there because we can't think of anythnig else to do with it, but it's the wrong place for it.

Quoted 6 lines

Is there a better alternative? One thing that springs to mind is that we are not exactly tracking very well what effect these policy changes have. The analysis scripts I have do a reasonable job on tracking reclaim activity (although only as part of the mmtests tarball, I should split them out as a standalone tool) but not the impact - namely minor and major faults. I should sort that out so we can put better reclaim analysis in place.

Quoted 4 lines

It can help very much. :)

Also, I need time since I am so busy.

No worries, I had a framework in place that made it easy enough to collect. The necessary information is available in /proc/vmstat in this case so a tester just needs to record vmstat before and after the target workload runs. For the reclaim/compaction series, a partial run of the series and the subsequent report looks like;

proc vmstat: Faults
traceonly reclaimcompact obeysync
Major Faults 84102 6724 7298
Minor Faults 139704394 138778777 138777304

Page ins                                   4966564   3621280   3569508
Page outs                                 11283328   7980576   7959352

Swap ins 85800 5647 7062
Swap outs 828488 8799 10565

Series acted as expected - major faults were reduced. Minor faults on on the high side which I didn't analyse further. Main thing that it's possible to collect the information on what reclaim is doing and how it affects processes. I don't have anything in place to evaluate this series unfortunately as I haven't automated a workload that depends on the behaviour of fadvise.

Signature · 3 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab
#41 lore raw
In reply to Minchan Kim
Quoted 9 lines

By Other approach, app developer uses POSIX_FADV_DONTNEED. But it has a problem. If kernel meets page is writing during invalidate_mapping_pages, it can't work.
It is very hard for application programmer to use it. Because they always have to sync data before calling fadivse(..POSIX_FADV_DONTNEED) to make sure the pages could be discardable. At last, they can't use deferred write of kernel so that they could see performance loss.
(http://insights.oetiker.ch/linux/fadvise.html)

If rsync use the above url patch, we don't need your patch. fdatasync() + POSIX_FADV_DONTNEED should work fine.

So, I think the core worth of previous PeterZ's patch is in readahead based heuristics. I'm curious why you drop it.

Quoted 3 lines

In fact, invalidate is very big hint to reclaimer. It means we don't use the page any more. So let's move the writing page into inactive list's head.

But, I agree this.

Quoted 71 lines

If it is real working set, it could have a enough time to activate the page since we always try to keep many pages in inactive list.

I reuse lru_demote of Peter with some change.

Cc Rik van Riel <[email protected]>
Cc KOSAKI Motohiro <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Nick Piggin <[email protected]>

Ben, Remain thing is to modify rsync and use
fadvise(POSIX_FADV_DONTNEED). Could you test it?

---
 include/linux/swap.h |    1 +
 mm/swap.c            |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++
 mm/truncate.c        |   11 +++++---
 3 files changed, 69 insertions(+), 4 deletions(-)
include/linux/swap.h +1 -0
index eba53e7..a3c9248 100644
@@ -213,6 +213,7 @@ extern void mark_page_accessed(struct page *);
 extern void lru_add_drain(void);
 extern int lru_add_drain_all(void);
 extern void rotate_reclaimable_page(struct page *page);
+extern void lru_deactive_page(struct page *page);
 extern void swap_setup(void);
 
 extern void add_page_to_unevictable_list(struct page *page);
mm/swap.c +21 -0
index 3f48542..56fa298 100644
@@ -39,6 +39,8 @@ int page_cluster;
 
 static DEFINE_PER_CPU(struct pagevec[NR_LRU_LISTS], lru_add_pvecs);
 static DEFINE_PER_CPU(struct pagevec, lru_rotate_pvecs);
+static DEFINE_PER_CPU(struct pagevec, lru_deactive_pvecs);
+
 
 /*
  * This path almost never happens for VM activity - pages are normally
@@ -266,6 +268,45 @@ void add_page_to_unevictable_list(struct page *page)
 	spin_unlock_irq(&zone->lru_lock);
 }
 
+static void __pagevec_lru_deactive(struct pagevec *pvec)
+{
+	int i, lru, file;
+
+	struct zone *zone = NULL;
+
+	for (i = 0; i < pagevec_count(pvec); i++) {
+		struct page *page = pvec->pages[i];
+		struct zone *pagezone = page_zone(page);
+
+		if (pagezone != zone) {
+			if (zone)
+				spin_unlock_irq(&zone->lru_lock);
+			zone = pagezone;
+			spin_lock_irq(&zone->lru_lock);
+		}
+
+		if (PageLRU(page)) {
+			if (PageActive(page)) {

mm/swap.c void add_page_to_unevictable_list(struct page *page) · line 299

Quoted 10 lines
mm/swap.c +10 -0
+				file = page_is_file_cache(page);
+				lru = page_lru_base_type(page);
+				del_page_from_lru_list(zone, page,
+						lru + LRU_ACTIVE);
+				ClearPageActive(page);
+				ClearPageReferenced(page);
+				add_page_to_lru_list(zone, page, lru);
+				__count_vm_event(PGDEACTIVATE);
+
+				update_page_reclaim_stat(zone, page, file, 0);

When PageActive is unset, we need to change cgroup lru too.

Quoted 20 lines
mm/swap.c +13 -0
+			}
+		}
+	}
+	if (zone)
+		spin_unlock_irq(&zone->lru_lock);
+
+	release_pages(pvec->pages, pvec->nr, pvec->cold);
+	pagevec_reinit(pvec);
+}
+
 /*
  * Drain pages out of the cpu's pagevecs.
  * Either "cpu" is the current CPU, and preemption has already been
@@ -292,8 +333,28 @@ static void drain_cpu_pagevecs(int cpu)
 		pagevec_move_tail(pvec);
 		local_irq_restore(flags);
 	}
+
+	pvec = &per_cpu(lru_deactive_pvecs, cpu);
+	if (pagevec_count(pvec))

mm/swap.c static void drain_cpu_pagevecs(int cpu) · line 348

Quoted 10 lines
mm/swap.c +10 -0
+		__pagevec_lru_deactive(pvec);
+}
+
+/*
+ * Function used to forecefully demote a page to the head of the inactive
+ * list.
+ */
+void lru_deactive_page(struct page *page)
+{
+	if (likely(get_page_unless_zero(page))) {

Probably, we can check PageLRU and PageActive here too. It help to avoid unnecessary batching and may slightly increase performance.

Quoted 56 lines
mm/swap.c +7 -0
+		struct pagevec *pvec = &get_cpu_var(lru_deactive_pvecs);
+
+		if (!pagevec_add(pvec, page))
+			__pagevec_lru_deactive(pvec);
+		put_cpu_var(lru_deactive_pvecs);
+	}
 }
 
+
 void lru_add_drain(void)
 {
 	drain_cpu_pagevecs(get_cpu());
mm/truncate.c +7 -4
index cd94607..c73fb19 100644
@@ -332,7 +332,8 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
 {
 	struct pagevec pvec;
 	pgoff_t next = start;
-	unsigned long ret = 0;
+	unsigned long ret;
+	unsigned long count = 0;
 	int i;
 
 	pagevec_init(&pvec, 0);
@@ -359,8 +360,10 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
 			if (lock_failed)
 				continue;
 
-			ret += invalidate_inode_page(page);
-
+			ret = invalidate_inode_page(page);
+			if (!ret)
+				lru_deactive_page(page);
+			count += ret;
 			unlock_page(page);
 			if (next > end)
 				break;
@@ -369,7 +372,7 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
 		mem_cgroup_uncharge_end();
 		cond_resched();
 	}
-	return ret;
+	return count;
 }
 EXPORT_SYMBOL(invalidate_mapping_pages);
 
Signature · 7 lines
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#42 lore raw

Hi KOSAKI,

2010/11/23 KOSAKI Motohiro <[email protected]>:

Quoted 10 lines
Quoted 9 lines

By Other approach, app developer uses POSIX_FADV_DONTNEED. But it has a problem. If kernel meets page is writing during invalidate_mapping_pages, it can't work.
It is very hard for application programmer to use it. Because they always have to sync data before calling fadivse(..POSIX_FADV_DONTNEED) to make sure the pages could be discardable. At last, they can't use deferred write of kernel so that they could see performance loss.
(http://insights.oetiker.ch/linux/fadvise.html)

Quoted 2 lines

If rsync use the above url patch, we don't need your patch. fdatasync() + POSIX_FADV_DONTNEED should work fine.

It works well. But it needs always fdatasync before calling fadvise. For small file, it hurt performance since we can't use the deferred write.

Quoted 4 lines

So, I think the core worth of previous PeterZ's patch is in readahead based heuristics. I'm curious why you drop it.

In previous peter's patch, it couldn't move active page into inactive list. So it's not what i want and I think invalidation is stronger hint than the readahead heuristic.
But if we need it, I will add it in my series. It can help reclaiming unnecessary inactive page asap.
but before that, I hope we make sure fadvise works well enough.

Quoted 6 lines
Quoted 4 lines

In fact, invalidate is very big hint to reclaimer. It means we don't use the page any more. So let's move the writing page into inactive list's head.

But, I agree this.

Thank you.

Quoted 77 lines
Quoted 77 lines

If it is real working set, it could have a enough time to activate the page since we always try to keep many pages in inactive list.

I reuse lru_demote of Peter with some change.

Cc Rik van Riel <[email protected]>
Cc KOSAKI Motohiro <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Nick Piggin <[email protected]>

Ben, Remain thing is to modify rsync and use fadvise(POSIX_FADV_DONTNEED). Could you test it?
---
 include/linux/swap.h |    1 +
 mm/swap.c            |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++ mm/truncate.c        |   11 +++++---

 3 files changed, 69 insertions(+), 4 deletions(-)
include/linux/swap.h +1 -0
index eba53e7..a3c9248 100644
@@ -213,6 +213,7 @@ extern void mark_page_accessed(struct page *);
  extern void lru_add_drain(void);
  extern int lru_add_drain_all(void);
  extern void rotate_reclaimable_page(struct page *page);
+extern void lru_deactive_page(struct page *page);
  extern void swap_setup(void);
 
  extern void add_page_to_unevictable_list(struct page *page);
mm/swap.c +25 -0
index 3f48542..56fa298 100644
@@ -39,6 +39,8 @@ int page_cluster;
 
  static DEFINE_PER_CPU(struct pagevec[NR_LRU_LISTS], lru_add_pvecs);
  static DEFINE_PER_CPU(struct pagevec, lru_rotate_pvecs);
+static DEFINE_PER_CPU(struct pagevec, lru_deactive_pvecs);
+
 
  /*
   * This path almost never happens for VM activity - pages are normally
@@ -266,6 +268,45 @@ void add_page_to_unevictable_list(struct page *page)
       spin_unlock_irq(&zone->lru_lock);
  }
 
+static void __pagevec_lru_deactive(struct pagevec *pvec)
+{
+     int i, lru, file;
+
+     struct zone *zone = NULL;
+
+     for (i = 0; i < pagevec_count(pvec); i++) {
+             struct page *page = pvec->pages[i];
+             struct zone *pagezone = page_zone(page);
+
+             if (pagezone != zone) {
+                     if (zone)
+                             spin_unlock_irq(&zone->lru_lock);
+                     zone = pagezone;
+                     spin_lock_irq(&zone->lru_lock);
+             }
+
+             if (PageLRU(page)) {
+                     if (PageActive(page)) {
+                             file = page_is_file_cache(page);
+                             lru = page_lru_base_type(page);
+                             del_page_from_lru_list(zone, page,
+                                             lru + LRU_ACTIVE);
Quoted 8 lines

mm/swap.c void add_page_to_unevictable_list(struct page *page) · line 299

Quoted 6 lines
mm/swap.c +6 -0
+                             ClearPageActive(page);
+                             ClearPageReferenced(page);
+                             add_page_to_lru_list(zone, page, lru);
+                             __count_vm_event(PGDEACTIVATE);
+
+                             update_page_reclaim_stat(zone, page, file, 0);

When PageActive is unset, we need to change cgroup lru too.

Doesn't add_page_to_lru_list/del_page_from_lru_list do it?

Quoted 27 lines
Quoted 27 lines
mm/swap.c +18 -0
+                     }
+             }
+     }
+     if (zone)
+             spin_unlock_irq(&zone->lru_lock);
+
+     release_pages(pvec->pages, pvec->nr, pvec->cold);
+     pagevec_reinit(pvec);
+}
+
  /*
   * Drain pages out of the cpu's pagevecs.
   * Either "cpu" is the current CPU, and preemption has already been
@@ -292,8 +333,28 @@ static void drain_cpu_pagevecs(int cpu)
               pagevec_move_tail(pvec);
               local_irq_restore(flags);
       }
+
+     pvec = &per_cpu(lru_deactive_pvecs, cpu);
+     if (pagevec_count(pvec))
+             __pagevec_lru_deactive(pvec);
+}
+
+/*
+ * Function used to forecefully demote a page to the head of the inactive
Quoted 8 lines

mm/swap.c static void drain_cpu_pagevecs(int cpu) · line 348

Quoted 5 lines
mm/swap.c +5 -0
+ * list.
+ */
+void lru_deactive_page(struct page *page)
+{
+     if (likely(get_page_unless_zero(page))) {

Probably, we can check PageLRU and PageActive here too. It help to avoid unnecessary batching and may slightly increase performance.

Yes. Thanks. Will fix.

Quoted 62 lines
Quoted 58 lines
mm/swap.c +7 -0
+             struct pagevec *pvec = &get_cpu_var(lru_deactive_pvecs);
+
+             if (!pagevec_add(pvec, page))
+                     __pagevec_lru_deactive(pvec);
+             put_cpu_var(lru_deactive_pvecs);
+     }
  }
 
+
  void lru_add_drain(void)
  {
       drain_cpu_pagevecs(get_cpu());
mm/truncate.c +7 -5
index cd94607..c73fb19 100644
@@ -332,7 +332,8 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
  {
       struct pagevec pvec;
       pgoff_t next = start;
-     unsigned long ret = 0;
+     unsigned long ret;
+     unsigned long count = 0;
       int i;
 
       pagevec_init(&pvec, 0);
@@ -359,8 +360,10 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
                       if (lock_failed)
                               continue;
 
-                     ret += invalidate_inode_page(page);
-
+                     ret = invalidate_inode_page(page);
+                     if (!ret)
+                             lru_deactive_page(page);
+                     count += ret;
                       unlock_page(page);
                       if (next > end)
                               break;
@@ -369,7 +372,7 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
               mem_cgroup_uncharge_end();
               cond_resched();
       }
-     return ret;
+     return count;
  }
  EXPORT_SYMBOL(invalidate_mapping_pages);
 
--

1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Signature · 2 lines
Kind regards,
Minchan Kim
maintainer
#43 lore raw
Quoted 13 lines · On Tue, 23 Nov 2010 16:40:03 +0900 Minchan Kim <[email protected]> wrote:

Hi KOSAKI,

2010/11/23 KOSAKI Motohiro <[email protected]>:

Quoted 10 lines
Quoted 9 lines

By Other approach, app developer uses POSIX_FADV_DONTNEED. But it has a problem. If kernel meets page is writing during invalidate_mapping_pages, it can't work.
It is very hard for application programmer to use it. Because they always have to sync data before calling fadivse(..POSIX_FADV_DONTNEED) to make sure the pages could be discardable. At last, they can't use deferred write of kernel so that they could see performance loss.
(http://insights.oetiker.ch/linux/fadvise.html)

Quoted 5 lines
Quoted 2 lines

If rsync use the above url patch, we don't need your patch. fdatasync() + POSIX_FADV_DONTNEED should work fine.

It works well. But it needs always fdatasync before calling fadvise. For small file, it hurt performance since we can't use the deferred write.

fdatasync() is (much) better than nothing, but a userspace application which is carefully managing its IO scheduling should use sync_file_range(SYNC_FILE_RANGE_WRITE) to push data at the disk and should then run fadvise(DONTNEED) against the same data a few seconds later, after the IO has completed.

That way, the application won't block against the write I/O at all, unless of course someone else is thrashing the disk as well, etc.

If the app is doing a lot of file I/O (eg, rsync) then this shouldn't be too hard to arrange. Although the payback will be pretty small unless the IO-intensive process is also compute-intensive at times. And such applications are a) fairly rare and b) poorly designed:
shouldn't be doing heavy IO and heavy compute in the same thread!

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#44 lore raw
In reply to Minchan Kim
Quoted 13 lines

Hi KOSAKI,

2010/11/23 KOSAKI Motohiro <[email protected]>:

Quoted 10 lines
Quoted 9 lines

By Other approach, app developer uses POSIX_FADV_DONTNEED. But it has a problem. If kernel meets page is writing during invalidate_mapping_pages, it can't work.
It is very hard for application programmer to use it. Because they always have to sync data before calling fadivse(..POSIX_FADV_DONTNEED) to make sure the pages could be discardable. At last, they can't use deferred write of kernel so that they could see performance loss.
(http://insights.oetiker.ch/linux/fadvise.html)

Quoted 5 lines
Quoted 2 lines

If rsync use the above url patch, we don't need your patch. fdatasync() + POSIX_FADV_DONTNEED should work fine.

It works well. But it needs always fdatasync before calling fadvise. For small file, it hurt performance since we can't use the deferred write.

I doubt rsync need to call fdatasync. Why?

If rsync continue to do following loop, some POSIX_FADV_DONTNEED may not drop some dirty pages. But they can be dropped at next loop's POSIX_FADV_DONTNEED. Then, It doesn't make serious issue.

1) read
2) write
3) POSIX_FADV_DONTNEED
4) goto 1

Am I missing anything?

Quoted 10 lines
Quoted 3 lines

So, I think the core worth of previous PeterZ's patch is in readahead based heuristics. I'm curious why you drop it.

In previous peter's patch, it couldn't move active page into inactive list. So it's not what i want and I think invalidation is stronger hint than the readahead heuristic.
But if we need it, I will add it in my series. It can help reclaiming unnecessary inactive page asap.
but before that, I hope we make sure fadvise works well enough.

I've got it.Yeah, 1) implement manual oepration 2) add automatic heuristic is right order. I think. we can easily test your one.

Quoted 40 lines
Quoted 5 lines
Quoted 3 lines

In fact, invalidate is very big hint to reclaimer. It means we don't use the page any more. So let's move the writing page into inactive list's head.

But, I agree this.

Thank you.

Quoted 23 lines
Quoted 23 lines
mm/swap.c +23 -0
+static void __pagevec_lru_deactive(struct pagevec *pvec)
+{
+     int i, lru, file;
+
+     struct zone *zone = NULL;
+
+     for (i = 0; i < pagevec_count(pvec); i++) {
+             struct page *page = pvec->pages[i];
+             struct zone *pagezone = page_zone(page);
+
+             if (pagezone != zone) {
+                     if (zone)
+                             spin_unlock_irq(&zone->lru_lock);
+                     zone = pagezone;
+                     spin_lock_irq(&zone->lru_lock);
+             }
+
+             if (PageLRU(page)) {
+                     if (PageActive(page)) {
+                             file = page_is_file_cache(page);
+                             lru = page_lru_base_type(page);
+                             del_page_from_lru_list(zone, page,
+                                             lru + LRU_ACTIVE);
Quoted 8 lines
Quoted 6 lines

+                             ClearPageActive(page);
+                             ClearPageReferenced(page);
+                             add_page_to_lru_list(zone, page, lru);
+                             __count_vm_event(PGDEACTIVATE);
+
+                             update_page_reclaim_stat(zone, page, file, 0);

When PageActive is unset, we need to change cgroup lru too.

Quoted 1 line

Doesn't add_page_to_lru_list/del_page_from_lru_list do it?

Grr, my fault. I've forgot to we changed add_page_to_lru_list.

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#45 lore raw
Quoted 21 lines · KOSAKI Motohiro
Quoted 13 lines

Hi KOSAKI,

2010/11/23 KOSAKI Motohiro <[email protected]>:

Quoted 10 lines
Quoted 9 lines

By Other approach, app developer uses POSIX_FADV_DONTNEED. But it has a problem. If kernel meets page is writing during invalidate_mapping_pages, it can't work.
It is very hard for application programmer to use it. Because they always have to sync data before calling fadivse(..POSIX_FADV_DONTNEED) to make sure the pages could be discardable. At last, they can't use deferred write of kernel so that they could see performance loss.
(http://insights.oetiker.ch/linux/fadvise.html)

Quoted 5 lines
Quoted 2 lines

If rsync use the above url patch, we don't need your patch. fdatasync() + POSIX_FADV_DONTNEED should work fine.

It works well. But it needs always fdatasync before calling fadvise. For small file, it hurt performance since we can't use the deferred write.

I doubt rsync need to call fdatasync. Why?

Quoted 8 lines

If rsync continue to do following loop, some POSIX_FADV_DONTNEED may not drop some dirty pages. But they can be dropped at next loop's POSIX_FADV_DONTNEED. Then, It doesn't make serious issue.

1) read
2) write
3) POSIX_FADV_DONTNEED
4) goto 1

fadvise need pair (offset and len).
if the pair in next turn is different with one's previous turn, it couldn't be dropped.

Signature · 9 lines
Kind regards,
Minchan Kim

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#46 lore raw
Quoted 27 lines
Quoted 25 lines · KOSAKI Motohiro
Quoted 13 lines

Hi KOSAKI,

2010/11/23 KOSAKI Motohiro <[email protected]>:

Quoted 10 lines
Quoted 9 lines

By Other approach, app developer uses POSIX_FADV_DONTNEED. But it has a problem. If kernel meets page is writing during invalidate_mapping_pages, it can't work.
It is very hard for application programmer to use it. Because they always have to sync data before calling fadivse(..POSIX_FADV_DONTNEED) to make sure the pages could be discardable. At last, they can't use deferred write of kernel so that they could see performance loss.
(http://insights.oetiker.ch/linux/fadvise.html)

Quoted 5 lines
Quoted 2 lines

If rsync use the above url patch, we don't need your patch. fdatasync() + POSIX_FADV_DONTNEED should work fine.

It works well. But it needs always fdatasync before calling fadvise. For small file, it hurt performance since we can't use the deferred write.

I doubt rsync need to call fdatasync. Why?

If rsync continue to do following loop, some POSIX_FADV_DONTNEED may not drop some dirty pages. But they can be dropped at next loop's POSIX_FADV_DONTNEED. Then, It doesn't make serious issue.

Quoted 8 lines
Quoted 4 lines

1) read
2) write
3) POSIX_FADV_DONTNEED
4) goto 1

fadvise need pair (offset and len).
if the pair in next turn is different with one's previous turn, it couldn't be dropped.

invalidate_mapping_pages() are using pagevec_lookup() and pagevec_lookup() are using radix tree lookup. Then, Even if rsync always use [0, inf) pair, I don't think it makes much slowdown.

#47 lore raw
Quoted 32 lines · KOSAKI Motohiro
Quoted 32 lines
Quoted 29 lines · KOSAKI Motohiro
Quoted 13 lines

Hi KOSAKI,

2010/11/23 KOSAKI Motohiro <[email protected]>:

Quoted 10 lines
Quoted 9 lines

By Other approach, app developer uses POSIX_FADV_DONTNEED. But it has a problem. If kernel meets page is writing during invalidate_mapping_pages, it can't work.
It is very hard for application programmer to use it. Because they always have to sync data before calling fadivse(..POSIX_FADV_DONTNEED) to make sure the pages could be discardable. At last, they can't use deferred write of kernel so that they could see performance loss.
(http://insights.oetiker.ch/linux/fadvise.html)

Quoted 5 lines
Quoted 2 lines

If rsync use the above url patch, we don't need your patch. fdatasync() + POSIX_FADV_DONTNEED should work fine.

It works well. But it needs always fdatasync before calling fadvise. For small file, it hurt performance since we can't use the deferred write.

I doubt rsync need to call fdatasync. Why?

If rsync continue to do following loop, some POSIX_FADV_DONTNEED may not drop some dirty pages. But they can be dropped at next loop's POSIX_FADV_DONTNEED. Then, It doesn't make serious issue.

1) read
2) write
3) POSIX_FADV_DONTNEED
4) goto 1

Quoted 8 lines
Quoted 3 lines

fadvise need pair (offset and len).
if the pair in next turn is different with one's previous turn, it couldn't be dropped.

invalidate_mapping_pages() are using pagevec_lookup() and pagevec_lookup() are using radix tree lookup. Then, Even if rsync always use [0, inf) pair, I don't think it makes much slowdown.

I mean fdatasync causes slowdown, not fadvise.
if you fadvise(don't need) without fdatasync, you could loss the data.

Signature · 9 lines
Kind regards,
Minchan Kim

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#48 lore raw
Quoted 38 lines · Minchan Kim
Quoted 36 lines · KOSAKI Motohiro
Quoted 35 lines
Quoted 21 lines · KOSAKI Motohiro
Quoted 13 lines

Hi KOSAKI,

2010/11/23 KOSAKI Motohiro <[email protected]>:

Quoted 10 lines
Quoted 9 lines

By Other approach, app developer uses POSIX_FADV_DONTNEED. But it has a problem. If kernel meets page is writing during invalidate_mapping_pages, it can't work.
It is very hard for application programmer to use it. Because they always have to sync data before calling fadivse(..POSIX_FADV_DONTNEED) to make sure the pages could be discardable. At last, they can't use deferred write of kernel so that they could see performance loss.
(http://insights.oetiker.ch/linux/fadvise.html)

Quoted 5 lines
Quoted 2 lines

If rsync use the above url patch, we don't need your patch. fdatasync() + POSIX_FADV_DONTNEED should work fine.

It works well. But it needs always fdatasync before calling fadvise. For small file, it hurt performance since we can't use the deferred write.

I doubt rsync need to call fdatasync. Why?

Quoted 8 lines

If rsync continue to do following loop, some POSIX_FADV_DONTNEED may not drop some dirty pages. But they can be dropped at next loop's POSIX_FADV_DONTNEED. Then, It doesn't make serious issue.

1) read
2) write
3) POSIX_FADV_DONTNEED
4) goto 1

fadvise need pair (offset and len).
if the pair in next turn is different with one's previous turn, it couldn't be dropped.

Quoted 7 lines
Quoted 4 lines

invalidate_mapping_pages() are using pagevec_lookup() and pagevec_lookup() are using radix tree lookup. Then, Even if rsync always use [0, inf) pair, I don't think it makes much slowdown.

I mean fdatasync causes slowdown, not fadvise.
if you fadvise(don't need) without fdatasync, you could loss the data.

Oops sorry. Not lose data.
Frequent fdatasync call doesn't use buffered write so that it causes slowdown than using deferred write.

Quoted 4 lines

--
Kind regards,
Minchan Kim

Signature · 9 lines
Kind regards,
Minchan Kim

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#49 lore raw
In reply to KOSAKI Motohiro
Quoted 10 lines · KOSAKI Motohiro
Quoted 9 lines

By Other approach, app developer uses POSIX_FADV_DONTNEED. But it has a problem. If kernel meets page is writing during invalidate_mapping_pages, it can't work.
It is very hard for application programmer to use it. Because they always have to sync data before calling fadivse(..POSIX_FADV_DONTNEED) to make sure the pages could be discardable. At last, they can't use deferred write of kernel so that they could see performance loss.
(http://insights.oetiker.ch/linux/fadvise.html)

Quoted 3 lines

If rsync use the above url patch, we don't need your patch. fdatasync() + POSIX_FADV_DONTNEED should work fine.

This is quite true, but the patch itself is fairly invasive and unnecessarily so which makes it unsuitable for merging in the eyes of the rsync maintainers (not that I can blame them). This is by no fault of its author; using fadvise is just far harder than it should be.

- Ben

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#50 lore raw
Quoted 11 lines · KOSAKI Motohiro
Quoted 10 lines
Quoted 9 lines

By Other approach, app developer uses POSIX_FADV_DONTNEED. But it has a problem. If kernel meets page is writing during invalidate_mapping_pages, it can't work.
It is very hard for application programmer to use it. Because they always have to sync data before calling fadivse(..POSIX_FADV_DONTNEED) to make sure the pages could be discardable. At last, they can't use deferred write of kernel so that they could see performance loss.
(http://insights.oetiker.ch/linux/fadvise.html)

Quoted 7 lines
Quoted 3 lines

If rsync use the above url patch, we don't need your patch. fdatasync() + POSIX_FADV_DONTNEED should work fine.

This is quite true, but the patch itself is fairly invasive and unnecessarily so which makes it unsuitable for merging in the eyes of the rsync maintainers (not that I can blame them). This is by no fault of its author; using fadvise is just far harder than it should be.

Yeah. I agree with this patch don't have negative impact. I was only curious why Minchan drop autodetect logic.

Please don't think I'm against your effort.

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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#51 lore raw
In reply to Minchan Kim
Quoted 73 lines · Minchan Kim

Recently, there are reported problem about thrashing.
(http://marc.info/?l=rsync&m=128885034930933&w=2)
It happens by backup workloads(ex, nightly rsync). That's because the workload makes just use-once pages and touches pages twice. It promotes the page into active list so that it results in working set page eviction.

Some app developer want to support POSIX_FADV_NOREUSE. But other OSes don't support it, either.
(http://marc.info/?l=linux-mm&m=128928979512086&w=2)

By Other approach, app developer uses POSIX_FADV_DONTNEED. But it has a problem. If kernel meets page is writing during invalidate_mapping_pages, it can't work.
It is very hard for application programmer to use it. Because they always have to sync data before calling fadivse(..POSIX_FADV_DONTNEED) to make sure the pages could be discardable. At last, they can't use deferred write of kernel so that they could see performance loss.
(http://insights.oetiker.ch/linux/fadvise.html)

In fact, invalidate is very big hint to reclaimer. It means we don't use the page any more. So let's move the writing page into inactive list's head.

If it is real working set, it could have a enough time to activate the page since we always try to keep many pages in inactive list.

I reuse lru_demote of Peter with some change.

Cc Rik van Riel <[email protected]>
Cc KOSAKI Motohiro <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Nick Piggin <[email protected]>

Ben, Remain thing is to modify rsync and use fadvise(POSIX_FADV_DONTNEED). Could you test it?

---
 include/linux/swap.h |    1 +
 mm/swap.c            |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++
 mm/truncate.c        |   11 +++++---
 3 files changed, 69 insertions(+), 4 deletions(-)
include/linux/swap.h +1 -0
index eba53e7..a3c9248 100644
@@ -213,6 +213,7 @@ extern void mark_page_accessed(struct page *);
 extern void lru_add_drain(void);
 extern int lru_add_drain_all(void);
 extern void rotate_reclaimable_page(struct page *page);
+extern void lru_deactive_page(struct page *page);
 extern void swap_setup(void);
 
 extern void add_page_to_unevictable_list(struct page *page);
mm/swap.c +2 -0
index 3f48542..56fa298 100644
@@ -39,6 +39,8 @@ int page_cluster;
 
 static DEFINE_PER_CPU(struct pagevec[NR_LRU_LISTS], lru_add_pvecs);
 static DEFINE_PER_CPU(struct pagevec, lru_rotate_pvecs);
+static DEFINE_PER_CPU(struct pagevec, lru_deactive_pvecs);
+
 
 /*
  * This path almost never happens for VM activity - pages are normally

mm/swap.c void add_page_to_unevictable_list(struct page *page) · line 272

Quoted 5 lines
mm/swap.c +2 -0
@@ -266,6 +268,45 @@ void add_page_to_unevictable_list(struct page *page)
 	spin_unlock_irq(&zone->lru_lock);
 }
 
+static void __pagevec_lru_deactive(struct pagevec *pvec)
+{

Might be worth commenting that this function must be called with pre-emption disabled. FWIW, I am reasonably sure your implementation is prefectly safe but a note wouldn't hurt.

Quoted 16 lines
mm/swap.c +16 -0
+	int i, lru, file;
+
+	struct zone *zone = NULL;
+
+	for (i = 0; i < pagevec_count(pvec); i++) {
+		struct page *page = pvec->pages[i];
+		struct zone *pagezone = page_zone(page);
+
+		if (pagezone != zone) {
+			if (zone)
+				spin_unlock_irq(&zone->lru_lock);
+			zone = pagezone;
+			spin_lock_irq(&zone->lru_lock);
+		}
+
+		if (PageLRU(page)) {

mm/swap.c void add_page_to_unevictable_list(struct page *page) · line 298

Quoted 10 lines
mm/swap.c +10 -0
+			if (PageActive(page)) {
+				file = page_is_file_cache(page);
+				lru = page_lru_base_type(page);
+				del_page_from_lru_list(zone, page,
+						lru + LRU_ACTIVE);
+				ClearPageActive(page);
+				ClearPageReferenced(page);
+				add_page_to_lru_list(zone, page, lru);
+				__count_vm_event(PGDEACTIVATE);
+

What about memcg, do we not need to be calling mem_cgroup_add_lru_list() here as well? I'm looking at the differences between what move_active_pages_to_lru() is doing and this. I'm wondering if it'd be worth your whole building a list of active pages that are to be moved to the inactive list and passing them to move_active_pages_to_lru() ? I confuess I have not thought about it deeply so it might be a terrible suggestion but it might reduce duplication of code.

Quoted 17 lines
mm/swap.c +11 -0
+				update_page_reclaim_stat(zone, page, file, 0);
+			}
+		}
+	}
+	if (zone)
+		spin_unlock_irq(&zone->lru_lock);
+
+	release_pages(pvec->pages, pvec->nr, pvec->cold);
+	pagevec_reinit(pvec);
+}
+
 /*
  * Drain pages out of the cpu's pagevecs.
  * Either "cpu" is the current CPU, and preemption has already been
@@ -292,8 +333,28 @@ static void drain_cpu_pagevecs(int cpu)
 		pagevec_move_tail(pvec);
 		local_irq_restore(flags);

mm/swap.c static void drain_cpu_pagevecs(int cpu) · line 344

Quoted 10 lines
mm/swap.c +9 -0
 	}
+
+	pvec = &per_cpu(lru_deactive_pvecs, cpu);
+	if (pagevec_count(pvec))
+		__pagevec_lru_deactive(pvec);
+}
+
+/*
+ * Function used to forecefully demote a page to the head of the inactive
+ * list.

s/forecefully/forcefully/

The comment should also state *why* and under what circumstances we move pages to the inactive list like this. Also based on the discussions elsewhere in this thread, it'd be nice to include a comment why it's the head of the inactive list and not the tail.

Quoted 52 lines
mm/swap.c +11 -0
+ */
+void lru_deactive_page(struct page *page)
+{
+	if (likely(get_page_unless_zero(page))) {
+		struct pagevec *pvec = &get_cpu_var(lru_deactive_pvecs);
+
+		if (!pagevec_add(pvec, page))
+			__pagevec_lru_deactive(pvec);
+		put_cpu_var(lru_deactive_pvecs);
+	}
 }
 
+
 void lru_add_drain(void)
 {
 	drain_cpu_pagevecs(get_cpu());
mm/truncate.c +7 -4
index cd94607..c73fb19 100644
@@ -332,7 +332,8 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
 {
 	struct pagevec pvec;
 	pgoff_t next = start;
-	unsigned long ret = 0;
+	unsigned long ret;
+	unsigned long count = 0;
 	int i;
 
 	pagevec_init(&pvec, 0);
@@ -359,8 +360,10 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
 			if (lock_failed)
 				continue;
 
-			ret += invalidate_inode_page(page);
-
+			ret = invalidate_inode_page(page);
+			if (!ret)
+				lru_deactive_page(page);
+			count += ret;
 			unlock_page(page);
 			if (next > end)
 				break;
@@ -369,7 +372,7 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
 		mem_cgroup_uncharge_end();
 		cond_resched();
 	}
-	return ret;
+	return count;
 }
 EXPORT_SYMBOL(invalidate_mapping_pages);
 
Signature · 10 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#52 lore raw

Hi Mel,

Quoted 77 lines · Mel Gorman
Quoted 76 lines · Minchan Kim

Recently, there are reported problem about thrashing.
(http://marc.info/?l=rsync&m=128885034930933&w=2)
It happens by backup workloads(ex, nightly rsync). That's because the workload makes just use-once pages and touches pages twice. It promotes the page into active list so that it results in working set page eviction.

Some app developer want to support POSIX_FADV_NOREUSE. But other OSes don't support it, either.
(http://marc.info/?l=linux-mm&m=128928979512086&w=2)

By Other approach, app developer uses POSIX_FADV_DONTNEED. But it has a problem. If kernel meets page is writing during invalidate_mapping_pages, it can't work.
It is very hard for application programmer to use it. Because they always have to sync data before calling fadivse(..POSIX_FADV_DONTNEED) to make sure the pages could be discardable. At last, they can't use deferred write of kernel so that they could see performance loss.
(http://insights.oetiker.ch/linux/fadvise.html)

In fact, invalidate is very big hint to reclaimer. It means we don't use the page any more. So let's move the writing page into inactive list's head.

If it is real working set, it could have a enough time to activate the page since we always try to keep many pages in inactive list.

I reuse lru_demote of Peter with some change.

Cc Rik van Riel <[email protected]>
Cc KOSAKI Motohiro <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Nick Piggin <[email protected]>

Ben, Remain thing is to modify rsync and use fadvise(POSIX_FADV_DONTNEED). Could you test it?
---
 include/linux/swap.h |    1 +
 mm/swap.c            |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++ mm/truncate.c        |   11 +++++---

 3 files changed, 69 insertions(+), 4 deletions(-)
include/linux/swap.h +1 -0
index eba53e7..a3c9248 100644
@@ -213,6 +213,7 @@ extern void mark_page_accessed(struct page *);
  extern void lru_add_drain(void);
  extern int lru_add_drain_all(void);
  extern void rotate_reclaimable_page(struct page *page);
+extern void lru_deactive_page(struct page *page);
  extern void swap_setup(void);
 
  extern void add_page_to_unevictable_list(struct page *page);
mm/swap.c +2 -0
index 3f48542..56fa298 100644
@@ -39,6 +39,8 @@ int page_cluster;
 
  static DEFINE_PER_CPU(struct pagevec[NR_LRU_LISTS], lru_add_pvecs);
  static DEFINE_PER_CPU(struct pagevec, lru_rotate_pvecs);
+static DEFINE_PER_CPU(struct pagevec, lru_deactive_pvecs);
+
 
  /*
   * This path almost never happens for VM activity - pages are normally
@@ -266,6 +268,45 @@ void add_page_to_unevictable_list(struct page *page)
       spin_unlock_irq(&zone->lru_lock);
  }
 
Quoted 6 lines

mm/swap.c void add_page_to_unevictable_list(struct page *page) · line 272

Quoted 2 lines
mm/swap.c +2 -0
+static void __pagevec_lru_deactive(struct pagevec *pvec)
+{

Might be worth commenting that this function must be called with pre-emption disabled. FWIW, I am reasonably sure your implementation is prefectly safe but a note wouldn't hurt.

Will fix.

Quoted 22 lines
Quoted 22 lines
mm/swap.c +21 -0
+     int i, lru, file;
+
+     struct zone *zone = NULL;
+
+     for (i = 0; i < pagevec_count(pvec); i++) {
+             struct page *page = pvec->pages[i];
+             struct zone *pagezone = page_zone(page);
+
+             if (pagezone != zone) {
+                     if (zone)
+                             spin_unlock_irq(&zone->lru_lock);
+                     zone = pagezone;
+                     spin_lock_irq(&zone->lru_lock);
+             }
+
+             if (PageLRU(page)) {
+                     if (PageActive(page)) {
+                             file = page_is_file_cache(page);
+                             lru = page_lru_base_type(page);
+                             del_page_from_lru_list(zone, page,
+                                             lru + LRU_ACTIVE);
Quoted 8 lines

mm/swap.c void add_page_to_unevictable_list(struct page *page) · line 298

Quoted 5 lines
mm/swap.c +5 -0
+                             ClearPageActive(page);
+                             ClearPageReferenced(page);
+                             add_page_to_lru_list(zone, page, lru);
+                             __count_vm_event(PGDEACTIVATE);
+

What about memcg, do we not need to be calling mem_cgroup_add_lru_list() here as well? I'm looking at the differences between what move_active_pages_to_lru()

Recently, add_page_to_lru_list contains mem_cgroup_add_lru_list.

Quoted 4 lines

is doing and this. I'm wondering if it'd be worth your whole building a list of active pages that are to be moved to the inactive list and passing them to move_active_pages_to_lru() ? I confuess I have not thought about it deeply so it might be a terrible suggestion but it might reduce duplication of code.

Firstly I tried it so I sent a patch about making move_to_active_pages_to_lru more generic. move_to_active_pages_to_lru needs zone argument so I need gathering pages per zone in truncate.
I don't want for user of the function to consider even zone and zone->lru_lock handling.

I think the lru_demote_pages could be used elsewhere(ex, readahead max size heuristic).
So it's generic and easy to use. :)

Quoted 31 lines
Quoted 18 lines
mm/swap.c +11 -0
+                             update_page_reclaim_stat(zone, page, file, 0);
+                     }
+             }
+     }
+     if (zone)
+             spin_unlock_irq(&zone->lru_lock);
+
+     release_pages(pvec->pages, pvec->nr, pvec->cold);
+     pagevec_reinit(pvec);
+}
+
  /*
   * Drain pages out of the cpu's pagevecs.
   * Either "cpu" is the current CPU, and preemption has already been
@@ -292,8 +333,28 @@ static void drain_cpu_pagevecs(int cpu)
               pagevec_move_tail(pvec);
               local_irq_restore(flags);

mm/swap.c static void drain_cpu_pagevecs(int cpu) · line 344

Quoted 10 lines
mm/swap.c +9 -0
       }
+
+     pvec = &per_cpu(lru_deactive_pvecs, cpu);
+     if (pagevec_count(pvec))
+             __pagevec_lru_deactive(pvec);
+}
+
+/*
+ * Function used to forecefully demote a page to the head of the inactive
+ * list.

s/forecefully/forcefully/

Quoted 4 lines

The comment should also state *why* and under what circumstances we move pages to the inactive list like this. Also based on the discussions elsewhere in this thread, it'd be nice to include a comment why it's the head of the inactive list and not the tail.

Fair enough.

Thanks for the comment, Mel.

Signature · 2 lines
Kind regards,
Minchan Kim
#53 lore raw
Quoted 11 lines · Minchan Kim
Quoted 8 lines

mm/swap.c void add_page_to_unevictable_list(struct page *page) · line 272

Quoted 4 lines

<SNIP>

mm/swap.c +2 -0
+static void __pagevec_lru_deactive(struct pagevec *pvec)
+{

Might be worth commenting that this function must be called with pre-emption disabled. FWIW, I am reasonably sure your implementation is prefectly safe but a note wouldn't hurt.

Will fix.

Thanks

Quoted 31 lines
Quoted 22 lines
Quoted 22 lines
mm/swap.c +21 -0
+     int i, lru, file;
+
+     struct zone *zone = NULL;
+
+     for (i = 0; i < pagevec_count(pvec); i++) {
+             struct page *page = pvec->pages[i];
+             struct zone *pagezone = page_zone(page);
+
+             if (pagezone != zone) {
+                     if (zone)
+                             spin_unlock_irq(&zone->lru_lock);
+                     zone = pagezone;
+                     spin_lock_irq(&zone->lru_lock);
+             }
+
+             if (PageLRU(page)) {
+                     if (PageActive(page)) {
+                             file = page_is_file_cache(page);
+                             lru = page_lru_base_type(page);
+                             del_page_from_lru_list(zone, page,
+                                             lru + LRU_ACTIVE);
Quoted 8 lines

mm/swap.c void add_page_to_unevictable_list(struct page *page) · line 298

Quoted 5 lines
mm/swap.c +5 -0
+                             ClearPageActive(page);
+                             ClearPageReferenced(page);
+                             add_page_to_lru_list(zone, page, lru);
+                             __count_vm_event(PGDEACTIVATE);
+

What about memcg, do we not need to be calling mem_cgroup_add_lru_list() here as well? I'm looking at the differences between what move_active_pages_to_lru()

Quoted 2 lines

Recently, add_page_to_lru_list contains mem_cgroup_add_lru_list.

My bad, you're right. I was thrown by move_active_pages_to_lru() needing to do memcg stuff manually and didn't spot why it ok to miss it here.

Quoted 12 lines
Quoted 4 lines

is doing and this. I'm wondering if it'd be worth your whole building a list of active pages that are to be moved to the inactive list and passing them to move_active_pages_to_lru() ? I confuess I have not thought about it deeply so it might be a terrible suggestion but it might reduce duplication of code.

Firstly I tried it so I sent a patch about making move_to_active_pages_to_lru more generic. move_to_active_pages_to_lru needs zone argument so I need gathering pages per zone in truncate.
I don't want for user of the function to consider even zone and zone->lru_lock handling.

Quoted 4 lines

I think the lru_demote_pages could be used elsewhere(ex, readahead max size heuristic).
So it's generic and easy to use. :)

Ok, that's fair enough.

Quoted 44 lines
Quoted 31 lines
Quoted 18 lines
mm/swap.c +11 -0
+                             update_page_reclaim_stat(zone, page, file, 0);
+                     }
+             }
+     }
+     if (zone)
+             spin_unlock_irq(&zone->lru_lock);
+
+     release_pages(pvec->pages, pvec->nr, pvec->cold);
+     pagevec_reinit(pvec);
+}
+
 /*
  * Drain pages out of the cpu's pagevecs.
  * Either "cpu" is the current CPU, and preemption has already been
@@ -292,8 +333,28 @@ static void drain_cpu_pagevecs(int cpu)
              pagevec_move_tail(pvec);
              local_irq_restore(flags);

mm/swap.c static void drain_cpu_pagevecs(int cpu) · line 344

Quoted 10 lines
mm/swap.c +9 -0
      }
+
+     pvec = &per_cpu(lru_deactive_pvecs, cpu);
+     if (pagevec_count(pvec))
+             __pagevec_lru_deactive(pvec);
+}
+
+/*
+ * Function used to forecefully demote a page to the head of the inactive
+ * list.

s/forecefully/forcefully/

Quoted 4 lines

The comment should also state *why* and under what circumstances we move pages to the inactive list like this. Also based on the discussions elsewhere in this thread, it'd be nice to include a comment why it's the head of the inactive list and not the tail.

Fair enough.

Thanks for the comment, Mel.

Signature · 2 lines
Kind regards,
Minchan Kim
Signature · 10 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>