Register now and start sharing your code snippets.
-->

Fixing slowdown of X after installing 4Gb of RAM

Shell Script (Bash) posted 11 months ago by marko

Both X and 3D acceleration of my Lenovo X61s became horrendously slow after I upgraded to 4Gb of RAM . After a while of Googling I found a thread that explained why it had become slow. In my dmesg I could see the following error, which hinted me to the cause.

   1  mtrr: type mismatch for e0000000,10000000 old: write-back new: write-combining

I want to emphasize that I’m not the author of this script. But I want to store it here because forums and topics sometimes disappear. The original author seems to be “hubick” of the thread linked above. For me this script was plug & play, so many props to the original author if you happen to read this ;) I just needed to run it before X was started.

   1  #!/bin/sh
   2  # Fixup /proc/mtrr
   3  #
   4  # chkconfig: 12345 0 99
   5  # description: Fixup /proc/mtrr
   6  #
   7  # Save this file as /etc/init.d/mtrrfixup and
   8  # use "chkconfig --add mtrrfixup"
   9  # to have this script run by init when the system starts.
  10  #
  11  # The default mtrr table after boot looks like the following:
  12  # reg00: base=0xd8000000 (3456MB), size= 128MB: uncachable, count=1
  13  # reg01: base=0xe0000000 (3584MB), size= 512MB: uncachable, count=1
  14  # reg02: base=0x00000000 (   0MB), size=4096MB: write-back, count=1
  15  # reg03: base=0x100000000 (4096MB), size= 512MB: write-back, count=1
  16  # reg04: base=0x120000000 (4608MB), size= 128MB: write-back, count=1
  17  # reg05: base=0xd7f80000 (3455MB), size= 512KB: uncachable, count=1
  18  #
  19  # The main problem is entry 1, which covers
  20  # the AGP aperature and Video Card memory.
  21  # Being present and uncachable, it prevents
  22  # the fglrx driver module from using/creating a
  23  # write-combined region for the video card.
  24  # The second problem is entry 2, covering all
  25  # our ram, which prevents us from creating
  26  # any new sections which aren't uncachable.
  27  #
  28  # We have a maximum of 7 mtrr registers.
  29  # All sizes must be a power of two.
  30  # The start and end of any page must
  31  # have the same 'upper bits'.
  32  
  33  # First remove all existing values...
  34  # Order matters - wrong order locks system hard!
  35  echo "disable=2" >| /proc/mtrr
  36  echo "disable=5" >| /proc/mtrr
  37  echo "disable=1" >| /proc/mtrr
  38  echo "disable=3" >| /proc/mtrr
  39  echo "disable=4" >| /proc/mtrr
  40  echo "disable=0" >| /proc/mtrr
  41  
  42  # Now create the right ones...
  43  
  44  # Main Memory: 0-2048,2048-3072,3072-3328,3328-3456
  45  # These are powers of two, they get progressively smaller
  46  # so we can get right up to the system device page below.
  47  echo "base=0x00000000 size=0x80000000 type=write-back" >| /proc/mtrr
  48  echo "base=0x80000000 size=0x40000000 type=write-back" >| /proc/mtrr
  49  echo "base=0xC0000000 size=0x10000000 type=write-back" >| /proc/mtrr
  50  echo "base=0xD0000000 size=0x08000000 type=write-back" >| /proc/mtrr
  51  
  52  # System Devices: 3456-3584
  53  echo "base=0xD8000000 size=0x08000000 type=uncachable" >| /proc/mtrr
  54  
  55  # AGP Aperature: 3584-3712
  56  echo "base=0xE0000000 size=0x08000000 type=write-combining" >| /proc/mtrr
  57  
  58  # Video Card: 3712-3840
  59  echo "base=0xE8000000 size=0x08000000 type=write-combining" >| /proc/mtrr
  60  
  61  # High memory area: 4096-5096
  62  echo "base=0x100000000 size=0x40000000 type=write-back" >| /proc/mtrr

Tagged mtrr, large memory, slowdown, x, 3d, fglrx