cregit-Linux how code gets into the kernel

Release 4.7 mm/filemap.c

Directory: mm
/*
 *      linux/mm/filemap.c
 *
 * Copyright (C) 1994-1999  Linus Torvalds
 */

/*
 * This file handles the generic file mmap semantics used by
 * most "normal" filesystems (but you don't /have/ to use this:
 * the NFS filesystem used to do this differently, for example)
 */
#include <linux/export.h>
#include <linux/compiler.h>
#include <linux/dax.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/capability.h>
#include <linux/kernel_stat.h>
#include <linux/gfp.h>
#include <linux/mm.h>
#include <linux/swap.h>
#include <linux/mman.h>
#include <linux/pagemap.h>
#include <linux/file.h>
#include <linux/uio.h>
#include <linux/hash.h>
#include <linux/writeback.h>
#include <linux/backing-dev.h>
#include <linux/pagevec.h>
#include <linux/blkdev.h>
#include <linux/security.h>
#include <linux/cpuset.h>
#include <linux/hardirq.h> /* for BUG_ON(!in_atomic()) only */
#include <linux/hugetlb.h>
#include <linux/memcontrol.h>
#include <linux/cleancache.h>
#include <linux/rmap.h>
#include "internal.h"


#define CREATE_TRACE_POINTS
#include <trace/events/filemap.h>

/*
 * FIXME: remove all knowledge of the buffer layer from the core VM
 */
#include <linux/buffer_head.h> /* for try_to_free_buffers */

#include <asm/mman.h>

/*
 * Shared mappings implemented 30.11.1994. It's not fully working yet,
 * though.
 *
 * Shared mappings now work. 15.8.1995  Bruno.
 *
 * finished 'unifying' the page and buffer cache and SMP-threaded the
 * page-cache, 21.05.1999, Ingo Molnar <mingo@redhat.com>
 *
 * SMP-threaded pagemap-LRU 1999, Andrea Arcangeli <andrea@suse.de>
 */

/*
 * Lock ordering:
 *
 *  ->i_mmap_rwsem              (truncate_pagecache)
 *    ->private_lock            (__free_pte->__set_page_dirty_buffers)
 *      ->swap_lock             (exclusive_swap_page, others)
 *        ->mapping->tree_lock
 *
 *  ->i_mutex
 *    ->i_mmap_rwsem            (truncate->unmap_mapping_range)
 *
 *  ->mmap_sem
 *    ->i_mmap_rwsem
 *      ->page_table_lock or pte_lock   (various, mainly in memory.c)
 *        ->mapping->tree_lock  (arch-dependent flush_dcache_mmap_lock)
 *
 *  ->mmap_sem
 *    ->lock_page               (access_process_vm)
 *
 *  ->i_mutex                   (generic_perform_write)
 *    ->mmap_sem                (fault_in_pages_readable->do_page_fault)
 *
 *  bdi->wb.list_lock
 *    sb_lock                   (fs/fs-writeback.c)
 *    ->mapping->tree_lock      (__sync_single_inode)
 *
 *  ->i_mmap_rwsem
 *    ->anon_vma.lock           (vma_adjust)
 *
 *  ->anon_vma.lock
 *    ->page_table_lock or pte_lock     (anon_vma_prepare and various)
 *
 *  ->page_table_lock or pte_lock
 *    ->swap_lock               (try_to_unmap_one)
 *    ->private_lock            (try_to_unmap_one)
 *    ->tree_lock               (try_to_unmap_one)
 *    ->zone.lru_lock           (follow_page->mark_page_accessed)
 *    ->zone.lru_lock           (check_pte_range->isolate_lru_page)
 *    ->private_lock            (page_remove_rmap->set_page_dirty)
 *    ->tree_lock               (page_remove_rmap->set_page_dirty)
 *    bdi.wb->list_lock         (page_remove_rmap->set_page_dirty)
 *    ->inode->i_lock           (page_remove_rmap->set_page_dirty)
 *    ->memcg->move_lock        (page_remove_rmap->lock_page_memcg)
 *    bdi.wb->list_lock         (zap_pte_range->set_page_dirty)
 *    ->inode->i_lock           (zap_pte_range->set_page_dirty)
 *    ->private_lock            (zap_pte_range->__set_page_dirty_buffers)
 *
 * ->i_mmap_rwsem
 *   ->tasklist_lock            (memory_failure, collect_procs_ao)
 */


static void page_cache_tree_delete(struct address_space *mapping, struct page *page, void *shadow) { struct radix_tree_node *node; VM_BUG_ON(!PageLocked(page)); node = radix_tree_replace_clear_tags(&mapping->page_tree, page->index, shadow); if (shadow) { mapping->nrexceptional++; /* * Make sure the nrexceptional update is committed before * the nrpages update so that final truncate racing * with reclaim does not see both counters 0 at the * same time and miss a shadow entry. */ smp_wmb(); } mapping->nrpages--; if (!node) return; workingset_node_pages_dec(node); if (shadow) workingset_node_shadows_inc(node); else if (__radix_tree_delete_node(&mapping->page_tree, node)) return; /* * Track node that only contains shadow entries. DAX mappings contain * no shadow entries and may contain other exceptional entries so skip * those. * * Avoid acquiring the list_lru lock if already tracked. The * list_empty() test is safe as node->private_list is * protected by mapping->tree_lock. */ if (!dax_mapping(mapping) && !workingset_node_pages(node) && list_empty(&node->private_list)) { node->private_data = mapping; list_lru_add(&workingset_shadow_nodes, &node->private_list); } }

Contributors

PersonTokensPropCommitsCommitProp
johannes weinerjohannes weiner13391.10%240.00%
jan karajan kara74.79%120.00%
matthew wilcoxmatthew wilcox42.74%120.00%
ross zwislerross zwisler21.37%120.00%
Total146100.00%5100.00%

/* * Delete a page from the page cache and free it. Caller has to make * sure the page is locked and that nobody else uses it - or that usage * is safe. The caller must hold the mapping's tree_lock. */
void __delete_from_page_cache(struct page *page, void *shadow) { struct address_space *mapping = page->mapping; trace_mm_filemap_delete_from_page_cache(page); /* * if we're uptodate, flush out into the cleancache, otherwise * invalidate any existing cleancache entries. We can't leave * stale data around in the cleancache once our page is gone */ if (PageUptodate(page) && PageMappedToDisk(page)) cleancache_put_page(page); else cleancache_invalidate_page(mapping, page); VM_BUG_ON_PAGE(page_mapped(page), page); if (!IS_ENABLED(CONFIG_DEBUG_VM) && unlikely(page_mapped(page))) { int mapcount; pr_alert("BUG: Bad page cache in process %s pfn:%05lx\n", current->comm, page_to_pfn(page)); dump_page(page, "still mapped when deleted"); dump_stack(); add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE); mapcount = page_mapcount(page); if (mapping_exiting(mapping) && page_count(page) >= mapcount + 2) { /* * All vmas have already been torn down, so it's * a good bet that actually the page is unmapped, * and we'd prefer not to leak it: if we're wrong, * some other bad page check should catch it later. */ page_mapcount_reset(page); page_ref_sub(page, mapcount); } } page_cache_tree_delete(mapping, page, shadow); page->mapping = NULL; /* Leave page->index set: truncation lookup relies upon it */ /* hugetlb pages do not participate in page cache accounting. */ if (!PageHuge(page)) __dec_zone_page_state(page, NR_FILE_PAGES); if (PageSwapBacked(page)) __dec_zone_page_state(page, NR_SHMEM); /* * At this point page must be either written or cleaned by truncate. * Dirty page here signals a bug and loss of unwritten data. * * This fixes dirty accounting after removing the page entirely but * leaves PageDirty set: it has no effect for truncated page and * anyway will be cleared before returning page into buddy allocator. */ if (WARN_ON_ONCE(PageDirty(page))) account_page_cleaned(page, mapping, inode_to_wb(mapping->host)); }

Contributors

PersonTokensPropCommitsCommitProp
hugh dickinshugh dickins9843.56%210.53%
pre-gitpre-git2712.00%315.79%
dan magenheimerdan magenheimer2611.56%210.53%
linus torvaldslinus torvalds156.67%15.26%
kosaki motohirokosaki motohiro146.22%15.26%
michal hockomichal hocko94.00%15.26%
johannes weinerjohannes weiner73.11%15.26%
tejun heotejun heo62.67%15.26%
andrew mortonandrew morton52.22%15.26%
robert jarzmikrobert jarzmik52.22%15.26%
christoph lameterchristoph lameter41.78%15.26%
konstantin khlebnikovkonstantin khlebnikov41.78%15.26%
joonsoo kimjoonsoo kim31.33%15.26%
minchan kimminchan kim10.44%15.26%
greg thelengreg thelen10.44%15.26%
Total225100.00%19100.00%

/** * delete_from_page_cache - delete page from page cache * @page: the page which the kernel is trying to remove from page cache * * This must be called only on pages that have been verified to be in the page * cache and locked. It will never put the page into the free list, the caller * has a reference on the page. */
void delete_from_page_cache(struct page *page) { struct address_space *mapping = page->mapping; unsigned long flags; void (*freepage)(struct page *); BUG_ON(!PageLocked(page)); freepage = mapping->a_ops->freepage; spin_lock_irqsave(&mapping->tree_lock, flags); __delete_from_page_cache(page, NULL); spin_unlock_irqrestore(&mapping->tree_lock, flags); if (freepage) freepage(page); put_page(page); }

Contributors

PersonTokensPropCommitsCommitProp
linus torvaldslinus torvalds2830.43%18.33%
pre-gitpre-git2729.35%216.67%
andrew mortonandrew morton1415.22%216.67%
greg thelengreg thelen1213.04%18.33%
minchan kimminchan kim77.61%325.00%
johannes weinerjohannes weiner22.17%18.33%
kirill a. shutemovkirill a. shutemov11.09%18.33%
matt mackallmatt mackall11.09%18.33%
Total92100.00%12100.00%

EXPORT_SYMBOL(delete_from_page_cache);
static int filemap_check_errors(struct address_space *mapping) { int ret = 0; /* Check for outstanding write errors */ if (test_bit(AS_ENOSPC, &mapping->flags) && test_and_clear_bit(AS_ENOSPC, &mapping->flags)) ret = -ENOSPC; if (test_bit(AS_EIO, &mapping->flags) && test_and_clear_bit(AS_EIO, &mapping->flags)) ret = -EIO; return ret; }

Contributors

PersonTokensPropCommitsCommitProp
dmitriy monakhovdmitriy monakhov5472.97%150.00%
jens axboejens axboe2027.03%150.00%
Total74100.00%2100.00%

/** * __filemap_fdatawrite_range - start writeback on mapping dirty pages in range * @mapping: address space structure to write * @start: offset in bytes where the range starts * @end: offset in bytes where the range ends (inclusive) * @sync_mode: enable synchronous operation * * Start writeback against all of a mapping's dirty pages that lie * within the byte offsets <start, end> inclusive. * * If sync_mode is WB_SYNC_ALL then this is a "data integrity" operation, as * opposed to a regular memory cleansing writeback. The difference between * these two operations is that if a dirty page/buffer is encountered, it must * be waited upon, and not just skipped over. */
int __filemap_fdatawrite_range(struct address_space *mapping, loff_t start, loff_t end, int sync_mode) { int ret; struct writeback_control wbc = { .sync_mode = sync_mode, .nr_to_write = LONG_MAX, .range_start = start, .range_end = end, }; if (!mapping_cap_writeback_dirty(mapping)) return 0; wbc_attach_fdatawrite_inode(&wbc, mapping->host); ret = do_writepages(mapping, &wbc); wbc_detach_inode(&wbc); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
andrew mortonandrew morton4045.45%847.06%
tejun heotejun heo1618.18%15.88%
suparna bhattacharyasuparna bhattacharya1517.05%15.88%
pre-gitpre-git910.23%317.65%
david howellsdavid howells44.55%15.88%
hirofumi ogawahirofumi ogawa22.27%15.88%
linus torvaldslinus torvalds11.14%15.88%
nick pigginnick piggin11.14%15.88%
Total88100.00%17100.00%


static inline int __filemap_fdatawrite(struct address_space *mapping, int sync_mode) { return __filemap_fdatawrite_range(mapping, 0, LLONG_MAX, sync_mode); }

Contributors

PersonTokensPropCommitsCommitProp
suparna bhattacharyasuparna bhattacharya2696.30%150.00%
hirofumi ogawahirofumi ogawa13.70%150.00%
Total27100.00%2100.00%


int filemap_fdatawrite(struct address_space *mapping) { return __filemap_fdatawrite(mapping, WB_SYNC_ALL); }

Contributors

PersonTokensPropCommitsCommitProp
andrew mortonandrew morton18100.00%1100.00%
Total18100.00%1100.00%

EXPORT_SYMBOL(filemap_fdatawrite);
int filemap_fdatawrite_range(struct address_space *mapping, loff_t start, loff_t end) { return __filemap_fdatawrite_range(mapping, start, end, WB_SYNC_ALL); }

Contributors

PersonTokensPropCommitsCommitProp
suparna bhattacharyasuparna bhattacharya28100.00%1100.00%
Total28100.00%1100.00%

EXPORT_SYMBOL(filemap_fdatawrite_range); /** * filemap_flush - mostly a non-blocking flush * @mapping: target address_space * * This is a mostly non-blocking flush. Not suitable for data-integrity * purposes - I/O may not be started against all dirty pages. */
int filemap_flush(struct address_space *mapping) { return __filemap_fdatawrite(mapping, WB_SYNC_NONE); }

Contributors

PersonTokensPropCommitsCommitProp
andrew mortonandrew morton18100.00%1100.00%
Total18100.00%1100.00%

EXPORT_SYMBOL(filemap_flush);
static int __filemap_fdatawait_range(struct address_space *mapping, loff_t start_byte, loff_t end_byte) { pgoff_t index = start_byte >> PAGE_SHIFT; pgoff_t end = end_byte >> PAGE_SHIFT; struct pagevec pvec; int nr_pages; int ret = 0; if (end_byte < start_byte) goto out; pagevec_init(&pvec, 0); while ((index <= end) && (nr_pages = pagevec_lookup_tag(&pvec, mapping, &index, PAGECACHE_TAG_WRITEBACK, min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1)) != 0) { unsigned i; for (i = 0; i < nr_pages; i++) { struct page *page = pvec.pages[i]; /* until radix tree lookup accepts end_index */ if (page->index > end) continue; wait_on_page_writeback(page); if (TestClearPageError(page)) ret = -EIO; } pagevec_release(&pvec); cond_resched(); } out: return ret; }

Contributors

PersonTokensPropCommitsCommitProp
andrew mortonandrew morton9553.98%533.33%
pre-gitpre-git1910.80%213.33%
christoph hellwigchristoph hellwig1810.23%16.67%
suparna bhattacharyasuparna bhattacharya169.09%16.67%
linus torvaldslinus torvalds126.82%16.67%
jun'ichi nomurajun'ichi nomura63.41%16.67%
dmitriy monakhovdmitriy monakhov52.84%16.67%
kirill a. shutemovkirill a. shutemov21.14%16.67%
mika kukkonenmika kukkonen21.14%16.67%
rik van rielrik van riel10.57%16.67%
Total176100.00%15100.00%

/** * filemap_fdatawait_range - wait for writeback to complete * @mapping: address space structure to wait for * @start_byte: offset in bytes where the range starts * @end_byte: offset in bytes where the range ends (inclusive) * * Walk the list of under-writeback pages of the given address space * in the given range and wait for all of them. Check error status of * the address space and return it. * * Since the error status of the address space is cleared by this function, * callers are responsible for checking the return value and handling and/or * reporting the error. */
int filemap_fdatawait_range(struct address_space *mapping, loff_t start_byte, loff_t end_byte) { int ret, ret2; ret = __filemap_fdatawait_range(mapping, start_byte, end_byte); ret2 = filemap_check_errors(mapping); if (!ret) ret = ret2; return ret; }

Contributors

PersonTokensPropCommitsCommitProp
jun'ichi nomurajun'ichi nomura3160.78%116.67%
andrew mortonandrew morton1325.49%350.00%
dmitriy monakhovdmitriy monakhov611.76%116.67%
pre-gitpre-git11.96%116.67%
Total51100.00%6100.00%

EXPORT_SYMBOL(filemap_fdatawait_range); /** * filemap_fdatawait_keep_errors - wait for writeback without clearing errors * @mapping: address space structure to wait for * * Walk the list of under-writeback pages of the given address space * and wait for all of them. Unlike filemap_fdatawait(), this function * does not clear error status of the address space. * * Use this function if callers don't handle errors themselves. Expected * call sites are system-wide / filesystem-wide data flushers: e.g. sync(2), * fsfreeze(8) */
void filemap_fdatawait_keep_errors(struct address_space *mapping) { loff_t i_size = i_size_read(mapping->host); if (i_size == 0) return; __filemap_fdatawait_range(mapping, 0, i_size - 1); }

Contributors

PersonTokensPropCommitsCommitProp
jun'ichi nomurajun'ichi nomura38100.00%1100.00%
Total38100.00%1100.00%

/** * filemap_fdatawait - wait for all under-writeback pages to complete * @mapping: address space structure to wait for * * Walk the list of under-writeback pages of the given address space * and wait for all of them. Check error status of the address space * and return it. * * Since the error status of the address space is cleared by this function, * callers are responsible for checking the return value and handling and/or * reporting the error. */
int filemap_fdatawait(struct address_space *mapping) { loff_t i_size = i_size_read(mapping->host); if (i_size == 0) return 0; return filemap_fdatawait_range(mapping, 0, i_size - 1); }

Contributors

PersonTokensPropCommitsCommitProp
marcelo tosattimarcelo tosatti2048.78%133.33%
andrew mortonandrew morton2048.78%133.33%
christoph hellwigchristoph hellwig12.44%133.33%
Total41100.00%3100.00%

EXPORT_SYMBOL(filemap_fdatawait);
int filemap_write_and_wait(struct address_space *mapping) { int err = 0; if ((!dax_mapping(mapping) && mapping->nrpages) || (dax_mapping(mapping) && mapping->nrexceptional)) { err = filemap_fdatawrite(mapping); /* * Even if the above returned error, the pages may be * written partially (e.g. -ENOSPC), so we wait for it. * But the -EIO is special case, it may indicate the worst * thing (e.g. bug) happened, so we avoid waiting for it. */ if (err != -EIO) { int err2 = filemap_fdatawait(mapping); if (!err) err = err2; } } else { err = filemap_check_errors(mapping); } return err; }

Contributors

PersonTokensPropCommitsCommitProp
andrew mortonandrew morton3842.70%125.00%
hirofumi ogawahirofumi ogawa2224.72%125.00%
ross zwislerross zwisler1921.35%125.00%
dmitriy monakhovdmitriy monakhov1011.24%125.00%
Total89100.00%4100.00%

EXPORT_SYMBOL(filemap_write_and_wait); /** * filemap_write_and_wait_range - write out & wait on a file range * @mapping: the address_space for the pages * @lstart: offset in bytes where the range starts * @lend: offset in bytes where the range ends (inclusive) * * Write out and wait upon file offsets lstart->lend, inclusive. * * Note that `lend' is inclusive (describes the last byte to be written) so * that this function can be used to write to the very end-of-file (end = -1). */
int filemap_write_and_wait_range(struct address_space *mapping, loff_t lstart, loff_t lend) { int err = 0; if ((!dax_mapping(mapping) && mapping->nrpages) || (dax_mapping(mapping) && mapping->nrexceptional)) { err = __filemap_fdatawrite_range(mapping, lstart, lend, WB_SYNC_ALL); /* See comment of filemap_write_and_wait() */ if (err != -EIO) { int err2 = filemap_fdatawait_range(mapping, lstart, lend); if (!err) err = err2; } } else { err = filemap_check_errors(mapping); } return err; }

Contributors

PersonTokensPropCommitsCommitProp
zach brownzach brown5249.52%116.67%
hirofumi ogawahirofumi ogawa2220.95%116.67%
ross zwislerross zwisler2019.05%233.33%
dmitriy monakhovdmitriy monakhov109.52%116.67%
christoph hellwigchristoph hellwig10.95%116.67%
Total105100.00%6100.00%

EXPORT_SYMBOL(filemap_write_and_wait_range); /** * replace_page_cache_page - replace a pagecache page with a new one * @old: page to be replaced * @new: page to replace with * @gfp_mask: allocation mode * * This function replaces a page in the pagecache with a new one. On * success it acquires the pagecache reference for the new page and * drops it for the old page. Both the old and new pages must be * locked. This function does not add the new page to the LRU, the * caller must do that. * * The remove + add is atomic. The only way this function can fail is * memory allocation failure. */
int replace_page_cache_page(struct page *old, struct page *new, gfp_t gfp_mask) { int error; VM_BUG_ON_PAGE(!PageLocked(old), old); VM_BUG_ON_PAGE(!PageLocked(new), new); VM_BUG_ON_PAGE(new->mapping, new); error = radix_tree_preload(gfp_mask & ~__GFP_HIGHMEM); if (!error) { struct address_space *mapping = old->mapping; void (*freepage)(struct page *); unsigned long flags; pgoff_t offset = old->index; freepage = mapping->a_ops->freepage; get_page(new); new->mapping = mapping; new->index = offset; spin_lock_irqsave(&mapping->tree_lock, flags); __delete_from_page_cache(old, NULL); error = radix_tree_insert(&mapping->page_tree, offset, new); BUG_ON(error); mapping->nrpages++; /* * hugetlb pages do not participate in page cache accounting. */ if (!PageHuge(new)) __inc_zone_page_state(new, NR_FILE_PAGES); if (PageSwapBacked(new)) __inc_zone_page_state(new, NR_SHMEM); spin_unlock_irqrestore(&mapping->tree_lock, flags); mem_cgroup_migrate(old, new); radix_tree_preload_end(); if (freepage) freepage(old); put_page(old); } return error; }

Contributors

PersonTokensPropCommitsCommitProp
miklos szeredimiklos szeredi19181.97%111.11%
greg thelengreg thelen125.15%111.11%
sasha levinsasha levin93.86%111.11%
michal hockomichal hocko93.86%111.11%
kamezawa hiroyukikamezawa hiroyuki62.58%111.11%
johannes weinerjohannes weiner31.29%222.22%
kirill a. shutemovkirill a. shutemov20.86%111.11%
minchan kimminchan kim10.43%111.11%
Total233100.00%9100.00%

EXPORT_SYMBOL_GPL(replace_page_cache_page);
static int page_cache_tree_insert(struct address_space *mapping, struct page *page, void **shadowp) { struct radix_tree_node *node; void **slot; int error; error = __radix_tree_create(&mapping->page_tree, page->index, 0, &node, &slot); if (error) return error; if (*slot) { void *p; p = radix_tree_deref_slot_protected(slot, &mapping->tree_lock); if (!radix_tree_exceptional_entry(p)) return -EEXIST; mapping->nrexceptional--; if (!dax_mapping(mapping)) { if (shadowp) *shadowp = p; if (node) workingset_node_shadows_dec(node); } else { /* DAX can replace empty locked entry with a hole */ WARN_ON_ONCE(p != (void *)(RADIX_TREE_EXCEPTIONAL_ENTRY | RADIX_DAX_ENTRY_LOCK)); /* DAX accounts exceptional entries as normal pages */ if (node) workingset_node_pages_dec(node); /* Wakeup waiters for exceptional entry lock */ dax_wake_mapping_entry_waiter(mapping, page->index, false); } } radix_tree_replace_slot(slot, page); mapping->nrpages++; if (node) { workingset_node_pages_inc(node); /* * Don't track node that contains actual pages. * * Avoid acquiring the list_lru lock if already * untracked. The list_empty() test is safe as * node->private_list is protected by * mapping->tree_lock. */ if (!list_empty(&node->private_list)) list_lru_del(&workingset_shadow_nodes, &node->private_list); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
johannes weinerjohannes weiner16373.76%342.86%
jan karajan kara4922.17%228.57%
ross zwislerross zwisler73.17%114.29%
matthew wilcoxmatthew wilcox20.90%114.29%
Total221100.00%7100.00%


static int __add_to_page_cache_locked(struct page *page, struct address_space *mapping, pgoff_t offset, gfp_t gfp_mask, void **shadowp) { int huge = PageHuge(page); struct mem_cgroup *memcg; int error; VM_BUG_ON_PAGE(!PageLocked(page), page); VM_BUG_ON_PAGE(PageSwapBacked(page), page); if (!huge) { error = mem_cgroup_try_charge(page, current->mm, gfp_mask, &memcg, false); if (error) return error; } error = radix_tree_maybe_preload(gfp_mask & ~__GFP_HIGHMEM); if (error) { if (!huge) mem_cgroup_cancel_charge(page, memcg, false); return error; } get_page(page); page->mapping = mapping; page->index = offset; spin_lock_irq(&mapping->tree_lock); error = page_cache_tree_insert(mapping, page, shadowp); radix_tree_preload_end(); if (unlikely(error)) goto err_insert; /* hugetlb pages do not participate in page cache accounting. */ if (!huge) __inc_zone_page_state(page, NR_FILE_PAGES); spin_unlock_irq(&mapping->tree_lock); if (!huge) mem_cgroup_commit_charge(page, memcg, false, false); trace_mm_filemap_add_to_page_cache(page); return 0; err_insert: page->mapping = NULL; /* Leave page->index set: truncation relies upon it */ spin_unlock_irq(&mapping->tree_lock); if (!huge) mem_cgroup_cancel_charge(page, memcg, false); put_page(page); return error; }

Contributors

PersonTokensPropCommitsCommitProp
johannes weinerjohannes weiner6324.05%39.09%
nick pigginnick piggin4115.65%26.06%
andrew mortonandrew morton3312.60%618.18%
kirill a. shutemovkirill a. shutemov3312.60%39.09%
balbir singhbalbir singh249.16%39.09%
daisuke nishimuradaisuke nishimura166.11%13.03%
pre-gitpre-git124.58%39.09%
hugh dickinshugh dickins83.05%26.06%
linus torvaldslinus torvalds83.05%39.09%
sasha levinsasha levin62.29%13.03%
michal hockomichal hocko62.29%13.03%
robert jarzmikrobert jarzmik51.91%13.03%
christoph lameterchristoph lameter41.53%13.03%
badari pulavartybadari pulavarty10.38%13.03%
al viroal viro10.38%13.03%
jan karajan kara10.38%13.03%
Total262100.00%33100.00%

/** * add_to_page_cache_locked - add a locked page to the pagecache * @page: page to add * @mapping: the page's address_space * @offset: page index * @gfp_mask: page allocation mode * * This function is used to add a page to the pagecache. It must be locked. * This function does not add the page to the LRU. The caller must do that. */
int add_to_page_cache_locked(struct page *page, struct address_space *mapping, pgoff_t offset, gfp_t gfp_mask) { return __add_to_page_cache_locked(page, mapping, offset, gfp_mask, NULL); }

Contributors

PersonTokensPropCommitsCommitProp
johannes weinerjohannes weiner35100.00%1100.00%
Total35100.00%1100.00%

EXPORT_SYMBOL(add_to_page_cache_locked);
int add_to_page_cache_lru(struct page *page, struct address_space *mapping, pgoff_t offset, gfp_t gfp_mask) { void *shadow = NULL; int ret; __SetPageLocked(page); ret = __add_to_page_cache_locked(page, mapping, offset, gfp_mask, &shadow); if (unlikely(ret)) __ClearPageLocked(page); else { /* * The page might have been evicted from cache only * recently, in which case it should be activated like * any other repeatedly accessed page. * The exception is pages getting rewritten; evicting other * data from the working set, only to cache data that will * get overwritten with something else, is a waste of memory. */ if (!(gfp_mask & __GFP_WRITE) && shadow && workingset_refault(shadow)) { SetPageActive(page); workingset_activation(page); } else ClearPageActive(page); lru_cache_add(page); } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
johannes weinerjohannes weiner5247.71%19.09%
andrew mortonandrew morton3431.19%327.27%
rik van rielrik van riel1614.68%218.18%
linus torvaldslinus torvalds32.75%218.18%
kirill a. shutemovkirill a. shutemov21.83%19.09%
pre-gitpre-git10.92%19.09%
al viroal viro10.92%19.09%
Total109100.00%11100.00%

EXPORT_SYMBOL_GPL(add_to_page_cache_lru); #ifdef CONFIG_NUMA
struct page *__page_cache_alloc(gfp_t gfp) { int n; struct page *page; if (cpuset_do_page_mem_spread()) { unsigned int cpuset_mems_cookie; do { cpuset_mems_cookie = read_mems_allowed_begin(); n = cpuset_mem_spread_node(); page = __alloc_pages_node(n, gfp, 0); } while (!page && read_mems_allowed_retry(cpuset_mems_cookie)); return page; } return alloc_pages(gfp, 0); }

Contributors

PersonTokensPropCommitsCommitProp
paul jacksonpaul jackson3141.33%116.67%
mel gormanmel gorman2128.00%233.33%
miao xiemiao xie1722.67%116.67%
nick pigginnick piggin56.67%116.67%
vlastimil babkavlastimil babka11.33%116.67%
Total75100.00%6100.00%

EXPORT_SYMBOL(__page_cache_alloc); #endif /* * In order to wait for pages to become available there must be * waitqueues associated with pages. By using a hash table of * waitqueues where the bucket discipline is to maintain all * waiters on the same queue and wake all when any of the pages * become available, and for the woken contexts to check to be * sure the appropriate page became available, this saves space * at a cost of "thundering herd" phenomena during rare hash * collisions. */
wait_queue_head_t *page_waitqueue(struct page *page) { const struct zone *zone = page_zone(page); return &zone->wait_table[hash_ptr(page, zone->wait_table_bits)]; }

Contributors

PersonTokensPropCommitsCommitProp
rik van rielrik van riel2873.68%133.33%
rusty russellrusty russell821.05%133.33%
andrew mortonandrew morton25.26%133.33%
Total38100.00%3100.00%

EXPORT_SYMBOL(page_waitqueue);
void wait_on_page_bit(struct page *page, int bit_nr) { DEFINE_WAIT_BIT(wait, &page->flags, bit_nr); if (test_bit(bit_nr, &page->flags)) __wait_on_bit(page_waitqueue(page), &wait, bit_wait_io, TASK_UNINTERRUPTIBLE); }

Contributors

PersonTokensPropCommitsCommitProp
linus torvaldslinus torvalds2140.38%111.11%
william lee irwin iiiwilliam lee irwin iii1630.77%222.22%
andrew mortonandrew morton1121.15%444.44%
rik van rielrik van riel35.77%111.11%
neil brownneil brown11.92%111.11%
Total52100.00%9100.00%

EXPORT_SYMBOL(wait_on_page_bit);
int wait_on_page_bit_killable(struct page *page, int bit_nr) { DEFINE_WAIT_BIT(wait, &page->flags, bit_nr); if (!test_bit(bit_nr, &page->flags)) return 0; return __wait_on_bit(page_waitqueue(page), &wait, bit_wait_io, TASK_KILLABLE); }

Contributors

PersonTokensPropCommitsCommitProp
william lee irwin iiiwilliam lee irwin iii2136.84%114.29%
linus torvaldslinus torvalds1628.07%114.29%
andrew mortonandrew morton1017.54%342.86%
kosaki motohirokosaki motohiro915.79%114.29%
neil brownneil brown11.75%114.29%
Total57100.00%7100.00%


int wait_on_page_bit_killable_timeout(struct page *page, int bit_nr, unsigned long timeout) { DEFINE_WAIT_BIT(wait, &page->flags, bit_nr); wait.key.timeout = jiffies + timeout; if (!test_bit(bit_nr, &page->flags)) return 0; return __wait_on_bit(page_waitqueue(page), &wait, bit_wait_io_timeout, TASK_KILLABLE); }

Contributors

PersonTokensPropCommitsCommitProp
kosaki motohirokosaki motohiro5577.46%150.00%
neil brownneil brown1622.54%150.00%
Total71100.00%2100.00%

EXPORT_SYMBOL_GPL(wait_on_page_bit_killable_timeout); /** * add_page_wait_queue - Add an arbitrary waiter to a page's wait queue * @page: Page defining the wait queue of interest * @waiter: Waiter to add to the queue * * Add an arbitrary @waiter to the wait queue for the nominated @page. */
void add_page_wait_queue(struct page *page, wait_queue_t *waiter) { wait_queue_head_t *q = page_waitqueue(page); unsigned long flags; spin_lock_irqsave(&q->lock, flags); __add_wait_queue(q, waiter); spin_unlock_irqrestore(&q->lock, flags); }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells54100.00%1100.00%
Total54100.00%1100.00%

EXPORT_SYMBOL_GPL(add_page_wait_queue); /** * unlock_page - unlock a locked page * @page: the page * * Unlocks the page and wakes up sleepers in ___wait_on_page_locked(). * Also wakes sleepers in wait_on_page_writeback() because the wakeup * mechanism between PageLocked pages and PageWriteback pages is shared. * But that's OK - sleepers in wait_on_page_writeback() just go back to sleep. * * The 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()). */
void unlock_page(struct page *page) { page = compound_head(page); VM_BUG_ON_PAGE(!PageLocked(page), page); clear_bit_unlock(PG_locked, &page->flags); smp_mb__after_atomic(); wake_up_page(page, PG_locked); }

Contributors

PersonTokensPropCommitsCommitProp
linus torvaldslinus torvalds1939.58%111.11%
nick pigginnick piggin1327.08%222.22%
kirill a. shutemovkirill a. shutemov714.58%111.11%
william lee irwin iiiwilliam lee irwin iii48.33%222.22%
sasha levinsasha levin36.25%111.11%
andrew mortonandrew morton12.08%111.11%
peter zijlstrapeter zijlstra12.08%111.11%
Total48100.00%9100.00%

EXPORT_SYMBOL(unlock_page); /** * end_page_writeback - end writeback against a page * @page: the page */
void end_page_writeback(struct page *page) { /* * TestClearPageReclaim could be used here but it is an atomic * operation and overkill in this particular case. Failing to * shuffle a page marked for immediate reclaim is too mild to * justify taking an atomic operation penalty at the end of * ever page writeback. */ if (PageReclaim(page)) { ClearPageReclaim(page); rotate_reclaimable_page(page); } if (!test_clear_page_writeback(page)) BUG(); smp_mb__after_atomic(); wake_up_page(page, PG_writeback); }

Contributors

PersonTokensPropCommitsCommitProp
andrew mortonandrew morton3568.63%444.44%
mel gormanmel gorman917.65%111.11%
william lee irwin iiiwilliam lee irwin iii47.84%222.22%
miklos szeredimiklos szeredi23.92%111.11%
peter zijlstrapeter zijlstra11.96%111.11%
Total51100.00%9100.00%

EXPORT_SYMBOL(end_page_writeback); /* * After completing I/O on a page, call this routine to update the page * flags appropriately */
void page_endio(struct page *page, int rw, int err) { if (rw == READ) { if (!err) { SetPageUptodate(page); } else { ClearPageUptodate(page); SetPageError(page); } unlock_page(page); } else { /* rw == WRITE */ if (err)