filemap.c (3fba69a56e16e8dcf182fe6ca77735dd65a898aa) filemap.c (3fea5a499d57dec46043fcdb08e38eac1767bb0d)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * linux/mm/filemap.c
4 *
5 * Copyright (C) 1994-1999 Linus Torvalds
6 */
7
8/*

--- 818 unchanged lines hidden (view full) ---

827
828static int __add_to_page_cache_locked(struct page *page,
829 struct address_space *mapping,
830 pgoff_t offset, gfp_t gfp_mask,
831 void **shadowp)
832{
833 XA_STATE(xas, &mapping->i_pages, offset);
834 int huge = PageHuge(page);
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * linux/mm/filemap.c
4 *
5 * Copyright (C) 1994-1999 Linus Torvalds
6 */
7
8/*

--- 818 unchanged lines hidden (view full) ---

827
828static int __add_to_page_cache_locked(struct page *page,
829 struct address_space *mapping,
830 pgoff_t offset, gfp_t gfp_mask,
831 void **shadowp)
832{
833 XA_STATE(xas, &mapping->i_pages, offset);
834 int huge = PageHuge(page);
835 struct mem_cgroup *memcg;
836 int error;
837 void *old;
838
839 VM_BUG_ON_PAGE(!PageLocked(page), page);
840 VM_BUG_ON_PAGE(PageSwapBacked(page), page);
841 mapping_set_update(&xas, mapping);
842
835 int error;
836 void *old;
837
838 VM_BUG_ON_PAGE(!PageLocked(page), page);
839 VM_BUG_ON_PAGE(PageSwapBacked(page), page);
840 mapping_set_update(&xas, mapping);
841
843 if (!huge) {
844 error = mem_cgroup_try_charge(page, current->mm,
845 gfp_mask, &memcg);
846 if (error)
847 return error;
848 }
849
850 get_page(page);
851 page->mapping = mapping;
852 page->index = offset;
853
842 get_page(page);
843 page->mapping = mapping;
844 page->index = offset;
845
846 if (!huge) {
847 error = mem_cgroup_charge(page, current->mm, gfp_mask, false);
848 if (error)
849 goto error;
850 }
851
854 do {
855 xas_lock_irq(&xas);
856 old = xas_load(&xas);
857 if (old && !xa_is_value(old))
858 xas_set_err(&xas, -EEXIST);
859 xas_store(&xas, page);
860 if (xas_error(&xas))
861 goto unlock;

--- 7 unchanged lines hidden (view full) ---

869
870 /* hugetlb pages do not participate in page cache accounting */
871 if (!huge)
872 __inc_node_page_state(page, NR_FILE_PAGES);
873unlock:
874 xas_unlock_irq(&xas);
875 } while (xas_nomem(&xas, gfp_mask & GFP_RECLAIM_MASK));
876
852 do {
853 xas_lock_irq(&xas);
854 old = xas_load(&xas);
855 if (old && !xa_is_value(old))
856 xas_set_err(&xas, -EEXIST);
857 xas_store(&xas, page);
858 if (xas_error(&xas))
859 goto unlock;

--- 7 unchanged lines hidden (view full) ---

867
868 /* hugetlb pages do not participate in page cache accounting */
869 if (!huge)
870 __inc_node_page_state(page, NR_FILE_PAGES);
871unlock:
872 xas_unlock_irq(&xas);
873 } while (xas_nomem(&xas, gfp_mask & GFP_RECLAIM_MASK));
874
877 if (xas_error(&xas))
875 if (xas_error(&xas)) {
876 error = xas_error(&xas);
878 goto error;
877 goto error;
878 }
879
879
880 if (!huge)
881 mem_cgroup_commit_charge(page, memcg, false);
882 trace_mm_filemap_add_to_page_cache(page);
883 return 0;
884error:
885 page->mapping = NULL;
886 /* Leave page->index set: truncation relies upon it */
880 trace_mm_filemap_add_to_page_cache(page);
881 return 0;
882error:
883 page->mapping = NULL;
884 /* Leave page->index set: truncation relies upon it */
887 if (!huge)
888 mem_cgroup_cancel_charge(page, memcg);
889 put_page(page);
885 put_page(page);
890 return xas_error(&xas);
886 return error;
891}
892ALLOW_ERROR_INJECTION(__add_to_page_cache_locked, ERRNO);
893
894/**
895 * add_to_page_cache_locked - add a locked page to the pagecache
896 * @page: page to add
897 * @mapping: the page's address_space
898 * @offset: page index

--- 2604 unchanged lines hidden ---
887}
888ALLOW_ERROR_INJECTION(__add_to_page_cache_locked, ERRNO);
889
890/**
891 * add_to_page_cache_locked - add a locked page to the pagecache
892 * @page: page to add
893 * @mapping: the page's address_space
894 * @offset: page index

--- 2604 unchanged lines hidden ---