name='generator' content='cgit v1.2.2'/>
aboutsummaryrefslogblamecommitdiffstats
path: root/fs/fs-writeback.c
blob: 34591ee804b58ad8e81ee04b3754dba1bcf77f8c (plain) (tree)
1
2
3
4
5
6
7
8
9
10









                                                                 
                             




                                                           
                         
                           
                       


                        

                          



                              
                             
                     
 
  

                                                                        
                          


                                            


                                      
 
                                                               
                                                                     

  







                                                                           




                                                                           



                                                                           

                                                                       


                                                       
                                                            

 


                                                                        
 



                                                          

 




                                                            

                                                                               
 






                                                                              
                                                                  
         











                                                          
                                      

 

                                                                  
                                        
 
                                       
 



                                                                      

                                                  

                                                    
                                                      
                 
                       
         
 


                                          
 
                                  








                                                                   
                                                                 
                                                            

   
                                                                     
 
                                                   
 
 




                                                              



                                                                    


                                                                 



                                                                         
                                             


                                      


  










                                                     



                                                                             
                                                                           




                                                                              
                                                            
 
                                                
                                        
                                   
 
                                                  
                                                                         

                                                      
                                                   


  
                                                                   
   
                                           
 

                                                            
                                                
                                                     

 


                                                    

                                                
           
 



                                               







                                                                               
                                                             





                                                                  
  





                                                                     

                                     
                                      
                            
                           
 
                                             
                                                       
                                      
                                                                 
                              


                                            
                                                   

         





                                                                          

                                                      
                                              
                                                          
                                              
                                              
                                                                             
                 




                                                       







                                                                
   
                                                                              
 
                                                
                                                    
                                                                      

 
                                                                          
 
                                                                   
                                                                  
                 
 
 
  







                                                         

                                            
                                                 
                                                                          
                                               
                                          
         


  


                                                                            
  




                                                                            

          
                                                                          
 
                                                         
                       

                


                                                







                                                                             
                                                                             


                                                                           
                                                 
                   
                                                    









                                                             
                                        
 
                                             
                                 
                                         
                                    
                                         


                                          




                                                                         
                                            
                                                     



                                  




                                                                      
                                  

                                                             
                                    

                                                                 
                                                  



                                  
                                       
                                  
                                  
                                            
                                                                   

                                                                                
                                                                      
                           

                                                        
                                  
                                                                     
                                   
                                                  

                                  




                                                                               
                                   
                                                    
                         







                                                                           

                          


                                                                            
                           
                                                         

                 
                                   


                   
  
                                                                  

                                                                          
   
                                                        
 
                            




                                           
                      

                              
                                               
                               
                                    

                                       

                      
                     

 

                                                      

                                                         

                                                          
  


                                                      

                                                                                
 
                                        
                                   
                                                              
















                                                                            
                                 

                 




                                                                              
                                          
                                                                         
                                                    


                                          
 



                                                                          

                                                                
                                 
                 
 
                              
 
                                                   
                                                   




                                                                         
                                            
                 
                                            
                                                 
                            
                               
                                               

                                            
                                 
                 
                                                
                                         
         



                           

                                                  


                    

                                                                 
                                       

                                                       
 
                                        
                                                              
                                                     
 


                                                
                 

                                                              
 


                              
                                         


                                                




                                                                        
                                       


                                                       
                                         

 
  











                                                                          
                                                               

                                                  
                                                                        



                                                         
  



                                                                               
  


                                                                          
  

                                                                               
   
                                                  
                                                        
 
                                        
                                                          
                                               


                                                               


                                 
                         
                            
 




                                                                             



                                          
 

















                                                                              
                                                        

                  
                                                                 
                   
                                        
                              
 
                  









                                                                      

                                                                      
                   
                                                                   
                              
 
                                
                                              
                                      

                                                         

                                                                  

                                                      

                                                           

                                                                

                  
                                                                 
                   





                                                                          
                              


                                                       
                                                  





                                                            
                                               
                                                   
                                                             
                                                                
                                                  
                                                        
                                                    
                 
                                                 





                     
                                                                           
   
                                 
                                                
 
                                              
 
                                    



                                                                  
         
                                      
                    

 










                                                                    
















                                                               




                                                             





                                                       





                                                                        
                                        
 
                       
                                                 





                                                       
                                               
         









                                                              
                                       
                       
 
                                                        
                                                          

                                                                          
                                                      

                               
                                                      
 

                                                
                                                

                  

                                                                           
                   



                                             





                                                         
                                               
                                                          







                                                                         
                                    
 

                                               

                           
                                       
                        
                                  





                                                                            

                                          
                                        





                                                                               

                                                       

                                                             
                                  
                                                  
 
                                                      
                                                                            
                                                          
                                 

                 
                                                                    
                                                                                          





                                                                             
                                   
                 
 


                                
                                                       

                                         

                                         


                 
 
  

                                                                          
   
                                          
 
                                     
 

                                                             

                                                                   
 
                        
                                                           

                                           
                                                            
         
                          

 



























                                                                         
  








                                                                         
  

                                                               
  





                                                                               
   
                                                       
 
                                             
                                            
 





















                                                                             
                                  










                                                                             
                                              





                                                                     
                                                  
                                                      
                 
                                               
                                              





                                                                            
                                                













                                                                            
                         
 

                                                       
                                                      
                                                                       




                                                               
                 
         

                                    
 









                                                                           









                                                                               
                                                  






                                                                    
                                                 
 
                                       







                                                                        
                                                              
                                                                 
 



                                                                       
                                 
                 
                              
                                            

                                                 
                  





                                                                              







                                           
                                               
         
                                         
                        

 
   
                                                                             
                      
                                    
  

                                                                             
                                     
   
                                                                     
 

                                         

                                               
                                        
                                     
          
 
                                                 

                                         
 











                                                                             
                                                                
 
                                   

   








                                                                        
                                         
                                        
                                       






                                           




















                                                                        



                                                                      
               
   
                                           
 

                                         



                                              
                                        

          

                                                 


                                         
                           
 
                              
 
   





                                                                             
  
                                                                               
   




                                                  
                                                               

                                       


                                                           
                                    

                      
                                       
                                  
                                                  
                                    
                                         
                 
                                       


















                                                                            
                                       
                                  
                                                 
                                    
                                         


                          

   
                                               


                                   
                                                                      












                                                                            
/*
 * fs/fs-writeback.c
 *
 * Copyright (C) 2002, Linus Torvalds.
 *
 * Contains all the functions related to writing back and waiting
 * upon dirty inodes against superblocks, and writing back dirty
 * pages against inodes.  ie: data writeback.  Writeout of the
 * inode itself is not handled here.
 *
 * 10Apr2002	Andrew Morton
 *		Split out of fs/inode.c
 *		Additions for address_space-based writeback
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/spinlock.h>
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/kthread.h>
#include <linux/freezer.h>
#include <linux/writeback.h>
#include <linux/blkdev.h>
#include <linux/backing-dev.h>
#include <linux/buffer_head.h>
#include <linux/tracepoint.h>
#include "internal.h"

/*
 * Passed into wb_writeback(), essentially a subset of writeback_control
 */
struct wb_writeback_work {
	long nr_pages;
	struct super_block *sb;
	enum writeback_sync_modes sync_mode;
	unsigned int for_kupdate:1;
	unsigned int range_cyclic:1;
	unsigned int for_background:1;

	struct list_head list;		/* pending work list */
	struct completion *done;	/* set if the caller waits */
};

/*
 * Include the creation of the trace points after defining the
 * wb_writeback_work structure so that the definition remains local to this
 * file.
 */
#define CREATE_TRACE_POINTS
#include <trace/events/writeback.h>

/*
 * We don't actually have pdflush, but this one is exported though /proc...
 */
int nr_pdflush_threads;

/**
 * writeback_in_progress - determine whether there is writeback in progress
 * @bdi: the device's backing_dev_info structure.
 *
 * Determine whether there is writeback waiting to be handled against a
 * backing device.
 */
int writeback_in_progress(struct backing_dev_info *bdi)
{
	return test_bit(BDI_writeback_running, &bdi->state);
}

static inline struct backing_dev_info *inode_to_bdi(struct inode *inode)
{
	struct super_block *sb = inode->i_sb;

	if (strcmp(sb->s_type->name, "bdev") == 0)
		return inode->i_mapping->backing_dev_info;

	return sb->s_bdi;
}

static inline struct inode *wb_inode(struct list_head *head)
{
	return list_entry(head, struct inode, i_wb_list);
}

/* Wakeup flusher thread or forker thread to fork it. Requires bdi->wb_lock. */
static void bdi_wakeup_flusher(struct backing_dev_info *bdi)
{
	if (bdi->wb.task) {
		wake_up_process(bdi->wb.task);
	} else {
		/*
		 * The bdi thread isn't there, wake up the forker thread which
		 * will create and run it.
		 */
		wake_up_process(default_backing_dev_info.wb.task);
	}
}

static void bdi_queue_work(struct backing_dev_info *bdi,
			   struct wb_writeback_work *work)
{
	trace_writeback_queue(bdi, work);

	spin_lock_bh(&bdi->wb_lock);
	list_add_tail(&work->list, &bdi->work_list);
	if (!bdi->wb.task)
		trace_writeback_nothread(bdi, work);
	bdi_wakeup_flusher(bdi);
	spin_unlock_bh(&bdi->wb_lock);
}

static void
__bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages,
		      bool range_cyclic)
{
	struct wb_writeback_work *work;

	/*
	 * This is WB_SYNC_NONE writeback, so if allocation fails just
	 * wakeup the thread for old dirty data writeback
	 */
	work = kzalloc(sizeof(*work), GFP_ATOMIC);
	if (!work) {
		if (bdi->wb.task) {
			trace_writeback_nowork(bdi);
			wake_up_process(bdi->wb.task);
		}
		return;
	}