Porting libslz to Unikraft

After scouting out the dependencies of HAProxy for my third year project, I came across libslz which is one of the dependencies listed as an option in the quick-install section for HAProxy, of which a library similar replacement did not already exist. This was exciting both as libslz seemed to be a very useful tool for the use-cases HAProxy covers but also due to the small nature of the library which would provide a friendly introduction to officially porting an application to Unikraft; to get it running.

What is libslz?

You can find a link to libslz here. However, essentially the engineers state it as “a fast and memory-less stream compressor” with a specialisation in dealing with a high number of concurrent streams while limiting the consumption of system resources or throttling compression ratio. They also state its primary use case is with HTTP servers and gateways - which is exactly why as of version 1.6.0 HAProxy has begun to compress HTTP responses with SLZ.

Why libslz?

If you have used Unikraft before you may note that libslz is meant as a more performant alternative to zlib, of which Unikraft already has! Why not save time and port another HAProxy dependency? My answer to that is simply that this is intended as both an introduction to the porting workflow for Unikraft; also the uncertainty behind whether simply substituting libslz with zlib would work correctly which would cost more time trying to adapt and fix than it would to simply port the intended library. Also, the performance on bandwidth, CPU and memory using libslz compared to zlib is too good to pass up!

The Process

Makefile.uk

To begin I had to create a Makefile.uk config, this is structured like a Makefile and effectively instructs Unikraft where to grab your library from, in this case we have created a mirror via the Lancaster University GitLab which can be accessed from here (Thank you Alexander Jung!). The remainder of the Makefile.uk unzips, mentions any flags, targets, includes, and the sources to build from.

Config.uk

This was a means to have libslz come up on the Unikraft configuration menu, there is not much to be said in the porting of this library other than giving libslz a description.

Concluding Thoughts

While it took a bit of a learning curve figuring out what was expected inside the Makefile.uk and with helpful guidance from a PhD student & member of NEC Labs I believe this has certainly been a good primer for the more verbose HAProxy and any other dependencies I may come across; require to port.

Thankfully there was also not much of a need to port beyond the configuration file due to how libslz was written :)

Further Reading

Unikraft Developer Documentation

Link to my libslz port on Github