CMA po polsku

Posted by Michał ‘mina86’ Nazarewicz on 22nd of January 2013

Będę miał dzisiaj przyjemność prezentować Contiguous Memory Allocator na seminarium dyplomowym (CMA jest bowiem tematem mojej pracy). Dostępny jest również referat opisujący z większą ilością detali zawartość slajdów. Aktualizacja: Z racji, że jestem już po obronie, dodaję również link do pracy inżynierskiej.

Prezentacja nie opisuje sposobu użycia CMA zatem po więcej szczegółów odsyłam do materiałów z LCE 2012. No i oczywiście jest również strona mina86.com/cma/, z której linkuję do przeróżnych materiałów dotyczących CMA.

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 big 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 big 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 big corporation 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 ;) ).

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++.

Python, wrażenia

Posted by Michał ‘mina86’ Nazarewicz on 31st of January 2010

Niedawno miałem okazję stworzyć trochę kodu w Pythonie. Popisałem sobie w nim kilka dni i muszę przyznać… język jest tragiczny, zastanowię się kilka razy zanim po raz kolejny go użyję.

Wpis ten dedykuję pewnej osobie, która ciągle mi przypomina, abym pisał nowe wpisy. :)

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 just 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 and then to turn it off), is in such a lucrative position on the keyboard? And how about Ctrl? Compared to Caps Lock it seems like miles away. 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.