3 ms·
I can't help myself digging into the referenced source code. The membarrier syscall can fail to allocate, returning ENOMEM. The way Folly calls it, the program
by jeffbee 3mo ago
I can't help myself digging into the referenced source code. The membarrier syscall can fail to allocate, returning ENOMEM. The way Folly calls it, the program would abort. Which I guess is a fair strategy but it's good to know when your synchronization primitive is actually SynchronizeOrCrash.
- loeg 3mo ago> The membarrier syscall can fail to allocate, returning ENOMEM. This is mentioned in the source comment, but not documented in the membarrier(2) manual page. https://elixir.bootlin.com/linux/v7.1.2/source/kernel/sched/membarrier.c#L618 https://elixir.bootlin.com/linux/v7.1.2/source/kernel/sched/... In reality... what is it allocating? https://elixir.bootlin.com/linux/v7.1.2/source/kernel/sched/membarrier.c#L367 https://elixir.bootlin.com/linux/v7.1.2/source/kernel/sched/... Ok, so it needs to allocate a cpumask (tiny) under some usages. Similar requirement in other sites, e.g.: https://elixir.bootlin.com/linux/v7.1.2/source/kernel/sched/membarrier.c#L467 https://elixir.bootlin.com/linux/v7.1.2/source/kernel/sched/... Depending on kernel config (e.g., !CONFIG_CPUMAKS_OFFSTACK), this allocation literally cannot fail: https://elixir.bootlin.com/linux/v7.1.2/source/include/linux/cpumask.h#L1093 https://elixir.bootlin.com/linux/v7.1.2/source/include/linux... On OFFSTACK configs, it's merely a tiny heap allocation: https://elixir.bootlin.com/linux/v7.1.2/source/lib/cpumask.c#L30 https://elixir.bootlin.com/linux/v7.1.2/source/lib/cpumask.c... If this fails, your system is already hosed; program abort vs kernel lock up a few seconds later is probably immaterial. I think folly's choice to abort is a reasonable one.
- ot 3mo agoIn Linux everything is XOrCrash, since allocations never fail but the OOM killer can get you later.