CMA on LCE/ELCE 2012

Posted by Michał ‘mina86’ Nazarewicz on 7th of November 2012

LinuxCon / Embedded Linux Conference Europe 2012 is nearly over, and I had a pleasure of talking about the Contiguous Memory Allocator. The slides from the talk are embedded below, are available for download from Google Drive, and their source code can be accessed at GitHub.

Unfortunately, in contrast to other LCE/ELCE conferences, talks were not recorded, so the video of the presentation is not available.

For more links regarding CMA, I have set up a resource page at mina86.com/cma/. Beside the link to the final CMA patchset and to the LCE/ELCE presentation, it links to various articles and patches relating to CMA directly or indirectly.

LazyProxy in Python

Posted by Michał ‘mina86’ Nazarewicz on 8th of July 2012

Paths of destiny lead mysterious ways. Not so long ago, I was a hard-core C hacker and now, I spend a lot of the time coding in Python.

In somehow related news, I have discovered that my search-foo is not good enough, when I was unable to find a decent implementations of several design patterns in Python.

What I needed was a generic proxy that would defer initialisation of an object to the moment it is first used. Here is what I came up with:

class LazyProxy(object):
    __slots__ = '__get'

    def __init__(self, cls, *args, **kw):
        object.__setattr__(self, '_LazyProxy__get',
                           lambda: self.__set(cls(*args, **kw)))

    def __set(self, obj):
        object.__setattr__(self, '_LazyProxy__get', lambda: obj)
        return obj

    def __getattr__(self, name):
        return getattr(self.__get(), name)

    def __setattr__(self, name, value):
        return setattr(self.__get(), name, value)

    def __delattr__(self, name):
        return delattr(self.__get(), name)

Deep Dive into Contiguous Memory Allocator

Posted by Michał ‘mina86’ Nazarewicz on 10th of June 2012

This is an extended version of an LWN article on CMA. It contains more detail on how to use CMA and a lot of boring code samples.

Contiguous Memory Allocator (or CMA) has been developed to allow large physically contiguous memory allocations. By initialising early at boot time and with some fairly intrusive changes to Linux memory management, it is able to allocate large memory chunks without a need to grab memory for exclusive use.

Simple in principle, it grew to be a quite complicated system which requires cooperation between boot-time allocator, buddy system, DMA subsystem, and some architecture-specific code. Still, all that complexity is usually hidden away and normal users won’t be exposed to it. Depending on perspective, CMA appears slightly different and there are different things to be done and look for.

Null: The never-ending story

Posted by Michał ‘mina86’ Nazarewicz on 27th of March 2011

I have already mentioned some problems with the null pointer but my recent discovery knocked my socks off.

By now, it should come with no surprise to anyone that 0 in pointer context acts as a null pointer (no matter of its actual representation). Moreover, it takes only a tiny bit of experimenting to figure out that expressions like (int)0 do as well. The latter is in itself a bit of a pita but it is conforming to the C++ standard which says:

Prime numbers less than 100

Posted by Michał ‘mina86’ Nazarewicz on 12th of December 2010

Anyone working in a major company must have been hit by some ‘funny’ mail from a coworker that helps everyone gets through the day. No different at my office — at one point all engineers have been challenged to write the shortest code in C that prints all prime numbers (and only prime numbers) less than a hundred each on separate line.

This is an interesting brain-teaser so posting it here so others may choose to think about it while their code’s compiling.

Of course, a ‘C program’ needs not to be taken too seriously — depending on not too far fetched undefined behaviours of given implementation is all right (but please do not use system or exec family of calls; not that I can see how that would help).

By the way, if you’re interested in how this challenge looks solved in Rust, I’ve described that as well.

0 is ambiguous

Posted by Michał ‘mina86’ Nazarewicz on 24th of October 2010

It has been a long time since my last entry, so inspired by Adriaan de Groot’s entry, I decided to write something about 0, NULL and upcoming nullptr.

I will try to be informative and explain what the whole buzz is about and then give my opinion about nullptr. Let us first inspect how a null pointer can be donated in C and C++.

Synchronizacja w jądrze Linux

Posted by Michał ‘mina86’ Nazarewicz on 3rd of April 2010

Prezentacja z seminarium dyplomowego na temat mechanizmów synchronizacji w jądrze Linux. Pokrótce przedstawia bariery pamięci, zmienne atomowe, semafory, spinlocki itp.

Dni Wolnego Oprogramowania

Posted by Michał ‘mina86’ Nazarewicz on 25th of February 2010

UPDATE: Dni ciągle jeszcze trwają, acz moja prelekcja już się odbyła, w związku z czym umieszczam nowszą, a tym samym poprawioną wersję prezentacji wraz z pełnymi kodami źródłowymi.

Niektóry wiedzą, inni właśnie się dowiedzą, iż w przyszły piątek (5 marca) ruszają III Dni Wolnego Oprogramowania w Bielsku-Białej. Będę miał przyjemność nie tylko bycia na tej imprezie, ale również aktywnego uczestnictwa. Dla wszelkich osób zainteresowanych udostępniam wersję alfa prezentacji, którą będę przedstawiał. Po zakończeniu wystawię wersję finalną wraz ze wszystkimi kodami źródłowymi.

NTP over HTTP

Posted by Michał ‘mina86’ Nazarewicz on 16th of January 2010

Sitting in a dark office, after swearing for hours at ATI video cards I noticed time on my computer was incorrect. ‘No problem,’ I thought as I started typing ntpdate. That’s where it struck me that our beloved IT department had blocked most of the Internet. Checking the time on a watch or a mobile phone was not an option — I had neither — nor was looking at GKrellM on another PC — that’s lame.

‘I wish there was a NTP-over-HTTP protocol’ I sighed. And then I realised there was…

Total Control Exchange (No Caps Lock)

Posted by Michał ‘mina86’ Nazarewicz on 11th of October 2009

Have you ever wondered why Caps Lock, a key you press twice a decade (once to turn it on by accident and then to turn it off), is in such a lucrative position on the keyboard? And what about Ctrl? It’s miles away compared to Caps Lock. If you think about it old Unix keyboards with those keys swapped seem to got it right.

I’ve gone one step further and recommend turning Caps Lock into Ctrl key altogether. In this article I will describe how to do that in various systems and platforms. But lets start with some propaganda.