Unverified Commit 4a58051a authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!10517 mm/dynamic_pool: two bugfix about THP and migration

Merge Pull Request from: @ci-robot 
 
PR sync from: Liu Shixin <liushixin2@huawei.com>
https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/74LMQP3DGZZJ6M7HMKLQKHP4WBOGQPSZ/ 
Recently, we found there are some cases that the dynamic pool is not working
as expected and the pages is allocated from buddy system. There are mainly
two reason:

 1. THP is not supported on dynamic pool, some path is not restricted to
    allocate THP which the allocation from dynamic pool is failed and
    fallback to allocate from buddy system.
 2. The numa balance will try to migrate the pages coming from dynamic pool
    and use pages from buddy system instead.

Liu Shixin (2):
  mm/dynamic_pool: replace task_in_dynamic_pool() with
    mm_in_dynamic_pool()
  mm/dynamic_pool: check page_from_dynamic_pool() on migration


-- 
2.25.1
 
https://gitee.com/openeuler/kernel/issues/IAF8L3 
 
Link:https://gitee.com/openeuler/kernel/pulls/10517

 

Reviewed-by: default avatarZhang Peng <zhangpeng362@huawei.com>
Signed-off-by: default avatarZhang Peng <zhangpeng362@huawei.com>
parents a632ad99 c6b4cc53
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -77,13 +77,13 @@ struct dpool_info {
	struct range pfn_ranges[];
};

bool __task_in_dynamic_pool(struct task_struct *tsk);
static inline bool task_in_dynamic_pool(struct task_struct *tsk)
bool __mm_in_dynamic_pool(struct mm_struct *mm);
static inline bool mm_in_dynamic_pool(struct mm_struct *mm)
{
	if (!dpool_enabled)
		return false;

	return __task_in_dynamic_pool(tsk);
	return __mm_in_dynamic_pool(mm);
}

static inline bool page_from_dynamic_pool(struct page *page)
@@ -103,6 +103,11 @@ static inline bool file_in_dynamic_pool(struct hugetlbfs_inode_info *p)
}

bool page_in_dynamic_pool(struct page *page);
static inline bool page_from_or_in_dynamic_pool(struct page *page)
{
	return page_from_dynamic_pool(page) || page_in_dynamic_pool(page);
}

int dynamic_pool_can_attach(struct task_struct *tsk, struct mem_cgroup *memcg);
struct page *dynamic_pool_alloc_page(gfp_t gfp, unsigned int order,
				     unsigned int alloc_flags);
@@ -140,7 +145,7 @@ static inline bool page_from_dynamic_pool(struct page *page)
	return false;
}

static inline bool task_in_dynamic_pool(struct task_struct *tsk)
static inline bool mm_in_dynamic_pool(struct mm_struct *mm)
{
	return false;
}
@@ -150,6 +155,11 @@ static inline bool page_in_dynamic_pool(const struct page *page)
	return false;
}

static inline bool page_from_or_in_dynamic_pool(struct page *page)
{
	return false;
}

static inline int dynamic_pool_can_attach(struct task_struct *tsk,
					  struct mem_cgroup *memcg)
{
+1 −1
Original line number Diff line number Diff line
@@ -2135,7 +2135,7 @@ static isolate_migrate_t isolate_migratepages(struct compact_control *cc)
			continue;
		}

		if (page_in_dynamic_pool(page))
		if (page_from_or_in_dynamic_pool(page))
			continue;

		/*
+17 −2
Original line number Diff line number Diff line
@@ -137,14 +137,29 @@ static struct dynamic_pool *dpool_get_from_page(struct page *page)
	return dpool;
}

bool __task_in_dynamic_pool(struct task_struct *tsk)
static struct dynamic_pool *dpool_get_from_mm(struct mm_struct *mm)
{
	struct dynamic_pool *dpool = NULL;
	struct mem_cgroup *memcg;

	memcg = get_mem_cgroup_from_mm(mm);
	if (!memcg)
		return NULL;

	dpool = dpool_get_from_memcg(memcg);
	css_put(&memcg->css);

	return dpool;
}

bool __mm_in_dynamic_pool(struct mm_struct *mm)
{
	struct dynamic_pool *dpool;

	if (!dpool_enabled)
		return false;

	dpool = dpool_get_from_task(tsk);
	dpool = dpool_get_from_mm(mm);
	dpool_put(dpool);

	return !!dpool;
+2 −2
Original line number Diff line number Diff line
@@ -2368,7 +2368,7 @@ int dissolve_free_huge_page(struct page *page)
	if (!folio_test_hugetlb(folio))
		return 0;

	if (page_from_dynamic_pool(page) || page_in_dynamic_pool(page))
	if (page_from_or_in_dynamic_pool(page))
		return -EBUSY;

	spin_lock_irq(&hugetlb_lock);
@@ -3079,7 +3079,7 @@ int isolate_or_dissolve_huge_page(struct page *page, struct list_head *list)
	struct folio *folio = page_folio(page);
	int ret = -EBUSY;

	if (page_from_dynamic_pool(page) || page_in_dynamic_pool(page))
	if (page_from_or_in_dynamic_pool(page))
		return -EBUSY;

	/*
+2 −2
Original line number Diff line number Diff line
@@ -363,7 +363,7 @@ int hugepage_madvise(struct vm_area_struct *vma,
			return 0;
#endif

		if (task_in_dynamic_pool(current))
		if (mm_in_dynamic_pool(vma->vm_mm))
			return -EINVAL;

		*vm_flags &= ~VM_NOHUGEPAGE;
@@ -2743,7 +2743,7 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev,
	if (!thp_vma_allowable_order(vma, vma->vm_flags, 0, PMD_ORDER))
		return -EINVAL;

	if (task_in_dynamic_pool(current))
	if (mm_in_dynamic_pool(mm))
		return -EINVAL;

	cc = kmalloc(sizeof(*cc), GFP_KERNEL);
Loading