Featured post

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

Introduction

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

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

What’s with the name?

I chose “offlinemark” as a handle for a few reasons:

  • I didn’t want to use my real full name as the handle because of privacy and because I don’t consider my last name a 100% stable API. Ideally this username would last a long time.
  • I like adjectives as usernames, but also including my first name makes it feel a bit personal.
  • It’s highly unique. There’s a strong chance I can always get this username.
  • Aesthetics. I dislike numbers in usernames. I like the visual appearance of the text (all on one line, no underhanging characters).
  • It’s an aspirational reminder. A lot of the best things in life are offline.
  • It appeals to my ironic and quirky sense of humor.

How to enable colored compiler output with CMake + VSCode

Assuming you’re using the “CMake Tools” VSCode extension, here’s what works for me.

What works for me:

1 – Set CMAKE_COLOR_DIAGNOSTICS to ON in your environment

This makes CMake pass -fcolor-diagnostics to clang. If you build on the command line, you’ll now have color. But the VSCode “output” pane will still be non-colored.

2 – Install the “Output Colorizer” extension from IBM.

This adds color to the Output pane.

It looks like this:

Links:

https://github.com/ninja-build/ninja/issues/174

https://github.com/microsoft/vscode-cmake-tools/issues/478

Should everyone be a leader?

I’ve been thinking about leadership lately.

Many children’s programs are designed to foster leadership skills. Why? Does this imply that everyone should have leadership skills? That everyone should be a leader?

This interests me because for the longest time, I never felt like a “Leader”. I didn’t have anything in common with “Leaders” I saw. It didn’t resonate.

But I’ve realized the answer is yes. Everyone should learn leadership skills.

Even if you have no aspirations to start a company or lead a nation, leadership is everywhere.

It’s obviously present on smaller scales — in local organizations, communities, and workplaces. And even if you don’t aspire to be at the top, in any non-trivial organization, it’s still leadership all the way down. Even if you explicitly reject managing people, you can still find yourself as a leader — for example, being a skilled individual specialist carries leadership in its own way.

But less obviously, as soon as you start any kind of project or endeavor of any kind — guess what, you’re now a leader. Any kind of pursuit creates an opening for a leader. By default, the creator fills the role.

Examples of endeavors:

  • Starting a family
  • Co-creating a relationship
  • Organizing a party
  • Planning a trip
  • A creative practice

Without leadership, you can only ever be a “leaf” node, at the end of the chain. Without leadership, you can only ever be a consumer, a viewer, an audience member.

Even if you never start any endeavor, at the very least, you are the leader of your own life. (Which, by the way, is a creative project.)

So, yes, everyone should have leadership skills — not because everyone “should” be a leader, but because everyone already is.

Why I enjoy hanging out with entrepreneurs

I’ve been a regular attendee at the Indie Hackers Berlin meetup lately. I’m not particularly an entrepreneur myself, but I love hanging out with them because they generally have many of the following qualities:

  • High functioning
  • Smart/Clever (to be successfull, you kind of have to be)
  • Ambitious
  • Creative
  • Unconventional thinkers
  • Into self development
  • Leadership

All of which make them very fun and interesting to be around!

Why I write in public

Note to self. I write because:

  • Improved clarity of thought
  • Archive of thought
  • Improves writing skills

In addition, I write in public because:

  • It reinforces a mindset of speaking my mind in public (i.e. courage)
  • Receive valuable feedback and external perspectives
  • Build relationships

Furthermore, I’ve found that it’s addicting to write in public.

  • It feels good to look back on writing and realize you’ve expressed yourself clear and well. And that you understand the topic well know.
  • It feels good to develop a voice.
  • It feels good to watch yourself improve. You can write better, faster with practice.
  • You become more self-observant of your thoughts, and realize that there are so many interesting things to write about.
  • It feels good to get positive feedback on your writing.

Can we have non-atomic std::shared_ptr in C++?

Turns out, we do have them. libstdc++ contains a heuristic kludge where it checks if libpthread is linked into the process and conditionally executes an atomic add or non-atomic add depending on the result. Post 2020, it doesn’t directly use the libpthread hack, but uses glibc’s native support for this.

These kinds of things always make me sad about C++ (especially compared to how nice and clean things seem to be in Rust world), but at least it’s nice knowing that the committee did consider it and there are good reasons why to not have this in the C++ stdlib. The most compelling reason is that in the absence of a borrow checker, it is all too easy to silently use a non-atomic shared_ptr in multithreaded code.

Full thread:

Location Capital

Traditional forms of capital include money, relationships, and health. There’s another I’ve discovered but never heard mentioned before: location capital.

Location capital is how much experience you have with a physical place on Earth. For example, if you have a lot of New York City capital, you’re the one that knows all the cool restaurants and bars in NYC. Friends ask for recommendations for the perfect spot for their birthday.

Everyone has location capital of some kind. But no one can have all the location capital for every place, so everyone (even Jeff Bezos) needs to decide what places are most important for them to build capital in.

It’s useful to be aware of location capital because it can affect your decisions around where you spend time.

Let’s say you’re alone and deciding whether to eat out at a restaurant you’ve never been to. What’s the cost/benefit? In exchange for money, you get good food and save time & labor (from not cooking/cleaning/grocery shopping).

But that’s not all — because you’re going to a new restaurant, you also build location capital. This is a one-time “boost” you get from going to a new place. On further visits you’ll still get some, but less.

Your decision will ultimately depend on how much you value food, time, labor, money, and location capital.

Location capital can also act as a hedge against risk. If you’re planning a date, preferring a new place will help make sure your time isn’t totally wasted if the date goes poorly.

I wish I was aware of location capital sooner. I used to prefer staying in over eating out in order to save money. But now I realize those decisions came with opportunity cost. And as a result, I’ve built less capital for the cities I’ve previously “lived” in than I’d like.

In general, I think it’s a good policy to always be building capital (mostly the non-monetary kinds). Location capital is an interesting form of it and being aware of it can influence how you live your life.