Commit 160a6705 authored by Kairui Song's avatar Kairui Song Committed by Peng Zhang
Browse files

mm/filemap: clean up hugetlb exclusion code

maillist inclusion
category: performance
bugzilla: https://gitee.com/openeuler/kernel/issues/I9JAY9
CVE: NA

Reference: https://lore.kernel.org/linux-mm/20240416071722.45997-1-ryncsn@gmail.com/#t

--------------------------------

__filemap_add_folio only has two callers, one never passes hugetlb folio
and one always passes in hugetlb folio.  So move the hugetlb related
cgroup charging out of it to make the code cleaner.

Link: https://lkml.kernel.org/r/20240415171857.19244-3-ryncsn@gmail.com


Signed-off-by: default avatarKairui Song <kasong@tencent.com>
Acked-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>

Conflicts:
	mm/filemap.c

Signed-off-by: default avatarZhangPeng <zhangpeng362@huawei.com>
parent e60537f4
Loading
Loading
Loading
Loading
+8 −13
Original line number Diff line number Diff line
@@ -849,20 +849,12 @@ noinline int __filemap_add_folio(struct address_space *mapping,
{
	XA_STATE(xas, &mapping->i_pages, index);
	int huge = folio_test_hugetlb(folio);
	bool charged = false;
	long nr = 1;
	long nr;

	VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
	VM_BUG_ON_FOLIO(folio_test_swapbacked(folio), folio);
	mapping_set_update(&xas, mapping);

	if (!huge) {
		int error = mem_cgroup_charge(folio, NULL, gfp);
		if (error)
			return error;
		charged = true;
	}

	VM_BUG_ON_FOLIO(index & (folio_nr_pages(folio) - 1), folio);
	xas_set_order(&xas, index, folio_order(folio));
	nr = folio_nr_pages(folio);
@@ -927,8 +919,6 @@ noinline int __filemap_add_folio(struct address_space *mapping,
	trace_mm_filemap_add_to_page_cache(folio);
	return 0;
error:
	if (charged)
		mem_cgroup_uncharge(folio);
	folio->mapping = NULL;
	/* Leave page->index set: truncation relies upon it */
	folio_put_refs(folio, nr);
@@ -942,11 +932,16 @@ int filemap_add_folio(struct address_space *mapping, struct folio *folio,
	void *shadow = NULL;
	int ret;

	ret = mem_cgroup_charge(folio, NULL, gfp);
	if (ret)
		return ret;

	__folio_set_locked(folio);
	ret = __filemap_add_folio(mapping, folio, index, gfp, &shadow);
	if (unlikely(ret))
	if (unlikely(ret)) {
		mem_cgroup_uncharge(folio);
		__folio_clear_locked(folio);
	else {
	} else {
		/*
		 * The folio might have been evicted from cache only
		 * recently, in which case it should be activated like