# kswapd reaching 97% CPU utilization under heavy disk IO.

## dma

(EDIT: I'm in UDMA5 mode in case you miss it in there...)

In one terminal, I did this:

```
dd if=/dev/zero of=/crap bs=8k count=20000
```

top gives me this:

```
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  Command

    4 root      25   0     0    0    0 R 97.3  0.0 178:13.52 kswapd

```

The machine DOES get VERY unresponsive.

here's some output from hdparm:

```
root@laureate:~# hdparm -i /dev/hda

/dev/hda:

 Model=Maxtor 54098H8, FwRev=DAC10SC0, SerialNo=K80BNJFC

 Config={ Fixed }

 RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=57

 BuffType=DualPortCache, BuffSize=2048kB, MaxMultSect=16, MultSect=16

 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=80041248

 IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}

 PIO modes:  pio0 pio1 pio2 pio3 pio4

 DMA modes:  mdma0 mdma1 mdma2

 UDMA modes: udma0 udma1 udma2 udma3 udma4 *udma5

 AdvancedPM=yes: disabled (255) WriteCache=enabled

 Drive conforms to: ATA/ATAPI-6 T13 1410D revision 0:  1 2 3 4 5 6

root@laureate:~# hdparm -tT /dev/hda

/dev/hda:

 Timing buffer-cache reads:   128 MB in  0.42 seconds =301.89 MB/sec

 Timing buffered disk reads:  64 MB in  2.26 seconds = 28.28 MB/sec

root@laureate:~#

```

For the record, I'm using an A7V8X board with this:

```
00:11.0 ISA bridge: VIA Technologies, Inc. VT8235 ISA Bridge

00:11.1 IDE interface: VIA Technologies, Inc. VT82C586/B/686A/B PIPC Bus Master IDE (rev 06)
```

Here's some output from free:

Before dd:

```
root@laureate:~# free

             total       used       free     shared    buffers     cached

Mem:        773220     607884     165336          0     150080     337120

-/+ buffers/cache:     120684     652536

Swap:      2000084       8040    1992044
```

During dd:

```
root@laureate:~# free

             total       used       free     shared    buffers     cached

Mem:        773220     766440       6780          0     150436     498588

-/+ buffers/cache:     117416     655804

Swap:      2000084       8040    1992044
```

And the proverbial "wtf" moment (after dd):

```
root@laureate:/usr/src/linux# free

             total       used       free     shared    buffers     cached

Mem:        773220     766128       7092          0     150472     499880

-/+ buffers/cache:     115776     657444

Swap:      2000084       8040    1992044

root@laureate:/usr/src/linux# rm /crap

root@laureate:/usr/src/linux# free

             total       used       free     shared    buffers     cached

Mem:        773220     558996     214224          0     150472     290988

-/+ buffers/cache:     117536     655684

Swap:      2000084       8040    1992044

```

Notice how all of that "cached" stuff gets freed (and I go from 8mb of memory free to over 100mb).

Anyone else have this problem?  I'm still using gentoo-sources-2.4.20-r1 + ptrace fix + ebuild's XFS patch.

I'd really like to fix this!

EDIT: I put my kernel config (/proc/config) at http://www.lovedoesnotexist.com/config.txt

----------

## Naan Yaar

The last part (re: cached stuff being freed) is not really a problem and is to be expected - when the file is being used, it is going to be cached; once it is removed, the cached stuff can be released.

However, kswapd's behavior seems anomalous.  On my gentoo box with the ck6 kernel, everything seems OK: dd chews up CPU during the copy and I don't see kswapd near the top at all.  I remember that there were some issues with high CPU usage with kswapd during file i/o...

----------

## dma

Well I've been looking here:

http://www.linux-tutorial.info/cgi-bin/display.pl?311&0&68&0&3

And I've found some interesting stuff.

It seems to do it even after a 

```
swapoff -a
```

It might be that my page and buffer caches are being overused somehow.  What is interesting is that kswapd is using all of the CPU and "dd" is using none.  Maybe I'll try rebooting when I get back home and see if it does this before I get all of that stuff mapped into memory.

Unless there is another way to unload the page and buffer caches (as seen in "free").

----------

## Naan Yaar

There were several problems reported with kswapd and anomalous high CPU usage.  If you do a deja search with "kswapd" and "swapoff" (or other keywords), you will find quite a few.

 *dma wrote:*   

> ...
> 
> It seems to do it even after a 
> 
> ```
> ...

 

----------

