未验证 提交 2a888818 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!637 Introduce new memory policy for OLK-5.10

Merge Pull Request from: @ma-wupeng 
 
Introduce new syscall set_mempolicy_home_node and mempolicy
MPOL_PREFERRED_MANY.

This patch series introduces the concept of the MPOL_PREFERRED_MANY mempolicy.
This mempolicy mode can be used with either the set_mempolicy(2) or mbind(2)
interfaces. Like the MPOL_PREFERRED interface, it allows an application to set a
preference for nodes which will fulfil memory allocation requests. Unlike the
MPOL_PREFERRED mode, it takes a set of nodes. Like the MPOL_BIND interface, it
works over a set of nodes. Unlike MPOL_BIND, it will not cause a SIGSEGV or
invoke the OOM killer if those preferred nodes are not available.

mm: add new syscall set_mempolicy_home_node 
 
Link:https://gitee.com/openeuler/kernel/pulls/637 

Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com> 
Signed-off-by: Jialin Zhang <zhangjialin11@huawei.com> 
......@@ -245,6 +245,13 @@ MPOL_INTERLEAVED
address range or file. During system boot up, the temporary
interleaved system default policy works in this mode.
MPOL_PREFERRED_MANY
This mode specifices that the allocation should be preferrably
satisfied from the nodemask specified in the policy. If there is
a memory pressure on all nodes in the nodemask, the allocation
can fall back to all existing numa nodes. This is effectively
MPOL_PREFERRED allowed for a mask rather than a single node.
NUMA memory policy supports the following optional mode flags:
MPOL_F_STATIC_NODES
......@@ -253,10 +260,10 @@ MPOL_F_STATIC_NODES
nodes changes after the memory policy has been defined.
Without this flag, any time a mempolicy is rebound because of a
change in the set of allowed nodes, the node (Preferred) or
nodemask (Bind, Interleave) is remapped to the new set of
allowed nodes. This may result in nodes being used that were
previously undesired.
change in the set of allowed nodes, the preferred nodemask (Preferred
Many), preferred node (Preferred) or nodemask (Bind, Interleave) is
remapped to the new set of allowed nodes. This may result in nodes
being used that were previously undesired.
With this flag, if the user-specified nodes overlap with the
nodes allowed by the task's cpuset, then the memory policy is
......@@ -401,7 +408,7 @@ follows:
Memory Policy APIs
==================
Linux supports 3 system calls for controlling memory policy. These APIS
Linux supports 4 system calls for controlling memory policy. These APIS
always affect only the calling task, the calling task's address space, or
some shared object mapped into the calling task's address space.
......@@ -453,6 +460,20 @@ requested via the 'flags' argument.
See the mbind(2) man page for more details.
Set home node for a Range of Task's Address Spacec::
long sys_set_mempolicy_home_node(unsigned long start, unsigned long len,
unsigned long home_node,
unsigned long flags);
sys_set_mempolicy_home_node set the home node for a VMA policy present in the
task's address range. The system call updates the home node only for the existing
mempolicy range. Other address ranges are ignored. A home node is the NUMA node
closest to which page allocation will come from. Specifying the home node override
the default allocation policy to allocate memory close to the local node for an
executing CPU.
Memory Policy Command Line Interface
====================================
......
......@@ -483,3 +483,4 @@
554 common landlock_create_ruleset sys_landlock_create_ruleset
555 common landlock_add_rule sys_landlock_add_rule
556 common landlock_restrict_self sys_landlock_restrict_self
560 common set_mempolicy_home_node sys_ni_syscall
......@@ -463,7 +463,7 @@
447 common kabi_reserved447 sys_ni_syscall
448 common kabi_reserved448 sys_ni_syscall
449 common kabi_reserved449 sys_ni_syscall
450 common kabi_reserved450 sys_ni_syscall
450 common set_mempolicy_home_node sys_set_mempolicy_home_node
451 common kabi_reserved451 sys_ni_syscall
452 common kabi_reserved452 sys_ni_syscall
453 common kabi_reserved453 sys_ni_syscall
......
......@@ -42,7 +42,6 @@
#define __ARM_NR_compat_cacheflush (__ARM_NR_COMPAT_BASE + 2)
#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5)
#define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800)
#define __NR_compat_syscalls 457
#endif
......
......@@ -908,8 +908,8 @@ __SYSCALL(__NR_kabi_reserved447, sys_ni_syscall)
__SYSCALL(__NR_kabi_reserved448, sys_ni_syscall)
#define __NR_kabi_reserved449 449
__SYSCALL(__NR_kabi_reserved449, sys_ni_syscall)
#define __NR_kabi_reserved450 450
__SYSCALL(__NR_kabi_reserved450, sys_ni_syscall)
#define __NR_set_mempolicy_home_node 450
__SYSCALL(__NR_set_mempolicy_home_node, sys_set_mempolicy_home_node)
#define __NR_kabi_reserved451 451
__SYSCALL(__NR_kabi_reserved451, sys_ni_syscall)
#define __NR_kabi_reserved452 452
......
......@@ -364,3 +364,4 @@
444 common landlock_create_ruleset sys_landlock_create_ruleset
445 common landlock_add_rule sys_landlock_add_rule
446 common landlock_restrict_self sys_landlock_restrict_self
450 common set_mempolicy_home_node sys_set_mempolicy_home_node
......@@ -443,3 +443,4 @@
444 common landlock_create_ruleset sys_landlock_create_ruleset
445 common landlock_add_rule sys_landlock_add_rule
446 common landlock_restrict_self sys_landlock_restrict_self
450 common set_mempolicy_home_node sys_set_mempolicy_home_node
......@@ -449,3 +449,4 @@
444 common landlock_create_ruleset sys_landlock_create_ruleset
445 common landlock_add_rule sys_landlock_add_rule
446 common landlock_restrict_self sys_landlock_restrict_self
450 common set_mempolicy_home_node sys_set_mempolicy_home_node
......@@ -382,3 +382,4 @@
444 n32 landlock_create_ruleset sys_landlock_create_ruleset
445 n32 landlock_add_rule sys_landlock_add_rule
446 n32 landlock_restrict_self sys_landlock_restrict_self
450 n32 set_mempolicy_home_node sys_set_mempolicy_home_node
......@@ -358,3 +358,4 @@
444 n64 landlock_create_ruleset sys_landlock_create_ruleset
445 n64 landlock_add_rule sys_landlock_add_rule
446 n64 landlock_restrict_self sys_landlock_restrict_self
450 common set_mempolicy_home_node sys_set_mempolicy_home_node
......@@ -431,3 +431,4 @@
444 o32 landlock_create_ruleset sys_landlock_create_ruleset
445 o32 landlock_add_rule sys_landlock_add_rule
446 o32 landlock_restrict_self sys_landlock_restrict_self
450 o32 set_mempolicy_home_node sys_set_mempolicy_home_node
......@@ -441,3 +441,4 @@
444 common landlock_create_ruleset sys_landlock_create_ruleset
445 common landlock_add_rule sys_landlock_add_rule
446 common landlock_restrict_self sys_landlock_restrict_self
450 common set_mempolicy_home_node sys_set_mempolicy_home_node
......@@ -539,7 +539,7 @@
447 common kabi_reserved447 sys_ni_syscall
448 common kabi_reserved448 sys_ni_syscall
449 common kabi_reserved449 sys_ni_syscall
450 common kabi_reserved450 sys_ni_syscall
450 nospu set_mempolicy_home_node sys_set_mempolicy_home_node
451 common kabi_reserved451 sys_ni_syscall
452 common kabi_reserved452 sys_ni_syscall
453 common kabi_reserved453 sys_ni_syscall
......
......@@ -446,3 +446,4 @@
444 common landlock_create_ruleset sys_landlock_create_ruleset sys_landlock_create_ruleset
445 common landlock_add_rule sys_landlock_add_rule sys_landlock_add_rule
446 common landlock_restrict_self sys_landlock_restrict_self sys_landlock_restrict_self
450 common set_mempolicy_home_node sys_set_mempolicy_home_node sys_set_mempolicy_home_node
......@@ -446,3 +446,4 @@
444 common landlock_create_ruleset sys_landlock_create_ruleset
445 common landlock_add_rule sys_landlock_add_rule
446 common landlock_restrict_self sys_landlock_restrict_self
450 common set_mempolicy_home_node sys_set_mempolicy_home_node
......@@ -489,3 +489,4 @@
444 common landlock_create_ruleset sys_landlock_create_ruleset
445 common landlock_add_rule sys_landlock_add_rule
446 common landlock_restrict_self sys_landlock_restrict_self
450 common set_mempolicy_home_node sys_set_mempolicy_home_node
......@@ -454,7 +454,7 @@
447 i386 kabi_reserved447 sys_ni_syscall
448 i386 kabi_reserved448 sys_ni_syscall
449 i386 kabi_reserved449 sys_ni_syscall
450 i386 kabi_reserved450 sys_ni_syscall
450 i386 set_mempolicy_home_node sys_set_mempolicy_home_node
451 i386 kabi_reserved451 sys_ni_syscall
452 i386 kabi_reserved452 sys_ni_syscall
453 i386 kabi_reserved453 sys_ni_syscall
......
......@@ -371,7 +371,7 @@
447 common kabi_reserved447 sys_ni_syscall
448 common kabi_reserved448 sys_ni_syscall
449 common kabi_reserved449 sys_ni_syscall
450 common kabi_reserved450 sys_ni_syscall
450 common set_mempolicy_home_node sys_set_mempolicy_home_node
451 common kabi_reserved451 sys_ni_syscall
452 common kabi_reserved452 sys_ni_syscall
453 common kabi_reserved453 sys_ni_syscall
......
......@@ -414,3 +414,4 @@
444 common landlock_create_ruleset sys_landlock_create_ruleset
445 common landlock_add_rule sys_landlock_add_rule
446 common landlock_restrict_self sys_landlock_restrict_self
450 common set_mempolicy_home_node sys_set_mempolicy_home_node
......@@ -57,6 +57,11 @@ struct mempolicy {
} w;
};
struct mempolicy_wrapper {
struct mempolicy policy;
int home_node; /* Home node to use for MPOL_BIND and MPOL_PREFERRED_MANY */
};
/*
* Support for managing mempolicy data objects (clone, copy, destroy)
* The default fast path of a NULL MPOL_DEFAULT policy is always inlined.
......@@ -154,13 +159,6 @@ extern bool mempolicy_nodemask_intersects(struct task_struct *tsk,
const nodemask_t *mask);
extern nodemask_t *policy_nodemask(gfp_t gfp, struct mempolicy *policy);
static inline nodemask_t *policy_nodemask_current(gfp_t gfp)
{
struct mempolicy *mpol = get_task_policy(current);
return policy_nodemask(gfp, mpol);
}
extern unsigned int mempolicy_slab_node(void);
extern enum zone_type policy_zone;
......@@ -204,6 +202,14 @@ extern void mpol_put_task_policy(struct task_struct *);
extern long __do_mbind(unsigned long start, unsigned long len,
unsigned short mode, unsigned short mode_flags,
nodemask_t *nmask, unsigned long flags, struct mm_struct *mm);
static inline bool mpol_is_preferred_many(struct mempolicy *pol)
{
return (pol->mode == MPOL_PREFERRED_MANY);
}
extern bool apply_policy_zone(struct mempolicy *policy, enum zone_type zone);
#else
struct mempolicy {};
......@@ -315,9 +321,9 @@ static inline void mpol_put_task_policy(struct task_struct *task)
{
}
static inline nodemask_t *policy_nodemask_current(gfp_t gfp)
static inline bool mpol_is_preferred_many(struct mempolicy *pol)
{
return NULL;
return false;
}
#endif /* CONFIG_NUMA */
#endif
......@@ -1039,6 +1039,9 @@ asmlinkage long sys_landlock_create_ruleset(const struct landlock_ruleset_attr _
asmlinkage long sys_landlock_add_rule(int ruleset_fd, enum landlock_rule_type rule_type,
const void __user *rule_attr, __u32 flags);
asmlinkage long sys_landlock_restrict_self(int ruleset_fd, __u32 flags);
asmlinkage long sys_set_mempolicy_home_node(unsigned long start, unsigned long len,
unsigned long home_node,
unsigned long flags);
/*
* Architecture-specific system calls
......
......@@ -878,8 +878,8 @@ __SYSCALL(__NR_kabi_reserved447, sys_ni_syscall)
__SYSCALL(__NR_kabi_reserved448, sys_ni_syscall)
#define __NR_kabi_reserved449 449
__SYSCALL(__NR_kabi_reserved449, sys_ni_syscall)
#define __NR_kabi_reserved450 450
__SYSCALL(__NR_kabi_reserved450, sys_ni_syscall)
#define __NR_set_mempolicy_home_node 450
__SYSCALL(__NR_set_mempolicy_home_node, sys_set_mempolicy_home_node)
#define __NR_kabi_reserved451 451
__SYSCALL(__NR_kabi_reserved451, sys_ni_syscall)
#define __NR_kabi_reserved452 452
......
......@@ -22,6 +22,7 @@ enum {
MPOL_BIND,
MPOL_INTERLEAVE,
MPOL_LOCAL,
MPOL_PREFERRED_MANY,
MPOL_MAX, /* always last member of enum */
};
......@@ -58,7 +59,6 @@ enum {
* are never OR'ed into the mode in mempolicy API arguments.
*/
#define MPOL_F_SHARED (1 << 0) /* identify shared policies */
#define MPOL_F_LOCAL (1 << 1) /* preferred local allocation */
#define MPOL_F_MOF (1 << 3) /* this policy wants migrate on fault */
#define MPOL_F_MORON (1 << 4) /* Migrate On protnone Reference On Node */
......
......@@ -298,6 +298,7 @@ COND_SYSCALL(migrate_pages);
COND_SYSCALL_COMPAT(migrate_pages);
COND_SYSCALL(move_pages);
COND_SYSCALL_COMPAT(move_pages);
COND_SYSCALL(set_mempolicy_home_node);
COND_SYSCALL(perf_event_open);
COND_SYSCALL(accept4);
......
......@@ -1154,7 +1154,7 @@ static struct page *dequeue_huge_page_vma(struct hstate *h,
unsigned long address, int avoid_reserve,
long chg)
{
struct page *page;
struct page *page = NULL;
struct mempolicy *mpol;
gfp_t gfp_mask;
nodemask_t *nodemask;
......@@ -1175,7 +1175,19 @@ static struct page *dequeue_huge_page_vma(struct hstate *h,
gfp_mask = htlb_alloc_mask(h);
nid = huge_node(vma, address, gfp_mask, &mpol, &nodemask);
page = dequeue_huge_page_nodemask(h, gfp_mask, nid, nodemask, mpol);
if (mpol_is_preferred_many(mpol)) {
page = dequeue_huge_page_nodemask(h, gfp_mask, nid, nodemask,
mpol);
/* Fallback to all nodes if page==NULL */
nodemask = NULL;
}
if (!page)
page = dequeue_huge_page_nodemask(h, gfp_mask, nid, nodemask,
mpol);
if (page && !avoid_reserve && vma_has_reserves(vma, chg)) {
SetHPageRestoreReserve(page);
h->resv_huge_pages--;
......@@ -2200,16 +2212,26 @@ static
struct page *alloc_buddy_huge_page_with_mpol(struct hstate *h,
struct vm_area_struct *vma, unsigned long addr)
{
struct page *page;
struct page *page = NULL;
struct mempolicy *mpol;
gfp_t gfp_mask = htlb_alloc_mask(h);
int nid;
nodemask_t *nodemask;
nid = huge_node(vma, addr, gfp_mask, &mpol, &nodemask);
page = alloc_surplus_huge_page(h, gfp_mask, nid, nodemask);
mpol_cond_put(mpol);
if (mpol_is_preferred_many(mpol)) {
gfp_t gfp = gfp_mask | __GFP_NOWARN;
gfp &= ~(__GFP_DIRECT_RECLAIM | __GFP_NOFAIL);
page = alloc_surplus_huge_page(h, gfp_mask, nid, nodemask);
/* Fallback to all nodes if page==NULL */
nodemask = NULL;
}
if (!page)
page = alloc_surplus_huge_page(h, gfp_mask, nid, nodemask);
mpol_cond_put(mpol);
return page;
}
......@@ -3850,19 +3872,35 @@ static int __init default_hugepagesz_setup(char *s)
}
__setup("default_hugepagesz=", default_hugepagesz_setup);
static nodemask_t *policy_mbind_nodemask(gfp_t gfp)
{
#ifdef CONFIG_NUMA
struct mempolicy *mpol = get_task_policy(current);
/*
* Only enforce MPOL_BIND policy which overlaps with cpuset policy
* (from policy_nodemask) specifically for hugetlb case
*/
if (mpol->mode == MPOL_BIND &&
(apply_policy_zone(mpol, gfp_zone(gfp)) &&
cpuset_nodemask_valid_mems_allowed(&mpol->v.nodes)))
return &mpol->v.nodes;
#endif
return NULL;
}
static unsigned int allowed_mems_nr(struct hstate *h)
{
int node;
unsigned int nr = 0;
nodemask_t *mpol_allowed;
nodemask_t *mbind_nodemask;
unsigned int *array = h->free_huge_pages_node;
gfp_t gfp_mask = htlb_alloc_mask(h);
mpol_allowed = policy_nodemask_current(gfp_mask);
mbind_nodemask = policy_mbind_nodemask(gfp_mask);
for_each_node_mask(node, cpuset_current_mems_allowed) {
if (!mpol_allowed ||
(mpol_allowed && node_isset(node, *mpol_allowed)))
if (!mbind_nodemask ||
(mbind_nodemask && node_isset(node, *mbind_nodemask)))
nr += array[node];
}
......
此差异已折叠。
......@@ -878,8 +878,8 @@ __SYSCALL(__NR_kabi_reserved447, sys_ni_syscall)
__SYSCALL(__NR_kabi_reserved448, sys_ni_syscall)
#define __NR_kabi_reserved449 449
__SYSCALL(__NR_kabi_reserved449, sys_ni_syscall)
#define __NR_kabi_reserved450 450
__SYSCALL(__NR_kabi_reserved450, sys_ni_syscall)
#define __NR_set_mempolicy_home_node 450
__SYSCALL(__NR_set_mempolicy_home_node, sys_set_mempolicy_home_node)
#define __NR_kabi_reserved451 451
__SYSCALL(__NR_kabi_reserved451, sys_ni_syscall)
#define __NR_kabi_reserved452 452
......@@ -893,6 +893,9 @@ __SYSCALL(__NR_kabi_reserved455, sys_ni_syscall)
#define __NR_kabi_reserved456 456
__SYSCALL(__NR_kabi_reserved456, sys_ni_syscall)
#define __NR_set_mempolicy_home_node 450
__SYSCALL(__NR_set_mempolicy_home_node, sys_set_mempolicy_home_node)
#undef __NR_syscalls
#define __NR_syscalls 457
......
......@@ -539,7 +539,7 @@
447 common kabi_reserved447 sys_ni_syscall
448 common kabi_reserved448 sys_ni_syscall
449 common kabi_reserved449 sys_ni_syscall
450 common kabi_reserved450 sys_ni_syscall
450 nospu set_mempolicy_home_node sys_set_mempolicy_home_node
451 common kabi_reserved451 sys_ni_syscall
452 common kabi_reserved452 sys_ni_syscall
453 common kabi_reserved453 sys_ni_syscall
......
......@@ -388,3 +388,4 @@
378 common s390_guarded_storage sys_s390_guarded_storage compat_sys_s390_guarded_storage
379 common statx sys_statx compat_sys_statx
380 common s390_sthyi sys_s390_sthyi compat_sys_s390_sthyi
450 common set_mempolicy_home_node sys_set_mempolicy_home_node sys_set_mempolicy_home_node
\ No newline at end of file
......@@ -371,7 +371,7 @@
447 common kabi_reserved447 sys_ni_syscall
448 common kabi_reserved448 sys_ni_syscall
449 common kabi_reserved449 sys_ni_syscall
450 common kabi_reserved450 sys_ni_syscall
450 common set_mempolicy_home_node sys_set_mempolicy_home_node
451 common kabi_reserved451 sys_ni_syscall
452 common kabi_reserved452 sys_ni_syscall
453 common kabi_reserved453 sys_ni_syscall
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册