Author Topic: Performance Tuning For The 'overburdened' Zaurus  (Read 6237 times)

iamasmith

  • Hero Member
  • *****
  • Posts: 1248
    • View Profile
Performance Tuning For The 'overburdened' Zaurus
« on: February 12, 2006, 06:36:09 pm »
Don't bother reading this any further if your only concern is a Linux based system. This tuning is only available for the Zaurus if running OpenBSD since sysctl is part of OpenBSD and the libc implementation is part of OpenBSD rather than using the GNU libc.

Now, before we go any further let me warn you that some of the tuning options that I suggest will actively disable some of the security features of OpenBSD related to guarding the system against buffer overrun exploits/stack smashing and encryption of the paging subsystem. If you want to retain your Zaurus in the most secure fashion then you should probably leave it at the default settings, however, most users will accept that tuning is based upon your use profile for the device.

The usage profile that I wanted to enhance was system performance when the system had become overburdened, particularly  when running X and in my case XFCE4 which I love as a desktop environment. - To this end the settings are designed to improve system performance when memory utilisation is getting high, something that is likely to happen with most Zaurus users running OpenBSD.

The settings are quick to apply and require a reboot once applied, likewise they can be quickly removed and a reboot will clear them entirely.

sysctl settings

The OpenBSD Kernel can be tuned by various system settings directly through the program sysctl. If these settings are stored in /etc/sysctl.conf they will be implemented at boot time.

The following settings I am recommending should be changed or added in sysctl.conf

vm.swapencrypt.enable=0

This setting disables swap (page partition) encryption so should yield a performance boost when the system is overburdened at the cost of the potential ability to decode sensitive data stored in the page partition should the device fall into the wrong hands.

kern.stackgap_random=0

This parameter governs the size of the random amount of memory allocated to the stack during certain operations. The mechanism is there to stop predictable stack smashing exploits but can add a considerable amount of memory allocation to processes (hundreds of Kilobytes in some cases).

malloc settings

The memory allocation features within BSD (unlike Linux) are tuneable. They are implemented within /src/lib/libc/stdlib/malloc.c and it is only by understanding this file that an accurate assessment of the options can be made. The malloc man page lists all the settings, however, it does not go on to explain what 'Hinting' does etc.

The settings that I am going to recommend (see the malloc man page) are more fully explained as follows.

a = Don't cause Abort (core dumps on failures)
z = Turn off zeroing of pages, time consuming and with it turned on the J/j parameter is ignored! (need to read the source to see this)
j = Don't fill allocations with junk (our processor has enough to do already).
g = Don't allocate Guard Pages that waste our memory (security feature here)
p = Turn off pointer protection - again allocates more memory in each malloc/realloc call (this can skip some major options if left enabled such as the realloc stuff [R])
H = Turn on Hinting (unused pages are marked with MADV_FREE - see madvise man page, the kernel will therefore discard them rather than page them under low memory condition)
R = Turn on always realloc (reallocation to aid compacting performances). Applications such as AbiWord in particular that make significant use of heap space frequently realloc and will release pages more frequently.

The way to make these settings global is to create a symbolic link as follows...

ln -s 'azjgpHR' /etc/malloc.conf

Normally symlinks point to files, however, in this case libc reads the symlink directly for the options. This is a performance technique since the settings will be more directly cached for access than being stored within a file.

Notice that I don't make recommendations about the use of the < or > flags to reduce or increase the malloc cache size. With the useage profile that I have I have found no discernable benefit from changing it, however, you may wish to profile applications and daemons to discern an appropriate setting for yourself.

Note the settings will NOT work if you create a regular file called /etc/malloc.conf

Some stats

The real statistics behind this tuning will only become evident when we overload the Zaurus to the point that paging occurs.

The following 3 'top' snapshots were taken from an ssh connection to a Zaurus running full XFCE4 and AbiWord 2.4 with ispell dictionaries built in. Each snapshot represents a newly booted configuration.

Snapshot 1 - Default configuration + sysctl vm.swapencrypt=0

load averages:  0.66,  0.70,  0.41                                     21:49:43
29 processes:  28 idle, 1 on processor
CPU states: 10.8% user,  0.0% nice,  5.6% system,  0.0% interrupt, 83.6% idle
Memory: Real: 32M/57M act/tot  Free: 888K  Swap: 2304K/128M used/tot

  PID USERNAME PRI NICE  SIZE   RES STATE    WAIT     TIME    CPU COMMAND
31620 andrews    2    0 5472K   11M sleep    poll     0:41  9.33% xfce4-panel
23208 andrews    2    0 8752K   15M sleep    poll     0:24  5.27% AbiWord-2.4
12371 andrews    2    0 5864K 5424K sleep    select   0:20  4.05% Xorg
 8585 andrews    2    0 2280K 6476K sleep    poll     0:06  0.00% xfdesktop
 3123 andrews    2    0 1808K 6584K idle     poll     0:05  0.00% xfwm4
32699 andrews    2    0 1852K 6948K idle     poll     0:04  0.00% xftaskbar4
 1088 andrews    2    0  624K 1532K sleep    poll     0:03  0.00% xscreensaver
32600 andrews    2    0  856K 4424K idle     poll     0:03  0.00% xfce4-session
26271 andrews    2    0 1500K 4724K sleep    poll     0:02  0.00% xfce-mcs-mana
23507 root       2    0  688K  568K idle     select   0:01  0.00% sshd
15707 root       2    0 3256K  720K idle     netio    0:00  0.00% sshd
 9959 andrews   28    0  524K  984K onproc   -        0:00  0.00% top
15009 _syslogd   2    0  460K  496K idle     poll     0:00  0.00% syslogd
27878 root       2    0 1140K  980K sleep    select   0:00  0.00% sendmail
12721 andrews    2    0 3256K 1200K sleep    select   0:00  0.00% sshd
 5402 andrews   18    0  668K    8K idle     pause    0:00  0.00% ksh
10667 andrews   10    0  472K  728K idle     wait     0:00  0.00% xinit
32524 andrews   18    0  556K    8K idle     pause    0:00  0.00% sh
13282 root       2    0  300K  452K idle     kqread   0:00  0.00% apmd
 4478 root       2    0  564K  596K idle     select   0:00  0.00% cron
22154 root       3    0  224K  480K idle     ttyin    0:00  0.00% getty
  818 andrews   18    0  512K    8K idle     pause    0:00  0.00% ksh
    1 root      10    0  444K    8K idle     wait     0:00  0.00% init
26439 root       2    0  312K  440K idle     select   0:00  0.00% inetd
26977 root       2    0  432K  340K idle     netio    0:00  0.00% syslogd
11796 root      -6    0  148K  428K idle     htplev   0:00  0.00% hotplugd
 5010 andrews    2    0 2000K  392K idle     netio    0:00  0.00% Xorg
15720 andrews   18    0  548K    8K idle     pause    0:00  0.00% sh
20786 andrews    2    0  532K  444K idle     select   0:00  0.00% ssh-agent


Snapshot 2 - After applying sysctl kern.stackgap_random = 0

Here we expect to see a random element removed from the memory allocation of the processes. The processes should show as smaller than the original but the amount is indeterminable due to the random amount of bloat imposed by the stackgap_random mechanism.

load averages:  0.74,  0.77,  0.39                                     21:59:28
29 processes:  3 running, 25 idle, 1 on processor
CPU states: 11.2% user,  0.0% nice,  4.7% system,  0.0% interrupt, 84.2% idle
Memory: Real: 32M/57M act/tot  Free: 1172K  Swap: 6592K/128M used/tot

  PID USERNAME PRI NICE  SIZE   RES STATE    WAIT     TIME    CPU COMMAND
 3082 andrews    2    0 5240K 7792K run      -        0:29  9.57% xfce4-panel
31372 andrews   28    0 8604K   15M run      -        0:23  4.30% AbiWord-2.4
 2484 andrews    2    0 5632K 5180K run      -        0:15  3.27% Xorg
31105 andrews    2    0 2024K 5784K sleep    poll     0:06  0.00% xfdesktop
31443 andrews    2    0 1756K 6472K idle     poll     0:05  0.00% xfwm4
 6667 andrews    2    0 1624K 6892K idle     poll     0:05  0.00% xftaskbar4
22111 andrews    2    0  628K 1532K sleep    poll     0:04  0.00% xscreensaver
 5673 andrews    2    0  756K 4280K idle     poll     0:03  0.00% xfce4-session
28783 andrews    2    0 1412K 4164K sleep    poll     0:02  0.00% xfce-mcs-mana
 1574 root       2    0  540K  416K idle     select   0:01  0.00% sshd
29507 root       2    0 3148K  552K idle     netio    0:00  0.00% sshd
  825 andrews   28    0  388K  928K onproc   -        0:00  0.00% top
 2677 _syslogd   2    0  256K  472K idle     poll     0:00  0.00% syslogd
13631 andrews    2    0 3160K 1032K sleep    select   0:00  0.00% sshd
30489 root       2    0 1004K  952K sleep    select   0:00  0.00% sendmail
14046 andrews   18    0  484K    8K idle     pause    0:00  0.00% ksh
16693 andrews   10    0  220K  708K idle     wait     0:00  0.00% xinit
 3895 andrews   18    0  480K    8K idle     pause    0:00  0.00% sh
 2724 root       3    0  192K  452K idle     ttyin    0:00  0.00% getty
22854 andrews   18    0  480K    8K idle     pause    0:00  0.00% ksh
    1 root      10    0  576K    8K idle     wait     0:00  0.00% init
11291 root       2    0  232K  412K idle     select   0:00  0.00% inetd
26294 root       2    0  408K  612K idle     select   0:00  0.00% cron
19721 root       2    0  232K  312K idle     netio    0:00  0.00% syslogd
 4774 root       2    0  156K  424K idle     kqread   0:00  0.00% apmd
20647 root      -6    0  148K  400K idle     htplev   0:00  0.00% hotplugd
18752 andrews    2    0 1772K  364K idle     netio    0:00  0.00% Xorg
17329 andrews    2    0  276K  292K idle     select   0:00  0.00% ssh-agent
  797 andrews   18    0  472K    8K idle     pause    0:00  0.00% sh



Snapshot 3 - After applying the /etc/malloc.conf tuning.

Now we expect to see less memory utilisation both in terms of  process size and resident statistics for each of the XFCE4 processes. It it possible that AbiWord at this stage may use more memory since the operating system is free to give it.

load averages:  1.13,  0.92,  0.46                                     22:17:37
29 processes:  1 running, 27 idle, 1 on processor
CPU states: 14.3% user,  0.0% nice,  5.3% system,  0.0% interrupt, 80.4% idle
Memory: Real: 30M/56M act/tot  Free: 2112K  Swap: 4736K/128M used/tot

  PID USERNAME PRI NICE  SIZE   RES STATE    WAIT     TIME    CPU COMMAND
 2201 andrews    2    0 8604K   14M sleep    poll     0:25 32.86% AbiWord-2.4
15806 andrews    2    0 5244K 7628K run      -        0:30 10.06% xfce4-panel
23689 andrews    2    0 5624K 5036K sleep    select   0:17  8.25% Xorg
 7526 andrews    2    0 1656K 6768K sleep    poll     0:05  3.32% xftaskbar4
22566 andrews    2    0 1752K 6432K sleep    poll     0:05  0.88% xfwm4
16586 andrews    2    0  608K 1516K sleep    poll     0:05  0.49% xscreensaver
13100 andrews    2    0 2016K 5700K sleep    poll     0:06  0.00% xfdesktop
31169 andrews    2    0  764K 4196K sleep    poll     0:03  0.00% xfce4-session
20358 andrews    2    0 1384K 4128K sleep    poll     0:02  0.00% xfce-mcs-mana
27366 root       2    0  540K  444K idle     select   0:01  0.00% sshd
 7761 root       2    0 3168K  584K idle     netio    0:00  0.00% sshd
28565 andrews   28    0  392K  956K onproc   -        0:00  0.00% top
12637 andrews    2    0 3168K 1056K sleep    select   0:00  0.00% sshd
18604 _syslogd   2    0  268K  496K sleep    poll     0:00  0.00% syslogd
  128 andrews   18    0  484K    8K idle     pause    0:00  0.00% ksh
21710 root       2    0  996K  980K sleep    select   0:00  0.00% sendmail
14304 andrews   10    0  212K  732K idle     wait     0:00  0.00% xinit
13362 andrews   18    0  476K    8K idle     pause    0:00  0.00% sh
13211 root       2    0  408K  636K idle     select   0:00  0.00% cron
14142 root       3    0  192K  480K idle     ttyin    0:00  0.00% getty
28839 root       2    0  252K  444K idle     select   0:00  0.00% inetd
    1 root      10    0  352K    8K idle     wait     0:00  0.00% init
23654 andrews   18    0  480K    8K idle     pause    0:00  0.00% ksh
15315 root       2    0  240K  340K idle     netio    0:00  0.00% syslogd
24014 andrews    2    0 1772K  392K idle     netio    0:00  0.00% Xorg
27988 root      -6    0  148K  428K idle     htplev   0:00  0.00% hotplugd
11991 root       2    0  156K  452K idle     kqread   0:00  0.00% apmd
 9891 andrews   18    0  468K    8K idle     pause    0:00  0.00% sh
 5227 andrews    2    0  280K  320K idle     select   0:00  0.00% ssh-agent



Test 1 summary

 PID USERNAME PRI NICE  SIZE   RES STATE    WAIT     TIME    CPU COMMAND

12371 andrews    2    0 5864K 5424K sleep    select   0:20  4.05% Xorg
 3123 andrews    2    0 1808K 6584K idle     poll     0:05  0.00% xfwm4
 8585 andrews    2    0 2280K 6476K sleep    poll     0:06  0.00% xfdesktop
31620 andrews    2    0 5472K   11M sleep    poll     0:41  9.33% xfce4-panel
32699 andrews    2    0 1852K 6948K idle     poll     0:04  0.00% xftaskbar4
32600 andrews    2    0  856K 4424K idle     poll     0:03  0.00% xfce4-session
26271 andrews    2    0 1500K 4724K sleep    poll     0:02  0.00% xfce-mcs-mana
23208 andrews    2    0 8752K   15M sleep    poll     0:24  5.27% AbiWord-2.4

Test 2 summary

 PID USERNAME PRI NICE  SIZE   RES STATE    WAIT     TIME    CPU COMMAND

 2484 andrews    2    0 5632K 5180K run      -        0:15  3.27% Xorg
31443 andrews    2    0 1756K 6472K idle     poll     0:05  0.00% xfwm4
31105 andrews    2    0 2024K 5784K sleep    poll     0:06  0.00% xfdesktop
 3082 andrews    2    0 5240K 7792K run      -        0:29  9.57% xfce4-panel
 6667 andrews    2    0 1624K 6892K idle     poll     0:05  0.00% xftaskbar4
 5673 andrews    2    0  756K 4280K idle     poll     0:03  0.00% xfce4-session
28783 andrews    2    0 1412K 4164K sleep    poll     0:02  0.00% xfce-mcs-mana
31372 andrews   28    0 8604K   15M run      -        0:23  4.30% AbiWord-2.4

Test 3 Summary

 PID USERNAME PRI NICE  SIZE   RES STATE    WAIT     TIME    CPU COMMAND

23689 andrews    2    0 5624K 5036K sleep    select   0:17  8.25% Xorg
22566 andrews    2    0 1752K 6432K sleep    poll     0:05  0.88% xfwm4
13100 andrews    2    0 2016K 5700K sleep    poll     0:06  0.00% xfdesktop
15806 andrews    2    0 5244K 7628K run      -        0:30 10.06% xfce4-panel
 7526 andrews    2    0 1656K 6768K sleep    poll     0:05  3.32% xftaskbar4
31169 andrews    2    0  764K 4196K sleep    poll     0:03  0.00% xfce4-session
20358 andrews    2    0 1384K 4128K sleep    poll     0:02  0.00% xfce-mcs-mana
 2201 andrews    2    0 8604K   14M sleep    poll     0:25 32.86% AbiWord-2.4


With such a rudimentary test we cannot begin to predict the real/page memory usage patterns, however, we can look at individual process memory utilisation based upon the SIZE and RES fields in the top display.

The RES field is the resident memory usage field for the process, whereas the size field is the total process size.

These fields may differ quite radically since the operating system may over-allocate memory to a process speculatively (accounting for a large RES field and a smaller SIZE field), an extremely large SIZE field and a small RES field may indicate that a significant amount of the process is paged out etc.

What we are looking for realistically in this test is a downward trend in these stats and almost without exception we see that trend in both size and resident statistics for each process.

Summary

It appears with these tunings we have freed some memory for use by other processes.

We should notice that in such an environment the systems will converge upon a good working set more rapidly and will therefore seem faster following initial boot and major memory reallocation.

We have also adopted an allocation flag that secures more frequent use of memory compaction techniques thus allowing more efficient use of the available memory.
OpenBSD 4.2 -current on full 4Gb of SL-C3000
Microdrive replaced with 4Gb SanDisk Extreme III card

ins0mniaque

  • Newbie
  • *
  • Posts: 27
    • View Profile
Performance Tuning For The 'overburdened' Zaurus
« Reply #1 on: February 12, 2006, 08:34:01 pm »
Well thank you for all this. You don't get a lot of answers on these forums, but I wanted to let you know that your work on that is appreciated.

iamasmith

  • Hero Member
  • *****
  • Posts: 1248
    • View Profile
Performance Tuning For The 'overburdened' Zaurus
« Reply #2 on: March 04, 2006, 05:17:10 am »
Another thing worth mentioning... possibly the most obvious in saving wear on your Zaurus and improving performane but DOH!, I forgot to check it until last night .

By default, as you may expect, the root file system mounts with access times meaning that when you read anything from the drive it writes back the access time (i.e. not just on writes)... this causes a lot more disk IO than you possibly want on a Microdrive..

Update /etc/fstab and add noatime to the list of options to the / mount to disable this behaviour. It does make a difference.

(man I feel dumb for not spotting this earlier )

-Andy
OpenBSD 4.2 -current on full 4Gb of SL-C3000
Microdrive replaced with 4Gb SanDisk Extreme III card

Sequethin

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Performance Tuning For The 'overburdened' Zaurus
« Reply #3 on: March 07, 2006, 04:39:45 pm »
this is great because I am currently using my z as a dev box for php/mysql web stuff. I overburden the poor thing pretty often.  keep up the good work iamasmith!

iamasmith

  • Hero Member
  • *****
  • Posts: 1248
    • View Profile
Performance Tuning For The 'overburdened' Zaurus
« Reply #4 on: March 07, 2006, 07:01:28 pm »
oh another fs tuning for your disk is softdep (only for ffs partitions).. note softdep as an option cannot be used with -u option on mount, it can only be specified when the actual mount takes place.

http://www.mckusick.com/softdep/

I have just started using this and it seems pretty snappy so far... we shall see.

-Andy
« Last Edit: March 07, 2006, 07:02:47 pm by iamasmith »
OpenBSD 4.2 -current on full 4Gb of SL-C3000
Microdrive replaced with 4Gb SanDisk Extreme III card

dda71

  • Newbie
  • *
  • Posts: 14
    • View Profile
Performance Tuning For The 'overburdened' Zaurus
« Reply #5 on: April 12, 2006, 07:43:22 am »
Quote
oh another fs tuning for your disk is softdep (only for ffs partitions).. note softdep as an option cannot be used with -u option on mount, it can only be specified when the actual mount takes place.

http://www.mckusick.com/softdep/

I have just started using this and it seems pretty snappy so far... we shall see.

-Andy
[div align=\"right\"][a href=\"index.php?act=findpost&pid=117479\"][{POST_SNAPBACK}][/a][/div]

NICE article! You really seem to be the openbsd zaurus god  here  

Are you still using softdep, is it worth using it on the zaurus?

iamasmith

  • Hero Member
  • *****
  • Posts: 1248
    • View Profile
Performance Tuning For The 'overburdened' Zaurus
« Reply #6 on: April 12, 2006, 07:59:36 am »
Yes, I use noatime and softdep on all my ffs mounts on desktop and Zaurus and never had a problem. noatime particularly helps if you run things like moinmoin that perform a lot of reads. softdep helps a lot by ordering writes and does give some performance boost. softdep boost is most noticable when deleting a lot of files.

-Andy
OpenBSD 4.2 -current on full 4Gb of SL-C3000
Microdrive replaced with 4Gb SanDisk Extreme III card