提交 ceadb7d1 编写于 作者: T Tang Yizhou 提交者: Yang Yingliang

share_pool: Add group max process num limitation

ascend inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I4EUVI
CVE: NA

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

The max num of process in a group is MAX_PROC_PER_GROUP.
Signed-off-by: NTang Yizhou <tangyizhou@huawei.com>
Reviewed-by: NWeilong Chen <chenweilong@huawei.com>
Reviewed-by: NDing Tianhong <dingtianhong@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 41ad3fd5
...@@ -80,6 +80,8 @@ struct sp_group { ...@@ -80,6 +80,8 @@ struct sp_group {
int hugepage_failures; int hugepage_failures;
struct file *file; struct file *file;
struct file *file_hugetlb; struct file *file_hugetlb;
/* number of process in this group */
int proc_num;
/* list head of processes (sp_group_node, each represents a process) */ /* list head of processes (sp_group_node, each represents a process) */
struct list_head procs; struct list_head procs;
/* list head of sp_area. it is protected by spin_lock sp_area_lock */ /* list head of sp_area. it is protected by spin_lock sp_area_lock */
......
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
#define MAX_GROUP_FOR_SYSTEM 50000 #define MAX_GROUP_FOR_SYSTEM 50000
#define MAX_GROUP_FOR_TASK 3000 #define MAX_GROUP_FOR_TASK 3000
#define MAX_PROC_PER_GROUP 1024
#define PF_DOMAIN_CORE 0x10000000 /* AOS CORE processes in sched.h */ #define PF_DOMAIN_CORE 0x10000000 /* AOS CORE processes in sched.h */
...@@ -536,6 +537,7 @@ static struct sp_group *find_or_alloc_sp_group(int spg_id) ...@@ -536,6 +537,7 @@ static struct sp_group *find_or_alloc_sp_group(int spg_id)
} }
spg->id = spg_id; spg->id = spg_id;
spg->proc_num = 0;
atomic_set(&spg->spa_num, 0); atomic_set(&spg->spa_num, 0);
atomic64_set(&spg->size, 0); atomic64_set(&spg->size, 0);
atomic64_set(&spg->alloc_nsize, 0); atomic64_set(&spg->alloc_nsize, 0);
...@@ -686,6 +688,13 @@ static int mm_add_group_finish(struct mm_struct *mm, struct sp_group *spg) ...@@ -686,6 +688,13 @@ static int mm_add_group_finish(struct mm_struct *mm, struct sp_group *spg)
spg_node->master = master; spg_node->master = master;
down_write(&spg->rw_lock); down_write(&spg->rw_lock);
if (spg->proc_num + 1 == MAX_PROC_PER_GROUP) {
up_write(&spg->rw_lock);
pr_err_ratelimited("add group: group reaches max process num\n");
kfree(spg_node);
return -ENOSPC;
}
spg->proc_num++;
list_add_tail(&spg_node->proc_node, &spg->procs); list_add_tail(&spg_node->proc_node, &spg->procs);
up_write(&spg->rw_lock); up_write(&spg->rw_lock);
...@@ -3347,6 +3356,7 @@ int sp_group_exit(struct mm_struct *mm) ...@@ -3347,6 +3356,7 @@ int sp_group_exit(struct mm_struct *mm)
/* a dead group should NOT be reactive again */ /* a dead group should NOT be reactive again */
if (spg_valid(spg) && list_is_singular(&spg->procs)) if (spg_valid(spg) && list_is_singular(&spg->procs))
is_alive = spg->is_alive = false; is_alive = spg->is_alive = false;
spg->proc_num--;
list_del(&spg_node->proc_node); list_del(&spg_node->proc_node);
up_write(&spg->rw_lock); up_write(&spg->rw_lock);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册