LJ Archive

UpFront

diff -u: What's New in Kernel Development

Zack Brown

Issue #258, October 2015

Over time, memory can become more and more fragmented on a system, making it difficult to find contiguous blocks of RAM to satisfy ongoing allocation requests. At certain times the running system may compact regions of memory together to free up larger blocks, but Vlastimil Babka recently pointed out that this wasn't done regularly enough to avoid latency problems for code that made larger memory requests.

Vlastimil wanted to create a new per-CPU dæmon, called kcompactd, that would do memory compaction as an ongoing system activity.

The basic objection, voiced by David Rientjes, was that creating a whole new thread on all CPUs carried its own overhead issues. He suggested having one of the other per-CPU threads simply take on the additional memory compaction responsibilities. He identified the khugepaged dæmon as the best candidate.

Vlastimil actually had identified khugepaged as a candidate and rejected it, on the grounds that khugepage dealt only with THP (Transparent HugePages) memory use cases. These are an abstraction layer above regular memory allocation, so it wouldn't cover all possible cases, only user code that dealt with THPs.

David argued that THP allocations were where most compaction problems occurred, and that other allocation systems, like the SLUB allocator (used for highly efficient kernel allocations), were not part of the problem.

Eventually, it came out that David actually envisioned two forms of memory compaction. The first would be a periodic compaction effort that would happen regardless of the state of RAM. The second would be a compaction effort that would be triggered when particular regions of RAM were detected as being overly fragmented. By splitting these two forms of memory compaction from each other, David felt it would be possible to piggy-back various pieces of functionality onto different existing threads and avoid having to create a new per-CPU thread in the kernel.

A final design did not get hashed out during the discussion, but no one seemed to be saying that memory compaction itself was a bad goal. The question always was how to implement it. Mel Gorman even suggested that a fair bit of the work could be done from user space, via the SysFS interface. But, that idea wasn't explored during the discussion, so it seems that only technical obstacles could get in the way of some background memory compaction going into the kernel.

One problem with enabling the CONFIG_TRACING option in the kernel, as Tal Shorer recently pointed out, is that it would enable absolutely every tracepoint, causing a significant performance penalty. It made more sense, he felt, to allow users to enable tracepoints on just the subsystems they were interested in testing.

He posted a patch to do this. Or rather, he posted a patch to ditch the old system and allow users to enable tracepoints on only the GPIO subsystem. He picked GPIO, he said, as a test case. If it met with approval, he offered to submit patches for all the rest of the subsystems.

Because of the overall kernel development cycle, it took a couple weeks for his patches to make the rounds. The new merge window had opened, so folks like Steven Rostedt, who ordinarily would be the one looking over Tal's submission, were too busy for any new code, until after the merge window had closed again.

Once that was ironed out though, he seemed to have mostly positive feedback for Tal. It looks as though tracepoints soon will be per subsystem, rather than kernel-wide.

In order to allow non-root users to write good system monitoring software, Prarit Bhargava wanted to expose the MSR values to non-root users, on a read-only basis. MSR registers are an Intel-specific set of registers that Intel originally intended for its own debugging purposes and made no guarantees that future chipsets would provide the same values. But over time, those registers seem to have coalesced around debugging and monitoring features, and the Linux kernel does expose them to the root user.

Prarit felt that allowing read-only access would avoid any potential security issues, because users would be unable to mess around with the actual values of those registers. But as other folks pointed out, the dangers of the MSR registers also existed in the kernel objects and regions of memory they exposed. Even read-only access could be sufficient for a hostile user to gain enough information to attack a running system successfully.

So, working with Andy Lutomirski and Pavel Machek, Prarit wrote a PMU (Performance Monitoring Unit) driver that would expose only a specifically whitelisted set of MSR data to users. This way, they could write their system monitoring software without risking a new attack, and if Intel changed the MSR registers in future chips, the changes would need to be vetted and the whitelist would need to be updated before any of that altered data would be exposed to regular users.

As an example of the importance of this particular issue, Len Brown mentioned during the discussion that Lawrence Livermore National Laboratory was keenly interested in the design and outcome of Prarit's efforts. The folks there wanted a secure and efficient way to access those MSR registers, and this work would provide it.

Android Candy: Who Ya Gonna Call? Anyone!

Shawn Powers

Issue #258, October 2015

I have a love/hate relationship with the contact manager on my phone. I absolutely love having all of that information available, and I love even more that it syncs with my Google contacts. What I don't love, however, is the cumbersome way you have to scroll around looking for who you want to call. Yes, I normally just look at my recent calls to find who I want, but it seems like there should be a better way to look at my contacts.

Enter Drupe. It feels a bit like a mix between a game and a standardized test's matching exercise. That might sound like an odd comparison, but Drupe makes it easy not only just to call, but also to communicate with contacts with a simple drag. Want to call Mom? Drag her face to the phone icon. Want to text your significant other? Drag his or her face to the SMS icon. (Okay, maybe “drag her face” sounds a bit violent.)

(Screenshot from getdrupe.com)

If you like a graphical, easy way to start communicating with your contacts, I urge you to give Drupe a try. It's completely free, supports a huge number of protocols, and it even offers free themes so you can change the way it looks.

Non-Linux FOSS: Code Your Way To Victory!

Shawn Powers

Issue #258, October 2015

One of my favorite things about grade school was when the teacher would review for a test by playing Jeopardy. I'm pretty old, so my version of classroom Jeopardy was done on a chalkboard with the teacher reading answers from index cards, but the new computer-based versions I see in schools are at least as cool. There's just something about learning while playing games that is awesome.

Learning to write code is a chore that often is considered boring. Heck, the only way I'm able to slog through the process is to have a project in mind. I need to be solving a problem in order to find the motivation to write the code, and learning the “tools” really becomes part of the enjoyment. Thankfully, I'm not alone in my desire to tie learning into fun. The folks over at CodeCombat have created a gaming system that uses proper coding techniques to help your hero solve a quest.

The “game” actually feels like a cross between The Incredible Machine (or Crayon Physics if you're too old to remember TIM), and the old LOGOS turtle we guided around the screen in the 1980s and 1990s. Some of the gaming elements seem like a stretch (magic boots give you the ability to write code that moves your character), but the goofiness adds to the fun a bit. Plus, the graphics are really well done, and the background music rocks.

CodeCombat is free to use, and it includes 100 or so coding exercises. If you're really into the game and want to improve your coding skills further, there is a $9.99/month subscription that opens up video tutorials, more levels and so on. There's even a price break if you buy multiple subscriptions for those little coders in your life.

Even though the game itself isn't FOSS, and actually runs in a Web browser instead of a particular platform, I put Code Combat in our Non-Linux FOSS spot this month because it teaches code. Teaching people to write code is the first step in creating a FOSS world, and for that reason, I also award Code Combat this month's Editors' Choice Award. Check it out today, and see if it's a good fit for you or other potential coders in your life: https://codecombat.com.

Science on Android

Joey Bernard

Issue #258, October 2015

I have covered a lot of different scientific packages that are available under Linux in this space, but the focus has been on Linux running on desktop machines. This has been rather short-sighted, however, as lots of other platforms have Linux available and shouldn't be neglected. So in this article, I start looking at the type of science you can do on the Android platform. For my next several articles, I plan to include occasional Android applications that you may find useful.

The first application I want to explore is Maxima for Android (https://sites.google.com/site/maximaonandroid). Maxima has been under development since the 1960s at MIT, and it continues to this day under an open-source license. It is a full computer algebra system, written in Common Lisp. Luckily, Embeddable Common Lisp has been ported to Android, so this provides the Lisp engine needed to run the Maxima engine.

Installing Maxima on your Android device is a two-step process. The first step is to install the base application from the Google Play store. Once it is installed and you run it for the first time, the application will unpack the bulk of the application. Because this section is so large, the app will ask you where to unpack it, so you can put it on some other media if you don't have a lot of room in internal storage.

When you initially start Maxima, you get a display of the licensing information and the version number, and then you are presented with an input prompt labeled as “(%i1)”. Depending on the device you are using and the age of your eyes, you may have a hard time seeing the output displayed on the screen. If so, you can zoom in and out with a two-finger pinch or zoom, just like in other Android applications. Your other option is actually to change the font size. You can use the command textSize:XX, where XX is the size you want to use for the font in pixels. The suggested range is 10–50 pixels.

Figure 1. When you start Maxima, you get the standard license and version information.

At the bottom of the screen, you will find a text entry box outlined in orange. This is where you enter the Maxima commands you want to run. Once you have entered your command and press Enter, it is displayed in the main window, along with the results. The MathJax library handles the pretty-print display of this mathematical information. The history mechanism used in order to re-use previous commands is very intuitive. When you tap a previous command, it is copied and pasted into the text input command box, ready for you to make any necessary edits before executing it again.

The Android version of Maxima includes a full set of documentation that is available by tapping on the menu icon and selecting the “Manual” option. A lot of examples are available in each section of the manual that you may want to try. Assuming that this would be a common thing people would want to do, you simply can tap the example you want to work with, which will copy the example into the command text input box. This way you can find an example that is close to what you want to try to do and easily copy it into the command box. You then can edit it and make any required changes before running it. This really can speed up any research work you are trying to do with Maxima.

There is also a function named example(). If you call example without any parameters, it will generate a list of all of the subjects that have examples provided. You then can look at the examples for a specific subject by calling example with the named subject. For instance, you can learn about arrays with the command example(arrays). This will pull up and run a series of examples on how to use arrays within Maxima.

The other useful function for speeding up research is the ability to load files of Maxima commands. Maxima for Android automatically looks in the main Download directory when you try to load files. Also, files with the “.txt” filename ending are found and loaded without having to include the file ending. This means if you have a file named “my_script.txt” in the Download directory, you can load it with the command load(my_script). If you use Dropbox and synchronize the Download directory, you easily can move files back and forth between your Android device and your desktop.

One major area that is not completely implemented yet is the graphical system for plots and graphs. However, new features are being added with each new version. The graphical functions actually are provided by gnuplot. The functions currently implemented are plot2d, plot3d, implicit_plot, contour_plot, draw, draw2d and draw3d. These commands pop open a new window to display the results of the plot command.

Because everything is full screen on Android, you need to tap on the back icon to get back to the main Maxima window. If you want to see the plot again, you can tap on the menu and select the “Graph” option. This will re-open the last plotting window.

Another major issue is the lapack library. Trying to load it will cause an error, so you won't have access to the optimized linear algebra functions provided through lapack.

When you are doing complicated research, you may need to stop part way through the process and pick it up again at a later time. This is handled by the concept of a session. Tapping the menu icon, you can select the “Session” option. This will pop open a sub-menu where you can choose either to “Save”, “Restore” or “Playback” your session. You have just one saved session state at a time, however, so it is really useful only when you need to stop in the middle of a workflow.

If you are working on a larger project where you are using the same libraries for an extended period of time, you can set initialization code that gets run whenever Maxima starts. This code needs to be stored in the file /data/local/tmp/maxima-init.mac. Any arbitrary Maxima code can be placed here, so you can initialize a pretty complicated environment if you like.

Now you can carry Maxima around in your pocket, ready to work out all of those troublesome problems that come up in everyday life. So, you won't have any excuse for not solving the equations you need in order to plot out your space travel, all on the train ride to work. Just promise to be good, and don't try to use it on your next physics exam.

Protection, Privacy and Playoffs

Shawn Powers

Issue #258, October 2015

I'm not generally a privacy nut when it comes to my digital life. That's not really a good thing, as I think privacy is important, but it often can be very inconvenient. For example, if you strolled into my home office, you'd find I don't password-protect my screensaver. Again, it's not because I want to invite snoops, but rather it's just a pain to type in my password every time I come back from going to get a cup of tea. (Note: when I worked in a traditional office environment, I did lock my screen. I'm sure working from a home office is why I'm comfortable with lax security.)

Somewhere I don't like to slack off on security is when I'm out and about, especially on someone else's network. Make that a public Wi-Fi network, and my paranoia level skyrockets. I always have a VPN set up at home so I can connect remotely, but sometimes my home bandwidth is just too slow for comfortable remote use. Recently I paid $39.95 for a year subscription to www.privateinternetaccess.com, and I couldn't be any happier with my decision.

PIA offers PPTP, OpenVPN, L2TP/IPSec and the ability to connect up to five devices at the same time. That means I can protect my network (I don't really trust Charter) and connect my laptop while on the road. PIA offers unlimited bandwidth, it doesn't log traffic, and even the account purchasing is anonymous. You can buy your subscription with a Starbucks gift card if you want!

One of my favorite features, however, is that with the option of multiple VPN gateway locations, you can mask your traffic to get around blackout restrictions. For me, that means I can watch Tigers baseball games normally unavailable to me in the MLB app by routing my traffic through the West coast. The $40 price tag seemed pretty steep at first, but with the amount of use I've gotten out of PIA, I'll be signing up again next year without question. You get a seven-day money-back guarantee, so there's no reason not to try it. Visit www.privateinternetaccess.com for more details!

They Said It

It's a funny thing about life; if you refuse to accept anything but the best, you very often get it.

—W. Somerset Maugham

Self-development is a higher duty than self-sacrifice.

—Elizabeth Cady Stanton

Mistakes are part of the dues one pays for a full life.

—Sophia Loren

A moment's insight is sometimes worth a lifetime's experience.

—Oliver Wendell Holmes Jr.

Cheese—milk's leap toward immortality.

—Clifton Fadiman

Roll Your Own Enterprise Wi-Fi

Shawn Powers

Issue #258, October 2015

As you can tell by my Wi-Fi focus in The Open-Source Classroom this month, I really love wireless networking. I've implemented wireless solutions for schools on a shoestring budget, and I've helped plan campus-wide rollouts of redundantly controlled enterprise solutions. The one thing I really like about the enterprise solutions is the single point of management. The problem is those controllers and enterprise-capable access points are so darn expensive! That's why I love Ubiquiti.

The UniFi line of products from Ubiquiti is affordable and reliable, but the really awesome feature is its (free!) Web-based controller app. The only UniFi products I have are wireless access points, even though the company also has added switches, gateways and even VoIP products to the mix. Even with my limited selection of products, however, the Web controller makes designing and maintaining a wireless network not just easy, but fun!

The Web controller runs happily on a little Atom Web server, and if it happens to go off-line, the access points keep working independently. If you'd like robust hardware with a powerful Web controller application, but you're not ready to invest the thousands of dollars for a traditional enterprise solution, check out the UniFi product line (https://www.ubnt.com). If you're half as nerdy as I am, you won't regret the decision!

LJ Archive