Recent submissions

Comment · 10 years ago
How useful is a lock-free (not wait-free) approach in a real-time context? The point is that any thread contending on lock-free data is liable to starve, so the worst-case behavior is still quite bad, no? The only benefit I see is freedom from priority inversion, and that's a fixable problem anyway. Are there other properties of the system that you somehow use to get real-time guarantees?

On the other hand, if you combine interrupt-disabling with a fair lock, then your lock wait time can be bounded in every thread. This is probably only an option inside the kernel, though.

In userspace, and with more threads than CPUs, the lock-free approach probably will save you a lot of context-switching time. It'll probably also be at least as fine-grained as the most fine-grained locking scheme you can come up with, probably with less overhead.

So I'd say that the lock-free approach is an optimistic strategy, and I don't see the benefit except for performance. I say this as someone who really likes lockfree programming.

Comment · 12 years ago
Comment · 12 years ago
You don't need to have a single frontier, and IIRC no one does these days. A stack of slabs per "arena" suffices, and the extra cost is only a read from a cacheline you'll soon need anyway. It looks like jemalloc uses a tree of "runs" for that.

I don't know exactly what you're imagining, but I don't see how you can pass this off to the kernel. You need a slab which has free memory. How do you know where to find it? You could write a nasty new syscall to ask the kernel for a ZFOD page(s), and then cry because your program is slow.

Also, unless your slabs are huge and your allocator is being used to fuel some kind of pre-caching, faulting pages is going to be suboptimal. You incur at least twice as many mode switches: one for the mmap call, one for each faulting page. I've measured this, and it gets pretty expensive. I'm kind of dubious about the performance of schemes which stray from the principle of "allocate what you actually need; free it when you don't."

The bottom line is that a slab allocator should be solving a different, mostly less general problem than the kernel. It needs finer granularity and it's optimizing for common block sizes that are small enough to fit into slabs of known sizes. So it should optimize for allocating page chunks in a small subset of possible sizes (namely, the slab size(s)), while the kernel should be worried about unbounded, oddly-sized page chunks.

I toyed with scalable allocators for a course a few years back. It's a little embarassing, but if you want to see what the costs actually are: http://www.andrew.cmu.edu/user/apodolsk/418/finalreport.html

You can do lockfree slab allocators pretty easily, so the game in scalable malloc is really about avoiding inter-CPU cacheline sharing and fitting your data structures into per-CPU caches. Slabs happen to be really good for that, for non-obvious reasons.

Comment · 12 years ago
I'm a very happy user. It's pretty well designed, and extensible in javascript. It's nice having EVERYTHING about the browser at your fingertips in fully customizable way, not just the the link-following mechanism. I use lots of vim hotkeys, just like I do in emacs.

Conkeror has sometimes struggled to keep up with xulrunner development, and there are sometimes bugs.

Comment · 12 years ago
I suppose it was bound to happen.
Comment · 12 years ago
By storing the struct in union with an integral type - or, if you need a value but not an address, casting to such a union. You might also think to just abuse pointer casting, but IIRC that breaks C strict aliasing assumptions and causes GCC's optimizations to do bad things to your program.
Comment · 12 years ago
But, like you said, you still need protection of kernel data, which means that you need to execute kernel code on a stack not writeable by the user, at a greater permission level that allows ONLY the kernel code to modify kernel pages. Single-address-space or not I can't see these needs being met in a cheaper way than what we already have, presuming that kernel code/data are in never-invalidated global pages available in every address space.

Edit: Oh, I see from your other comment that you're talking about the benefits to people who don't feel this need.

Comment · 12 years ago
Well, I'd done a small kernel for a class. Later, I wrote a lockfree malloc and realized that large lockfree programs are actually pretty managable, and that was the start. It's generally just a matter of designing around simple data structures (which are the only ones you can really do lockfree) and a repetition of some key tricks like refcounting, generation counting, and type-stable memory. Writing the data structures and primitives was tough, but otherwise you don't have to worry about locking and things come out quite neatly as a result.
Comment · 12 years ago
Lockfree OS kernel. Give it a couple weeks.
Comment · 13 years ago
For that price, I can buy 10 pairs of jeans on ebay, in a style that I like. Or I can go to the thrift store and get 50. I'll have wet ankles when I bike in the rain in a poncho, but whatever.
Comment · 13 years ago
Comment · 13 years ago
1) Math is way more than calculus. Writing proofs is the best way to train the general skills that will get you recognized as smart.

2) Stop being a coward. Always push yourself to do embarrassing, uncomfortable, or hard things, or you'll still be 16 when you're 21.

3) Gaming and computing is addictive. Don't waste precious life on it.

4) You're an idiot, and your unexamined decisions make you a bad person, though you don't intend to harm anyone. Find values to believe in, and use them to make hard or painful decisions with dignity. Foremost of those should be: treat your people well, even at your own expense.

5) Examine, accept, and embrace your feelings and your past, for better and worse.

6) Read more fiction to learn more about life.

7) You're a social animal. You'll never grow as much, or be as happy, as when you're surrounded by people.

8) Don't stop doubting yourself.

Very little of this has to do with programming or careers. But I don't regret not knowing C at 16 nearly as much as I regret all of the above. Learning to live well is so much more important.

Comment · 13 years ago
It's true that, if you learn to enjoy CS-related work, it's thrilling and rewarding. You'll find dazzling solutions to interesting problems, and have a blast doing it. But as respectable a craft as CS work is, does your output really improve anyone's life? Probably not, and it likely even contributes to some mild social ill. And once the dopamine wears off, have the lonely hours spent solving fun puzzles in front of a screen been a good use of your time on Earth?

I'd still recommend a CS major, but I urge perspective.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton