Featured post

Linux Internals: How /proc/self/mem writes to unwritable memory


An obscure quirk of the /proc/*/mem pseudofile is its “punch through” semantics. Writes performed through this file will succeed even if the destination virtual memory is marked unwritable. In fact, this behavior is intentional and actively used by projects such as the Julia JIT compiler and rr debugger.

This behavior raises some questions: Is privileged code subject to virtual memory permissions? In general, to what degree can the hardware inhibit kernel memory access?

By exploring these questions1, this article will shed light on the nuanced relationship between an operating system and the hardware it runs on. We’ll examine the constraints the CPU can impose on the kernel, and how the kernel can bypass these constraints.

Continue reading
Featured post

Double fetches, scheduling algorithms, and onion rings

Most people thought I was crazy for doing this, but I spent the last few months of my gap year working as a short order cook at a family-owned fast-food restaurant. (More on this here.) I’m a programmer by trade, so I enjoyed thinking about the restaurant’s systems from a programmer’s point of view. Here’s some thoughts about two such systems.

Continue reading
Featured post

What they don’t tell you about demand paging in school

This post details my adventures with the Linux virtual memory subsystem, and my discovery of a creative way to taunt the OOM (out of memory) killer by accumulating memory in the kernel, rather than in userspace.

Keep reading and you’ll learn:

  • Internal details of the Linux kernel’s demand paging implementation
  • How to exploit virtual memory to implement highly efficient sparse data structures
  • What page tables are and how to calculate the memory overhead incurred by them
  • A cute way to get killed by the OOM killer while appearing to consume very little memory (great for parties)

Note: Victor Michel wrote a great follow up to this post here.

Continue reading
Featured post

How setjmp and longjmp work (2016)

Pretty recently I learned about setjmp() and longjmp(). They’re a neat pair of libc functions which allow you to save your program’s current execution context and resume it at an arbitrary point in the future (with some caveats1). If you’re wondering why this is particularly useful, to quote the manpage, one of their main use cases is “…for dealing with errors and interrupts encountered in a low-level subroutine of a program.” These functions can be used for more sophisticated error handling than simple error code return values.

I was curious how these functions worked, so I decided to take a look at musl libc’s implementation for x86. First, I’ll explain their interfaces and show an example usage program. Next, since this post isn’t aimed at the assembly wizard, I’ll cover some basics of x86 and Linux calling convention to provide some required background knowledge. Lastly, I’ll walk through the source, line by line.

Continue reading

WIP: We grow old because we stop making art

We don’t stop playing because we grow old; we grow old because we stop playing.

George Bernard Shaw

I’d like to offer a variation of this.

We don’t stop making art because we grow old; we grow old because we stop making art.

Children are naturally curious, creative, and artistic. They freely draw, sing, and ask questions. At the core is a youthful fearlessness. They’re not afraid — of being judged or looking stupid (yet).

We lose this as we grow older. We become concerned with appearances, and learn to avoid actions that might cause us to be judged or look stupid. We become afraid.

There is something deeply healthy about engaging in a creative practice, that connects us back to this youthful fearlessness. Just like how a personal fitness practice is essential for maintaining physical function despite the natural progression of entropy, a personal creative practice is essential for resisting the tendency to become fearful.

Where do you feel creative? At a piano? Taking photos? Writing words? Cooking? Working out? Playing sports? Dancing? Look more closely — that might be your fountain of youth.

To have good ideas, stop auto-rejecting your ideas

Half of having good ideas is not immediately rejecting the ideas you do have, but rather allowing yourself to respect them, give them the chance, and even consider them as worth sharing.

This is just an observation of my own shift in mental state over the last few years. I don’t consider myself particularly smart or insightful, compared to all those “wise” people with “famous quotes”.

But I’ve found that releasing myself from this automatic “self-doubt instinct” has led to a more nurturing mental space where weak, fledgling ideas have the space to potentially grow into stronger ones. And that is what eventually leads to genuinely amazing, novel ideas.

At least, I hope. We’ll see if I have one one day.

Creative pitfall: You don’t need to innovate in every area

I think a massive creative pitfall beginners make is subconsciously assuming they need to innovate in many areas, at the same time.

For example, to get started making music, a budding musician might assume she needs to:

  • 1 – Write her own lyrics
  • 2 – Write her own vocal melody
  • 3 – Write her own chord progression
  • 4 – Write her own instrumental melody
  • 5 – Write her own song arrangement

…which sounds like a tremendous amount of work! (And it is!)

But that’s not accurate assessment of the effort needed to complete the goal (make a song). It’s actually an assessment of the upper bound of the effort.

In reality, you can (and should) “steal like an artist”:

  • 1 – Use your favorite song’s lyrics
  • 2 – Use your favorite song’s vocal melody
  • 3 – Use your favorite song’s chord progression
  • 4 – Use your favorite song’s instrumental melody
  • 5 – Use your favorite song’s arrangement

(You will probably also do this subconsciously anyway, as you draw from your influences.)

Of course, these vary in terms of how acceptable they are to “ship in production” without giving credit to the original. #1 should always be done with credit, and is usually considered “Doing a cover” song. On the other hand #3 is 100% fair game to use, and release with no credit. There are only so many chord progressions actually used in popular music.

However, provided you give credit where it’s due, as you mix and match these options, you can explore the creative space of tradeoffs between originality and effort.

The lower bound is “stealing” on every dimension possible, which produces the platonic ideal of a “Cover Song”. There is nothing wrong with this, and this is how virtually every artist in the world gets started. (e.g. Justin Bieber)

At this level of your journey, the absolute most important metric to optimize (lower) is the friction & effort of doing the craft. Only once you’ve built your creative muscle stronger, can you tolerate more strenuous artistic projects that explore different parts of the effort vs originality space.

This concept applies to any other creative practice, including starting a business or learning to code. In fact, the inspiration for this idea was this Indie Hackers interview with Michael Seibel of Y Combinator, where he advises startups to select where they innovate.

It’s not enough to have good ideas

You also need to present them well.

This is one of the things I’ve learned on Twitter in my decade using it. On Twitter, the slightest change of phrasing can make or break a tweet. Part of learning the game is learning how to express information in a way that’s more likely to be received well. Usually that means being a combination of: valuable, concise, and punchy.

The general lesson is that you need to be aware of the venue, and its communication norms. What is the communication style is common, and commonly successful?

This applies not only to online platforms, but also real life communities you may be a part of, such as your work.

So if your ideas aren’t landing how you’d like them to, or you believe a great idea you have is being unfairly overlooked by others, take a moment to pause. How do the successful people in the venue communicate? And are there any ways you could restructure your presentation to better fit the venue? You might be surprised at how little it takes.

How to learn everything

Some people ask how I can do many things — code, make music, make visual art, live stream, blog, podcast, indie hack.

I don’t think it’s because I’m ultra talented or special. I do believe talent is real, that people can have natural aptitudes, and that I might have some — maybe for music or code — but definitely not for all of these areas.

I think it’s simply because after a lifetime of trying things, I’ve realized that the process of learning is basically the same for everything.

And the most important part is to have confidence that you can actually do the thing. Not counting yourself out from Day 1 is half the battle. (I see this all the time — “Oh wow, I would love to learn to paint… too bad I’m not artistic.”)

Much of what makes crafts seem difficult is the unknown of what happens behind the scenes. Before you learn to produce music, or make visual art, or code, you look at the artifacts produced by those artists and your jaw drops. You have no sense of what the creative process looks like, so it’s natural for it to seem intimidating and beyond your ability.

But then you get a chance to observe the artist, and you see that they’re simply using a bunch of Ableton Live presets, or Photoshop layer effects, or a bunch of code libraries that someone else built. And you see that it’s not so hard, after all. (Usually thanks to the efforts of skilled tool-builders, behind the scenes. Giants whose shoulders you stand on.)

This is not to say that one can realistically become expert-level skilled at everything. For example, I’ve spend hundreds of hours skateboarding, and although I love the sport & art form, that is one thing I simply do not have natural ability for. That’s fine.

It’s just to say that once you start doing different things, you stop being scared at the prospect of learning something new. You learn the ways you learn things, and also have the confidence that you can do it. Your learning muscle grows stronger every time, accelerating future learning.

You also stop being scared of being a beginner and looking bad. Because once you’ve exited the beginner stage of anything once, you now know that being a beginner is actually a noble state, and nothing to be ashamed of. Everyone was a beginner once. The only people that make fun of beginners, are those perpetually on the sidelines, that have never dared to step into the arena.

In short, over time, learning gets easier because you develop familiarity with the activity of learning. The phases of learning become like old friends that you visit and catch up with after not meeting for some time. But most importantly you build significant confidence in yourself. And that’s what matters most.

You need your own workshop

This is originally Derek Sivers’ idea, from his book “Anything you want”.

We all need a place to play.

Kids need playgrounds and sandboxes. Musicians need an instrument. Mad scientists need a laboratory.

Those of us with business ideas? We need a company.

Not for the money, but because it’s our place to experiment, create, and turn thoughts into reality. We need to pursue our intrinsic motivation.

We have so many interesting ideas and theories. We need to try them!

The happiest people are not lounging on beaches. They’re engaged in interesting work!

Following curiosity is much more fun than being idle. Even if you never have to work a day in your life.

That’s the best reason to have a company. It’s your playground, your instrument, your laboratory. It’s your place to play!

Get the ideas out of your head and into the world.

  • Gardeners need a garden.
  • Car enthusiasts need a garage.
  • Entrepreneurs need a business.
  • Artists need a studio.

But what about systems programmers?

Systems programmers need a project. A place for them to explore, work, play.

Live streaming myself working on my baby operating system has felt great over the last 14 weeks. And now with Sivers’ idea in mind, I can totally see why. It’s finally my own project where I have full control, and it’s a large enough project where there is infinite potential for the things and can do and learn within it.

No matter what your craft is, if you aspire to be great at it, you need a safe, comfortable “space” to work on your craft.

If you have aspirations, but don’t have a space, you likely haven’t fully committed, or given yourself permission to publicly identify as an enthusiast of the craft. (Actions speak louder than words).

Taking action to make that space for yourself can be scary, because it exposes physical, undeniable proof of your interest, which is vulnerable. But in my experience, it can also be deeply affirming, exciting, and motivating.

Getting into reading again by playing offense

I used to look at long non-fiction books and immediately wince, thinking of how long it would probably take me to read it, and what a slog it would probably be. Of course, this is a strange point of view that seems to forget that books can actually be captivating and fun.

But beyond that, something that helped me is changing my perspective. Rather than letting the book be in control, I now try to play more on offense.

Instead of allowing a long book to suck a potentially infinite time out of me (which means in practice, I won’t even start), I now give books a budget. If I only have 2 hours of time to give a book, oh well, that’s all it gets. I stop and move on. Hopefully the book can deliver some of its meaning in that time frame, or even better, captivate me and convince me to renegotiate my relationship with it — and give it more time.

Instead of putting the responsibility on you to slog through and make it to the end, put the responsibility on the book to earn your time.

(This does work better when you don’t pay for the book – ideally by lending it from someone else.)

I like WordPress

Among programmers, it’s very unfashionable to use WordPress for your blog. (“PHP? Yuck.”) Instead, you should be using the latest minimalist static site generator, hosted on the latest free static hosting.

(A decade ago, this was Jekyll on Github Pages — I haven’t bothered to keep up, but I did put in my time. At various points, my blog was based on Jekyll, Pelican, and Octopress).

In 2020 I decided to restart my blog, but just use WordPress.

Three years, later this has been an unambiguously good decision. I keep running into things that save me significant time, compared to me trying to code this myself, or use a static site generator.

I think the proof is in the pudding. If the goal is to actually publish writing on the internet, consistently, over a long period of time, I’ve done that (or at least am well on my way — see the Archive).

Here are some handy things I’ve found myself needing that were just there for me. I’ll add to it as I run into more.

  • Automatic redirects if you change a post slug
  • Rich plugin ecosystem for nearly everything
  • Extensive documentation, both first and third-party on how to do things. Even ChatGPT can advise.
  • Ability to customize with PHP if absolutely necessary
  • Migrating to a different permalink structure was a piece of case with the Redirects plugin
  • Built in RSS feed
  • Built in Recent post
  • Built in Top posts/pages (via Jetpack)
  • Built in downtime monitoring (via Jetpack)
  • Easy mailing list integration (MailChimp, ConvertKit, etc)
  • Built in grouping and taxonomy features (Tags, Categories)
  • Built in Monthly Archives
  • Built in comments
  • WordPress/Jetpack mobile app for easy editing/moderation on the go

Be your most authentic self (and write about whatever you want)

I love writing about computers, but I also love writing about other topics like creativity, art, and productivity. However, many programmers out there strictly blog about technical topics, which made me feel a bit weird for posting random stuff like poems or my experience with GTD.

This led me to a dilemma: Do I blog all in one place, or do do I perhaps create a separate blog for non-technical content?

My answer is to apply my “golden piece of advice”: Do what feels most authentic to you.

For me, writing about all of my interests is the most authentic expression of myself, so when in doubt, I do this. Curbing this instinct, and making a strictly technical blog just to be like “all the other programmers” wouldn’t be.

It’s totally possible that “all the other programmers” simply don’t feel a desire to write about anything else. So making a strictly technical blog is their maximally authentic expression of themselves — which is great for them! Let’s all do what feels most authentic to us.

Hiding in this case study is a profound lesson about life. The situation applies equally to any other life situation where you feel some pull to act in one way, but feel some hesitation upon observing “everyone around you” seems to act.1

When in doubt, apply the “golden advice”: Do what feels most authentic to you.

I’m very happy with this decision. It feels great to have a single place which all of my thinking, which also has the practical benefit of making it easier for potential followers to submerge themselves in all my content.

I also believe this will win in the long run as it’s more likely to resonate with like-minded people that can respect having a myriad of interests — the kind of people I’m looking to connect with!

Lastly, there’s the non-trivial but subtle benefit that simplicity of infrastructure & accounts actually matters and translated into a lot of time saved.

WIP: Fame is a hamster wheel

Different forms of capital have different benefits and drawbacks. Money has the benefit that it can grow itself over time, with the downside that it is heavily scrutinized and taxed. Fame has the benefit that it is not taxed, but has the interesting drawback in that it requires maintenance, and lessens over time.

To retain your fame, you need to continually be doing things and delivering value to your audience. Otherwise, your audience will naturally shrink as people forget about you, and their attention is diverted elsewhere by others playing the fame game.

So if you think achieving fame will make you happy, be careful. The moment you achieve the fame you’ve been seeking is not the “end” — it’s actually the beginning of a hamster wheel you’ve just stepped onto. You might stop to celebrate, but don’t stop for too long — now you need to worry about maintaining it (or even exploiting it), lest you lose it and become a “one hit wonder”. The only other alternative is to keep running.

(This post was written based on my small experiences obtaining nano-fame with my offlinemark and comfort projects).