From: Ma Wupeng mawupeng1@huawei.com
remote_pager: fix msg_handler_peer.c build failed.
Chunsheng Luo (3): mmap: export __do_mmap_mm symbol remote_pager: fix msg_handler_peer.c build failed remote_pager: delete unused file
drivers/remote_pager/Kconfig | 9 + drivers/remote_pager/Makefile | 1 + drivers/remote_pager/main.c | 7 - drivers/remote_pager/msg_handler_peer.c | 111 ++------ drivers/remote_pager/swap/device/ksymbol.c | 83 ------ drivers/remote_pager/swap/device/ksymbol.h | 35 --- .../remote_pager/swap/device/swap_manager.c | 256 ------------------ .../remote_pager/swap/device/swap_manager.h | 28 -- .../swap/device/swap_policy/policy_list_lru.c | 108 -------- .../swap/device/swap_policy/swap_policy.h | 16 -- mm/mmap.c | 1 + 11 files changed, 33 insertions(+), 622 deletions(-) delete mode 100644 drivers/remote_pager/swap/device/ksymbol.c delete mode 100644 drivers/remote_pager/swap/device/ksymbol.h delete mode 100644 drivers/remote_pager/swap/device/swap_manager.c delete mode 100644 drivers/remote_pager/swap/device/swap_manager.h delete mode 100644 drivers/remote_pager/swap/device/swap_policy/policy_list_lru.c delete mode 100644 drivers/remote_pager/swap/device/swap_policy/swap_policy.h
From: Chunsheng Luo luochunsheng@huawei.com
euleros inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I7WLVX
---------------------------------------------
export __do_mmap_mm symbol for remote_pager module
Signed-off-by: Chunsheng Luo luochunsheng@huawei.com --- mm/mmap.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/mm/mmap.c b/mm/mmap.c index 2aef07b8a85e..819c37e7eb1f 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1469,6 +1469,7 @@ unsigned long __do_mmap_mm(struct mm_struct *mm, struct file *file, unsigned lon *populate = len; return addr; } +EXPORT_SYMBOL(__do_mmap_mm);
unsigned long do_mmap(struct file *file, unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags,
From: Chunsheng Luo luochunsheng@huawei.com
euleros inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I7WLVX
---------------------------------------------
If CONFIG_REMOTE_PAGER_SLAVE is enabled, this will lead to failure in compile msg_handler_peer.c. Fix it.
Fixes: bb659473cc9f ("drivers: remote_pager: introduce remote_pager module for gmem") Signed-off-by: Chunsheng Luo luochunsheng@huawei.com --- drivers/remote_pager/Kconfig | 9 ++ drivers/remote_pager/Makefile | 1 + drivers/remote_pager/main.c | 7 -- drivers/remote_pager/msg_handler_peer.c | 111 +++++------------------- 4 files changed, 32 insertions(+), 96 deletions(-)
diff --git a/drivers/remote_pager/Kconfig b/drivers/remote_pager/Kconfig index 27fb70b017f5..613cb770dbcf 100644 --- a/drivers/remote_pager/Kconfig +++ b/drivers/remote_pager/Kconfig @@ -16,4 +16,13 @@ config REMOTE_PAGER_MASTER help If unsure, say Y.
+config REMOTE_PAGER_SLAVE + tristate "remote pager slave" + default n + depends on ARM64 + depends on REMOTE_PAGER + help + If you want to remote_pager driver to support the peer function, + say m. + If unsure, say N. endmenu diff --git a/drivers/remote_pager/Makefile b/drivers/remote_pager/Makefile index 7d8cf1627a92..865ffa7eb0c5 100644 --- a/drivers/remote_pager/Makefile +++ b/drivers/remote_pager/Makefile @@ -9,3 +9,4 @@ remote_pager-$(CONFIG_REMOTE_PAGER) := main.o \ svm_proc_mng.o
remote_pager-$(CONFIG_REMOTE_PAGER_MASTER) += msg_handler_origin.o +remote_pager-$(CONFIG_REMOTE_PAGER_SLAVE) += msg_handler_peer.o diff --git a/drivers/remote_pager/main.c b/drivers/remote_pager/main.c index b7c8d8440bfa..29d4f88499f9 100644 --- a/drivers/remote_pager/main.c +++ b/drivers/remote_pager/main.c @@ -10,17 +10,10 @@ #include "msg_chan/msg_layer/msg_layer.h" #include "msg_handler.h"
-#if IS_ENABLED(CONFIG_REMOTE_PAGER_SLAVE) -#include "swap/device/swap_manager.h" -#endif - static int __init remote_pager_init(void) { msg_handle_init();
-#if IS_ENABLED(CONFIG_REMOTE_PAGER_SLAVE) - init_swap_manager("list_lru"); -#endif return 0; }
diff --git a/drivers/remote_pager/msg_handler_peer.c b/drivers/remote_pager/msg_handler_peer.c index 9912f89a43c6..ef9d13bce3ce 100644 --- a/drivers/remote_pager/msg_handler_peer.c +++ b/drivers/remote_pager/msg_handler_peer.c @@ -20,29 +20,16 @@ #include <linux/kprobes.h> #include <asm-generic/pgalloc.h> #include <linux/sched/mm.h> +#include <asm-generic/pgalloc.h> +#include <asm/pgalloc.h> +#include <linux/gmem.h> +#include <linux/hugetlb.h>
#include "msg_handler.h" #include "svm_proc_mng.h" -#include "swap/device/swap_manager.h" - -#define GM_READ 0x00000001 -#define GM_WRITE 0x00000002 -#define GM_EXEC 0x00000004
#define MAX_RETRY_TIME 10
-#ifndef WITH_GMEM -enum gm_ret { - GM_RET_SUCCESS = 0, - GM_RET_NOMEM, - GM_RET_PAGE_EXIST, - GM_RET_DMA_ERROR, - GM_RET_MIGRATING, - GM_RET_FAILURE_UNKNOWN, - GM_RET_UNIMPLEMENTED, -}; -#endif - static inline vm_fault_t get_page_size(enum page_entry_size pe_size, unsigned int *page_size, unsigned long *addr) @@ -177,8 +164,6 @@ int gmem_handle_task_pairing(struct rpg_kmsg_message *msg) return 0; }
-#define VM_PEER_SHARED BIT(56) - int vma_is_gmem(struct vm_area_struct *vma) { return (vma->vm_flags & VM_PEER_SHARED) != 0; @@ -202,11 +187,11 @@ int gmem_handle_alloc_vma_fixed(struct rpg_kmsg_message *msg) struct vm_area_struct *vma; int ret = GM_RET_SUCCESS;
- if (gmem_prot & GM_READ) + if (gmem_prot & VM_READ) prot |= PROT_READ; - if (gmem_prot & GM_WRITE) + if (gmem_prot & VM_WRITE) prot |= PROT_WRITE; - if (gmem_prot & GM_EXEC) + if (gmem_prot & VM_EXEC) prot |= PROT_EXEC;
tsk = find_get_task_by_vpid(my_pid); @@ -240,8 +225,7 @@ int gmem_handle_alloc_vma_fixed(struct rpg_kmsg_message *msg) }
vma->vm_ops = &gmem_vma_ops; - vma->vm_flags |= VM_HUGEPAGE; - vma->vm_flags |= VM_PEER_SHARED; + vm_flags_set(vma, VM_HUGEPAGE | VM_PEER_SHARED);
unlock: current->mm = NULL; @@ -267,6 +251,7 @@ int gmem_handle_free_vma(struct rpg_kmsg_message *msg) unsigned int peer_ws = recv->my_ws; struct task_struct *tsk; struct mm_struct *mm; + struct mm_struct *old_mm = current->mm;
int ret = 0;
@@ -284,9 +269,9 @@ int gmem_handle_free_vma(struct rpg_kmsg_message *msg) goto put_task; }
- mmap_write_lock(mm); - ret = __do_munmap(mm, va, size, NULL, false); - mmap_write_unlock(mm); + current->mm = mm; + ret = vm_munmap(va, size); + current->mm = old_mm;
if (ret < 0) ret = GM_RET_FAILURE_UNKNOWN; @@ -322,9 +307,6 @@ pmd_t *get_huge_pmd(const struct vm_area_struct *vma, u64 va) if (PXD_JUDGE(p4d) != 0) return NULL;
- /* if kernel version is above 4.11.0,then 5 level pt arrived. - pud_offset(pgd,va) changed to pud_offset(p4d,va) for x86 - but not changed in arm64 */ pud = pud_offset(p4d, va); if (PXD_JUDGE(pud) != 0) return NULL; @@ -345,10 +327,6 @@ static inline struct page *alloc_transhuge_page_node(int nid, int zero) if (!page) return NULL;
- INIT_LIST_HEAD(&page->lru); - INIT_LIST_HEAD(page_deferred_list(page)); - set_compound_page_dtor(page, TRANSHUGE_PAGE_DTOR); - return page; }
@@ -421,10 +399,6 @@ int gmem_handle_alloc_page(struct rpg_kmsg_message *msg) struct task_struct *tsk; struct mm_struct *mm; struct vm_area_struct *vma; - struct page *pgtable; - pmd_t *pmd; - spinlock_t *ptl; - int n_retry = 0; int ret = 0;
if (!proc) { @@ -443,11 +417,6 @@ int gmem_handle_alloc_page(struct rpg_kmsg_message *msg) if (recv->behavior == MADV_WILLNEED) { if (!page_info->page) goto new_page; - - ret = update_page(page_info->page); - if (ret) - pr_err("update_page failed, error: %d\n", ret); - goto out; }
@@ -455,22 +424,13 @@ int gmem_handle_alloc_page(struct rpg_kmsg_message *msg) /* TODO: How Can Know HBM node */ page = alloc_transhuge_page_node(1, !recv->dma_addr); if (!page) { - do_swap(); - if (n_retry++ < MAX_RETRY_TIME) { - goto new_page; - } else { - ret = -ENOMEM; - goto out; - } + ret = -ENOMEM; + goto out; }
- /* We need a condition */ - if (need_wake_up_swapd()) - wake_up_swapd(); - if (recv->dma_addr) { handle_migrate_page((void *)recv->dma_addr, page, page_size, - FORM_PEER); + FROM_PEER); }
tsk = find_get_task_by_vpid(my_pid); @@ -500,17 +460,6 @@ int gmem_handle_alloc_page(struct rpg_kmsg_message *msg) if (ret) goto put_mm;
- vma = find_vma(mm, addr); - if (!vma->anon_vma) - __anon_vma_prepare_symbol(vma); - __page_set_anon_rmap_symbol(page, vma, addr, 1); - add_swap_page(page); - - pmd = get_huge_pmd(vma, addr); - pgtable = alloc_pages(GFP_KERNEL | ___GFP_ZERO, 0); - ptl = pmd_lock(vma->vm_mm, pmd); - pgtable_trans_huge_deposit_symbol(vma->vm_mm, pmd, pgtable); - spin_unlock(ptl); page_info->page = page;
put_mm: @@ -578,13 +527,9 @@ int gmem_handle_free_page(struct rpg_kmsg_message *msg) int nid = recv->header.to_nid; struct task_struct *tsk; struct mm_struct *mm; - struct vm_area_struct *vma; - pmd_t *pmd; struct page_info *page_info; struct svm_proc *proc = search_svm_proc_by_pid(my_pid); struct page *page = NULL; - struct page *pgtable; - spinlock_t *ptl; int ret = 0;
if (!proc) { @@ -620,19 +565,7 @@ int gmem_handle_free_page(struct rpg_kmsg_message *msg) ret = -1; goto put_task; } - - vma = find_vma(mm, addr); - pmd = get_huge_pmd(vma, addr); - ptl = pmd_lock(vma->vm_mm, pmd); - pgtable = pgtable_trans_huge_withdraw_symbol(proc->mm, pmd); - spin_unlock(ptl); - pte_free(mm, pgtable); - /* mm should be freed at first */ - smp_rmb(); - - del_swap_page(page); - zap_clear_pmd(vma, addr, pmd); - + gmem_unmap_hugepage(proc, addr); mmput(mm);
if (recv->dma_addr) @@ -671,14 +604,14 @@ static int sync_gmem_vma_to_custom_process(struct svm_proc *svm_proc, struct mm_struct *old_mm = current->mm; unsigned long addr; unsigned long prot = PROT_READ; - + VMA_ITERATOR(vmi, mm, 0);
mmap_write_lock(mm); - for (vma = mm->mmap; vma; vma = vma->vm_next) { - if (!vma_is_gmem(vma)) + for_each_vma(vmi, vma) { + if (!vma_is_peer_shared(vma)) continue; current->mm = local_proc->mm; - pr_err("%s cur %lx local %lx start %lx -- end %lx\n", __func__, + pr_debug("%s cur %lx local %lx start %lx -- end %lx\n", __func__, (unsigned long)current->mm, (unsigned long)local_proc->mm, vma->vm_start, vma->vm_end); @@ -690,6 +623,7 @@ static int sync_gmem_vma_to_custom_process(struct svm_proc *svm_proc, MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE, 0, 0, &populate, NULL); + current->mm = old_mm; if (IS_ERR_VALUE(addr)) { pr_err("%s failed start %lx - end %lx ret %ld\n", __func__, vma->vm_start, vma->vm_end, addr); @@ -698,11 +632,10 @@ static int sync_gmem_vma_to_custom_process(struct svm_proc *svm_proc, local_vma = find_vma(local_proc->mm, addr); if (!local_vma) { local_vma->vm_ops = vma->vm_ops; - local_vma->vm_flags |= VM_HUGEPAGE; + vm_flags_set(vma, VM_HUGEPAGE | VM_PEER_SHARED); } } mmap_write_unlock(mm); - current->mm = old_mm;
return 0; }
From: Chunsheng Luo luochunsheng@huawei.com
euleros inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I7WLVX
---------------------------------------------
The file in the swap directory is not used, delete it.
Fixes: bb659473cc9f ("drivers: remote_pager: introduce remote_pager module for gmem") Signed-off-by: Chunsheng Luo luochunsheng@huawei.com --- drivers/remote_pager/swap/device/ksymbol.c | 83 ------ drivers/remote_pager/swap/device/ksymbol.h | 35 --- .../remote_pager/swap/device/swap_manager.c | 256 ------------------ .../remote_pager/swap/device/swap_manager.h | 28 -- .../swap/device/swap_policy/policy_list_lru.c | 108 -------- .../swap/device/swap_policy/swap_policy.h | 16 -- 6 files changed, 526 deletions(-) delete mode 100644 drivers/remote_pager/swap/device/ksymbol.c delete mode 100644 drivers/remote_pager/swap/device/ksymbol.h delete mode 100644 drivers/remote_pager/swap/device/swap_manager.c delete mode 100644 drivers/remote_pager/swap/device/swap_manager.h delete mode 100644 drivers/remote_pager/swap/device/swap_policy/policy_list_lru.c delete mode 100644 drivers/remote_pager/swap/device/swap_policy/swap_policy.h
diff --git a/drivers/remote_pager/swap/device/ksymbol.c b/drivers/remote_pager/swap/device/ksymbol.c deleted file mode 100644 index 9587cd760b27..000000000000 --- a/drivers/remote_pager/swap/device/ksymbol.c +++ /dev/null @@ -1,83 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Generalized Memory Management. - * - * Copyright (c) 2023- Huawei, Inc. - * Author: Jun Chen - * Co-Author: Cunshu Ni - */ -#include <linux/kprobes.h> - -#include "ksymbol.h" - -/* - * Get some symbol which are not exported by kernel - * rmap_walk_anon - * __anon_vma_prepare - * __page_set_anon_rmap - * pgtable_trans_huge_deposit - * pgtable_trans_huge_withdraw - */ - -rmap_walk_anon_symbol_t rmap_walk_anon_symbol; -__anon_vma_prepare_symbol_t __anon_vma_prepare_symbol; -__page_set_anon_rmap_symbol_t __page_set_anon_rmap_symbol; -pgtable_trans_huge_deposit_symbol_t pgtable_trans_huge_deposit_symbol; -pgtable_trans_huge_withdraw_symbol_t pgtable_trans_huge_withdraw_symbol; - -static unsigned long (*kallsyms_lookup_name_symbol)(const char *name); - -static int init_kallsyms_lookup_name(void) -{ - int ret; - - struct kprobe kprobe = { - .symbol_name = "kallsyms_lookup_name", - }; - - ret = register_kprobe(&kprobe); - if (ret) - return ret; - - kallsyms_lookup_name_symbol = (void *)kprobe.addr; - - unregister_kprobe(&kprobe); - - return 0; -} - -static void *__kallsyms_lookup_name(const char *name) -{ - void *symbol; - - symbol = (void *)kallsyms_lookup_name_symbol(name); - if (!symbol) - pr_err("Can not find symbol %s\n", name); - - return symbol; -} - -int kernel_symbol_init(void) -{ - int ret; - - ret = init_kallsyms_lookup_name(); - if (ret) { - pr_err("Can not find symbol kallsyms_lookup_name\n"); - return ret; - } - - rmap_walk_anon_symbol = __kallsyms_lookup_name("rmap_walk_anon"); - __anon_vma_prepare_symbol = __kallsyms_lookup_name("__anon_vma_prepare"); - __page_set_anon_rmap_symbol = __kallsyms_lookup_name("__page_set_anon_rmap"); - pgtable_trans_huge_deposit_symbol = __kallsyms_lookup_name("pgtable_trans_huge_deposit"); - pgtable_trans_huge_withdraw_symbol = __kallsyms_lookup_name("pgtable_trans_huge_withdraw"); - - ret = !rmap_walk_anon_symbol || - !__anon_vma_prepare_symbol || - !__page_set_anon_rmap_symbol || - !pgtable_trans_huge_deposit_symbol || - !pgtable_trans_huge_withdraw_symbol; - - return ret; -} diff --git a/drivers/remote_pager/swap/device/ksymbol.h b/drivers/remote_pager/swap/device/ksymbol.h deleted file mode 100644 index 3ea8d1c488dc..000000000000 --- a/drivers/remote_pager/swap/device/ksymbol.h +++ /dev/null @@ -1,35 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Generalized Memory Management. - * - * Copyright (c) 2023- Huawei, Inc. - * Author: Jun Chen - * Co-Author: Jiangtian Feng - */ -#ifndef __GMEM_KSYMBOL_H__ -#define __GMEM_KSYMBOL_H__ - -#include <linux/map.h> - -typedef int (*rmap_walk_anon_symbol_t)(struct page *page, - struct rmap_walk_control *rwc, bool locked); -extern rmap_walk_anon_symbol_t rmap_walk_anon_symbol; - -typedef int (*__anon_vma_prepare_symbol_t)(struct vm_area_struct *vma); -extern __anon_vma_prepare_symbol_t __anon_vma_prepare_symbol; - -typedef int (*__page_set_anon_rmap_symbol_t)(struct page *page, - struct vm_area_struct *vma, unsigned long address, int exclusive); -extern __page_set_anon_rmap_symbol_t __page_set_anon_rmap_symbol; - -typedef int (*pgtable_trans_huge_deposit_symbol_t)(struct mm_struct *mm, - pmd_t *pmdp, pgtable_t pgtable); -extern pgtable_trans_huge_deposit_symbol_t pgtable_trans_huge_deposit_symbol; - -typedef int (*pgtable_trans_huge_withdraw_symbol_t)(struct mm_struct *mm, - pmd_t *pmdp); -extern pgtable_trans_huge_withdraw_symbol_t pgtable_trans_huge_withdraw_symbol; - -int kernel_symbol_init(void); - -#endif diff --git a/drivers/remote_pager/swap/device/swap_manager.c b/drivers/remote_pager/swap/device/swap_manager.c deleted file mode 100644 index 6a4429c07950..000000000000 --- a/drivers/remote_pager/swap/device/swap_manager.c +++ /dev/null @@ -1,256 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only - -#include <linux/rmap.h> -#include <linux/kprobes.h> - -#include "../../msg_handler.h" -#include "../../svm_proc_mng.h" - -#include "ksymbol.h" -#include "swap_policy/swap_policy.h" - -extern struct swap_policy swap_policy_list_lru; - -static struct swap_manager { - struct swap_policy *policy; -} manager; - -int add_swap_page(struct page *page) -{ - if (manager.policy) - return manager.policy->add_page(page); - - return -ENODEV; -} - -int del_swap_page(struct page *page) -{ - if (manager.policy) - return manager.policy->del_page(page); - - return -ENODEV; -} - -int update_page(struct page *page) -{ - if (manager.policy) - return manager.policy->update_page(page); - - return -ENODEV; -} - -static int pick_victim_pages(struct list_head *page_list, int nid, unsigned long *nr) -{ - if (manager.policy) - return manager.policy->pick_victim_pages(page_list, nid, nr); - - return -ENODEV; -} - -static bool __do_swap_one_page(struct page *page, struct vm_area_struct *vma, - unsigned long addr, void *args) -{ - struct gm_evict_page_msg_rq req; - struct svm_proc *proc; - struct wait_station *ws; - struct comm_msg_rsp *rsp; - int ret = 0; - - proc = search_svm_proc_by_mm(vma->vm_mm); - if (!proc) { - pr_err("can not find proc of mm\n"); - return 0; /* return 0 if failed */ - } - - get_page(page); - - ws = get_wait_station(); - req.peer_pid = proc->peer_pid; - req.va = addr; - req.size = PageCompound(page) ? HPAGE_PMD_SIZE : PAGE_SIZE; - req.ws = ws->id; - ret = msg_send_nid(GMEM_EVICT_PAGE_REQUEST, proc->nid, proc->peer_nid, &req, sizeof(req)); - if (ret) { - pr_err("send GMEM_EVICT_PAGE_REQUEST failed\n"); - put_wait_station(ws); - goto out; - } - - rsp = wait_at_station(ws); - if (IS_ERR(rsp)) { - ret = PTR_ERR(rsp); - } else { - ret = rsp->ret; - kfree(rsp); - } - - if (ret) - pr_err("GMEM_EVICT_PAGE_REQUEST receive %d\n", ret); - -out: - put_page(page); - - return !ret; /* return 1 if success */ -} - -static int do_swap_one_page(struct page *page) -{ - struct rmap_walk_control rwc = { - .rmap_one = __do_swap_one_page, - }; - - rmap_walk_anon_symbol(page, &rwc, false); - - return 0; -} - -static int do_swap_pages(struct list_head *page_list) -{ - struct list_head *list = page_list; - struct page *page, *tmp; - - list_for_each_entry_safe(page, tmp, list, lru) - do_swap_one_page(page); - - return 0; -} - -static int swap_one_page_node(int nid) -{ - LIST_HEAD(evict_pages); - unsigned long nr_to_evict = 1; - - pick_victim_pages(&evict_pages, nid, &nr_to_evict); - - do_swap_pages(&evict_pages); - - return 0; -} - -#define HBM_WATERMARK_LOW 0x8000000 /* 128M */ -#define HBM_WATERMARK_HIG (2 * HBM_WATERMARK_LOW) - -static unsigned long zone_node_page_free(int node) -{ - struct zone *zones = NODE_DATA(node)->node_zones; - int i; - unsigned long count = 0; - - for (i = 0; i < MAX_NR_ZONES; i++) - count += zone_page_state(zones + i, NR_FREE_PAGES); - - return count * PAGE_SIZE; -} - -int need_wake_up_swapd_node(int nid) -{ - return zone_node_page_free(nid) < HBM_WATERMARK_LOW; -} - -int need_wake_up_swapd(void) -{ - int nid; - - for_each_node_state(nid, N_NORMAL_MEMORY) { - if (zone_node_page_free(nid) < HBM_WATERMARK_LOW) - return 1; - } - - return 0; -} - -int do_swap_node(int nid) -{ - swap_one_page_node(nid); - - return 0; -} - -int do_swap(void) -{ - int nid; - - for_each_node_state(nid, N_NORMAL_MEMORY) { - swap_one_page_node(nid); - } - - return 0; -} - -static int swapd_func(void *id) -{ - int nid = (unsigned long)id; - - while (!kthread_should_stop()) { - swap_one_page_node(nid); - if (zone_node_page_free(nid) > HBM_WATERMARK_HIG) { - set_current_state(TASK_INTERRUPTIBLE); - schedule(); - } else { - cond_resched(); - } - } - - return 0; -} - -static struct task_struct *swapd_task[MAX_NUMNODES]; - -static void init_swapd(void) -{ - unsigned long nid; - - for_each_online_node(nid) { - swapd_task[nid] = kthread_run(swapd_func, (void *)nid, "swapd"); - if (IS_ERR(swapd_task[nid])) - /* TODO: free task */ - swapd_task[nid] = NULL; - } -} - -static void wake_up_swapd_node(int nid) -{ - struct task_struct *tsk = swapd_task[nid]; - - if (likely(tsk)) - wake_up_process(tsk); -} - -void wake_up_swapd(void) -{ - unsigned long nid; - - for_each_online_node(nid) - wake_up_swapd_node(nid); -} - -int init_swap_manager(char *policy_name) -{ - int ret = 0; - - ret = kernel_symbol_init(); - if (ret) { - panic("Can not get all symbol\n"); - return ret; - } - - if (!policy_name) - return -EINVAL; - - if (!strncmp(policy_name, "list_lru", strlen("list_lru"))) - manager.policy = &swap_policy_list_lru; - - if (!manager.policy) - return -ENOENT; - - if (manager.policy->init) { - ret = manager.policy->init(); - if (ret) - return ret; - } - - init_swapd(); - - return 0; -} - diff --git a/drivers/remote_pager/swap/device/swap_manager.h b/drivers/remote_pager/swap/device/swap_manager.h deleted file mode 100644 index 3e97b265154b..000000000000 --- a/drivers/remote_pager/swap/device/swap_manager.h +++ /dev/null @@ -1,28 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Generalized Memory Management. - * - * Copyright (C) 2023- Huawei, Inc. - * Author: Chen Jun - * - */ -#ifndef _GMEM_SWAP_MANAGER_H_ -#define _GMEM_SWAP_MANAGER_H_ - -#include <linux/mm_types.h> - -#include "ksymbol.h" - -int init_swap_manager(char *policy_name); - -int add_swap_page(struct page *page); -int del_swap_page(struct page *page); -int update_page(struct page *page); - -int need_wake_up_swapd_node(int nid); -int need_wake_up_swapd(void); -int do_swap_node(int nid); -int do_swap(void); -void wake_up_swapd(void); - -#endif /* _GMEM_SWAP_MANAGER_H_ */ diff --git a/drivers/remote_pager/swap/device/swap_policy/policy_list_lru.c b/drivers/remote_pager/swap/device/swap_policy/policy_list_lru.c deleted file mode 100644 index 1bbe890969ed..000000000000 --- a/drivers/remote_pager/swap/device/swap_policy/policy_list_lru.c +++ /dev/null @@ -1,108 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Generalized Memory Management. - * - * Copyright (C) 2023- Huawei, Inc. - * Author: Chen Jun - * - */ -#include "swap_policy.h" - -#include <linux/list_lru.h> -#include <linux/mm.h> - -static struct list_lru swap_list_lru; - -static int add_page(struct page *page) -{ - struct list_lru *lru = &swap_list_lru; - int nid = page_to_nid(page); - struct list_head *item = &page->lru; - struct list_lru_node *nlru = &lru->node[nid]; - struct list_lru_one *l; - - spin_lock(&nlru->lock); - if (list_empty(item)) { - l = &nlru->lru; - list_move_tail(item, &l->list); - SetPageLRU(page); - spin_unlock(&nlru->lock); - return 0; - } - spin_unlock(&nlru->lock); - return -EINVAL; -} - -static int del_page(struct page *page) -{ - struct list_lru *lru = &swap_list_lru; - int nid = page_to_nid(page); - struct list_head *item = &page->lru; - struct list_lru_node *nlru = &lru->node[nid]; - struct list_lru_one *l; - - spin_lock(&nlru->lock); - if (PageLRU(page) && !list_empty(item)) { - l = &nlru->lru; - list_del_init(item); - __ClearPageLRU(page); - spin_unlock(&nlru->lock); - return 0; - } - spin_unlock(&nlru->lock); - return -EINVAL; -} - -static int update_page(struct page *page) -{ - struct list_lru *lru = &swap_list_lru; - int nid = page_to_nid(page); - struct list_head *item = &page->lru; - struct list_lru_node *nlru = &lru->node[nid]; - struct list_lru_one *l; - int page_isolate; - - spin_lock(&nlru->lock); - l = &nlru->lru; - list_move_tail(item, &l->list); - page_isolate = PageIsolated(page); - __ClearPageIsolated(page); - SetPageLRU(page); - spin_unlock(&nlru->lock); - - return 0; -} - -static enum lru_status lru_isolate_shrink(struct list_head *item, - struct list_lru_one *lru, spinlock_t *lru_lock, void *arg) -{ - struct list_head *victim_list = arg; - struct page *page = list_entry(item, struct page, lru); - - list_lru_isolate_move(lru, item, victim_list); - __ClearPageLRU(page); - __SetPageIsolated(page); - return LRU_REMOVED; -} - -static int pick_victim_pages(struct list_head *page_list, int nid, unsigned long *nr) -{ - list_lru_walk_node(&swap_list_lru, nid, lru_isolate_shrink, page_list, nr); - - return 0; -} - -static int init(void) -{ - list_lru_init(&swap_list_lru); - - return 0; -} - -struct swap_policy swap_policy_list_lru = { - .init = init, - .add_page = add_page, - .del_page = del_page, - .update_page = update_page, - .pick_victim_pages = pick_victim_pages, -}; diff --git a/drivers/remote_pager/swap/device/swap_policy/swap_policy.h b/drivers/remote_pager/swap/device/swap_policy/swap_policy.h deleted file mode 100644 index 1113096e8548..000000000000 --- a/drivers/remote_pager/swap/device/swap_policy/swap_policy.h +++ /dev/null @@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ - -#ifndef _GMEM_SWAP_POLICY_H -#define _GMEM_SWAP_POLICY_H - -#include <linux/mm_types.h> - -struct swap_policy { - int (*init)(void); - int (*add_page)(struct page *page); - int (*del_page)(struct page *page); - int (*update_page)(struct page *page); - int (*pick_victim_pages)(struct list_head *page_list, int nid, unsigned long *nr); -}; - -#endif /* _GMEM_SWAP_POLICY_H */
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/2246 邮件列表地址:https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/Z...
FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/2246 Mailing list address: https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/Z...