filemap.c (c3cc99ff5d24e2eeaf7ec2032e720681916990e3) | filemap.c (e286781d5f2e9c846e012a39653a166e9d31777d) |
---|---|
1/* 2 * linux/mm/filemap.c 3 * 4 * Copyright (C) 1994-1999 Linus Torvalds 5 */ 6 7/* 8 * This file handles the generic file mmap semantics used by --- 428 unchanged lines hidden (view full) --- 437 if (!err) 438 err = err2; 439 } 440 } 441 return err; 442} 443 444/** | 1/* 2 * linux/mm/filemap.c 3 * 4 * Copyright (C) 1994-1999 Linus Torvalds 5 */ 6 7/* 8 * This file handles the generic file mmap semantics used by --- 428 unchanged lines hidden (view full) --- 437 if (!err) 438 err = err2; 439 } 440 } 441 return err; 442} 443 444/** |
445 * add_to_page_cache - add newly allocated pagecache pages | 445 * add_to_page_cache_locked - add a locked page to the pagecache |
446 * @page: page to add 447 * @mapping: the page's address_space 448 * @offset: page index 449 * @gfp_mask: page allocation mode 450 * | 446 * @page: page to add 447 * @mapping: the page's address_space 448 * @offset: page index 449 * @gfp_mask: page allocation mode 450 * |
451 * This function is used to add newly allocated pagecache pages; 452 * the page is new, so we can just run SetPageLocked() against it. 453 * The other page state flags were set by rmqueue(). 454 * | 451 * This function is used to add a page to the pagecache. It must be locked. |
455 * This function does not add the page to the LRU. The caller must do that. 456 */ | 452 * This function does not add the page to the LRU. The caller must do that. 453 */ |
457int add_to_page_cache(struct page *page, struct address_space *mapping, | 454int add_to_page_cache_locked(struct page *page, struct address_space *mapping, |
458 pgoff_t offset, gfp_t gfp_mask) 459{ | 455 pgoff_t offset, gfp_t gfp_mask) 456{ |
460 int error = mem_cgroup_cache_charge(page, current->mm, | 457 int error; 458 459 VM_BUG_ON(!PageLocked(page)); 460 461 error = mem_cgroup_cache_charge(page, current->mm, |
461 gfp_mask & ~__GFP_HIGHMEM); 462 if (error) 463 goto out; 464 465 error = radix_tree_preload(gfp_mask & ~__GFP_HIGHMEM); 466 if (error == 0) { | 462 gfp_mask & ~__GFP_HIGHMEM); 463 if (error) 464 goto out; 465 466 error = radix_tree_preload(gfp_mask & ~__GFP_HIGHMEM); 467 if (error == 0) { |
468 page_cache_get(page); 469 page->mapping = mapping; 470 page->index = offset; 471 |
|
467 write_lock_irq(&mapping->tree_lock); 468 error = radix_tree_insert(&mapping->page_tree, offset, page); | 472 write_lock_irq(&mapping->tree_lock); 473 error = radix_tree_insert(&mapping->page_tree, offset, page); |
469 if (!error) { 470 page_cache_get(page); 471 SetPageLocked(page); 472 page->mapping = mapping; 473 page->index = offset; | 474 if (likely(!error)) { |
474 mapping->nrpages++; 475 __inc_zone_page_state(page, NR_FILE_PAGES); | 475 mapping->nrpages++; 476 __inc_zone_page_state(page, NR_FILE_PAGES); |
476 } else | 477 } else { 478 page->mapping = NULL; |
477 mem_cgroup_uncharge_cache_page(page); | 479 mem_cgroup_uncharge_cache_page(page); |
480 page_cache_release(page); 481 } |
|
478 479 write_unlock_irq(&mapping->tree_lock); 480 radix_tree_preload_end(); 481 } else 482 mem_cgroup_uncharge_cache_page(page); 483out: 484 return error; 485} | 482 483 write_unlock_irq(&mapping->tree_lock); 484 radix_tree_preload_end(); 485 } else 486 mem_cgroup_uncharge_cache_page(page); 487out: 488 return error; 489} |
486EXPORT_SYMBOL(add_to_page_cache); | 490EXPORT_SYMBOL(add_to_page_cache_locked); |
487 488int add_to_page_cache_lru(struct page *page, struct address_space *mapping, 489 pgoff_t offset, gfp_t gfp_mask) 490{ 491 int ret = add_to_page_cache(page, mapping, offset, gfp_mask); 492 if (ret == 0) 493 lru_cache_add(page); 494 return ret; --- 2088 unchanged lines hidden --- | 491 492int add_to_page_cache_lru(struct page *page, struct address_space *mapping, 493 pgoff_t offset, gfp_t gfp_mask) 494{ 495 int ret = add_to_page_cache(page, mapping, offset, gfp_mask); 496 if (ret == 0) 497 lru_cache_add(page); 498 return ret; --- 2088 unchanged lines hidden --- |