- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我观察到,当 linux futexes 发生争用时,系统会在自旋锁上花费大量时间。我注意到即使不直接使用 futex 也是一个问题,但在调用 malloc/free、rand、glib 互斥调用和其他调用 futex 的系统/库调用时也是如此。有什么任何方法可以摆脱这种行为?
我正在使用内核为 2.6.32-279.9.1.el6.x86_64 的 CentOS 6.3。我还尝试了直接从 kernel.org 下载的最新稳定内核 3.6.6。
最初,问题发生在具有 16GB RAM 的 24 核服务器上。该进程有 700 个线程。使用“perf record”收集的数据显示,自旋锁是从 __lll_lock_wait_private 和 __lll_unlock_wake_private 调用的 futex 调用的,占用了 50% 的 CPU 时间。当我用 gdb 停止进程时,回溯显示对 __lll_lock_wait_private 和 __lll_unlock_wake_private 的调用是从 malloc 和 free 进行的。
我试图减少这个问题,所以我写了一个简单的程序来显示它确实是导致自旋锁问题的 futexes。
启动 8 个线程,每个线程执行以下操作:
//...
static GMutex *lMethodMutex = g_mutex_new ();
while (true)
{
static guint64 i = 0;
g_mutex_lock (lMethodMutex);
// Perform any operation in the user space that needs to be protected.
// The operation itself is not important. It's the taking and releasing
// of the mutex that matters.
++i;
g_mutex_unlock (lMethodMutex);
}
//...
我在一台 8 核机器上运行它,有足够的 RAM。
使用“top”,我观察到机器空闲10%,用户态10%,系统态90%。
使用“perf top”,我观察到以下内容:
50.73% [kernel] [k] _spin_lock
11.13% [kernel] [k] hpet_msi_next_event
2.98% libpthread-2.12.so [.] pthread_mutex_lock
2.90% libpthread-2.12.so [.] pthread_mutex_unlock
1.94% libpthread-2.12.so [.] __lll_lock_wait
1.59% [kernel] [k] futex_wake
1.43% [kernel] [k] __audit_syscall_exit
1.38% [kernel] [k] copy_user_generic_string
1.35% [kernel] [k] system_call
1.07% [kernel] [k] schedule
0.99% [kernel] [k] hash_futex
我希望这段代码在自旋锁中花费一些时间,因为 futex 代码必须获取 futex 等待队列。我还希望代码在系统中花费一些时间,因为在这段代码中,用户空间中运行的代码非常少。然而,50% 的时间花在自旋锁上似乎有些过分,尤其是当需要这段 cpu 时间来做其他有用的工作时。
最佳答案
我也遇到过类似的问题。我的经验是,根据 libc 版本和许多其他晦涩的事情(例如调用 fork() 之类的 here ),您可能会在大量锁定和解锁时看到性能下降甚至死锁。
This guy通过切换到 tcmalloc 解决了他的性能问题,这可能是一个好主意,具体取决于用例。您也值得一试。
对我来说,当我有多个线程进行大量锁定和解锁时,我看到了可重现的死锁。我从 2010 年开始使用带有 libc 的 Debian 5.0 rootfs(嵌入式系统),通过升级到 Debian 6.0 解决了这个问题。
关于linux - 竞争 futex 时系统 CPU 使用率高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13293452/
使用共享内存中存储的 rwlock 对象的同一进程中的两个线程在 pthreads 压力测试期间遇到崩溃。我花了一段时间试图找到内存损坏或死锁,但到目前为止一无所获。这只是通知我我造成了僵局的一种不太
futex man page提供了一个简单的演示,但我无法得到页面描述的结果,结果似乎在我的机器上死锁(linux 5.2.1);父进程不会被子进程唤醒。手册页是否错误? 我的机器上的输出示例: [r
我有一个futex的示例代码。但是我无法理解代码流程.... #include #include #include #include #include #define NUM 50 int
我正在尝试使用信号量解决哲学家就餐问题。哲学家先拿起左边的 fork ,然后拿起右边的 fork ,吃完后放下。我正在使用 5 个线程一个用于每个哲学家和 5 个信号量一个用于每根筷子来实现这一点。需
我们在 Linux RedHat 机器上观察到我们的一个 Java 应用程序在尝试发布到外部 MQ 队列时出现异常延迟(以前从未发生过)。对盒子进行了快速健康检查,CPU/内存使用情况似乎还不错。 M
有什么方法可以在 iOS 上实现快速自旋锁,当且仅当存在争用时恢复为阻塞操作系统原语?我正在寻找与这些实现等效的东西: http://locklessinc.com/articles/keyed_ev
不相关的进程如何使用 futex 进行协作? 假设我有不相关的进程,例如,一个是我的模块的 apache 子进程,另一个是例如一个后台脚本。 我想使用 futex 在两者之间建立一个带有互斥锁的条件变
我需要在锁定/解锁上下文之外的用户空间中调用 do_futex() 的功能。也就是说,我不需要互斥体,而是内核调用 do_futex 的确切语义。 它似乎应该在用户空间中可用,因为其目的是尽量减少系统
我有一个用 Haskell 编写的微服务。它使用斯科蒂。 LTS 是 13.20。操作系统:Linux 3.10.0-957.el7.x86_64,运行在Kubernetes下。该服务工作了大约 0.
我正在阅读一些文档并尝试一些发出 futex 的代码示例。 Linux 中的系统调用。我读到如果 thread_a 获得了互斥锁使用 FUTEX_LOCK_PI ,并说如果另一个线程 thread_b
我有一个在生产环境中运行的 Python 守护进程。它使用 7 到 120 个线程。最近最小的实例(7 个线程)开始出现挂起,而所有其他实例从未出现过此类问题。将 strace 附加到 python
这个方法(我意识到这个函数可能需要一些额外的参数): void waitUntilNotEqual(volatile int* addr, int value) { while (*addr
我正在尝试同步 5 个进程,它们必须由同一个父进程创建。 我尝试插入 5 个 waitpids 以等待子进程结束,但代码从未到达 D4 和 D5。 #include #include #inclu
我一直在对基于 futex 的锁使用服务员计数方法:与 futex int 相邻,有第二个 int,这是服务员竞争的服务员计数对于锁,在执行 futex 等待操作之前自动递增,并在从 futex 系统
有人可以告诉我一个使用基于 futex 的锁定机制的例子吗? (多核 x86 CPU,CentOS) 最佳答案 Pthreads 的互斥量是在最新版本的 Linux 上使用 futexes 实现的。
我在尝试调试基于 Linux-futex 和原子操作的锁定原语中的竞争条件导致死锁时遇到了可怕的时间。这是我正在使用的代码(与真实代码完全相同的逻辑,只是去掉了对与问题无关的数据结构的依赖): int
我有一个等待 futex 的进程: # strace -p 5538 Process 5538 attached - interrupt to quit futex(0x7f86c9ed6a0c, F
我在 64 位 Linux 机器上: Linux illin793 2.6.32-279.5.2.el6.x86_64 #1 SMP Tue Aug 14 11:36:39 EDT 2012 x86_
我正在尝试在 Linux 中使用基于健壮的 futex 的 pthread 互斥体,因为我需要既快速又健壮(恢复“死”锁)。我如何检查任何 Linux 系统上的 pthread 互斥库是否基于健壮的
我有一个 sqoop 命令,它使用 hcatalog 参数将数据从 Oracle 导入到 hive orc 表中。 sqoop import -D oraoop.disabled=true -D ma
我是一名优秀的程序员,十分优秀!