Difference between revisions of "Swap on video ram"

From ArchWiki
Jump to: navigation, search
(initial write, not complete)
 
(27 intermediate revisions by 9 users not shown)
Line 1: Line 1:
 +
{{out of date}}
 +
{{accuracy}}
 
[[Category:Graphics]]
 
[[Category:Graphics]]
[[Category:Other hardware]]
+
'''Warning:''' unless your X11 driver can be made to use less ram than exists (can be detected) your X server will tend to crash when you try to use the same section of RAM to store textures (even Qt does it) as swap. Using a video driver that allows you to override videoram should increase stability (vga and radeon (xf86-video-ati) do at least). Even then, you or I might have made mistakes and you can still get crashes or freezes (that do not listen to ctrl-alt-backspace; use the magic sysrq).
{{stub}}
+
This is a work in progress
+
  
The fast memory on your graphics card (if you have one) can be used as general ram by using the MTD subsystem of the kernel. At the moment that part is not included in the stock arch kernel, so you have to build your own kernel, using [[abs]] is probably the easiest way.
+
==Why Do it==
 +
The fast memory on your graphics card (if you have one) can be used as general ram (actually swap) by using the MTD subsystem of the kernel. If you have lots of videoram (256 MiB) this can increase system responsiveness (if you have around 256 MiB main ram too :).
 +
 
 +
Agp has slow reads; ~8 M/s. Making this less desirable.
  
 
==How To==
 
==How To==
 
===Kernel Stuff===
 
===Kernel Stuff===
you could rebuild the whole kernel like shown here. The modules can probabally be built separately though (perhaps with a pkgbuild)
+
MTD is now included in the kernel as of 2.6.23.1-6.
# Get the [[abs]] tree
+
 
# copy the /var/abs/kernels/kernel26 to /var/abs/local/kernel26-mtd, that will be your working directory
+
===Post-Kernel Stuff===
# change the name of the package to something else ie. from kernel26 to kernel26-mtd or something like that
+
When you are running a kernel with MTD modules, you have to load the modules specifying  the pci address ranges that correspond to the ram on your video card.
# get and extract the sources with <pre>makepkg -o</pre>
+
 
# modify the configuration of the kernel, adding
+
check the ranges with  
## mtd_block (maybe mtd_char)
+
lspci -vvv
## mtd_slram
+
 
## mtd_phram (alternative and sucessor to slram)
+
Then you look for the sections that name your video card as an example mine is here:
## mtd_ram probably too.
+
## other settings that go with those choices:
+
<pre>CONFIG_MTD_MAP_BANK_WIDTH_1=y
+
CONFIG_MTD_MAP_BANK_WIDTH_2=y
+
CONFIG_MTD_MAP_BANK_WIDTH_4=y
+
# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
+
# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
+
# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
+
CONFIG_MTD_CFI_I1=y
+
CONFIG_MTD_CFI_I2=y</pre>
+
  
what the mtd section of my config ends up looking like (you could add this (almost?) anywhere in the config, just search for MTD, and replace the '#CONFIG_MTD= # is not set' with something else:
 
 
<pre>
 
<pre>
# Memory Technology Devices (MTD)
+
01:00.0 VGA compatible controller: ATI Technologies Inc RV350 AR [Radeon 9600] (prog-if 00 [VGA controller])
#
+
Subsystem: PC Partner Limited Unknown device 0830
CONFIG_MTD=m
+
Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx-
# CONFIG_MTD_DEBUG is not set
+
Status: Cap+ 66MHz+ UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
# CONFIG_MTD_CONCAT is not set
+
Latency: 64 (2000ns min), Cache Line Size: 32 bytes
CONFIG_MTD_PARTITIONS=y
+
Interrupt: pin A routed to IRQ 11
# CONFIG_MTD_REDBOOT_PARTS is not set
+
Region 0: Memory at e0000000 (32-bit, prefetchable) [size=256M]
 +
Region 1: I/O ports at c800 [size=256]
 +
Region 2: Memory at ff8f0000 (32-bit, non-prefetchable) [size=64K]
 +
Expansion ROM at ff8c0000 [disabled] [size=128K]
 +
Capabilities: <access denied>
  
#
+
01:00.1 Display controller: ATI Technologies Inc RV350 AR [Radeon 9600] (Secondary)
# User Modules And Translation Layers
+
Subsystem: PC Partner Limited Unknown device 0831
#
+
Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
CONFIG_MTD_CHAR=m
+
Status: Cap+ 66MHz+ UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
# CONFIG_MTD_BLKDEVS is not set
+
Latency: 64 (2000ns min), Cache Line Size: 32 bytes
CONFIG_MTD_BLOCK=m # is not set
+
Region 0: Memory at d0000000 (32-bit, prefetchable) [size=256M]
# CONFIG_MTD_BLOCK_RO is not set
+
Region 1: Memory at ff8e0000 (32-bit, non-prefetchable) [size=64K]
# CONFIG_FTL is not set
+
Capabilities: <access denied>
# CONFIG_NFTL is not set
+
</pre>
# CONFIG_INFTL is not set
+
# CONFIG_RFD_FTL is not set
+
# CONFIG_SSFDC is not set
+
  
#
+
What's important is Region 0, (the biggest one)
# RAM/ROM/Flash chip drivers
+
#
+
# CONFIG_MTD_CFI is not set
+
# CONFIG_MTD_JEDECPROBE is not set
+
CONFIG_MTD_MAP_BANK_WIDTH_1=y
+
CONFIG_MTD_MAP_BANK_WIDTH_2=y
+
CONFIG_MTD_MAP_BANK_WIDTH_4=y
+
# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
+
# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
+
# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
+
CONFIG_MTD_CFI_I1=y
+
CONFIG_MTD_CFI_I2=y
+
# CONFIG_MTD_CFI_I4 is not set
+
# CONFIG_MTD_CFI_I8 is not set
+
CONFIG_MTD_RAM=m
+
# CONFIG_MTD_ROM is not set
+
# CONFIG_MTD_ABSENT is not set
+
# CONFIG_MTD_OBSOLETE_CHIPS is not set
+
  
#
+
Since the video card needs some ram to serve its normal purpose, so you need to do some calculations. The offsets are easy to calculate as powers of 2. The card should use the beginning of the address range as framebuffer, textures etc. when limited (otherwise you get X11 crashing).
# Mapping drivers for chip access
+
#
+
# CONFIG_MTD_COMPLEX_MAPPINGS is not set
+
# CONFIG_MTD_TS5500 is not set
+
CONFIG_MTD_PLATRAM=m
+
  
#
+
Example: total 2^28 bytes (256M) videoram, leaving 2^24 (32M) for the normal function (less will work fine)
# Self-contained MTD device drivers
+
The start range, is 2^24 bytes more than the start of the pci address range shown by lspci -vvv.
#
+
# CONFIG_MTD_PMC551 is not set
+
# CONFIG_MTD_DATAFLASH is not set
+
# CONFIG_MTD_M25P80 is not set
+
CONFIG_MTD_SLRAM=m
+
CONFIG_MTD_PHRAM=m
+
# CONFIG_MTD_MTDRAM is not set
+
# CONFIG_MTD_BLOCK2MTD is not set
+
  
#
+
The end is your total minus the amount you left for the card.
# Disk-On-Chip Device Drivers
+
#
+
# CONFIG_MTD_DOC2000 is not set
+
# CONFIG_MTD_DOC2001 is not set
+
# CONFIG_MTD_DOC2001PLUS is not set
+
  
#
+
Load the modules in /etc/rc.conf
# NAND Flash Device Drivers
+
MODULES=(otherModulesYouNeed '''slram mtdblock''')
#
+
# CONFIG_MTD_NAND is not set
+
  
#
+
In /etc/rc.local
# OneNAND Flash Device Drivers
+
mkswap /dev/mtdblock0 && swapon /dev/mtdblock0 -p 10 #higher priority
#
+
 
# CONFIG_MTD_ONENAND is not set
+
Add this to /etc/modprobe.d/modprobe.conf
</pre>
+
options slram map=VRAM,0xStartRange,+0xUsedAmount
===Post-Kernel Stuff===
+
 
When you are running the new kernel with those modules built you choose the pci address ranges where the device goes and then add something the following to your rc.local or similar:
+
===Xorg Driver Config===
 +
To keep X stable, your video driver needs to be told to use less than the detected videoram. In the Device section of your /etc/X11/xorg.conf the declaration
 
<pre>
 
<pre>
# for using vram as swap
+
Section "Device"
modprobe slram map=VRAM,0xSTART RANGE HERE,+0xGOING THIS MUCH FARTHER
+
    Driver "radeon" # or whichever other driver you use
modprobe mtdchar
+
    VideoRam 32768
modprobe mtdblock
+
#other stuff
mkswap /dev/mtdblock0
+
EndSection
swapon /dev/mtdblock0 -p 10
+
 
</pre>
 
</pre>
you get the whole range you can take from lspci -vvv, looking for something that names your video card.
+
specifies that you use 32 MiB of ram. Other drivers might take the number for videoram as being in MiB (I think vga does), check manpages.
Learn hex aritmetic, or use a calculator (qalculate). You leave a certain space at the beginning of the address range, so that you graphics card can still function which is at least 4MiB if you decide to use the vga driver (at up to 1280x1024).
+
 
====Example====
+
==Checking the Swap space being used==
 +
The following command may help you getting the used swap in the different spaces like disk partitions, flash disks and possibly this example of the swap on video ram
 +
 
 
<pre>
 
<pre>
lspci -vvv
+
swapon -s
01:00.0 VGA compatible controller: ATI Technologies Inc RV350 AR [Radeon 9600] (prog-if 00 [VGA])
+
Subsystem: PC Partner Limited Unknown device 0830
+
Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B-
+
Status: Cap+ 66MHz+ UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
+
Latency: 64 (2000ns min), Cache Line Size: 32 bytes
+
Interrupt: pin A routed to IRQ 11
+
'' Region 0: Memory at e0000000 (32-bit, prefetchable) [size=256M]''
+
Region 1: I/O ports at c800 [size=256]
+
Region 2: Memory at ff8f0000 (32-bit, non-prefetchable) [size=64K]
+
Expansion ROM at ff8c0000 [disabled] [size=128K]
+
Capabilities: [58] AGP version 2.0
+
Status: RQ=80 Iso- ArqSz=0 Cal=0 SBA+ ITACoh- GART64- HTrans- 64bit- FW+ AGP3- Rate=x1,x2,x4
+
Command: RQ=32 ArqSz=0 Cal=0 SBA+ AGP+ GART64- 64bit- FW- Rate=x4
+
Capabilities: [50] Power Management version 2
+
Flags: PMEClk- DSI- D1+ D2+ AuxCurrent=0mA PME(D0-,D1-,D2-,D3hot-,D3cold-)
+
Status: D0 PME-Enable- DSel=0 DScale=0 PME-
+
 
</pre>
 
</pre>
So here I have an address range starting at 0xe0000000, with a size of 256MiB, aka +0x10000000.
 
So choose how much space you can spare, maybe it is 16MiB which happens to be: 0x01000000.
 
you want that space to be at the start of the address range, so add 0x01000000 to 0xe00000000 for the start, subtract that from the end (so that the swap is only on the video ram, and does not mess anything else up)
 
  
 
==External Links==
 
==External Links==
[http://www.linux-mtd.infradead.org MTD website]
+
*[http://www.linux-mtd.infradead.org MTD website]
[http://gentoo-wiki.com/TIP_Use_memory_on_video_card_as_swap Gentoo Wiki]
+
*[http://en.gentoo-wiki.com/wiki/Using_Graphics_Card_Memory_as_Swap Gentoo Wiki]

Revision as of 12:06, 23 April 2012

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: please use the first argument of the template to provide a brief explanation. (Discuss in Talk:Swap on video ram#)

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: please use the first argument of the template to provide a brief explanation. (Discuss in Talk:Swap on video ram#)

Warning: unless your X11 driver can be made to use less ram than exists (can be detected) your X server will tend to crash when you try to use the same section of RAM to store textures (even Qt does it) as swap. Using a video driver that allows you to override videoram should increase stability (vga and radeon (xf86-video-ati) do at least). Even then, you or I might have made mistakes and you can still get crashes or freezes (that do not listen to ctrl-alt-backspace; use the magic sysrq).

Why Do it

The fast memory on your graphics card (if you have one) can be used as general ram (actually swap) by using the MTD subsystem of the kernel. If you have lots of videoram (256 MiB) this can increase system responsiveness (if you have around 256 MiB main ram too :).

Agp has slow reads; ~8 M/s. Making this less desirable.

How To

Kernel Stuff

MTD is now included in the kernel as of 2.6.23.1-6.

Post-Kernel Stuff

When you are running a kernel with MTD modules, you have to load the modules specifying the pci address ranges that correspond to the ram on your video card.

check the ranges with

lspci -vvv

Then you look for the sections that name your video card as an example mine is here:

01:00.0 VGA compatible controller: ATI Technologies Inc RV350 AR [Radeon 9600] (prog-if 00 [VGA controller])
	Subsystem: PC Partner Limited Unknown device 0830
	Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx-
	Status: Cap+ 66MHz+ UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
	Latency: 64 (2000ns min), Cache Line Size: 32 bytes
	Interrupt: pin A routed to IRQ 11
	Region 0: Memory at e0000000 (32-bit, prefetchable) [size=256M]
	Region 1: I/O ports at c800 [size=256]
	Region 2: Memory at ff8f0000 (32-bit, non-prefetchable) [size=64K]
	Expansion ROM at ff8c0000 [disabled] [size=128K]
	Capabilities: <access denied>

01:00.1 Display controller: ATI Technologies Inc RV350 AR [Radeon 9600] (Secondary)
	Subsystem: PC Partner Limited Unknown device 0831
	Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
	Status: Cap+ 66MHz+ UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
	Latency: 64 (2000ns min), Cache Line Size: 32 bytes
	Region 0: Memory at d0000000 (32-bit, prefetchable) [size=256M]
	Region 1: Memory at ff8e0000 (32-bit, non-prefetchable) [size=64K]
	Capabilities: <access denied>

What's important is Region 0, (the biggest one)

Since the video card needs some ram to serve its normal purpose, so you need to do some calculations. The offsets are easy to calculate as powers of 2. The card should use the beginning of the address range as framebuffer, textures etc. when limited (otherwise you get X11 crashing).

Example: total 2^28 bytes (256M) videoram, leaving 2^24 (32M) for the normal function (less will work fine) The start range, is 2^24 bytes more than the start of the pci address range shown by lspci -vvv.

The end is your total minus the amount you left for the card.

Load the modules in /etc/rc.conf

MODULES=(otherModulesYouNeed slram mtdblock) 

In /etc/rc.local

mkswap /dev/mtdblock0 && swapon /dev/mtdblock0 -p 10 #higher priority

Add this to /etc/modprobe.d/modprobe.conf

options slram map=VRAM,0xStartRange,+0xUsedAmount

Xorg Driver Config

To keep X stable, your video driver needs to be told to use less than the detected videoram. In the Device section of your /etc/X11/xorg.conf the declaration

Section "Device"
    Driver "radeon" # or whichever other driver you use
    VideoRam 32768
	#other stuff
EndSection

specifies that you use 32 MiB of ram. Other drivers might take the number for videoram as being in MiB (I think vga does), check manpages.

Checking the Swap space being used

The following command may help you getting the used swap in the different spaces like disk partitions, flash disks and possibly this example of the swap on video ram

swapon -s 

External Links