mm: drain percpu lru add/rotate page-vectors on cpu hot-unplug
Subsystems (6)
PATCH 1/3 mm: drain percpu lru add/rotate page-vectors on cpu hot-unplug
This cpu hotplug hook was accidentally removed in commit v2.6.30-rc4-18-g00a62ce ("mm: fix Committed_AS underflow on large NR_CPUS environment")
--- include/linux/swap.h | 1 + mm/page_alloc.c | 1 + mm/swap.c | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-)
include/linux/swap.h +1 -0
@@ -215,6 +215,7 @@ extern void lru_add_page_tail(struct zone* zone,extern void activate_page (struct page *);extern void mark_page_accessed (struct page *);extern void lru_add_drain (void ); +extern void lru_add_drain_cpu (int cpu);extern int lru_add_drain_all (void );extern void rotate_reclaimable_page (struct page *page);extern void deactivate_page (struct page *page);
mm/page_alloc.c +1 -0
@@ -4821,6 +4821,7 @@ static int page_alloc_cpu_notify(struct notifier_block *self,int cpu = (unsigned long )hcpu;if (action ==CPU_DEAD || action ==CPU_DEAD_FROZEN ) { +lru_add_drain_cpu (cpu);drain_pages (cpu);/*
mm/swap.c +2 -2
@@ -496,7 +496,7 @@ static void lru_deactivate_fn(struct page *page, void *arg)* Either "cpu" is the current CPU, and preemption has already been * disabled; or "cpu" is being hot-unplugged, and is already dead. */ -static void drain_cpu_pagevecs (int cpu) +void lru_add_drain_cpu (int cpu) {struct pagevec *pvecs =per_cpu (lru_add_pvecs, cpu);struct pagevec *pvec;
@@ -553,7 +553,7 @@ void deactivate_page(struct page *page)void lru_add_drain (void ) { -drain_cpu_pagevecs (get_cpu ()); +lru_add_drain_cpu (get_cpu ());put_cpu (); }
--
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 internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/3 mm: replace per-cpu lru-add page-vectors with page-lists
This patch replaces page-vectors with page-lists in lru_cache_add*() functions. We can use page->lru for linking because page obviously not in lru.
Now per-cpu batch limited with its pages total size, not pages count, otherwise it can be extremely huge if there many huge-pages inside:PAGEVEC_SIZE * HPAGE_SIZE = 28Mb, per-cpu!
These pages are hidden from memory reclaimer for a while. New limit: LRU_CACHE_ADD_BATCH = 64 (* PAGE_SIZE = 256Kb)
So, huge-page adding now will always drain per-cpu list. Huge-page allocation and preparation is long procedure, thus nobody will notice this draining.
Draining procedure disables preemption only for pages list isolation, thus batch size can be increased without negative effect for latency.
Plus this patch introduces new function lru_cache_add_list() and use it in mpage_readpages() and read_pages(). There pages already collected in list. Unlike to single-page lru-add, list-add reuse page-referencies from caller, thus we save one page_get()/page_put() per page.
--- fs/mpage.c | 21 +++++++---- include/linux/swap.h | 2 + mm/readahead.c | 15 +++++--- mm/swap.c | 99 +++++++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 114 insertions(+), 23 deletions(-)
fs/mpage.c +13 -8
@@ -15,6 +15,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/mm.h> +#include <linux/swap.h> #include <linux/kdev_t.h> #include <linux/gfp.h> #include <linux/bio.h>
@@ -367,29 +368,33 @@ mpage_readpages(struct address_space *mapping, struct list_head *pages, unsigned nr_pages, get_block_t get_block) {struct bio *bio =NULL ; -unsigned page_idx;sector_t last_block_in_bio =0 ;struct buffer_head map_bh;unsigned long first_logical_block =0 ; +struct page *page, *next; +int nr_added =0 ; map_bh.b_state =0 ; map_bh.b_size =0 ; -for (page_idx =0 ; page_idx < nr_pages; page_idx++) { - struct page *page = list_entry(pages->prev, struct page, lru); +list_for_each_entry_safe (page, next, pages, lru) {prefetchw (&page->flags); -list_del (&page->lru); -if (!add_to_page_cache_lru (page, mapping, +if (!add_to_page_cache (page, mapping, page->index,GFP_KERNEL )) { bio =do_mpage_readpage (bio, page, - nr_pages - page_idx, + nr_pages, &last_block_in_bio, &map_bh, &first_logical_block, get_block); + nr_added++; + }else { +list_del (&page->lru); +page_cache_release (page); } -page_cache_release (page); + nr_pages--; } -BUG_ON (!list_empty (pages)); +BUG_ON (nr_pages); +lru_cache_add_list (pages, nr_added,LRU_INACTIVE_FILE );if (bio)mpage_bio_submit (READ , bio);return 0 ;
include/linux/swap.h +2 -0
@@ -212,6 +212,8 @@ extern void __lru_cache_add(struct page *, enum lru_list lru);extern void lru_cache_add_lru (struct page *,enum lru_list lru);extern void lru_add_page_tail (struct zone * zone,struct page *page,struct page *page_tail); +extern void lru_cache_add_list (struct list_head *pages, +int size,enum lru_list lru);extern void activate_page (struct page *);extern void mark_page_accessed (struct page *);extern void lru_add_drain (void );
mm/readahead.c +9 -6
@@ -11,6 +11,7 @@#include <linux/fs.h> #include <linux/gfp.h> #include <linux/mm.h> +#include <linux/swap.h> #include <linux/export.h> #include <linux/blkdev.h> #include <linux/backing-dev.h>
@@ -110,7 +111,7 @@ static int read_pages(struct address_space *mapping, struct file *filp, struct list_head *pages, unsigned nr_pages) {struct blk_plug plug; -unsigned page_idx; +struct page *page, *next;int ret;blk_start_plug (&plug);
@@ -122,15 +123,17 @@ static int read_pages(struct address_space *mapping, struct file *filp, goto out; } -for (page_idx =0 ; page_idx < nr_pages; page_idx++) { -struct page *page =list_to_page (pages); -list_del (&page->lru); -if (!add_to_page_cache_lru (page, mapping, +list_for_each_entry_safe (page, next, pages, lru) { +if (!add_to_page_cache (page, mapping, page->index,GFP_KERNEL )) { mapping->a_ops->readpage (filp, page); + }else { +list_del (&page->lru); +page_cache_release (page); + nr_pages--; } -page_cache_release (page); } +lru_cache_add_list (pages, nr_pages,LRU_INACTIVE_FILE ); ret =0 ; out:
mm/swap.c +90 -9
131 lines not on this page · raw message
--
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 internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/3] mm: replace per-cpu lru-add page-vectors with page-lists
Quoted 32 lines · Konstantin Khlebnikov
This patch replaces page-vectors with page-lists in lru_cache_add*() functions. We can use
page->lrufor linking because page obviously not in lru.Now per-cpu batch limited with its pages total size, not pages count, otherwise it can be extremely huge if there many huge-pages inside:
PAGEVEC_SIZE*HPAGE_SIZE= 28Mb, per-cpu!
These pages are hidden from memory reclaimer for a while. New limit:LRU_CACHE_ADD_BATCH= 64 (*PAGE_SIZE= 256Kb)So, huge-page adding now will always drain per-cpu list. Huge-page allocation and preparation is long procedure, thus nobody will notice this draining.
Draining procedure disables preemption only for pages list isolation, thus batch size can be increased without negative effect for latency.
Plus this patch introduces new function
lru_cache_add_list()and use it inmpage_readpages()andread_pages(). There pages already collected in list. Unlike to single-page lru-add, list-add reuse page-referencies from caller, thus we save one page_get()/page_put() per page.Signed-off-by Konstantin Khlebnikov<[email protected]>--- fs/mpage.c | 21 +++++++---- include/linux/swap.h | 2 + mm/readahead.c | 15 +++++--- mm/swap.c | 99 +++++++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 114 insertions(+), 23 deletions(-)pvec =&per_cpu(lru_rotate_pvecs, cpu);
mm/swap.c EXPORT_SYMBOL(pagevec_lookup_tag); · line 848
Quoted 8 lines
mm/swap.c +5
-0@@ -765,6 +841,11 @@ EXPORT_SYMBOL(pagevec_lookup_tag);void __init swap_setup (void ) {unsigned long megs = totalram_pages>> (20 -PAGE_SHIFT ); +int cpu, lru; + +for_each_possible_cpu (cpu) +for_each_lru (lru) +INIT_LIST_HEAD (per_cpu (lru_add_pages, cpu) + lru);
As I afraid, here is is too late for this initialization. This must be in core-initcall.
I'll send v2 together with update lru-lock splitting rebased to linux-next.
mm/swap.c EXPORT_SYMBOL(pagevec_lookup_tag);
Quoted 4 lines
mm/swap.c +0
-0#ifdef CONFIG_SWAP bdi_init (swapper_space.backing_dev_info);
--
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 internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 3/3 mm: deprecate pagevec lru-add functions
In reply to Konstantin KhlebnikovThey mostly unused, the last user is fs/cachefiles/rdwr.c This patch replaces __pagevec_lru_add() with smaller implementation. It is exported, so we should keep it for a while.
Plus simplify and fix pathetic single-page page-vector operations in nfs_symlink(), this was second pagevec_lru_add_file() user.
--- fs/nfs/dir.c | 10 +++------- include/linux/pagevec.h | 4 +++- mm/swap.c | 27 +++++++-------------------- 3 files changed, 13 insertions(+), 28 deletions(-)
fs/nfs/dir.c +3 -7
@@ -1850,7 +1850,6 @@ static int nfs_unlink(struct inode *dir, struct dentry *dentry)*/ static int nfs_symlink (struct inode *dir,struct dentry *dentry,const char *symname) { -struct pagevec lru_pvec;struct page *page;char *kaddr;struct iattr attr;
@@ -1890,15 +1889,12 @@ static int nfs_symlink(struct inode *dir, struct dentry *dentry, const char *sym* No big deal if we can't add this page to the page cache here. * READLINK will get the missing page from the server if needed. */ -pagevec_init (&lru_pvec,0 ); -if (!add_to_page_cache (page, dentry->d_inode->i_mapping,0 , +if (!add_to_page_cache_lru (page, dentry->d_inode->i_mapping,0 ,GFP_KERNEL )) { -pagevec_add (&lru_pvec, page); -pagevec_lru_add_file (&lru_pvec);SetPageUptodate (page);unlock_page (page); - }else -__free_page (page); + } +put_page (page);return 0 ; }
include/linux/pagevec.h +3 -1
@@ -21,7 +21,6 @@ struct pagevec { };void __pagevec_release (struct pagevec *pvec); -void __pagevec_lru_add (struct pagevec *pvec,enum lru_list lru);unsigned pagevec_lookup (struct pagevec *pvec,struct address_space *mapping,pgoff_t start,unsigned nr_pages); unsigned pagevec_lookup_tag(struct pagevec *pvec,
@@ -64,6 +63,9 @@ static inline void pagevec_release(struct pagevec *pvec)__pagevec_release (pvec); } +/* Use lru_cache_add_list() instead */ +void __deprecated __pagevec_lru_add (struct pagevec *pvec,enum lru_list lru); +static inline void __pagevec_lru_add_anon (struct pagevec *pvec) {__pagevec_lru_add (pvec,LRU_INACTIVE_ANON );
mm/swap.c +7 -20
@@ -772,33 +772,20 @@ void lru_add_page_tail(struct zone* zone, }#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ -static void __pagevec_lru_add_fn (struct page *page,void *arg) -{ -enum lru_list lru = (enum lru_list )arg; -struct zone *zone =page_zone (page); -int file =is_file_lru (lru); -int active =is_active_lru (lru); - -VM_BUG_ON (PageActive (page)); -VM_BUG_ON (PageUnevictable (page)); -VM_BUG_ON (PageLRU (page)); - -SetPageLRU (page); -if (active) -SetPageActive (page); -update_page_reclaim_stat (zone, page, file, active); -add_page_to_lru_list (zone, page, lru); -} -/* * Add the passed pages to the LRU, then drop the caller's refcount * on them. Reinitialises the caller's pagevec. */ void __pagevec_lru_add (struct pagevec *pvec,enum lru_list lru) { -VM_BUG_ON (is_unevictable_lru (lru)); +LIST_HEAD (pages); +int i; -pagevec_lru_move_fn (pvec, __pagevec_lru_add_fn, (void *)lru); +VM_BUG_ON (is_unevictable_lru (lru)); +for ( i =0 ; i < pvec->nr ; i++ ) +list_add_tail (&pvec->pages[i]->lru, &pages); +pagevec_reinit (pvec); +__lru_cache_add_list (&pages, lru); }EXPORT_SYMBOL (__pagevec_lru_add);
--
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 internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>