Lockless Inc
locklessinc.com · Personal blog · on HN since 2010
Lockless Inc. is a company site with articles on memory allocators, C optimization, assembly tricks, and low-level performance.
What HN saysHN links it for allocator benchmarks and C optimization articles; commenters say the papers helped them in their studies and cite its Lisp essay.
39HN people shared it
11linked it in comments
32stories submitted
278story points
5 years agolast shared
2010people per year2026
Most-shared posts
- 1Why Lisp Failed (2010)7 people · 133 points · first shared 2011 · 277 comments on HN
- 2Benchmarks allocator.shtml5 people · first shared 2012
- 3Optimizing the TCP/IP Checksum3 people · 7 points · first shared 2012 · 1 comments on HN
- 4Auto-vectorization with gcc 4.73 people · 5 points · first shared 2012 · discussion on HN
- 5Doubly Linked Lists in C3 people · 5 points · first shared 2013 · discussion on HN
- 6Optimization Tricks used by the Lockless Memory Allocator2 people · 61 points · first shared 2011 · 4 comments on HN
- 7Branchfree Saturating Arithmetic in C2 people · 4 points · first shared 2010 · discussion on HN
- 8Obscure C2 people · 3 points · first shared 2013 · discussion on HN
- 9Mutexes and Condition Variables using Futexes2 people · 1 points · first shared 2010 · discussion on HN
- 10Articles2 people · first shared 2019
- 11256 Bit Arithmetic1 people · 22 points · first shared 2010 · 5 comments on HN
- 12Spinlocks and Read-Write Locks1 people · 10 points · first shared 2010 · discussion on HN
- 13Mocking Functions in C1 people · 5 points · first shared 2013 · discussion on HN
- 14Lockless Inc. High-Performance Memory Allocator (Now Open Source GPL 3.0)1 people · 4 points · first shared 2011 · discussion on HN
- 15Weird Binary1 people · 4 points · first shared 2010 · discussion on HN
What HN people wrote when they linked it
runn1ng · 2019-07-07
Add (2009) to this article.
https://locklessinc.com/articles/
rramadass · 2019-07-06
This quiz wasn't illuminating at all. You generally start with assuming and validating a "C Datatype Model" i.e. ILP32/LP64 etc. for your system. Once you know that, these questions are easily answered.
If you want to see some real tricky C code, see some of the articles here: https://locklessinc.com/articles/
danbolt · 2016-01-27
The mindshare bit is an interesting one.
I once read an article [1] that argued Lisp did not reach the same level of industrial popularity as other programming languages due to the fact that Lisp enables you to program in a lot of different ways for different reasons. I'm admittedly not very familiar with Lisp, and I don't know if I fully agree with the article, but it made me wonder if ease-of-collaboration can be considered a useful perk for languages/frameworks.
[1] http://locklessinc.com/articles/why_lisp_failed/
throwawayaway · 2015-12-21
Wow! Want to do a full disclosure?
Your papers were very valuable while doing my undergraduate study. Is Hoard neck and neck with jemalloc and lockless' allocator nowadays?
http://locklessinc.com/benchmarks_allocator.shtml
chuckcode · 2015-06-07
I've found measuring memory usage with STL containers to be difficult as they have their own allocator and unless you're using reserve() often end up allocating extra space for things. Dr Dobbs had an interesting article a long time ago around optimizing allocators [1] and also memory management was one of the main reasons that Electronic Arts rolled their own variant of the STL [2]. I use a lot of STL for convenience but have been burned enough times that when memory consumption his high or has heavy usage I manage it manually and make sure to use a modern allocator like jemalloc or tcmalloc[3].
[1] http://www.drdobbs.com/cpp/improving-performance-with-custom-pool-a/18…
[2] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html#Mot…
[3] http://locklessinc.com/benchmarks_allocator.shtml
ramchip · 2014-06-21
> all decent C compilers can easily and robustly generate such code
From what I've seen auto-vectorization is anything but robust, often you need non-portable annotations to get anything decent. See e.g.: http://locklessinc.com/articles/vectorize/ where there's an interesting case where using "if" instead of a ternary operator is enough to prevent optimization.
gsg · 2013-12-02
You might find http://www.locklessinc.com/articles/dlist/ interesting: it describes a (perhaps excessively) clever way to do intrusive lists that gives type checking.
(Unfortunately it does rely on `typeof`, an extension.)
vgnet · 2012-03-26
There's a very interesting comparison between libumem (mtmalloc) and Hoard at http://www.oracle.com/technetwork/articles/servers-storage-dev/mem-all… (HN link: https://news.ycombinator.com/item?id=3755621). How do you view this class of allocators to tcmalloc, jemalloc, ptmalloc3, etc., specially in the concurrent multi-cpu scenario?
Here's what I'll be reading on allocators tonight, any further suggestions (following all the links in comments is part of the deal)?
http://en.wikipedia.org/wiki/C_dynamic_memory_allocation
http://www.facebook.com/notes/facebook-engineering/scalable-memory-all…
http://locklessinc.com/benchmarks_allocator.shtml
http://blog.reverberate.org/2009/02/20/one-malloc-to-rule-them-all/
vardump · 2015-06-25
For those who still think manual memory management and especially malloc and free are fast, check glibc implementation.
https://fossies.org/dox/glibc-2.21/malloc_8c_source.html#l02876
Also see this benchmark between different, faster allocators: http://locklessinc.com/benchmarks_allocator.shtml
The extra work doesn't end at allocation. When you actually implement a concurrent system, you'll usually end up having corner cases at object lifetime changes, which you need to synchronize. If the memory is only claimed when there are no more references to it, this extra synchronization step can be avoided. If you can't rely on this, you'll probably end up doing synchronization, such as (atomic) reference counting.
Synchronization is very expensive and it can quickly become the performance bottleneck for the whole system. On modern X86, you can do 5-20k floating point operations during one contended atomic sync op. Reference count increase or decrease is one sync op. A simple mutex needs two of those.
The more you have CPU cores, the more there will be synchronization (cache coherence) traffic broadcasted to all cores.
Words like "JIT" and "GC" seem to cause knee-jerk reactions in some developers. Likewise for manual memory management. It's not so black and white. There'll always be trade-offs. I usually write low level (firmware and kernel driver) and high performance code. C/C++/SIMD. Code that might need to react under a microsecond.
My message is just please be more open…
avdicius · 2015-04-24
Thank you very much for your review.
- I have a TATAS lock implementation elsewhere: https://github.com/ademakov/MainMemory/blob/master/src/base/lock.h
Could add it to Evenk as well.
- Exchanged value in FutexLock is not discarded, it is used in the conditions of the `if` and `while` statements. In both cases the returned value of 0 means that we've got the lock and the next thing executed will be the `break` statement. If either value of 1 or 2 is returned then we need to proceed with spinning. The `if` condition relies on short-circuiting of || operator, so the exchange is only done if the `value` variable is equal to 1. If it were equal to 0 then the CAS in the for loop would have returned true leading to an early exit.
The idea of using backoff before futex is picked from this article: http://locklessinc.com/articles/mutex_cv_futex/
The author suggests to spin a little in unlock as well, but I didn't go that far.
throwaway4891a · 2016-11-15
See also:
- http://locklessinc.com/benchmarks_allocator.shtml ($, use as a minimum performance target)
- http://www.nedprod.com/programs/portable/nedmalloc/
- http://phk.freebsd.dk/pubs/malloc.pdf [PDF] (phkmalloc)
- https://github.com/gperftools/gperftools (tcmalloc)
- https://github.com/ivmai/bdwgc/blob/master/malloc.c
- https://github.com/jemalloc/jemalloc
- http://gee.cs.oswego.edu/dl/html/malloc.html (dlmalloc)