Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions | Variables
page-writeback.c File Reference
#include <linux/kernel.h>
#include <linux/export.h>
#include <linux/spinlock.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/swap.h>
#include <linux/slab.h>
#include <linux/pagemap.h>
#include <linux/writeback.h>
#include <linux/init.h>
#include <linux/backing-dev.h>
#include <linux/task_io_accounting_ops.h>
#include <linux/blkdev.h>
#include <linux/mpage.h>
#include <linux/rmap.h>
#include <linux/percpu.h>
#include <linux/notifier.h>
#include <linux/smp.h>
#include <linux/sysctl.h>
#include <linux/cpu.h>
#include <linux/syscalls.h>
#include <linux/buffer_head.h>
#include <linux/pagevec.h>
#include <linux/timer.h>
#include <trace/events/writeback.h>

Go to the source code of this file.

Macros

#define MAX_PAUSE   max(HZ/5, 1)
 
#define DIRTY_POLL_THRESH   (128 >> (PAGE_SHIFT - 10))
 
#define BANDWIDTH_INTERVAL   max(HZ/5, 1)
 
#define RATELIMIT_CALC_SHIFT   10
 
#define VM_COMPLETIONS_PERIOD_LEN   (3*HZ)
 
#define WRITEBACK_TAG_BATCH   4096
 

Functions

 EXPORT_SYMBOL_GPL (dirty_writeback_interval)
 
 EXPORT_SYMBOL (laptop_mode)
 
void global_dirty_limits (unsigned long *pbackground, unsigned long *pdirty)
 
bool zone_dirty_ok (struct zone *zone)
 
int dirty_background_ratio_handler (struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
 
int dirty_background_bytes_handler (struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
 
int dirty_ratio_handler (struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
 
int dirty_bytes_handler (struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
 
void bdi_writeout_inc (struct backing_dev_info *bdi)
 
 EXPORT_SYMBOL_GPL (bdi_writeout_inc)
 
int bdi_set_min_ratio (struct backing_dev_info *bdi, unsigned int min_ratio)
 
int bdi_set_max_ratio (struct backing_dev_info *bdi, unsigned max_ratio)
 
 EXPORT_SYMBOL (bdi_set_max_ratio)
 
unsigned long bdi_dirty_limit (struct backing_dev_info *bdi, unsigned long dirty)
 
void __bdi_update_bandwidth (struct backing_dev_info *bdi, unsigned long thresh, unsigned long bg_thresh, unsigned long dirty, unsigned long bdi_thresh, unsigned long bdi_dirty, unsigned long start_time)
 
void set_page_dirty_balance (struct page *page, int page_mkwrite)
 
 DEFINE_PER_CPU (int, dirty_throttle_leaks)=0
 
void balance_dirty_pages_ratelimited_nr (struct address_space *mapping, unsigned long nr_pages_dirtied)
 
 EXPORT_SYMBOL (balance_dirty_pages_ratelimited_nr)
 
void throttle_vm_writeout (gfp_t gfp_mask)
 
int dirty_writeback_centisecs_handler (ctl_table *table, int write, void __user *buffer, size_t *length, loff_t *ppos)
 
void writeback_set_ratelimit (void)
 
void __init page_writeback_init (void)
 
void tag_pages_for_writeback (struct address_space *mapping, pgoff_t start, pgoff_t end)
 
 EXPORT_SYMBOL (tag_pages_for_writeback)
 
int write_cache_pages (struct address_space *mapping, struct writeback_control *wbc, writepage_t writepage, void *data)
 
 EXPORT_SYMBOL (write_cache_pages)
 
int generic_writepages (struct address_space *mapping, struct writeback_control *wbc)
 
 EXPORT_SYMBOL (generic_writepages)
 
int do_writepages (struct address_space *mapping, struct writeback_control *wbc)
 
int write_one_page (struct page *page, int wait)
 
 EXPORT_SYMBOL (write_one_page)
 
int __set_page_dirty_no_writeback (struct page *page)
 
void account_page_dirtied (struct page *page, struct address_space *mapping)
 
 EXPORT_SYMBOL (account_page_dirtied)
 
void account_page_writeback (struct page *page)
 
 EXPORT_SYMBOL (account_page_writeback)
 
int __set_page_dirty_nobuffers (struct page *page)
 
 EXPORT_SYMBOL (__set_page_dirty_nobuffers)
 
void account_page_redirty (struct page *page)
 
 EXPORT_SYMBOL (account_page_redirty)
 
int redirty_page_for_writepage (struct writeback_control *wbc, struct page *page)
 
 EXPORT_SYMBOL (redirty_page_for_writepage)
 
int set_page_dirty (struct page *page)
 
 EXPORT_SYMBOL (set_page_dirty)
 
int set_page_dirty_lock (struct page *page)
 
 EXPORT_SYMBOL (set_page_dirty_lock)
 
int clear_page_dirty_for_io (struct page *page)
 
 EXPORT_SYMBOL (clear_page_dirty_for_io)
 
int test_clear_page_writeback (struct page *page)
 
int test_set_page_writeback (struct page *page)
 
 EXPORT_SYMBOL (test_set_page_writeback)
 
int mapping_tagged (struct address_space *mapping, int tag)
 
 EXPORT_SYMBOL (mapping_tagged)
 

Variables

int dirty_background_ratio = 10
 
unsigned long dirty_background_bytes
 
int vm_highmem_is_dirtyable
 
int vm_dirty_ratio = 20
 
unsigned long vm_dirty_bytes
 
unsigned int dirty_writeback_interval = 5 * 100
 
unsigned int dirty_expire_interval = 30 * 100
 
int block_dump
 
int laptop_mode
 
unsigned long global_dirty_limit
 

Macro Definition Documentation

#define BANDWIDTH_INTERVAL   max(HZ/5, 1)

Definition at line 54 of file page-writeback.c.

#define DIRTY_POLL_THRESH   (128 >> (PAGE_SHIFT - 10))

Definition at line 49 of file page-writeback.c.

#define MAX_PAUSE   max(HZ/5, 1)

Definition at line 43 of file page-writeback.c.

#define RATELIMIT_CALC_SHIFT   10

Definition at line 56 of file page-writeback.c.

#define VM_COMPLETIONS_PERIOD_LEN   (3*HZ)

Definition at line 152 of file page-writeback.c.

#define WRITEBACK_TAG_BATCH   4096

Function Documentation

void __bdi_update_bandwidth ( struct backing_dev_info bdi,
unsigned long  thresh,
unsigned long  bg_thresh,
unsigned long  dirty,
unsigned long  bdi_thresh,
unsigned long  bdi_dirty,
unsigned long  start_time 
)

Definition at line 1012 of file page-writeback.c.

int __set_page_dirty_no_writeback ( struct page page)

Definition at line 1958 of file page-writeback.c.

int __set_page_dirty_nobuffers ( struct page page)

Definition at line 2009 of file page-writeback.c.

void account_page_dirtied ( struct page page,
struct address_space mapping 
)

Definition at line 1969 of file page-writeback.c.

void account_page_redirty ( struct page page)

Definition at line 2045 of file page-writeback.c.

void account_page_writeback ( struct page page)

Definition at line 1988 of file page-writeback.c.

void balance_dirty_pages_ratelimited_nr ( struct address_space mapping,
unsigned long  nr_pages_dirtied 
)

balance_dirty_pages_ratelimited_nr - balance dirty memory state : address_space which was dirtied : number of pages which the caller has just dirtied

Processes which are dirtying memory should call in here once for each page which was newly dirtied. The function will periodically check the system's dirty state and will initiate writeback if needed.

On really big machines, get_writeback_state is expensive, so try to avoid calling it too often (ratelimiting). But once we're over the dirty memory limit we decrease the ratelimiting by a lot, to prevent individual processes from overshooting the limit by (ratelimit_pages) each.

Definition at line 1452 of file page-writeback.c.

unsigned long bdi_dirty_limit ( struct backing_dev_info bdi,
unsigned long  dirty 
)

bdi_dirty_limit - 's share of dirty throttling threshold : the backing_dev_info to query : global dirty limit in pages

Returns 's dirty limit in pages. The term "dirty" in the context of dirty balancing includes all PG_dirty, PG_writeback and NFS unstable pages.

Note that balance_dirty_pages() will only seriously take it as a hard limit when sleeping max_pause per page is not enough to keep the dirty pages under control. For example, when the device is completely stalled due to some error conditions, or when there are 1000 dd tasks writing to a slow 10MB/s USB key. In the other normal situations, it acts more gently by throttling the tasks more (rather than completely block them) when the bdi dirty pages go high.

It allocates high/low dirty limits to fast/slow devices, in order to prevent

  • starving fast devices
  • piling up dirty pages (that will take long time to sync) on slow devices

The bdi's share of dirty limit will be adapting to its throughput and bounded by the bdi->min_ratio and/or bdi->max_ratio parameters, if set.

Definition at line 547 of file page-writeback.c.

int bdi_set_max_ratio ( struct backing_dev_info bdi,
unsigned  max_ratio 
)

Definition at line 494 of file page-writeback.c.

int bdi_set_min_ratio ( struct backing_dev_info bdi,
unsigned int  min_ratio 
)

Definition at line 473 of file page-writeback.c.

void bdi_writeout_inc ( struct backing_dev_info bdi)

Definition at line 424 of file page-writeback.c.

int clear_page_dirty_for_io ( struct page page)

Definition at line 2146 of file page-writeback.c.

DEFINE_PER_CPU ( int  ,
dirty_throttle_leaks   
)
pure virtual
int dirty_background_bytes_handler ( struct ctl_table table,
int  write,
void __user buffer,
size_t lenp,
loff_t *  ppos 
)

Definition at line 351 of file page-writeback.c.

int dirty_background_ratio_handler ( struct ctl_table table,
int  write,
void __user buffer,
size_t lenp,
loff_t *  ppos 
)

Definition at line 339 of file page-writeback.c.

int dirty_bytes_handler ( struct ctl_table table,
int  write,
void __user buffer,
size_t lenp,
loff_t *  ppos 
)

Definition at line 378 of file page-writeback.c.

int dirty_ratio_handler ( struct ctl_table table,
int  write,
void __user buffer,
size_t lenp,
loff_t *  ppos 
)

Definition at line 363 of file page-writeback.c.

int dirty_writeback_centisecs_handler ( ctl_table table,
int  write,
void __user buffer,
size_t length,
loff_t *  ppos 
)

Definition at line 1531 of file page-writeback.c.

int do_writepages ( struct address_space mapping,
struct writeback_control wbc 
)

Definition at line 1903 of file page-writeback.c.

EXPORT_SYMBOL ( laptop_mode  )
EXPORT_SYMBOL ( bdi_set_max_ratio  )
EXPORT_SYMBOL ( tag_pages_for_writeback  )
EXPORT_SYMBOL ( write_cache_pages  )
EXPORT_SYMBOL ( generic_writepages  )
EXPORT_SYMBOL ( write_one_page  )
EXPORT_SYMBOL ( account_page_dirtied  )
EXPORT_SYMBOL ( account_page_writeback  )
EXPORT_SYMBOL ( __set_page_dirty_nobuffers  )
EXPORT_SYMBOL ( account_page_redirty  )
EXPORT_SYMBOL ( redirty_page_for_writepage  )
EXPORT_SYMBOL ( set_page_dirty  )
EXPORT_SYMBOL ( set_page_dirty_lock  )
EXPORT_SYMBOL ( clear_page_dirty_for_io  )
EXPORT_SYMBOL ( test_set_page_writeback  )
EXPORT_SYMBOL ( mapping_tagged  )
EXPORT_SYMBOL_GPL ( dirty_writeback_interval  )
EXPORT_SYMBOL_GPL ( bdi_writeout_inc  )
int generic_writepages ( struct address_space mapping,
struct writeback_control wbc 
)

generic_writepages - walk the list of dirty pages of the given address space and writepage() all of them. : address space structure to write : subtract the number of written pages from *->nr_to_write

This is a library function, which implements the writepages() address_space_operation.

Definition at line 1885 of file page-writeback.c.

void global_dirty_limits ( unsigned long pbackground,
unsigned long pdirty 
)

Definition at line 243 of file page-writeback.c.

int mapping_tagged ( struct address_space mapping,
int  tag 
)

Definition at line 2273 of file page-writeback.c.

void __init page_writeback_init ( void  )

Definition at line 1642 of file page-writeback.c.

int redirty_page_for_writepage ( struct writeback_control wbc,
struct page page 
)

Definition at line 2061 of file page-writeback.c.

int set_page_dirty ( struct page page)

Definition at line 2080 of file page-writeback.c.

void set_page_dirty_balance ( struct page page,
int  page_mkwrite 
)

Definition at line 1410 of file page-writeback.c.

int set_page_dirty_lock ( struct page page)

Definition at line 2121 of file page-writeback.c.

void tag_pages_for_writeback ( struct address_space mapping,
pgoff_t  start,
pgoff_t  end 
)

tag_pages_for_writeback - tag pages to be written by write_cache_pages : address space structure to write : starting page index : ending page index (inclusive)

This function scans the page range from to (inclusive) and tags all pages that have DIRTY tag set with a special TOWRITE tag. The idea is that write_cache_pages (or whoever calls this function) will then use TOWRITE tag to identify pages eligible for writeback. This mechanism is used to avoid livelocking of writeback by a process steadily creating new dirty pages in the file (thus it is important for this function to be quick so that it can tag pages faster than a dirtying process can create them).

Definition at line 1667 of file page-writeback.c.

int test_clear_page_writeback ( struct page page)

Definition at line 2202 of file page-writeback.c.

int test_set_page_writeback ( struct page page)

Definition at line 2233 of file page-writeback.c.

void throttle_vm_writeout ( gfp_t  gfp_mask)

Definition at line 1498 of file page-writeback.c.

int write_cache_pages ( struct address_space mapping,
struct writeback_control wbc,
writepage_t  writepage,
void data 
)

write_cache_pages - walk the list of dirty pages of the given address space and write all of them. : address space structure to write : subtract the number of written pages from *->nr_to_write : function called for each page : data passed to writepage function

If a page is already under I/O, write_cache_pages() skips it, even if it's dirty. This is desirable behaviour for memory-cleaning writeback, but it is INCORRECT for data-integrity system calls such as fsync(). fsync() and msync() need to guarantee that all the data which was dirty at the time the call was made get new I/O started against them. If wbc->sync_mode is WB_SYNC_ALL then we were called for data integrity and we must wait for existing IO to complete.

To avoid livelocks (when other process dirties new pages), we first tag pages which should be written back with TOWRITE tag and only then start writing them. For data-integrity sync we have to be careful so that we do not miss some pages (e.g., because some other process has cleared TOWRITE tag we set). The rule we follow is that TOWRITE tag can be cleared only by the process clearing the DIRTY tag (and submitting the page for IO).

Definition at line 1708 of file page-writeback.c.

int write_one_page ( struct page page,
int  wait 
)

Definition at line 1925 of file page-writeback.c.

void writeback_set_ratelimit ( void  )

Definition at line 1593 of file page-writeback.c.

bool zone_dirty_ok ( struct zone zone)

zone_dirty_ok - tells whether a zone is within its dirty limits : the zone to check

Returns true when the dirty pages in are within the zone's dirty limit, false if the limit is exceeded.

Definition at line 330 of file page-writeback.c.

Variable Documentation

int block_dump

Definition at line 109 of file page-writeback.c.

unsigned long dirty_background_bytes

Definition at line 75 of file page-writeback.c.

int dirty_background_ratio = 10

Definition at line 69 of file page-writeback.c.

unsigned int dirty_expire_interval = 30 * 100

Definition at line 104 of file page-writeback.c.

unsigned int dirty_writeback_interval = 5 * 100

Definition at line 97 of file page-writeback.c.

unsigned long global_dirty_limit

Definition at line 121 of file page-writeback.c.

int laptop_mode

Definition at line 115 of file page-writeback.c.

unsigned long vm_dirty_bytes

Definition at line 92 of file page-writeback.c.

int vm_dirty_ratio = 20

Definition at line 86 of file page-writeback.c.

int vm_highmem_is_dirtyable

Definition at line 81 of file page-writeback.c.