The First Week is Always the Worst…

…or so I’ve been told. Well, if after the absolute bliss of the past week and a half, if it can only go up from here, I can’t wait to see how awesome this internship will get!

Don’t get me wrong; it’s been challenging, for sure. I’ve pushed myself, panicked, made some humiliating mistakes, hit the wall, and given up at the end of the day with a brain that felt like it was soaked in blackstrap molasses. I wouldn’t have it any other way. The bigger the challenge, the bigger the payoff, both in terms of self esteem and the utterly fascinating things I’m learning.

I couldn’t enumerate them, because there are so many, and because I’m not totally clear on them myself yet.

I’ve learned how the kernel keeps sets of data objects (such as struct pages, which represent pages of virtual memory) on a string like beads by running a struct list_head through them.

struct page {
        /* First double word block */
        unsigned long flags;
       struct list_head lru; 

I’ve learned how it uses this method to sort pages into four Least Recently Used lists: active and inactive file pages (which don’t need to go to swap space, because they’re backed by the original file on disk), and active and inactive anonymous pages (which have no file or device backing them). It uses these lists to choose which pages will be banished to swap when the time comes.

I’ve learned how the kernel finds a previously banished page in swap space and reads it back in. The location in swap space is stored in an unsigned long, so that it can fit into a page table entry. Some bits specify which swap area the page is in (there can be up to 32), and some specify the offset from the start of the swap area where the page is to be found. There are macros to sort it all out.

I’ve learned what a system call looks like within the kernel code. It’s just a function with its header replaced by a macro, like this: SYSCALL_DEFINE1(swapoff, const char __user *, specialfile).

I’ll stop there.

In the coming week, I hope to fit all these and more together into a clear working map of the Linux memory manager. I already have a partial map, but it’s just a start. I also hope to deepen my concentration and focus, and maintain them for longer periods of time. If it’s half as good as my first week, it will still be awesome.


One response »

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s