Skip to contentSkip to conversation

PATCH: deferred writes of mmaped pages [WIP] (1st try)

PATCH Juan J. Quintela 3 participants 3 messages Jun 7, 2000 – Jun 11, 2000

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

Hi
This is a first version of making deferred writes when we hit a dirty page belonging to a file in swap_out. It is unfinished work, I am posting it because:
- people asked for it
- I would like to receive feedback about the ideas

Note that is a Work in progress and I will do more improvements before asking for inclusion.

The important idea is that we want to limit the amount of IO that is generated for each page that we need, that is difficult with the existing scheme when we are doing IO in several swap routines. The first try was to start asynchronously several writes of buffers in shrink_mmap and then wait for some of them to perform. Next was the deferred swap, we found a dirty anon page in swap_out, we mark it as dirty and we will swap that page in shrink_mmap. Now is the turn of pages from the file-system.

The patch does:
- The patch is against 2.4.0-test1-ac10.
- Use a new field in the page structure to store the file that we want to write. Just now it stores the file for all the pages, it is needed only for file-systems that are not of disk. I will do that optimization later.
- It modifies truncate*page and invalidate*page to support the use of this new field.
- It modifies try_to_swap_out to mark pages as dirty instead of start the write asynchronously.
- It modifies shrink_mmap to start the write of dirty pages, working now also for pages in the page cache.

After I have been chatting with Ben LaHaise, he has suggested, instead of using especial code for NFS pages and block pages to change/add a new function to address_operations to do the swapout in try_to_swap_pages and the writepage in shrink_mmap. That would simplify a lot the code and will make it very easy to add more pages/caches to the scheme, obvious candidates are the SHM pages and the swap_cache (thinking about the last ones). Comments about the idea? If nobody is against that I will begin doing something about that tomorrow.

The other question is what the people think about this movement that makes the transition easy towards an scheme using several queues like the one proposed by Rik.

I have tested this code and it works rock solid. It hangs with mmap002 over NFS, but then I repeat the test without my patches and mmap002 also hangs the computer with stock ac10.

I will like to hear suggestions/comments/reports of success/failures.

I begin this patch thinking that it will reduce the stalls running big *dirtier* of pages, i.e. dd of a cdrom to hd, mmap002 and similar, but the stalls are similar. I am investigating yet on that, suggestions here are also welcome.

Later, Juan.

include/linux/mm.h +1 -0
diff -urN --exclude-from=/home/lfcia/quintela/work/kernel/exclude base/include/linux/mm.h working/include/linux/mm.h
@@ -154,6 +154,7 @@
 	unsigned long virtual; /* nonzero if kmapped */
 	struct zone_struct *zone;
 	unsigned int age;
+	struct file *file;
 } mem_map_t;
 
 #define get_page(p)		atomic_inc(&(p)->count)
mm/filemap.c +66 -9

133 lines not on this page · raw message

mm/mremap.c +1 -1
diff -urN --exclude-from=/home/lfcia/quintela/work/kernel/exclude base/mm/mremap.c working/mm/mremap.c
@@ -144,7 +144,7 @@
 			vmlist_modify_lock(current->mm);
 			insert_vm_struct(current->mm, new_vma);
 			merge_segments(current->mm, new_vma->vm_start, new_vma->vm_end);
-			vmlist_modify_unlock(vma->vm_mm);
+			vmlist_modify_unlock(current->mm);
 			do_munmap(current->mm, addr, old_len);
 			current->mm->total_vm += new_len >> PAGE_SHIFT;
 			if (new_vma->vm_flags & VM_LOCKED) {
mm/page_alloc.c +2 -0
diff -urN --exclude-from=/home/lfcia/quintela/work/kernel/exclude base/mm/page_alloc.c working/mm/page_alloc.c
@@ -95,6 +95,8 @@
 		BUG();
 	if (PageDirty(page))
 		BUG();
+	if (page->file)
+		BUG();
 
 	zone = page->zone;
 
mm/swap_state.c +0 -1
diff -urN --exclude-from=/home/lfcia/quintela/work/kernel/exclude base/mm/swap_state.c working/mm/swap_state.c
@@ -73,7 +73,6 @@
 		PAGE_BUG(page);
 
 	PageClearSwapCache(page);
-	ClearPageDirty(page);
 	remove_inode_page(page);
 }
 
mm/vmscan.c +28 -19

65 lines not on this page · raw message

Signature · 6 lines
In theory, practice and theory are the same, but in practice they 
are different -- Larry McVoy
--
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.eu.org/Linux-MM/
#1 lore raw

VM callbacks and VM design

Quoted 4 lines · Juan J. Quintela

After I have been chatting with Ben LaHaise, he has suggested, instead of using especial code for NFS pages and block pages to change/add a new function to address_operations to do the swapout in try_to_swap_pages and the writepage in shrink_mmap.

I believe that is exactly what David's anon patch does. The function is called try_to_free_page. Personally, I think it is a great idea.

IMHO, the long term goal should be to futher unify the Linux VM system. Here is my (possibly misinformed) take on the issue:

The resource being managed the the VM system is physical pages. When this resource becomes scarce, pressure must be placed on the users of these pages. Pages which well not be needed in the near future should be the ones to be freed.

In order to decide which pages are good candidates for freeing the temporal locality heuristic should be used (ie. pages needed recently will also be needed in the near future). Note that this is different that "most often used". I think Rik's latest aging patch is slightly wrong in this regard.

The users who have lots of physical pages in memory will feel the most pressure. If they are actively using these pages the pressure will be reduced. LRU (or some variant to eliminate pathological worst case behavior) should be the unified heuristic to determine which pages should be freed. This will provide good performance and balance to the system.

Creating a bunch of distinct caches and trying to balance them is the wrong solution.

Unfortunately with the current design we do not have a relation from physical pages to users of those pages (at least not for all types of pages). David's anon patch fixes this for anonymous pages. With this change the memory management code becomes much simpler. A similar approach should be taken with the SHM code.

Unfortunately these kinds of changes are too radical to make during the so called code freeze so we will have to wait until 2.5. I look forward to getting my hands dirty and providing some help in this effort.

Thanks for the patch Juan.

Neil

Signature · 6 lines
"Everyone can be taught to sculpt: Michelangelo would have had to
be taught how not to. So it is with the great programmers" -- Alan Perlis
--
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.eu.org/Linux-MM/
#2 lore raw

Re: VM callbacks and VM design

Neil Schemenauer <[email protected]> writes:

[...]

Quoted 2 lines

In order to decide which pages are good candidates for freeing the temporal locality heuristic should be used (ie. pages needed

Why?

Quoted 3 lines

recently will also be needed in the near future). Note that this is different that "most often used". I think Rik's latest aging patch is slightly wrong in this regard.

If you're greping through a large file you don't want to swap out your processes.

Also, you might like to look at the ideas behind generational garbage collection; i.e. most objects are used briefly then forgotten about forever, but those which are still being used after a while will probably keep on being used.

[...]

Signature · 5 lines
	http://altern.org/vii
--
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.eu.org/Linux-MM/