From: Wang Wensheng wangwensheng4@huawei.com
ascend inclusion category: Feature bugzilla: https://gitee.com/openeuler/kernel/issues/I4NDAW CVE: NA
-------------------
We store the preferred node_id in sp_area in sp_alloc() and use it for memory alloc in shmem_fault.
Signed-off-by: Wang Wensheng wangwensheng4@huawei.com Signed-off-by: Peng Wu wupeng58@huawei.com Reviewed-by: Kefeng Wangwangkefeng.wang@huawei.com Reviewed-by: Weilong Chen chenweilong@huawei.com Signed-off-by: Zheng Zengkai zhengzengkai@huawei.com --- include/linux/share_pool.h | 1 + mm/share_pool.c | 20 +++++++++++++++++++- mm/shmem.c | 5 +++-- 3 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/include/linux/share_pool.h b/include/linux/share_pool.h index 0254ea95f034..ca9fcde90211 100644 --- a/include/linux/share_pool.h +++ b/include/linux/share_pool.h @@ -262,6 +262,7 @@ extern int sp_group_exit(struct mm_struct *mm); extern void sp_group_post_exit(struct mm_struct *mm); extern bool sp_check_addr(unsigned long addr); extern bool sp_check_mmap_addr(unsigned long addr, unsigned long flags); +extern int sp_node_id(struct vm_area_struct *vma);
static inline bool sp_is_enabled(void) { diff --git a/mm/share_pool.c b/mm/share_pool.c index 7853054ed005..05218c6dd250 100644 --- a/mm/share_pool.c +++ b/mm/share_pool.c @@ -1971,7 +1971,6 @@ static int sp_check_caller_permission(struct sp_group *spg, struct mm_struct *mm return ret; }
- #define FREE_CONT 1 #define FREE_END 2
@@ -3616,6 +3615,25 @@ bool mg_is_sharepool_addr(unsigned long addr) } EXPORT_SYMBOL_GPL(mg_is_sharepool_addr);
+int sp_node_id(struct vm_area_struct *vma) +{ + struct sp_area *spa; + int node_id = numa_node_id(); + + if (!sp_is_enabled()) + return node_id; + + if (vma) { + spa = __find_sp_area(vma->vm_start); + if (spa) { + node_id = spa->node_id; + __sp_area_drop(spa); + } + } + + return node_id; +} + static int __init mdc_default_group(char *s) { enable_mdc_default_group = 1; diff --git a/mm/shmem.c b/mm/shmem.c index 51f8f3b75803..60644e9b1a7b 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -80,6 +80,7 @@ static struct vfsmount *shm_mnt; #include <linux/userfaultfd_k.h> #include <linux/rmap.h> #include <linux/uuid.h> +#include <linux/share_pool.h>
#include <linux/uaccess.h>
@@ -1889,11 +1890,11 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, }
alloc_huge: - page = shmem_alloc_and_acct_page(gfp, inode, index, true, numa_node_id()); + page = shmem_alloc_and_acct_page(gfp, inode, index, true, sp_node_id(vma)); if (IS_ERR(page)) { alloc_nohuge: page = shmem_alloc_and_acct_page(gfp, inode, - index, false, numa_node_id()); + index, false, sp_node_id(vma)); } if (IS_ERR(page)) { int retry = 5;