PATCH: Improvements in shrink_mmap and kswapd
Subsystems (6)
Hi
this patch makes kswapd use less resources. It should solve
the kswapd eats xx% of my CPU problems. It appears that it improves IO a bit here. Could people having problems with IO told me if this patch improves things, I am interested in knowing that it don't makes things worst never. This patch is stable here. I am finishing the deferred mmaped pages form file writing patch, that should solve several other problems.
Reports of success/failure are welcome. Comments are also welcome.
Later, Juan.
This patch implements:
- never loops infinitely is shrink_mmap (it walks as maximum once per page)
- it changes the nr_dirty logic to max_launder_page logic. We start writing async a maximum of max_launder_page (100), and after that point we never start more writes for that run of shrink_mmap. If we start max_launder_page writes, we wait at the end of the function if possible (i.e __gfp_mask let do that).
- It checks that there is some zone with need of pages before continue with the loop. If there is no pages, stop walking the LRU.
- I have got the patch from Roger Larson for the memory pressure and have partially re implemented/increasing it.
- kswapd rewrite in similar way that Roger Larson one.
- added the function memory_pressure that returns 1 if there is memory_pressure and 0 if there is no pressure.
- I have got Manfred patch to use test_and_test_and_clear_bit optimization in ClearPageReferenced.
- Added ClearPageDirty(page) to __remove_inode_pages to solve the ramfs problems.
- Added __lru_cache_del and __lru_cache_add and use them in shrink_mmap.
- Makes a cleanup of several cruft in shirk_mmap.
include/asm-i386/bitops.h +8 -0
@@ -29,6 +29,7 @@extern void change_bit (int nr,volatile void * addr);extern int test_and_set_bit (int nr,volatile void * addr);extern int test_and_clear_bit (int nr,volatile void * addr); +extern int test_and_test_and_clear_bit (int nr,volatile void * addr);extern int test_and_change_bit (int nr,volatile void * addr);extern int __constant_test_bit (int nr,const volatile void * addr);extern int __test_bit (int nr,volatile void * addr);
@@ -87,6 +88,13 @@ :"=r" (oldbit),"=m" (ADDR) :"Ir" (nr));return oldbit; +} + +extern __inline__int test_and_test_and_clear_bit (int nr,volatile void *addr) +{ +if (!(((unsigned long )addr) & (1 <<nr))) +return 0 ; +return test_and_clear_bit (nr,addr); }extern __inline__int test_and_change_bit (int nr,volatile void * addr)
include/linux/mm.h +1 -1
@@ -203,7 +203,7 @@#define PageReferenced (page) test_bit(PG_referenced, &(page)->flags)#define SetPageReferenced (page) set_bit(PG_referenced, &(page)->flags)#define ClearPageReferenced (page) clear_bit(PG_referenced, &(page)->flags) -#define PageTestandClearReferenced (page) test_and_clear_bit(PG_referenced, &(page)->flags) +#define PageTestandClearReferenced (page) test_and_test_and_clear_bit(PG_referenced, &(page)->flags)#define PageDecrAfter (page) test_bit(PG_decr_after, &(page)->flags)#define SetPageDecrAfter (page) set_bit(PG_decr_after, &(page)->flags)#define PageTestandClearDecrAfter (page) test_and_clear_bit(PG_decr_after, &(page)->flags)
include/linux/swap.h +10 -3
@@ -87,6 +87,7 @@/* linux/mm/vmscan.c */ extern int try_to_free_pages (unsigned int gfp_mask); +extern int memory_pressure (void );/* linux/mm/page_io.c */ extern void rw_swap_page (int ,struct page *,int );
@@ -173,11 +174,17 @@/* * Helper macros for lru_pages handling. */ -#define lru_cache_add (page) \ + +#define __lru_cache_add (page) \ do { \ - spin_lock(&pagemap_lru_lock); \ list_add(&(page)->lru, &lru_cache); \ nr_lru_pages++; \ +} while (0) + +#define lru_cache_add (page) \ +do { \ + spin_lock(&pagemap_lru_lock); \ + __lru_cache_add(page); \ page->age = PG_AGE_START; \ ClearPageReferenced(page); \ SetPageActive(page); \
@@ -187,7 +194,6 @@#define __lru_cache_del (page) \ do { \ list_del(&(page)->lru); \ - ClearPageActive(page); \ nr_lru_pages--; \ } while (0)
@@ -196,6 +202,7 @@if (!PageLocked (page)) \BUG (); \spin_lock (&pagemap_lru_lock); \ +ClearPageActive (page); \__lru_cache_del (page); \spin_unlock (&pagemap_lru_lock); \ }while (0 )
mm/filemap.c +72 -43
199 lines not on this page · raw message
mm/swap_state.c +0 -1
@@ -73,7 +73,6 @@PAGE_BUG (page);PageClearSwapCache (page); -ClearPageDirty (page);remove_inode_page (page); }
mm/vmscan.c +39 -28
134 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/
Quoted 1 line · Juan J. Quintela
Reports of success/failure are welcome. Comments are also welcome.
I have a few comments on the patch. They have mostly to do with the maxlaunder logic.
A few days ago I sent you the buffer.c patch where try_to_free_buffers was modified so that it would never try to do IO on pages if the 'wait' argument has a value of -1.
This can be combined with maxlaunder in a nice way. Firstly we need to wakeup_bdflush() if we queued some buffers or swap pages for IO, that way bdflush will flush dirty and IO queued pages to disk.
Secondly we need to try try_to_free_buffers(page, -1) first, currently you count freeing buffers without doing IO as an IO operation (and also, you're starting IO operations when __GFP_IO isn't set). If that fails and maxlaunder isn't reached yet, we can try to start asynchronous IO on the page.
When we reach the end of shrink_mmap, we can do something like this:
wait = 0;
if (nr_writes && (gfp_mask & __GFP_IO))
wait = 1;
wake_up_bdflush(wait);
if (wait && !ret) {
goto again; /* bdflush just made pages available, roll again */
}
This will give us something like write throttling where apps will be waiting for bdflush to have done IO on pages so we'll have freeable pages around. If __GFP_IO isn't set we'll still fail, of course, but this will at least keep applications from failing needlessly.
regards,
Rik
--
The Internet is not a network of computers. It is a network of people. That is its real strength.
Wanna talk about the kernel? irc.openprojects.net / #kernelnewbies
http://www.conectiva.com/ http://www.surriel.com/
--
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/
Quoted 13 lines
diff -urN --exclude-from=/home/lfcia/quintela/work/kernel/exclude
base/include/asm-i386/bitops.hworking/include/asm-i386/bitops.hinclude/asm-i386/bitops.h Sat Jun 17 23:52:49 2000 renamed from include/asm-i386/bitops.h Sat Jun 17 23:37:03 2000 +1
-0@@ -29,6 +29,7 @@ extern void change_bit(int nr, volatile void * addr); extern int test_and_set_bit(int nr, volatile void * addr); extern int test_and_clear_bit(int nr, volatile void * addr); +extern int test_and_test_and_clear_bit(int nr, volatile void * addr); extern int test_and_change_bit(int nr, volatile void * addr); extern int __constant_test_bit(int nr, const volatile void * addr); extern int __test_bit(int nr, volatile void * addr);@@ -87,6 +88,13 @@ :"=r" (oldbit),"=m" (ADDR)
include/asm-i386/bitops.h Sat Jun 17 23:52:49 2000 line 98
Quoted 10 lines
include/asm-i386/bitops.h Sat Jun 17 23:52:49 2000 renamed from include/asm-i386/bitops.h Sat Jun 17 23:37:03 2000 +7
-0:"Ir" (nr)); return oldbit; +} + +extern __inline__ int test_and_test_and_clear_bit(int nr, volatile void *addr) +{ + if(!(((unsigned long)addr) & (1<<nr))) + return 0; + return test_and_clear_bit(nr,addr); }
This does not look correct. It basically tests if the ADDRESS has bit #nr set...
Shouldn't it be
+ if(!(((unsigned long)*addr) & (1<<nr)))
/RogerL
--
Home page:
http://www.norran.net/nra02596/
--
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/
Quoted 28 lines · Roger Larsson
Quoted 13 lines
diff -urN --exclude-from=/home/lfcia/quintela/work/kernel/exclude
base/include/asm-i386/bitops.hworking/include/asm-i386/bitops.hinclude/asm-i386/bitops.h Sat Jun 17 23:52:49 2000 renamed from include/asm-i386/bitops.h Sat Jun 17 23:37:03 2000 +1
-0@@ -29,6 +29,7 @@ extern void change_bit(int nr, volatile void * addr); extern int test_and_set_bit(int nr, volatile void * addr); extern int test_and_clear_bit(int nr, volatile void * addr); +extern int test_and_test_and_clear_bit(int nr, volatile void * addr); extern int test_and_change_bit(int nr, volatile void * addr); extern int __constant_test_bit(int nr, const volatile void * addr); extern int __test_bit(int nr, volatile void * addr);@@ -87,6 +88,13 @@ :"=r" (oldbit),"=m" (ADDR)include/asm-i386/bitops.h Sat Jun 17 23:52:49 2000 line 98
Quoted 10 lines
include/asm-i386/bitops.h Sat Jun 17 23:52:49 2000 renamed from include/asm-i386/bitops.h Sat Jun 17 23:37:03 2000 +7
-0:"Ir" (nr)); return oldbit; +} + +extern __inline__ int test_and_test_and_clear_bit(int nr, volatile void *addr) +{ + if(!(((unsigned long)addr) & (1<<nr))) + return 0; + return test_and_clear_bit(nr,addr); }This does not look correct. It basically tests if the ADDRESS has bit #nr set...
Quoted 2 lines
Shouldn't it be
+if(!(((unsigned long)*addr) & (1<<nr)))
if(!((*(unsigned long *)addr) & (1<<nr))
is closer to what you want. it still breaks for nr > BITS_PER_LONG.
--
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/
Quoted 30 lines · Philipp Rumpf
Quoted 28 lines · Roger Larsson
Quoted 13 lines
diff -urN --exclude-from=/home/lfcia/quintela/work/kernel/exclude
base/include/asm-i386/bitops.hworking/include/asm-i386/bitops.hinclude/asm-i386/bitops.h Sat Jun 17 23:52:49 2000 renamed from include/asm-i386/bitops.h Sat Jun 17 23:37:03 2000 +1
-0@@ -29,6 +29,7 @@ extern void change_bit(int nr, volatile void * addr); extern int test_and_set_bit(int nr, volatile void * addr); extern int test_and_clear_bit(int nr, volatile void * addr); +extern int test_and_test_and_clear_bit(int nr, volatile void * addr); extern int test_and_change_bit(int nr, volatile void * addr); extern int __constant_test_bit(int nr, const volatile void * addr); extern int __test_bit(int nr, volatile void * addr);@@ -87,6 +88,13 @@ :"=r" (oldbit),"=m" (ADDR)include/asm-i386/bitops.h Sat Jun 17 23:52:49 2000 line 98
Quoted 10 lines
include/asm-i386/bitops.h Sat Jun 17 23:52:49 2000 renamed from include/asm-i386/bitops.h Sat Jun 17 23:37:03 2000 +7
-0:"Ir" (nr)); return oldbit; +} + +extern __inline__ int test_and_test_and_clear_bit(int nr, volatile void *addr) +{ + if(!(((unsigned long)addr) & (1<<nr))) + return 0; + return test_and_clear_bit(nr,addr); }This does not look correct. It basically tests if the ADDRESS has bit #nr set...
Quoted 6 lines
Quoted 2 lines
Shouldn't it be
+if(!(((unsigned long)*addr) & (1<<nr)))if(!((*(unsigned long *)addr) & (1<<nr))
is closer to what you want. it still breaks for nr >
BITS_PER_LONG.
Final attempt:
return test_bit(nr,addr) && test_and_clear_bit(nr,addr);
It even matches the name :-)
But it have to be moved some lines down.
(Exercise for the reader)
/RogerL
--
Home page:
http://www.norran.net/nra02596/
--
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/
Hi,
Comments below,
Quoted 33 lines · Juan J. Quintela
Hi
this patch makes kswapd use less resources. It should solve
the kswapd eats xx% of my CPU problems. It appears that it improves IO a bit here. Could people having problems with IO told me if this patch improves things, I am interested in knowing that it don't makes things worst never. This patch is stable here. I am finishing the deferred mmaped pages form file writing patch, that should solve several other problems.Reports of success/failure are welcome. Comments are also welcome.
Later, Juan.
mm/filemap.c +17
-0+/** +* shrink_mmap - Tries to free memory +* @priority: how hard we will try to free pages (0 hardest) +* @gfp_mask: Restrictions to free pages +* +* This function walks the lru list searching for free pages. It +* returns 1 to indicate success and 0 in the opposite case. It gets a +* lock in the pagemap_lru_lock and the pagecache_lock. */ +/* nr_to_examinate counts the number of pages that we will read as +* maximum as each call. This means that we don't loop. +*/ +/* nr_writes counts the number of writes that we have started to the +* moment. We limitate the number of writes in each round to +* max_page_launder. ToDo: Make that variable tunable through sysctl. +*/ +const int max_page_launder =100 ; +
mm/filemap.c line 321
Quoted 10 lines
mm/filemap.c +2
-4int shrink_mmap (int priority,int gfp_mask) { -int ret =0 , count, nr_dirty;struct list_head * page_lru;struct page * page =NULL ; - - count = nr_lru_pages / (priority +1 ); - nr_dirty = priority; +int ret; +int nr_to_examinate = nr_lru_pages;
Is this really enough?
PG_AGE_MAX * nr_lru_pages / (priority + 1)
is required to ensure that all pages have been scanned at an age of 0. But that is probably an overkill... there is a sum involved here...
PG_AGE_START * ...
Could be nice to get rid of streaming pages before other attempts are done.
Quoted 26 lines
diff -urN --exclude-from=/home/lfcia/quintela/work/kernel/exclude
base/mm/vmscan.cworking/mm/vmscan.cmm/vmscan.c Sun Jun 18 00:28:12 2000 renamed from mm/vmscan.c Sat Jun 17 23:51:24 2000 +0
-0[removed stuff]
mm/vmscan.c Sun Jun 18 00:28:12 2000 renamed from mm/vmscan.c Sat Jun 17 23:51:24 2000 +16
-0@@ -427,6 +425,32 @@ return __ret; } +/** + * memory_pressure - Is the system under memory pressure + * + * Returns 1 if the system is low on memory in any of its zones, + * otherwise returns 0. + */ +int memory_pressure(void) +{ + pg_data_t *pgdat = pgdat_list; + + do { + int i; + for(i = 0; i < MAX_NR_ZONES; i++) { + zone_t *zone = pgdat->node_zones + i; + if (!zone->size || !zone->zone_wake_kswapd) + continue;
mm/vmscan.c Sun Jun 18 00:28:12 2000 line 453
Quoted 10 lines
mm/vmscan.c Sun Jun 18 00:28:12 2000 renamed from mm/vmscan.c Sat Jun 17 23:51:24 2000 +10
-0+ if (zone->free_pages < zone->pages_low) + return 1; + } + pgdat = pgdat->node_next; + + } while (pgdat); + + return 0; +} +
This function effectively ignore 'zone_wake_kswapd' since it should always be set when free < low - if correct behaviour remove the test.
mm/vmscan.c Sun Jun 18 00:28:12 2000
Quoted 11 lines
mm/vmscan.c Sun Jun 18 00:28:12 2000 renamed from mm/vmscan.c Sat Jun 17 23:51:24 2000 +2
-1priority = 64; do { while (shrink_mmap(priority, gfp_mask)) { - ret = 1; if (!--count) goto done; } + if(!memory_pressure()) + return 1;
Needs lower than pages_low after shrink_mmap to pass this test and enter swapping... might be correct behaviour!
/RogerL
--
Home page:
http://www.norran.net/nra02596/
--
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/
Quoted 10 lines · Juan J. Quintela
Hi
this patch makes kswapd use less resources. It should solve
the kswapd eats xx% of my CPU problems. It appears that it improves IO a bit here. Could people having problems with IO told me if this patch improves things, I am interested in knowing that it don't makes things worst never. This patch is stable here. I am finishing the deferred mmaped pages form file writing patch, that should solve several other problems.Reports of success/failure are welcome. Comments are also welcome.
Hi Juan,
I added this patch to ac20 + Roger Larsonn fix and gave it a quick burn. I saw a slight performance drop in both make -j30 build times and streaming IO (iozone). I didn't do sustained pounding though (consistancy), so...
-Mike
--
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/
PATCH: Improvements in shrink_mmap and kswapd (take 2)
In reply to Juan J. QuintelaHi
here appear to give similar results as ac22-riel, but shouldn't degenerate in bad behaviour as fast as ac22-riel in tests like Zlatko.
Reports of success/failure are welcome. Comments are also welcome.
Later, Juan.
take 1 comments:
Quoted 7 lines
this patch makes kswapd use less resources. It should solve
the kswapd eats xx% of my CPU problems. It appears that it improves IO a bit here. Could people having problems with IO told me if this patch improves things, I am interested in knowing that it don't makes things worst never. This patch is stable here. I am finishing the deferred mmaped pages form file writing patch, that should solve several other problems.
This patch implements:
take 2:
------
- against ac22-riel
- fixes the problems with test_and_test_and_clear_bit (thanks Roger Larson and Philipp Rumpf)
- Reintroduces the page->zone test dropped in ac21
- call to wakeup_bdflush() at the end of shrink_mmap (thanks Rick Riel)
- the rest of Riel suggestions haven't been introduced, they need infraestructure changes in buffer.c that I am studing.
take 1:
------
- never loops infinitely is shrink_mmap (it walks as maximum once per page)
- it changes the nr_dirty logic to max_launder_page logic. We start writing async a maximum of max_launder_page (100), and after that point we never start more writes for that run of shrink_mmap. If we start max_launder_page writes, we wait at the end of the function if possible (i.e __gfp_mask let do that).
- It checks that there is some zone with need of pages before continue with the loop. If there is no pages, stop walking the LRU.
- I have got the patch from Roger Larson for the memory pressure and have partially re implemented/increasing it.
- kswapd rewrite in similar way that Roger Larson one.
- added the function memory_pressure that returns 1 if there is memory_pressure and 0 if there is no pressure.
- I have got Manfred patch to use test_and_test_and_clear_bit optimization in ClearPageReferenced.
- Added ClearPageDirty(page) to __remove_inode_pages to solve the ramfs problems.
- Added __lru_cache_del and __lru_cache_add and use them in shrink_mmap.
- Makes a cleanup of several cruft in shirk_mmap.
include/asm-i386/bitops.h +10 -0
@@ -29,6 +29,7 @@extern void change_bit (int nr,volatile void * addr);extern int test_and_set_bit (int nr,volatile void * addr);extern int test_and_clear_bit (int nr,volatile void * addr); +extern int test_and_test_and_clear_bit (int nr,volatile void * addr);extern int test_and_change_bit (int nr,volatile void * addr);extern int __constant_test_bit (int nr,const volatile void * addr);extern int __test_bit (int nr,volatile void * addr);
@@ -123,6 +124,15 @@ (__builtin_constant_p (nr) ? \__constant_test_bit ((nr),(addr)) : \ __test_bit((nr),(addr))) + +extern __inline__int test_and_test_and_clear_bit (int nr,volatile void *addr) +{ +if (!test_bit (nr,addr)) +return 0 ; +return test_and_clear_bit (nr,addr); +} + +/* * Find-bit routines..
include/linux/mm.h +1 -1
@@ -203,7 +203,7 @@#define PageReferenced (page) test_bit(PG_referenced, &(page)->flags)#define SetPageReferenced (page) set_bit(PG_referenced, &(page)->flags)#define ClearPageReferenced (page) clear_bit(PG_referenced, &(page)->flags) -#define PageTestandClearReferenced (page) test_and_clear_bit(PG_referenced, &(page)->flags) +#define PageTestandClearReferenced (page) test_and_test_and_clear_bit(PG_referenced, &(page)->flags)#define PageDecrAfter (page) test_bit(PG_decr_after, &(page)->flags)#define SetPageDecrAfter (page) set_bit(PG_decr_after, &(page)->flags)#define PageTestandClearDecrAfter (page) test_and_clear_bit(PG_decr_after, &(page)->flags)
include/linux/swap.h +10 -3
@@ -87,6 +87,7 @@/* linux/mm/vmscan.c */ extern int try_to_free_pages (unsigned int gfp_mask); +extern int memory_pressure (void );/* linux/mm/page_io.c */ extern void rw_swap_page (int ,struct page *,int );
@@ -173,11 +174,17 @@/* * Helper macros for lru_pages handling. */ -#define lru_cache_add (page) \ + +#define __lru_cache_add (page) \ do { \ - spin_lock(&pagemap_lru_lock); \ list_add(&(page)->lru, &lru_cache); \ nr_lru_pages++; \ +} while (0) + +#define lru_cache_add (page) \ +do { \ + spin_lock(&pagemap_lru_lock); \ + __lru_cache_add(page); \ page->age = PG_AGE_START; \ ClearPageReferenced(page); \ SetPageActive(page); \
@@ -187,7 +194,6 @@#define __lru_cache_del (page) \ do { \ list_del(&(page)->lru); \ - ClearPageActive(page); \ nr_lru_pages--; \ } while (0)
@@ -196,6 +202,7 @@if (!PageLocked (page)) \BUG (); \spin_lock (&pagemap_lru_lock); \ +ClearPageActive (page); \__lru_cache_del (page); \spin_unlock (&pagemap_lru_lock); \ }while (0 )
mm/filemap.c +81 -44
204 lines not on this page · raw message
mm/swap_state.c +0 -1
@@ -73,7 +73,6 @@PAGE_BUG (page);PageClearSwapCache (page); -ClearPageDirty (page);remove_inode_page (page); }
mm/vmscan.c +40 -26
123 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/