Rollup patch of basic rmap against 2.5.26
Subsystems (14)
Over the past couple of weeks we've been doing some basic performance testing of the rmap overhead. For this I put together a rollup patch against 2.5.26 that includes what I'd consider basic rmap. As a reference, I'm also posting the patch here, so people can see what it consists of.
The list of patches included are:
minrmap The original minimal rmap patch
truncate_leak A bug fix
dmc_optimize Don't allocate pte_chain for one mapping
vmstat Add rmap statistics for vmstat
ptechain slab Allocate pte_chains from a slab
daniel_rmap_speedup Use hashed pte_chain locks
akpm_rmap_speedup Make pte_chain hold multiple pte ptrs
Again, this patch applies against 2.5.26, and clearly does not include many of the recent rmap optimizations.
Dave McCracken
======================================================================
Dave McCracken IBM Linux Base Kernel Team 1-512-838-3059
[email protected] T/L 678-3059
# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.737 -> 1.745 # include/linux/swap.h 1.47 -> 1.49 # include/linux/mm.h 1.56 -> 1.58 # mm/page_alloc.c 1.78 -> 1.83 # kernel/fork.c 1.49 -> 1.50 # mm/vmscan.c 1.81 -> 1.87 # fs/proc/proc_misc.c 1.30 -> 1.32 # include/linux/page-flags.h 1.9 -> 1.14 # init/main.c 1.49 -> 1.51 # mm/swapfile.c 1.52 -> 1.53 # mm/filemap.c 1.108 -> 1.112 # fs/exec.c 1.31 -> 1.32 # mm/swap.c 1.16 -> 1.18 # include/linux/kernel_stat.h 1.5 -> 1.6 # mm/swap_state.c 1.33 -> 1.35 # mm/memory.c 1.74 -> 1.78 # mm/mremap.c 1.13 -> 1.14 # mm/Makefile 1.11 -> 1.12 # (new) -> 1.1 include/asm-cris/rmap.h # (new) -> 1.1 include/asm-mips/rmap.h # (new) -> 1.1 include/asm-sparc/rmap.h # (new) -> 1.1 include/asm-ppc/rmap.h # (new) -> 1.1 include/asm-sparc64/rmap.h # (new) -> 1.3 include/asm-generic/rmap.h # (new) -> 1.1 include/linux/rmap-locking.h # (new) -> 1.1 include/asm-m68k/rmap.h # (new) -> 1.1 include/asm-arm/rmap.h # (new) -> 1.1 include/asm-s390/rmap.h # (new) -> 1.1 include/asm-mips64/rmap.h # (new) -> 1.1 include/asm-i386/rmap.h # (new) -> 1.7 mm/rmap.c # (new) -> 1.1 include/asm-alpha/rmap.h # (new) -> 1.1 include/asm-parisc/rmap.h # (new) -> 1.1 include/asm-sh/rmap.h # (new) -> 1.1 include/asm-ia64/rmap.h # (new) -> 1.1 include/asm-s390x/rmap.h
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 02/08/15 [email protected] 1.738
# 00_minrmap.txt
# --------------------------------------------
# 02/08/15 [email protected] 1.739
# 01_truncate_leak.txt
# --------------------------------------------
# 02/08/15 [email protected] 1.740
# 02_dmc_optimize.txt
# --------------------------------------------
# 02/08/15 [email protected] 1.741
# Merge vmstat patch
# --------------------------------------------
# 02/08/15 [email protected] 1.742
# Merge ptechains from slab
# --------------------------------------------
# 02/08/15 [email protected] 1.743
# Merge daniel-rmap-speedup
# --------------------------------------------
# 02/08/15 [email protected] 1.744
# Merge akpm rmap-speedup
# --------------------------------------------
# 02/08/15 [email protected] 1.745
# Resolve merge errors
# --------------------------------------------
#
fs/exec.c +2 -0
@@ -36,6 +36,7 @@#include <linux/spinlock.h> #include <linux/personality.h> #include <linux/binfmts.h> +#include <linux/swap.h> #define __NO_VERSION__#include <linux/module.h> #include <linux/namei.h>
@@ -283,6 +284,7 @@flush_dcache_page (page);flush_page_to_ram (page);set_pte (pte,pte_mkdirty (pte_mkwrite (mk_pte (page,PAGE_COPY )))); +page_add_rmap (page, pte);pte_unmap (pte); tsk->mm->rss++;spin_unlock (&tsk->mm->page_table_lock);
fs/proc/proc_misc.c +27 -3
@@ -159,7 +159,9 @@"SwapTotal: %8lu kB\n" "SwapFree: %8lu kB\n" "Dirty: %8lu kB\n" -"Writeback: %8lu kB\n" , +"Writeback: %8lu kB\n" +"PageTables: %8lu kB\n" +"ReverseMaps: %8lu\n" ,K (i.totalram),K (i.freeram), K(i.sharedram),
@@ -174,7 +176,9 @@K (i.totalswap),K (i.freeswap),K (ps.nr_dirty), -K (ps.nr_writeback) +K (ps.nr_writeback), +K (ps.nr_page_table_pages), + ps.nr_reverse_maps );return proc_calc_metrics (page, start, off, count, eof, len);
@@ -347,9 +351,29 @@ } len +=sprintf (page + len, -"\nctxt %lu\n" +"\npageallocs %u\n" +"pagefrees %u\n" +"pageactiv %u\n" +"pagedeact %u\n" +"pagefault %u\n" +"majorfault %u\n" +"pagescan %u\n" +"pagesteal %u\n" +"pageoutrun %u\n" +"allocstall %u\n" +"ctxt %lu\n" "btime %lu\n" "processes %lu\n" , + kstat.pgalloc, + kstat.pgfree, + kstat.pgactivate, + kstat.pgdeactivate, + kstat.pgfault, + kstat.pgmajfault, + kstat.pgscan, + kstat.pgsteal, + kstat.pageoutrun, + kstat.allocstall,nr_context_switches (), xtime.tv_sec - jif /HZ , total_forks);
include/asm-alpha/rmap.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _ALPHA_RMAP_H +#define _ALPHA_RMAP_H + +/* nothing to see, move along */ +#include <asm-generic/rmap.h> + +#endif
include/asm-arm/rmap.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _ARM_RMAP_H +#define _ARM_RMAP_H + +/* nothing to see, move along :) */ +#include <asm-generic/rmap.h> + +#endif /* _ARM_RMAP_H */
include/asm-cris/rmap.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _CRIS_RMAP_H +#define _CRIS_RMAP_H + +/* nothing to see, move along :) */ +#include <asm-generic/rmap.h> + +#endif
include/asm-generic/rmap.h new file +55 -0
55 lines not on this page · raw message
include/asm-i386/rmap.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _I386_RMAP_H +#define _I386_RMAP_H + +/* nothing to see, move along */ +#include <asm-generic/rmap.h> + +#endif
include/asm-ia64/rmap.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _IA64_RMAP_H +#define _IA64_RMAP_H + +/* nothing to see, move along */ +#include <asm-generic/rmap.h> + +#endif
include/asm-m68k/rmap.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _M68K_RMAP_H +#define _M68K_RMAP_H + +/* nothing to see, move along */ +#include <asm-generic/rmap.h> + +#endif
include/asm-mips/rmap.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _MIPS_RMAP_H +#define _MIPS_RMAP_H + +/* nothing to see, move along */ +#include <asm-generic/rmap.h> + +#endif
include/asm-mips64/rmap.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _MIPS64_RMAP_H +#define _MIPS64_RMAP_H + +/* nothing to see, move along */ +#include <asm-generic/rmap.h> + +#endif
include/asm-parisc/rmap.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _PARISC_RMAP_H +#define _PARISC_RMAP_H + +/* nothing to see, move along */ +#include <asm-generic/rmap.h> + +#endif
include/asm-ppc/rmap.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef _PPC_RMAP_H +#define _PPC_RMAP_H + +/* PPC calls pte_alloc() before mem_map[] is setup ... */ +#define BROKEN_PPC_PTE_ALLOC_ONE + +#include <asm-generic/rmap.h> + +#endif
include/asm-s390/rmap.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _S390_RMAP_H +#define _S390_RMAP_H + +/* nothing to see, move along */ +#include <asm-generic/rmap.h> + +#endif
include/asm-s390x/rmap.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _S390X_RMAP_H +#define _S390X_RMAP_H + +/* nothing to see, move along */ +#include <asm-generic/rmap.h> + +#endif
include/asm-sh/rmap.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _SH_RMAP_H +#define _SH_RMAP_H + +/* nothing to see, move along */ +#include <asm-generic/rmap.h> + +#endif
include/asm-sparc/rmap.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _SPARC_RMAP_H +#define _SPARC_RMAP_H + +/* nothing to see, move along */ +#include <asm-generic/rmap.h> + +#endif
include/asm-sparc64/rmap.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _SPARC64_RMAP_H +#define _SPARC64_RMAP_H + +/* nothing to see, move along */ +#include <asm-generic/rmap.h> + +#endif
include/linux/kernel_stat.h +12 -0
@@ -26,6 +26,11 @@unsigned int dk_drive_wblk[DK_MAX_MAJOR ][DK_MAX_DISK ];unsigned int pgpgin, pgpgout;unsigned int pswpin, pswpout; +unsigned int pgalloc, pgfree; +unsigned int pgactivate, pgdeactivate; +unsigned int pgfault, pgmajfault; +unsigned int pgscan, pgsteal; +unsigned int pageoutrun, allocstall;#if !defined(CONFIG_ARCH_S390 )unsigned int irqs[NR_CPUS ][NR_IRQS ];#endif
@@ -34,6 +39,13 @@extern struct kernel_stat kstat;extern unsigned long nr_context_switches (void ); + +/* +* Maybe we need to smp-ify kernel_stat some day. It would be nice to do +* that without having to modify all the code that increments the stats. +*/ +#define KERNEL_STAT_INC (x) kstat.x++ +#define KERNEL_STAT_ADD (x, y) kstat.x += y#if !defined(CONFIG_ARCH_S390 )/*
include/linux/mm.h +8 -0
@@ -130,6 +130,9 @@struct page * (*nopage)(struct vm_area_struct * area,unsigned long address,int unused); }; +/* forward declaration; pte_chain is meant to be internal to rmap.c */ +struct pte_chain ; +/* * Each physical page in the system has a struct page associated with * it to keep track of whatever it is we are using the page for at the
@@ -154,6 +157,11 @@updated asynchronously */ struct list_head lru;/* Pageout list, eg. active_list; protected by pagemap_lru_lock !! */ +union { +struct pte_chain * chain;/* Reverse pte mapping pointer. +* protected by PG_chainlock */ +pte_t * direct; + } pte;unsigned long private;/* mapping-private opaque data */ /*
include/linux/page-flags.h +11 -2
@@ -47,7 +47,7 @@* locked- and dirty-page accounting. The top eight bits of page->flags are * used for page->zone, so putting flag bits there doesn't work. */ -#define PG_locked 0/* Page is locked. Don't touch. */ +#define PG_locked 0/* Page is locked. Don't touch. */ #define PG_error 1#define PG_referenced 2#define PG_uptodate 3
@@ -64,7 +64,8 @@#define PG_private 12/* Has something at ->private */ #define PG_writeback 13/* Page is under writeback */ -#define PG_nosave 15/* Used for system suspend/resume */ +#define PG_nosave 14/* Used for system suspend/resume */ +#define PG_direct 15/* ->pte_chain points directly at pte */ /* * Global page accounting. One instance per CPU.
@@ -75,6 +76,8 @@unsigned long nr_pagecache;unsigned long nr_active;/* on active_list LRU */ unsigned long nr_inactive;/* on inactive_list LRU */ +unsigned long nr_page_table_pages; +unsigned long nr_reverse_maps; }____cacheline_aligned_in_smp page_states[NR_CPUS ];extern void get_page_state (struct page_state *ret);
@@ -215,6 +218,12 @@#define TestSetPageNosave (page) test_and_set_bit(PG_nosave, &(page)->flags)#define ClearPageNosave (page) clear_bit(PG_nosave, &(page)->flags)#define TestClearPageNosave (page) test_and_clear_bit(PG_nosave, &(page)->flags) + +#define PageDirect (page) test_bit(PG_direct, &(page)->flags) +#define SetPageDirect (page) set_bit(PG_direct, &(page)->flags) +#define TestSetPageDirect (page) test_and_set_bit(PG_direct, &(page)->flags) +#define ClearPageDirect (page) clear_bit(PG_direct, &(page)->flags) +#define TestClearPageDirect (page) test_and_clear_bit(PG_direct, &(page)->flags)/* * The PageSwapCache predicate doesn't use a PG_flag at this time,
include/linux/rmap-locking.h new file +109 -0
109 lines not on this page · raw message
include/linux/swap.h +16 -0
@@ -142,6 +142,21 @@struct address_space ;struct zone_t ; +/* linux/mm/rmap.c */ +extern int FASTCALL (page_referenced (struct page *)); +extern void FASTCALL (__page_add_rmap (struct page *,pte_t *)); +extern void FASTCALL (page_add_rmap (struct page *,pte_t *)); +extern void FASTCALL (__page_remove_rmap (struct page *,pte_t *)); +extern void FASTCALL (page_remove_rmap (struct page *,pte_t *)); +extern int FASTCALL (try_to_unmap (struct page *)); +extern int FASTCALL (page_over_rsslimit (struct page *)); + +/* return values of try_to_unmap */ +#define SWAP_SUCCESS 0 +#define SWAP_AGAIN 1 +#define SWAP_FAIL 2 +#define SWAP_ERROR 3 +/* linux/mm/swap.c */ extern void FASTCALL (lru_cache_add (struct page *));extern void FASTCALL (__lru_cache_del (struct page *));
@@ -168,6 +183,7 @@extern void show_swap_cache_info (void );#endif extern int add_to_swap_cache (struct page *,swp_entry_t ); +extern int add_to_swap (struct page *);extern void __delete_from_swap_cache (struct page *page);extern void delete_from_swap_cache (struct page *page);extern int move_to_swap_cache (struct page *page,swp_entry_t entry);
init/main.c +5 -2
@@ -28,6 +28,7 @@#include <linux/bootmem.h> #include <linux/tty.h> #include <linux/percpu.h> +#include <linux/kernel_stat.h> #include <asm/io.h> #include <asm/bugs.h>
@@ -68,7 +69,7 @@extern void sysctl_init (void );extern void signals_init (void );extern void buffer_init (void ); - +extern void pte_chain_init (void );extern void radix_tree_init (void );extern void free_initmem (void );
@@ -384,7 +385,7 @@mem_init ();kmem_cache_sizes_init ();pgtable_cache_init (); - +pte_chain_init (); mempages = num_physpages;fork_init (mempages);
@@ -501,6 +502,8 @@*/ free_initmem ();unlock_kernel (); + + kstat.pgfree =0 ;if (open ("/dev/console" ,O_RDWR ,0 ) <0 )printk ("Warning: unable to open an initial console.\n" );
kernel/fork.c +0 -4
@@ -189,7 +189,6 @@ mm->map_count =0 ; mm->rss =0 ; mm->cpu_vm_mask =0 ; - mm->swap_address =0 ; pprev = &mm->mmap;/*
@@ -308,9 +307,6 @@void mmput (struct mm_struct *mm) {if (atomic_dec_and_lock (&mm->mm_users, &mmlist_lock)) { -extern struct mm_struct *swap_mm; -if (swap_mm == mm) - swap_mm = list_entry(mm->mmlist.next, struct mm_struct, mmlist);list_del (&mm->mmlist); mmlist_nr--;spin_unlock (&mmlist_lock);
mm/Makefile +1 -1
@@ -16,6 +16,6 @@ vmalloc.o slab.o bootmem.o swap.o vmscan.o page_io.o \ page_alloc.o swap_state.o swapfile.o numa.o oom_kill.o \ shmem.o highmem.o mempool.o msync.o mincore.o readahead.o \ - pdflush.o page-writeback.o + pdflush.o page-writeback.o rmap.o include $(TOPDIR)/Rules.make
mm/filemap.c +19 -12
@@ -20,6 +20,7 @@#include <linux/iobuf.h> #include <linux/hash.h> #include <linux/writeback.h> +#include <linux/kernel_stat.h> /* * This is needed for the following functions: * - try_to_release_page
@@ -50,14 +51,20 @@/* * Lock ordering: * -* pagemap_lru_lock -* ->i_shared_lock (vmtruncate) -* ->private_lock (__free_pte->__set_page_dirty_buffers) +* ->i_shared_lock (vmtruncate) +* ->private_lock (__free_pte->__set_page_dirty_buffers) * ->swap_list_lock -* ->swap_device_lock (exclusive_swap_page, others) -* ->mapping->page_lock -* ->inode_lock (__mark_inode_dirty) -* ->sb_lock (fs/fs-writeback.c) +* ->swap_device_lock (exclusive_swap_page, others) +* ->rmap_lock (to/from swapcache) +* ->mapping->page_lock +* ->pagemap_lru_lock (zap_pte_range) +* ->inode_lock (__mark_inode_dirty) +* ->sb_lock (fs/fs-writeback.c) +* +* mm->page_table_lock +* ->rmap_lock (copy_page_range) +* ->mapping->page_lock (try_to_unmap_one) +* */ spinlock_t pagemap_lru_lock __cacheline_aligned_in_smp = SPIN_LOCK_UNLOCKED;
@@ -176,14 +183,13 @@*/ static void truncate_complete_page (struct page *page) { -/* Leave it on the LRU if it gets converted into anonymous buffers */ -if (!PagePrivate (page) ||do_invalidatepage (page,0 )) { -lru_cache_del (page); - }else { +/* Drop fs-specific data so the page might become freeable. */ +if (PagePrivate (page) && !do_invalidatepage (page,0 )) {if (current->flags &PF_INVALIDATE )printk ("%s: buffer heads were leaked\n" , current->comm); } +ClearPageDirty (page);ClearPageUptodate (page);remove_inode_page (page);
@@ -660,7 +666,7 @@* But that's OK - sleepers in wait_on_page_writeback() just go back to sleep. * * The first mb is necessary to safely close the critical section opened by the -* TryLockPage(), the second mb is necessary to enforce ordering between +* TestSetPageLocked(), the second mb is necessary to enforce ordering between * the clear_bit and the read of the waitqueue (to avoid SMP races with a * parallel wait_on_page_locked()). */
@@ -1534,6 +1540,7 @@return NULL ; page_not_uptodate: +KERNEL_STAT_INC (pgmajfault);lock_page (page);/* Did it get unhashed while we waited for it? */
mm/memory.c +89 -28
284 lines not on this page · raw message
mm/mremap.c +8 -0
@@ -68,8 +68,14 @@ {int error =0 ;pte_t pte; +struct page * page =NULL ; + +if (pte_present (*src)) + page =pte_page (*src);if (!pte_none (*src)) { +if (page) +page_remove_rmap (page, src); pte =ptep_get_and_clear (src);if (!dst) {/* No dest? We must put it back. */
@@ -77,6 +83,8 @@ error++; }set_pte (dst, pte); +if (page) +page_add_rmap (page, dst); }return error; }
mm/page_alloc.c +14 -5
@@ -21,6 +21,7 @@#include <linux/compiler.h> #include <linux/module.h> #include <linux/suspend.h> +#include <linux/kernel_stat.h> unsigned long totalram_pages;unsigned long totalhigh_pages;
@@ -86,12 +87,19 @@struct page *base;zone_t *zone; +if (PageLRU (page)) { +BUG_ON (in_interrupt ()); +lru_cache_del (page); + } + +KERNEL_STAT_ADD (pgfree,1 <<order); +BUG_ON (PagePrivate (page));BUG_ON (page->mapping !=NULL );BUG_ON (PageLocked (page)); -BUG_ON (PageLRU (page));BUG_ON (PageActive (page));BUG_ON (PageWriteback (page)); +BUG_ON (page->pte.chain !=NULL );if (PageDirty (page))ClearPageDirty (page);BUG_ON (page_count (page) !=0 );
@@ -236,6 +244,8 @@int order;list_t *curr; +KERNEL_STAT_ADD (pgalloc,1 <<order); +/* * Should not matter as we need quiescent system for * suspend anyway, but...
@@ -448,11 +458,8 @@void page_cache_release (struct page *page) { -if (!PageReserved (page) &&put_page_testzero (page)) { -if (PageLRU (page)) -lru_cache_del (page); +if (!PageReserved (page) &&put_page_testzero (page))__free_pages_ok (page,0 ); - } }void __free_pages (struct page *page,unsigned int order)
@@ -562,6 +569,8 @@ ret->nr_pagecache += ps->nr_pagecache; ret->nr_active += ps->nr_active; ret->nr_inactive += ps->nr_inactive; + ret->nr_page_table_pages += ps->nr_page_table_pages; + ret->nr_reverse_maps += ps->nr_reverse_maps; } }
mm/rmap.c new file +529 -0
529 lines not on this page · raw message
mm/swap.c +2 -1
@@ -14,11 +14,11 @@*/ #include <linux/mm.h> -#include <linux/kernel_stat.h> #include <linux/swap.h> #include <linux/swapctl.h> #include <linux/pagemap.h> #include <linux/init.h> +#include <linux/kernel_stat.h> #include <asm/dma.h> #include <asm/uaccess.h> /* for copy_to/from_user */
@@ -41,6 +41,7 @@if (PageLRU (page) && !PageActive (page)) {del_page_from_inactive_list (page);add_page_to_active_list (page); +KERNEL_STAT_INC (pgactivate); } }
mm/swap_state.c +72 -1
109 lines not on this page · raw message
mm/swapfile.c +1 -0
@@ -383,6 +383,7 @@return ;get_page (page);set_pte (dir,pte_mkold (mk_pte (page, vma->vm_page_prot))); +page_add_rmap (page, dir);swap_free (entry); ++vma->vm_mm->rss; }
mm/vmscan.c +102 -379
602 lines not on this page · raw message
Quoted 3 lines · Dave McCracken
...
daniel_rmap_speedupUse hashedpte_chainlocks
This one was shown to be a net loss on the NUMA-Q's. --
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/
Quoted 8 lines · Andrew Morton
Quoted 3 lines · Dave McCracken
...
daniel_rmap_speedupUse hashedpte_chainlocksThis one was shown to be a net loss on the NUMA-Q's.
But thanks for testing - I forgot to say that ;)
rmap's overhead manifests with workloads which are setting up and tearing doen pagetables a lot. fork/exec/exit/pagefaults/munmap/etc. I guess forking servers may hurt.
--
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/
Hi,
Quoted 4 lines · Andrew Morton
rmap's overhead manifests with workloads which are setting up and tearing doen pagetables a lot. fork/exec/exit/pagefaults/munmap/etc. I guess forking servers may hurt.
Hmm, so we gave up one of our advantages: fork() as fast as thread creation in other OSes.
Or did someone benchmark shell script execution on 2.4.x, 2.5.x, a later rmap-Kernel and compare that all with other Unices around?
Regards
Ingo Oeser
Signature · 5 lines
Science is what we can tell a computer. Art is everything else. --- D.E.Knuth -- 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/