disk space allocation (part 3: storing extents on disk)

Here I’m going to talk about how file systems store what part of the disk a part of the file occupies. If your database files are very fragmented, performance will suffer. How much depends on a number of things however.

XFS can store some extents directly in the inode (see xfs_dinode.h). If I’m reading things correctly, this can be 2 extents per fork (data fork and attribute fork). If more than this number of extents are needed, a btree is used instead.

HFS/HFS+ can store up to 8 extents directly in the catalog file entry (see Apple TechNote 1150 – which was updated in March 2004 with information on the journal format). If the file has more than 8 extents, a lookup then needs to be done into the extents overflow file. Interestingly enough, in MacOS X 10.4 and above (i think it was 10.4… may have been 10.3 as well) if a file is less than 20MB and has more than 8 extents, on an open, the OS will automatically try to defragment that file. Arguably you should just fix your allocation strategy, but hey – maybe this does actually help.

File systems such as ext2, ext3 and reiserfs just store a list of block numbers. In the case of ext2 and ext3, the futher into a file you are, the more steps are required to find the disk block number associated with that block in the file.

So what does an extent actually look like? Well, for XFS, the following excerpt from xfs_bmap_btree.h is interesting:

#define ISUNWRITTEN(x) ((x)->br_state == XFS_EXT_UNWRITTEN)

typedef struct xfs_bmbt_irec
{
xfs_fileoff_t br_startoff; /* starting file offset */
xfs_fsblock_t br_startblock; /* starting block number */
xfs_filblks_t br_blockcount; /* number of blocks */
xfs_exntst_t br_state; /* extent state */
} xfs_bmbt_irec_t;

It’s also rather self explanetry. Holes (for sparse files) in XFS don’t have extents, and an extent doesn’t have to have been written to disk. This allows you to preallocate space in chunks without having written anything to it. Reading from an unwritten extent gets you zeros (otherwise it would be a security hole!).

Sweden!

I’m in the Stockholm office at the moment. on the network, grabbing mail and all that foo.

Spent yesterday in London with Leandra, finally having arrived after the plane was delayed for four hours in Melbourne. Urgh.

There’s snow! it’s cool.

will have to check how photos look at some point.

and oh, good to be back in europe – good jam.

disk space allocation (part 2: examining your database files)

memberdb/log.MYD:
 EXT: FILE-OFFSET      BLOCK-RANGE      AG AG-OFFSET        TOTAL
   0: [0..943]:        5898248..5899191  3 (36536..37479)     944
   1: [944..1023]:     6071640..6071719  3 (209928..210007)    80
   2: [1024..1127]:    6093664..6093767  3 (231952..232055)   104
   3: [1128..1279]:    6074800..6074951  3 (213088..213239)   152
   4: [1280..1407]:    6074672..6074799  3 (212960..213087)   128
   5: [1408..1423]:    6074264..6074279  3 (212552..212567)    16
memberdb/log.MYI:
 EXT: FILE-OFFSET      BLOCK-RANGE        AG AG-OFFSET        TOTAL
   0: [0..7]:          10165832..10165839  5 (396312..396319)     8

The interesting thing about this is that the log table grows very slowly. This table stores a bunch of debugging output for my memberdb applicaiton. It should possibly be a partitioned ARCHIVE table (and probably will in the future).

The thing about a file growing slowly over time is that it’s more likely to have more than 1 extent (I’ll examine why in the near future).

My InnoDB data and log files only have 1 extent.. I think I’ve done a xfs_fsr on my file system though.

disk space allocation (part 1: seeing what’s happenned)

(a little while ago I was writing a really long entry on everything possible. I realised that this would be a long read for people and that less people would look at it, so I’ve split it up).

This sprung out of doing work on the NDB disk data tree. Anything where efficient use of the filesystem is concerned tickles my fancy, so I went to have a look at what was going on.

Filesystems store what part of the disk belongs to what file in one of two ways. The first is to keep a list of every disk block (typically 4kb) that’s being used by the file. A 400kb file will have 100 block numbers. The second way is to store a range (extent). That is, a 400kb file could use 100 blocks starting at disk block number 1000.

XFS has a tool called xfs_bmap. It gives you a list of the extents allocated to a file.

So, let’s have a look at what it tells us about some recordings on my MythTV box.

myth@orpheus:~$ ls -lah myth-recordings/10_20050912183000_20050912190000.nuv
 -rw-r--r--  1 myth myth 452M 2005-09-12 19:00 myth-recordings/10_20050912183000_20050912190000.nuv
myth@orpheus:~$ xfs_bmap -v myth-recordings/10_20050912183000_20050912190000.nuv
myth-recordings/10_20050912183000_20050912190000.nuv:
 EXT: FILE-OFFSET       BLOCK-RANGE          AG AG-OFFSET             TOTAL
   0: [0..639]:         228712176..228712815  7 (21106232..21106871)    640
   1: [640..1663]:      83674040..83675063    2 (24358056..24359079)   1024
   2: [1664..923519]:   83675368..84597223    2 (24359384..25281239) 921856
   3: [923520..924031]: 84631272..84631783    2 (25315288..25315799)    512

Just to make things fun, this is all in 512byte blocks. But anyway, the real interesting thing is the number of extents. Ideally, every file would have one extent as this means that we avoid disk seeks – *the* most expensive disk operation.

XFS also provides the xfs_fsr tool (File System Repacker) that can defragment files (even on a mounted file system). On IRIX this used to run out of cron – fun when a bunch of machines hit a CXFS volume all at the same time.

Pineapple

Today, for breakfast – my brother cut up possibly the most delicious pineapple ever. Sweet, juicy and nearly gone by now.

Oh how I love summer fruits.

Art of Software

1.5 is definitely better then 1.2, for instance it works.

Brian “Krow” Aker’s Idle Thoughts – Asterisk@Home 1.5

A comparison can be made between MemberDB 0.3 and 0.4. 0.4 will actually work (err, install without intimate knowledge)

Foot High In Tray

When the In tray gets to be over a foot high, you know it’s time to actually go through it.

It’s small again now – less than an hour (while doing other things).

I should really move to interrupt mode instead of batch mode.

Although most of the things that go into my in tray really only need filing, i’ve already taken the action.

Meet the IT Gigolo

Meet the IT Gigolo

I don’t really know what to say to go along with this one. Possibly some childish sniggering.

Corpse Bride

Saw Corpse Bride last night (IMDB). Was rather good and cleverly done. Will be interesting to see what Margaret and David give it.

=?ISO-8859-1?Q?FlamingMob._An_attempt_at_mobloging.?=

—-_MULTIPART_BOUNDARY_00005C81000072CC
Content-Type: TEXT/PLAIN;
charset=”UTF-8″
Content-Transfer-Encoding: BASE64

SSB3b25kZXIgaWYgdGhpcyB3aWxsIHNob3cgdXA6KQ==
—-_MULTIPART_BOUNDARY_00005C81000072CC
Content-Type: IMAGE/JPEG;
charset=”US-ASCII”;
name=”Picture(1).jpg”
Content-Disposition: attachment;
filename=”Picture(1).jpg”
Content-Transfer-Encoding: BASE64

/9j/4AAQSkZJRgABAgAAAQABAAD/2wCEABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkz
ODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2MBERISGBUYLxoaL2NCOEJjY2NjY2NjY2Nj
Y2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY//EA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VndJEtNscGZmJYYOeRS0AJTT3z0oJK86xFW2rg
+oqlHLhgAAD7UkBrA8UZqxsM1JbxuGLrjHTmgB7RSE5Uqp9jway9T0OW9lEgkjVsYPvSWjHcc2jy
lFUFMKMCoZtDnkjK5j596LmntE0ZzeE7rPEkWPqadH4WuVbLNGfxquYz0L8OjTRLgKn4Gll0m4ZR
tVMggjJpXNOdWsbURZF5TB9qVpHxwprKxFyrggncMHrQTVCEzTSNwxnGaLkiG0jIILnmok02BOjn
86EInFFVcoSnB2A4Y/nTEL5j/wB4/nR5r/3j+dAwEr/3j+dL5r/3jUjF81/7xo81/wC8aAsHnP8A
3qXzn/vUCsHnP/eo85/WgBjOW602kAlNPQUhBSg0wBTkUuaChM0ZqkIM0UAGaXNAxc0ZqQDNGaAD
NGaBCZpCaQhM8UhPIpAJketG9R/EKYCRtxUlUymJUReTcQqAj1zSAXdL/wA8v/HhRvk/55H8xVCF
3v8A88j+Yo3v/wA8m/MUBcPMf/nk350u9/8Ank350gDe/wDzyb86N7/88m/OgLhvf/nkfzpDI4/5
ZH86Qh6kkZIwaKAuIaPLVzlscUguL5MQ7r+VNYRL/wDqppCuf//Z
—-_MULTIPART_BOUNDARY_00005C81000072CC–

arjen_lentz: MySQL thread cache

arjen_lentz: MySQL thread cache

It should be noted however that creating and destroying threads on some platforms is a very very cheap operation. Linux with NPTL (esp on x86) is one such platform.

(even without NPTL on x86 it’s stil pretty cheap).

On PPC with LinuxThreads it’s quite expensive.

On PPC with MacOS X it’s also very expensive.

I think i’ve blogged about this previously.

But users on MacOS X, Windows and Linux without NPTL should certainly consider using the thread cache. Otherwise, if you’re on x86 with NPTL you probably don’t have to bother – or at least you notice a very small benefit.

0.3.2 release of MemberDB

I’ll upload tarballs soon – but there’s a branch in the tree for 0.3.2. It’s the same as 0.3.1 but with the export members functionality working (somehow it was broken).

GNOME board discussions

Seeing that I’m on the board of a FOSS related group (Linux Australia), I naturally take an interest in how similar organisations do things.

So it’s been interesting watching what GNOME Foundation has been doing. I haven’t been watching that closely, but planet GNOME helps :)

jdub blogs about his choices in the upcoming vote on GNOME Foundation board stuff. He does have a good point here, as do others indicating they’ll vote the other way.

Jeff is totally right that it’s not the board that should be the great doers – they should represent and get the admin stuff done (or delegate it to appropriate parties – such as accountants).

I think we’ve gotten better with LA stuff by educating members on this issue. People are learning that you shouldn’t vote for the person who’s had the most cvs commits to $project. You should vote for the person who can make sure the organisation can continue but is also approachable and will bring views to the rest of the board (i.e. represent).

One idea is to maybe have an advisory committee. This can be larger and represent all interested parties. The (smaller) board could then go to them for advice on what the larger group thinks.

I do think that 11 sounds big – but just reducing numbers won’t necessarily fix any problems.

Good luck guys – you are living in interesting times!

__packed

Blog | rml

struct __packed s { … }This attribute tells GCC that a type or variable should be packed into memory, using the minimum amount of space possible, potentially disregarding alignment requirements. If specified on a struct or union, all variables therein are so packed. If specified on just a specific variable, only that type is packed. As an example, a structure with a char followed by an int would most likely find the integer aligned to a memory address not immediately following the char (say, three bytes later). The compiler does this by inserting three bytes of unused packing between the two variables. A packed structure lacks this packing, potentially consuming less memory but failing to meet architecture alignment requirements.

It should also be noted that non aligned data access on some architectures (e.g. ppc) can totally cripple performance. We’re talking orders of magnatude here. IBM has a good article on their developer site.

http://www-128.ibm.com/developerworks/power/library/pa-dalign/

Apple has some good tools for this too – and docs if i remember correctly.

rml on GCC extensions (and making them portable)

Blog | rml talks about a bunch of useful GCC extensions.

We generally don’t use this within mysql code. Due (no doubt) to portability issues. Maybe we should look closer at it these days. I wonder if we’d get any noticable improvement in NDB by adding it to our ndbrequire/ndbassert and CRASH_INSERTION tests. In some areas of code we do have a number of asserts.

The place to play is ndb/src/kernel/vm/pc.hpp

as actually triggering a ndbassert or ndbrequire is something that should never happen, unlikely() is a good thing to put there.

Interestingly enough, this is probably the place we also want to play with for dtrace. either that or with EXECUTE_DIRECT (and another place that Mikael mentioned on IRC last night.

My next task is to get qemu network interface working so i can get the source across to my VM of Solaris 10 and then start playing.

Of course, the other option is to actually install it somewhere (or shell out for vmware). It would be a lot faster then though.

PortaWiki going well (Wiki for portability issues)

PortaWiki is going pretty well. We’ve got a couple of contribututors at the moment and getting good little bits on the various oddities of various platforms. I encourage you to check it out and add things that you know.

It’d be great to have a MySQL section there too. In versions previous to 5.0 for example, you may get different results from some math operations on different platforms as we used the floating point stuff. In 5.0 we have precision math so this isn’t a problem – but it probably caused somebody to raise an eyebrow in the past. Volunteers?

how not to design a website

be a speaker at OSDC. Use their web system. I’m a smart guy and getting confused. Honestly guys, send in the slides for a presentation should not be a difficult task.

Contrast this with the recent AUUG conf where i attached files to an email and then clicked on the big Send button.

If via a web form it should be the *exact* equivilent. Not four different fields to specify the darn title of the thing.

must be time to use the OSDC conference registration/paper submission site

it’s annoying. grr.

but, on the other hand, I am speaking about MySQL 5.0 at OSDC.

This is even cooler as 5.0 has gone GA. So it’s not “upcoming features” it’s the “here and now”.

I’ll now have to release MemberDB 0.4 (the MySQL release). Converting the Linux Australia installation over at some point soon too. The 0.4 tree fixes enough bugs that it’s worth it (one of which Pia found the other day).

MySQL 5.0 is GA

We at MySQL AB have unleased MySQL 5.0 upon the world. It’s now declared GA (stable) and recommended for use everywhere you can possibly fit it (yes, this means brain implants and other things we dare not mention).

On DevZone there’s also a photo titled “MySQL 5.0 Development Team” taken at the DevConf earlier this year in Prague (you can see the pretty buildings in the background). I have a bunh of nice photos from there. I plan to put the scenic ones up somewhere at some point.

There’s even a poll for your favourite new feature. There isn’t an option for “version number divisible by 5”, but hey :)

I am going to get up and dance.

This does mean I will look stupid, but it’s dancing towards ice cream. Everybody deservers ice cream. Especially those with MySQL 5.0. In fact, if you don’t have it – no ice cream for you. You know you want ice cream…