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.