mirror of
https://github.com/followmsi/android_kernel_google_msm.git
synced 2024-11-06 23:17:41 +00:00
shmem: cleanup shmem_add_to_page_cache
shmem_add_to_page_cache() has three callsites, but only one of them wants the radix_tree_preload() (an exceptional entry guarantees that the radix tree node is present in the other cases), and only that site can achieve mem_cgroup_uncharge_cache_page() (PageSwapCache makes it a no-op in the other cases). We did it this way originally to reflect add_to_page_cache_locked(); but it's confusing now, so move the radix_tree preloading and mem_cgroup uncharging to that one caller. Change-Id: Idd0fb8295f2930a01d5bd850fc5c4c097b7bb89e Signed-off-by: Hugh Dickins <hughd@google.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Michal Hocko <mhocko@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
6aa083b195
commit
abab053427
1 changed files with 29 additions and 31 deletions
60
mm/shmem.c
60
mm/shmem.c
|
@ -290,40 +290,31 @@ static int shmem_add_to_page_cache(struct page *page,
|
|||
struct address_space *mapping,
|
||||
pgoff_t index, gfp_t gfp, void *expected)
|
||||
{
|
||||
int error = 0;
|
||||
int error;
|
||||
|
||||
VM_BUG_ON(!PageLocked(page));
|
||||
VM_BUG_ON(!PageSwapBacked(page));
|
||||
|
||||
if (!expected)
|
||||
error = radix_tree_preload(gfp & GFP_RECLAIM_MASK);
|
||||
if (!error) {
|
||||
page_cache_get(page);
|
||||
page->mapping = mapping;
|
||||
page->index = index;
|
||||
page_cache_get(page);
|
||||
page->mapping = mapping;
|
||||
page->index = index;
|
||||
|
||||
spin_lock_irq(&mapping->tree_lock);
|
||||
if (!expected)
|
||||
error = radix_tree_insert(&mapping->page_tree,
|
||||
index, page);
|
||||
else
|
||||
error = shmem_radix_tree_replace(mapping, index,
|
||||
expected, page);
|
||||
if (!error) {
|
||||
mapping->nrpages++;
|
||||
__inc_zone_page_state(page, NR_FILE_PAGES);
|
||||
__inc_zone_page_state(page, NR_SHMEM);
|
||||
spin_unlock_irq(&mapping->tree_lock);
|
||||
} else {
|
||||
page->mapping = NULL;
|
||||
spin_unlock_irq(&mapping->tree_lock);
|
||||
page_cache_release(page);
|
||||
}
|
||||
if (!expected)
|
||||
radix_tree_preload_end();
|
||||
spin_lock_irq(&mapping->tree_lock);
|
||||
if (!expected)
|
||||
error = radix_tree_insert(&mapping->page_tree, index, page);
|
||||
else
|
||||
error = shmem_radix_tree_replace(mapping, index, expected,
|
||||
page);
|
||||
if (!error) {
|
||||
mapping->nrpages++;
|
||||
__inc_zone_page_state(page, NR_FILE_PAGES);
|
||||
__inc_zone_page_state(page, NR_SHMEM);
|
||||
spin_unlock_irq(&mapping->tree_lock);
|
||||
} else {
|
||||
page->mapping = NULL;
|
||||
spin_unlock_irq(&mapping->tree_lock);
|
||||
page_cache_release(page);
|
||||
}
|
||||
if (error)
|
||||
mem_cgroup_uncharge_cache_page(page);
|
||||
return error;
|
||||
}
|
||||
|
||||
|
@ -1210,11 +1201,18 @@ repeat:
|
|||
__set_page_locked(page);
|
||||
error = mem_cgroup_cache_charge(page, current->mm,
|
||||
gfp & GFP_RECLAIM_MASK);
|
||||
if (!error)
|
||||
error = shmem_add_to_page_cache(page, mapping, index,
|
||||
gfp, NULL);
|
||||
if (error)
|
||||
goto decused;
|
||||
error = radix_tree_preload(gfp & GFP_RECLAIM_MASK);
|
||||
if (!error) {
|
||||
error = shmem_add_to_page_cache(page, mapping, index,
|
||||
gfp, NULL);
|
||||
radix_tree_preload_end();
|
||||
}
|
||||
if (error) {
|
||||
mem_cgroup_uncharge_cache_page(page);
|
||||
goto decused;
|
||||
}
|
||||
lru_cache_add_anon(page);
|
||||
|
||||
spin_lock(&info->lock);
|
||||
|
|
Loading…
Reference in a new issue