gpt4 book ai didi

linux - 轮询/选择从用户空间复制到内核空间

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:48:15 26 4
gpt4 key购买 nike

如果在内核模式CPU可以访问用户空间内存,为什么我们在调用poll/select时需要将数据从用户空间复制到内核空间?

引自 Linux 编程接口(interface):

When running in user mode, the CPU can access only memory that is marked as being in user space; attempts to access memory in kernel space result in a hardware exception. When running in kernel mode, the CPU can access both user and kernel memory space.

最佳答案

据我所知,这样做是为了避免以下并发症:

  1. 安全性(多线程)
  2. 用户空间可以随时换出

有一些进步,例如 splice在某些情况下有帮助(尽可能避免复制)

这是一篇讨论如何在文件读/写期间执行零复制操作的文章:Zero Copy I: User-Mode Perspective

关于linux - 轮询/选择从用户空间复制到内核空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39272533/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com