What's with sync mouting?

The other day, I really noticed something for the first time. I realized the complete and total suckiness of synchronous mounting.

As you may or may not be aware, I use autofs to access my removable media, including my USB flash drives. I also have my autofs rules set up to mount volumes synchronously, so that when the writing is done, I can just yank the drive out, secure in the knowledge that there won't be any pending writes.

Well, earlier this week, I downloaded a couple of MP3s and decided to take them to work with me. They only totaled about 20MB, so I decided to put them on my JumpDrive. Putting this much data on my JumpDrive at once is actually pretty rare for me. Since the drive is only 32MB, I usually only put small files (< 1MB) on it and transport things like MP3s on CDs.

Well, when I started copying the MP3s, I noticed that the process was going slow. Unreasonably slow. I'm talking about transfer rates of 32KB per second, with an estimated completion time of 20 minutes. Now, I don't know much about USB flash drives, but I knew this couldn't possibly be right.

Well, a little experimenting revealed that the synchronous writes were the problem. When I mount a volume asynchronously, there is no problem at all and the write finishes in less than a minute. What's the deal with that? It's one thing to have a performance penalty associated with synchronous writing, but I'm just floored by the sheer magnitude of that penalty. I mean, 32KB per second?!? I can get faster transfer rates over a network! Why are the writes so slow? There must be some rational explanation for this.

Let's try a little more swap

I'm still having intermitent problems with my Kubuntu box just dying on me. This has been going on for a while and I can't figure out what the problem is. See, every now and then, the hard drive will just start thrashing like crazy and the system will go completely unresponsive. If I leave it alone for five or ten minutes, sometimes it will come back to life. Then again, sometimes it won't and my only option is to hit the reset button.

The problem appears to be something with X. If I catch it before it goes completely non-responsive, sometimes I can hit ctrl+alt+backspace and restart X. After that, it's just fine. I appears to be some kind of memory leak, as I found some messages in the system logs once that indicated processes were being killed due to insufficient memory. It's probably a slow leak, since it usually only gives me problems after I've been logged in and working for a long time. I haven't been able to connect the lock ups to any particular application, but it most often happens when I'm using Opera or Kontact. However, that doesn't necessarily mean anything because I'm nearly always running Opera and Kontact.

Anyway, I decided to mitigate the problem by adding some more swap space to my system. I've got half a gig of RAM in my current system, but only had about 256 MB of swap space due to an old partition scheme. So I decided to take that old 200MB partition I had been using as /var under an old Slackware installation and repurpose it to swap.

I'd never actually manually configured a swap partition before, but it turned out to be surprisingly easy. I had assumed I would need to change the partition type, but according the the mkswap man page, Linux doesn't actually check the type of the partition. So, basically, all I did was run mkswap -c /dev/hda5, change the /etc/fstab entry to mark the device as a swap partition, and run swapon -a. Now I've got another 200MB of swap space. We'll see if it makes any difference. At the very least, I'm hoping it will buy me enough time to notice the problem before the system locks up.

A new interest?

This week I've been playing around a little with the Community Z Tools. They are a set of free tools for working with the Z specification language. They're still not anywhere near complete, but I guess they're better than nothing.

If you're an average programmer, you're probably not familiar with Z. It's a formal specification language based on set theory and first-order predicate calculus. Basically, that means it's a mathematical language to write program specifications. You build schemas, the Z unit of encapsulation and reuse, using the notation of predicate logic and set theory, and then compose these schemas to describe the various states and operations of the system. This has several advantages over the traditional natural-language specification, including the ability to deductively prove various properties of the specified system, such as consistency, and the simple fact that formal languages are, by their very nature, much more precise than natural ones. If you're interested in learning more, take a look at the book Using Z. I've been reading it and I think it's pretty good. It's also available for free in PDF format, which is really nice.

So anyway, I was playing with the CZT. The current incarnation is pretty much just a bunch of Java classes that provide a plug-in to jEdit. The plug-in allows you write Z specificaitons in Unicode and LaTeX (note that Z, like most mathematical notaitons, uses lots fo funy symbols, so you can't just write it in a word processor), an XML schema, and a typechecker. The main problems, aside from being incomplete, are that saving and reloading Unicode specifications doesn't seem to work correctly and that installing CZT is hideously complex. OK, that's probably an overstatement, but it's cretainly not easy, and it's made more difficult by the fact that the main download site only offers source, not binaries (which makes no sense, since it's written in Java).

As a brief aside, jEdit seems pretty nice. It's not likely to replace Vim or Kate for my purposes, but I like it so far. My only real complaint is that Swing's GTK+ look doesn't seem to work the GTK/Qt theme engine.

Getting back to the point, since I had problems with editing specifications in Unicode, I decided to give LaTeX a try. I knew nothing about LaTeX other than it's related to TeX which is used for typesetting, so I went to the web site and ended up downloading The (Not So) Short Introduction to LaTeX2e.

I haven't gotten very far into it yet, but I have to say that LaTeX looks extremely cool. It's a "document preparation system" that, frankly, looks kind of like a programming language. It's generally written by editing text files, so it's not a WYSIWYG system. With LaTeX, you focus on the logical structure of the material rather than the details of how it looks on the screen. That immediately struck me as the right thing to do. I've seen too many Word documents that were an incoherent soup of seemingly random formatting that looked decent on paper, but was a huge pain to try to edit later. I'm actually kind of anxious to try LaTeX out.