JVM + Linux +英特尔的超线程 =
我注意到由于某些原因,JVM 线程在 Linux 下作为进程运行(如果我错了,请纠正我)。此外,事实上,英特尔的超线程仅为属于同一进程的两个线程提供额外的并行化。
这是否意味着单个多线程 JVM 程序不会从 Linux 下的超线程中获益,因为从 CPU“角度”来看,它的线程不是线程?
I noticed that JVM threads run as processes under Linux for some reasons (correct me if I'm wrong). Furthermore, it is a fact that Intel's Hyperthreading provides additional parallelization only for two threads belonging to same process.
Does that mean that a single multitheraded JVM program would not profit from Hyperthreading under Linux, because its threads are no threads from the CPUs "point of view"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Linux 中的调度程序对进程和线程的处理方式没有区别。有一系列资源可以被进程共享,如
clone
系统调用。通常使用的线程和进程只是常用配方的名称。如果您将线程视为 JVM 中的进程,那么这只是术语的混合。根据通常的定义,如果进程共享虚拟地址空间,那么它们就是进程内的“线程”。
无论使用什么术语,所有硬件调度都将受益于超线程。另外,为了完全公平,超线程不允许您并行运行更多线程:它使上下文切换更快,为进程提供更多运行时间。
Processes and threads are not treated differently by the scheduler in Linux. There are a range of resources that can be shared by processes, as defined by the
clone
system call. Threads and processes as they're typically used are just names for commonly used recipes.If you're observing threads as processes in the JVM, this is just a mixing of nomenclature. By the usual definition if processes are sharing a virtual address space, then they are "threads" within a process.
All hardware scheduling will benefit from hyper-threading, regardless of the terminology used. Also to be completely fair, hyper threading does not allow you to run more threads in parallel: it makes context switches faster, giving processes more run time.
“JVM 线程在 Linux 下作为进程运行”——不,它们作为 LWP(轻量级进程)运行。
Java 线程在内部实现为本地线程,即 LWP(在 Linux 中),您可以使用 ps -eLf 来查看它们。尽管本机线程和 Java 线程之间的映射很困难。唯一可以轻松映射的线程是主线程,因为它的 id 与进程 id 相同。
JVM 肯定会从 HT 中获益。
来自关于 Java 中的 HT 的文章:
"JVM threads run as processes under Linux "-- No they run as LWP(Light Weight Process).
Java threads are internally implemented as native threads i.e. LWP (in linux) and you can see them using
ps -eLf
. Though mapping between a native thread and a java thread is difficult. The only thread that can be mapped easily is the main-thread as it will have the id same as the process id.JVM will definitely profit from HT.
From an article on HT in java: