记录一个aio-nr
root@nyx:~# cat /proc/sys/fs/aio-nr
0
///////////
#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <errno.h>
#include <string.h>
// 手动定义 AIO 相关类型和常量
typedef struct io_context *io_context_t;
// 系统调用号(通常已定义在 <sys/syscall.h>,但安全起见显式写出)
#ifndef __NR_io_setup
#define __NR_io_setup 0
#endif
#ifndef __NR_io_destroy
#define __NR_io_destroy 1
#endif
int main() {
io_context_t ctx = 0;
long ret;
// 调用 io_setup,第一个参数是请求的最大数量,第二个是上下文指针
ret = syscall(__NR_io_setup, 128, &ctx);
if (ret < 0) {
printf("io_setup failed: %s\n", strerror(errno));
return 1;
}
printf("AIO context created. ctx = %p\n", ctx);
printf("Now check: cat /proc/sys/fs/aio-nr\n");
printf("Press Enter to destroy context and exit...");
getchar();
syscall(__NR_io_destroy, ctx);
printf("Context destroyed.\n");
return 0;
}
////////////
gcc
./a.out
root@nyx:~# cat /proc/sys/fs/aio-nr
256
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐


所有评论(0)