aboutsummaryrefslogtreecommitdiffstats
path: root/arch/m68k/sun3x/time.h
diff options
context:
space:
mode:
authorZelin Tong <ztong@ludwig.cs.unc.edu>2020-07-28 14:43:39 -0400
committerZelin Tong <ztong@ludwig.cs.unc.edu>2020-07-28 14:43:39 -0400
commit721f4add1fedf8ac62d0473b886e9d379867b45f (patch)
treebcec00bb97eb1bc90acad54ca7bff3bd4b868056 /arch/m68k/sun3x/time.h
parent098a298ef73dd8dbacf0d697eef2a6f2daa2081c (diff)
Latest ChangesHEADwip-joshua
Diffstat (limited to 'arch/m68k/sun3x/time.h')
0 files changed, 0 insertions, 0 deletions
n value='wip-semi-part-edfos-jerickso'>wip-semi-part-edfos-jerickso The LITMUS^RT kernel.Bjoern Brandenburg
aboutsummaryrefslogblamecommitdiffstats
path: root/mm/rmap.c
blob: 06132109b9df060593a0553c2b42e702965ae697 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16















                                                               
                                           




                       
                                                                              

                                        
                              
                          




                                                                       
                                                                       
                                                                           


                                                                      
                                                                             
  
                                                                             
                    
                   







                          
                      

                           
                         
                             
                               
                          
                          
                              


                         

                     
                                          
                                                


                                                   




                                                                 

                                                                     







                                                                             

 
                                                           
 
                                                    

          
                                                                  




                                                                          
                                                                           
          

                                                                       
                                                    
                                                                   



                                                                       
                      
                                                      
                                              
                                                

         

                                                   
 
                                                                    
 
                                                            

 
                                                                      



                                                               






                                                           
                                                               

 








                                                             
                                                         




                                                            
                                                                    










                                                             


                                                  
                                   



                                                  
                                           
 
                                                       


                                        
                                                        

                                 

                                                    
                                                         
                                             

                 
                                              



                                                                
                                                                

                                                                            
                                         
                                   

                                                  
                                                

                                        
                                                
                                  
                                                 

                 




                                 

 












                                                                                                   
                                               
                                
                                         






                                                              
                                       

 


                                            







                                                                              

                                                                          
 
                                          
                                     
 
                                                                           

                                          







                                                                      


                                                          











                                                                        
         

                                        
                                   
                 
 
                






                                                                                

                              

 





                                                                          
 

                                   
                  
 



                                                                      


                                                                            



                                                                   


                                          
 



                                                                  



                                        
                                               

                                             





                                                                         
                                          
          


                                                                            

                                     

                                                                           
                                      
                                                
                                   
                                        



                         
                               
           
                              
                       

 


                                                 
                                     
 



                                                                             
                                                                             


                                                          
                                                                       




                                                                 

                                                        
                                 
                 



                                         

                                        




                                                                               
                                                              



                                                                             
                                         

                                       




                                         
                                     
 
                                         
 
                                     
                                           
                                    




                                                                                
                                                                          
                                                                       


  








                                                                            




                                                                              






                                                                              
   
                                                     
 
                                         


                                   
                                                               
                                                                     




                                                                          



                                                        


                                                                           



                                                                               
           
                                 
                                  
                                       
                            
         

                          



                        






                                                                              
                                                           
 
                                         
                                       
                                   
 
                        
                                                               





                                                                          
                                                  
                                                       
                  

                                                                           
                                                    
                   
                                         
                                                       



                                        
 






                                                        
                                  
                                       
                            



                                                       
                                     




                                                                      
                                                                         
                   
                                               







                                         
                        

 
                                                         
 
                                       


  
                                                         
   

                                                            
 
                                            








                                                                       
                                                                              
 



                       
                                                        
                                                            


                                                                                
                              
                             






                                                                            
                                       

                                                                              


                                       



                                                                        

 




                                                               
                   









                                       




                                                                               

                    
                                                       




                           
  

                                                   



                                                                           
                                                 
   
                                                                    
                                                                             
 

                   
                        
 
                                       
                                                               
                                                   


                                    
                                                                   


                           

                                       

                            

                                                        
                                          



                               
                                   
      



                                                                      
         

                                   

 








                                                                      
                                                                     




                              

                                                                        








                                                                        





                                 
  
                                          
   
                                                                             
                                                         

                                          
                        
                           
                                              
 


                                            



                                                                    
                                                               

                                                                                
                                          

                                                
                                         

                                                                 



                                                                       
                                     
                                 

                           
 



                                                                    

                                                                     
                                          
 

                                                   

                                                                 

                 







                                                                              
                                                                   




                                             


                                               
         
 




                                                            

 
                                                                              
 

                                              
 

                                                
 
                     





                                                    
                               
                                                                                



                                                              

                                      
                                             
                                            
 
                
                          








                                                     
 
                      









                                                               
         
















                                                              

 
                                                                          
                                                             

                                          
                   

                        
                           
 
                                                             


                         

                                                 
 
                                                              
                                                            

                                             
                                                    

                        
 
                                   
 
                  
                                                          

                             
    
                          

 
                                                                      
 
                                      
                             
 
                    



                                   






                                                   


                                  







                                     
 
                       
 
                                
 
   














                                                                     
                                                
                                      
                                                                             





                                                          



                                                        
                                                                    

                                                   
                                                                         
 
                                                  
 
                          
 


                           
          


                                                              
           
                       
                                          
 

                                                          
                                                      


   
                                                                



















                                                                               
                                                                 




                                                               




                                                            
                                                                        


                                                                        



                                                          










                                                                         
                                                          
                    





                                                                            
                                        

                                                                             

                                                                     
         


                                    
                                                
                                                                          
                  
                                                                    
            
                                                           

 
   






                                                                     
                                   



                                                          
                                                                              

                                                                             
                                
                                                                           

                                                             
                                                    

 



                                                      
                                         


                                          
                                 
 
                                                 
                                                    
                                                            
                                                                             
         
                                        

 


                                                    
 
                                                 



















                                                                           
                                        

 



                                                       
                                         
   
                                        
 



                                            
 

                                                       




                                                                 

          

                                                                    
                                                                           
           





                                                                           

                                        
 








                                                               


  
                                                       
   
                                                                          
                                                      

                                          

                     
                        
                             
                                                   
 
                                                             
                 
                         





                                                               
                                          


                                              
                                        
                                       

                                           




                                                                       
 

                                                          
                                                     




                                                                          


                                                       
                                                                   





                                                                 
                                            
                                                                        









                                                                     
                                    
                                                                  
                              





                                                              




                                                                     





                                                                               
                                                         
                                                        
                                                          




                                                                            
                                                         
                                                                              
                 



                                                                
                                                  
                                             




                                                                      
                                                 
 
                               


                                 
                                   
                                                       
                                                          

                   
 






                                                                     
                                                                







                                                                        
                 
                                               
         


                   









































































































                                                                                
                                                                        









































                                                                        














                                                                       
                                                       












                                                                          




                                                                        




                                             


                                                                 
                           







                                                                    
                                  
   
                                                         

                



                                             

                                                     
 
                                                                     
 







                                                                 
                                                                        



                                                        
                                                    


                                   
 









                                                                     
                                                     
                                                                         
                                                   



                                      




                                             



                                                     
                                                                 
 

                                    
 
 
                                              
 
                                               
 
                                

                                                                     
 
 

                                                                      


                                  


                                            













                                                                             
  











                                                                               
   
                                                                           

                                  
                      
                                   

                             
                                                  

                           
 
                                    
                                                                               
                                                      
                                                               



                                                                        
                                                                  

                                      

                                                 
         
                                       


                   












                                                                                
                                                                           

                                                      
                      
                                   

                             



                                                                      
                                                       
           
                                                
 

                           
 
                                    
                                  
                                                                        
                                                               



                                                                        
                                                                  
                                      


                                                 
         
 
     
                                    


                   
                                                               
 
                                    
                                                
                                
                                                 
            
                                                 
 
 
                          








                                                                              
 
                          





                                          









                                                                              

                                  
                          
                                                                          











                                                                          
                                
/*
 * mm/rmap.c - physical to virtual reverse mappings
 *
 * Copyright 2001, Rik van Riel <riel@conectiva.com.br>
 * Released under the General Public License (GPL).
 *
 * Simple, low overhead reverse mapping scheme.
 * Please try to keep this thing as modular as possible.
 *
 * Provides methods for unmapping each kind of mapped page:
 * the anon methods track anonymous pages, and
 * the file methods track pages belonging to an inode.
 *
 * Original design by Rik van Riel <riel@conectiva.com.br> 2001
 * File methods by Dave McCracken <dmccr@us.ibm.com> 2003, 2004
 * Anonymous methods by Andrea Arcangeli <andrea@suse.de> 2004
 * Contributions by Hugh Dickins 2003, 2004
 */

/*
 * Lock ordering in mm:
 *
 * inode->i_mutex	(while writing or truncating, not reading or faulting)
 *   mm->mmap_sem
 *     page->flags PG_locked (lock_page)
 *       mapping->i_mmap_rwsem
 *         anon_vma->rwsem
 *           mm->page_table_lock or pte_lock
 *             zone->lru_lock (in mark_page_accessed, isolate_lru_page)
 *             swap_lock (in swap_duplicate, swap_info_get)
 *               mmlist_lock (in mmput, drain_mmlist and others)
 *               mapping->private_lock (in __set_page_dirty_buffers)
 *               inode->i_lock (in set_page_dirty's __mark_inode_dirty)
 *               bdi.wb->list_lock (in set_page_dirty's __mark_inode_dirty)
 *                 sb_lock (within inode_lock in fs/fs-writeback.c)
 *                 mapping->tree_lock (widely used, in set_page_dirty,
 *                           in arch-dependent flush_dcache_mmap_lock,
 *                           within bdi.wb->list_lock in __sync_single_inode)
 *
 * anon_vma->rwsem,mapping->i_mutex      (memory_failure, collect_procs_anon)
 *   ->tasklist_lock
 *     pte map lock
 */

#include <linux/mm.h>
#include <linux/pagemap.h>
#include <linux/swap.h>
#include <linux/swapops.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/ksm.h>
#include <linux/rmap.h>
#include <linux/rcupdate.h>
#include <linux/export.h>
#include <linux/memcontrol.h>
#include <linux/mmu_notifier.h>
#include <linux/migrate.h>
#include <linux/hugetlb.h>
#include <linux/backing-dev.h>

#include <asm/tlbflush.h>

#include "internal.h"

static struct kmem_cache *anon_vma_cachep;
static struct kmem_cache *anon_vma_chain_cachep;

static inline struct anon_vma *anon_vma_alloc(void)
{
	struct anon_vma *anon_vma;

	anon_vma = kmem_cache_alloc(anon_vma_cachep, GFP_KERNEL);
	if (anon_vma) {
		atomic_set(&anon_vma->refcount, 1);
		anon_vma->degree = 1;	/* Reference for first vma */
		anon_vma->parent = anon_vma;
		/*
		 * Initialise the anon_vma root to point to itself. If called
		 * from fork, the root will be reset to the parents anon_vma.
		 */
		anon_vma->root = anon_vma;
	}

	return anon_vma;
}

static inline void anon_vma_free(struct anon_vma *anon_vma)
{
	VM_BUG_ON(atomic_read(&anon_vma->refcount));

	/*
	 * Synchronize against page_lock_anon_vma_read() such that
	 * we can safely hold the lock without the anon_vma getting
	 * freed.
	 *
	 * Relies on the full mb implied by the atomic_dec_and_test() from
	 * put_anon_vma() against the acquire barrier implied by
	 * down_read_trylock() from page_lock_anon_vma_read(). This orders:
	 *
	 * page_lock_anon_vma_read()	VS	put_anon_vma()
	 *   down_read_trylock()		  atomic_dec_and_test()
	 *   LOCK				  MB
	 *   atomic_read()			  rwsem_is_locked()
	 *
	 * LOCK should suffice since the actual taking of the lock must
	 * happen _before_ what follows.
	 */
	might_sleep();
	if (rwsem_is_locked(&anon_vma->root->rwsem)) {
		anon_vma_lock_write(anon_vma);
		anon_vma_unlock_write(anon_vma);
	}

	kmem_cache_free(anon_vma_cachep, anon_vma);
}

static inline struct anon_vma_chain *anon_vma_chain_alloc(gfp_t gfp)
{
	return kmem_cache_alloc(anon_vma_chain_cachep, gfp);
}

static void anon_vma_chain_free(struct anon_vma_chain *anon_vma_chain)
{
	kmem_cache_free(anon_vma_chain_cachep, anon_vma_chain);
}

static void anon_vma_chain_link(struct vm_area_struct *vma,
				struct anon_vma_chain *avc,
				struct anon_vma *anon_vma)
{
	avc->vma = vma;
	avc->anon_vma = anon_vma;
	list_add(&avc->same_vma, &vma->anon_vma_chain);
	anon_vma_interval_tree_insert(avc, &anon_vma->rb_root);
}

/**
 * anon_vma_prepare - attach an anon_vma to a memory region
 * @vma: the memory region in question
 *
 * This makes sure the memory mapping described by 'vma' has
 * an 'anon_vma' attached to it, so that we can associate the
 * anonymous pages mapped into it with that anon_vma.
 *
 * The common case will be that we already have one, but if
 * not we either need to find an adjacent mapping that we
 * can re-use the anon_vma from (very common when the only
 * reason for splitting a vma has been mprotect()), or we
 * allocate a new one.
 *
 * Anon-vma allocations are very subtle, because we may have
 * optimistically looked up an anon_vma in page_lock_anon_vma_read()
 * and that may actually touch the spinlock even in the newly
 * allocated vma (it depends on RCU to make sure that the
 * anon_vma isn't actually destroyed).
 *
 * As a result, we need to do proper anon_vma locking even
 * for the new allocation. At the same time, we do not want
 * to do any locking for the common case of already having
 * an anon_vma.
 *
 * This must be called with the mmap_sem held for reading.
 */
int anon_vma_prepare(struct vm_area_struct *vma)
{
	struct anon_vma *anon_vma = vma->anon_vma;
	struct anon_vma_chain *avc;

	might_sleep();
	if (unlikely(!anon_vma)) {
		struct mm_struct *mm = vma->vm_mm;
		struct anon_vma *allocated;

		avc = anon_vma_chain_alloc(GFP_KERNEL);
		if (!avc)
			goto out_enomem;

		anon_vma = find_mergeable_anon_vma(vma);
		allocated = NULL;
		if (!anon_vma) {
			anon_vma = anon_vma_alloc();
			if (unlikely(!anon_vma))
				goto out_enomem_free_avc;
			allocated = anon_vma;
		}

		anon_vma_lock_write(anon_vma);
		/* page_table_lock to protect against threads */
		spin_lock(&mm->page_table_lock);
		if (likely(!vma->anon_vma)) {
			vma->anon_vma = anon_vma;
			anon_vma_chain_link(vma, avc, anon_vma);
			/* vma reference or self-parent link for new root */
			anon_vma->degree++;
			allocated = NULL;
			avc = NULL;
		}
		spin_unlock(&mm->page_table_lock);
		anon_vma_unlock_write(anon_vma);

		if (unlikely(allocated))
			put_anon_vma(allocated);
		if (unlikely(avc))
			anon_vma_chain_free(avc);
	}
	return 0;

 out_enomem_free_avc:
	anon_vma_chain_free(avc);
 out_enomem:
	return -ENOMEM;
}

/*
 * This is a useful helper function for locking the anon_vma root as
 * we traverse the vma->anon_vma_chain, looping over anon_vma's that
 * have the same vma.
 *
 * Such anon_vma's should have the same root, so you'd expect to see
 * just a single mutex_lock for the whole traversal.
 */
static inline struct anon_vma *lock_anon_vma_root(struct anon_vma *root, struct anon_vma *anon_vma)
{
	struct anon_vma *new_root = anon_vma->root;
	if (new_root != root) {
		if (WARN_ON_ONCE(root))
			up_write(&root->rwsem);
		root = new_root;
		down_write(&root->rwsem);
	}
	return root;
}

static inline void unlock_anon_vma_root(struct anon_vma *root)
{
	if (root)
		up_write(&root->rwsem);
}

/*
 * Attach the anon_vmas from src to dst.
 * Returns 0 on success, -ENOMEM on failure.
 *
 * If dst->anon_vma is NULL this function tries to find and reuse existing
 * anon_vma which has no vmas and only one child anon_vma. This prevents
 * degradation of anon_vma hierarchy to endless linear chain in case of
 * constantly forking task. On the other hand, an anon_vma with more than one
 * child isn't reused even if there was no alive vma, thus rmap walker has a
 * good chance of avoiding scanning the whole hierarchy when it searches where
 * page is mapped.
 */
int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
{
	struct anon_vma_chain *avc, *pavc;
	struct anon_vma *root = NULL;

	list_for_each_entry_reverse(pavc, &src->anon_vma_chain, same_vma) {
		struct anon_vma *anon_vma;

		avc = anon_vma_chain_alloc(GFP_NOWAIT | __GFP_NOWARN);
		if (unlikely(!avc)) {
			unlock_anon_vma_root(root);
			root = NULL;
			avc = anon_vma_chain_alloc(GFP_KERNEL);
			if (!avc)
				goto enomem_failure;
		}
		anon_vma = pavc->anon_vma;