402 Star 1.4K Fork 1.3K

GVPopenEuler / kernel

 / 详情

【OLK-5.10】新增进程级别指定swap设备

待办的
任务
创建于  
2023-08-24 19:47

背景

新增进程级别指定swap设备的特性,使用此特性可以指定一个进程只换出到某个swap设备上,不会使用其他swap设备

测试步骤

1、# 创建两个优先级不同的swap文件,swapfile2优先级较低
dd if=/dev/zero of=./swapfile bs=1024 count=1048576
dd if=/dev/zero of=./swapfile2 bs=1024 count=1048576
mkswap swapfile 
mkswap swapfile2
swapon swapfile
swapon swapfile2

2、编译如下测试代码进行测试

#include <sys/mman.h>
#include <stdio.h>
#include <memory.h>
#define MEMORY_LEN 500*1024*1024
int main()
{
        char *addr;
        int map_flags;
        int madv_flags;
        map_flags = MAP_PRIVATE | MAP_ANONYMOUS;
        madv_flags = MADV_PAGEOUT;
        addr = (char *)mmap(NULL, MEMORY_LEN, PROT_READ | PROT_WRITE, map_flags, -1, 0);
        if (addr == MAP_FAILED) {
            perror("map mem");
            addr = NULL;
            return -1;
        }
        memset(addr, 'a', MEMORY_LEN);
        getchar();//此时设置测试进程的preferred_swap
        madvise(addr, MEMORY_LEN, madv_flags);
        getchar();//此时验证swap使用情况
        munmap(addr, MEMORY_LEN);
        return 0;
}

3、测试步骤如下:
[root@localhost home]# swapon -s
Filename                                Type            Size            Used            Priority
/dev/dm-1                               partition       4153340         1708            -2
/home/swapfile                          file            1048572         0               -3
/home/swapfile2                         file            1048572         0               -4
[root@localhost home]# ./a.out
^Z
[1]+  Stopped                 ./a.out
[root@localhost home]# echo `pidof a.out`
1930248
[root@localhost home]# echo /home/swapfile2 > /proc/1930248/preferred_swap
[root@localhost home]# cat /proc/1930248/preferred_swap
/home/swapfile2
[root@localhost home]# fg
./a.out

^Z
[1]+  Stopped                 ./a.out
[root@localhost home]# swapon -s
Filename                                Type            Size            Used            Priority
/dev/dm-1                               partition       4153340         1964            -2
/home/swapfile                          file            1048572         0               -3
/home/swapfile2                         file            1048572         512000          -4
[root@localhost home]#

测试结果

低优先级的swapfile2在高优先级swap填满之前就被使用到了,说明设置的preferred_swap生效了

评论 (1)

Ni Cunshu 创建了任务

Hi ni-cunshu, welcome to the openEuler Community.
I'm the Bot here serving you. You can find the instructions on how to interact with me at Here.
If you have any questions, please contact the SIG: Kernel, and any of the maintainers.

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(2)
5329419 openeuler ci bot 1632792936
C
1
https://gitee.com/openeuler/kernel.git
git@gitee.com:openeuler/kernel.git
openeuler
kernel
kernel

搜索帮助