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 */