Difference between revisions of "Swap on video ram"

From ArchWiki
Jump to: navigation, search
(initial write, not complete)
 
(External Links: Renamed section to "See also".)
(30 intermediate revisions by 11 users not shown)
Line 1: Line 1:
 
[[Category:Graphics]]
 
[[Category:Graphics]]
[[Category:Other hardware]]
+
{{Expansion|This article may need to be expanded or revised for contemporary hardware.}}
{{stub}}
+
{{Out of date|Graphics hardware referenced is quite old at this point. rconf is referenced instead of systemd. This article primarily references a now archived article from Gentoo's wiki.}}
This is a work in progress
+
{{Article summary start}}
 +
{{Article summary text|A short article on utilizing video memory for system swap.}}
 +
{{Article summary heading|Related}}
 +
{{Article summary wiki|Maximizing Performance}}
 +
{{Article summary end}}
 +
{{Warning|This will not work with binary drivers.}}
 +
{{Warning|Unless your graphics driver can be made to use less ram than is detected, Xorg may crash when you try to use the same section of RAM to store textures as swap. Using a video driver that allows you to override videoram should increase stability.}}
  
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.
+
==Potential benefits==
 +
A graphics card with GDDR SDRAM or DDR SDRAM may be used as swap by using the MTD subsystem of the kernel. Systems with dedicated graphics memory of 256 MB or greater which also have limited amounts of system memory (DDR SDRAM) may benefit the most from this type of setup.
  
==How To==
+
{{Warning|The accelerated graphics bus (AGP) is a legacy bus and has a limited amount of bus bandwidth. This may limit reads to approximately 8 MB per second.}}
===Kernel Stuff===
+
you could rebuild the whole kernel like shown here. The modules can probabally be built separately though (perhaps with a pkgbuild)
+
# Get the [[abs]] tree
+
# copy the /var/abs/kernels/kernel26 to /var/abs/local/kernel26-mtd, that will be your working directory
+
# change the name of the package to something else ie. from kernel26 to kernel26-mtd or something like that
+
# get and extract the sources with <pre>makepkg -o</pre>
+
# modify the configuration of the kernel, adding
+
## mtd_block (maybe mtd_char)
+
## mtd_slram
+
## mtd_phram (alternative and sucessor to slram)
+
## 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:
+
==Kernel requirements==
<pre>
+
MTD is in the mainline kernel since version 2.6.23.
# Memory Technology Devices (MTD)
+
#
+
CONFIG_MTD=m
+
# CONFIG_MTD_DEBUG is not set
+
# CONFIG_MTD_CONCAT is not set
+
CONFIG_MTD_PARTITIONS=y
+
# CONFIG_MTD_REDBOOT_PARTS is not set
+
  
#
+
==Pre-setup==
# User Modules And Translation Layers
+
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.
#
+
CONFIG_MTD_CHAR=m
+
# CONFIG_MTD_BLKDEVS is not set
+
CONFIG_MTD_BLOCK=m # is not set
+
# CONFIG_MTD_BLOCK_RO is not set
+
# CONFIG_FTL is not set
+
# CONFIG_NFTL is not set
+
# CONFIG_INFTL is not set
+
# CONFIG_RFD_FTL is not set
+
# CONFIG_SSFDC is not set
+
  
#
+
To find the available memory ranges run the following command and look for the VGA compatible controller section (see the example below).
# 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
+
  
#
+
{{hc|$ lspci -vvv|<nowiki>
# Mapping drivers for chip access
+
01:00.0 VGA compatible controller: NVIDIA Corporation GK104 [GeForce GTX 670] (rev a1) (prog-if 00 [VGA controller])
#
+
Subsystem: ASUSTeK Computer Inc. Device 8405
# CONFIG_MTD_COMPLEX_MAPPINGS is not set
+
Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
# CONFIG_MTD_TS5500 is not set
+
Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
CONFIG_MTD_PLATRAM=m
+
Latency: 0
 +
Interrupt: pin A routed to IRQ 57
 +
Region 0: Memory at f5000000 (32-bit, non-prefetchable) [size=16M]
 +
Region 1: Memory at e8000000 (64-bit, prefetchable) [size=128M]
 +
Region 3: Memory at f0000000 (64-bit, prefetchable) [size=32M]
 +
Region 5: I/O ports at e000 [size=128]
 +
[virtual] Expansion ROM at f6000000 [disabled] [size=512K]
 +
Capabilities: <access denied>
 +
Kernel driver in use: nvidia
 +
Kernel modules: nouveau, nvidia</nowiki>}}
  
#
+
{{Note|Systems with multiple GPUs will likely have multiple entries here.}}
# Self-contained MTD device drivers
+
#
+
# 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
+
  
#
+
Of most potential benefit is a region that is prefectable, 64-bit, and the largest in size.
# Disk-On-Chip Device Drivers
+
{{Note|The graphics card used above has 2 GB of GDDR5 SDRAM, though as indicated above the full amount is not exposed or listed by the command provided above.}}
#
+
# CONFIG_MTD_DOC2000 is not set
+
# CONFIG_MTD_DOC2001 is not set
+
# CONFIG_MTD_DOC2001PLUS is not set
+
  
#
+
A video card needs some of its memory to function, as such some calculations are needed. The offsets are easy to calculate as powers of 2. The card should use the beginning of the address range as a framebuffer for textures and such. However, if limited or as indicated in the beginning of this article, if two programs try to write to the same sectors, stability issues are likely to occur.
# NAND Flash Device Drivers
+
#
+
# CONFIG_MTD_NAND is not set
+
  
#
+
{{Warning|The following example is dated and may no longer be accurate.}}
# OneNAND Flash Device Drivers
+
#
+
# CONFIG_MTD_ONENAND is not set
+
</pre>
+
===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:
+
<pre>
+
# for using vram as swap
+
modprobe slram map=VRAM,0xSTART RANGE HERE,+0xGOING THIS MUCH FARTHER
+
modprobe mtdchar
+
modprobe mtdblock
+
mkswap /dev/mtdblock0
+
swapon /dev/mtdblock0 -p 10
+
</pre>
+
you get the whole range you can take from lspci -vvv, looking for something that names your video card.
+
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====
+
<pre>
+
lspci -vvv
+
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>
+
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==
+
As an example: For a total of 256 MB of graphics memory, the forumla is 2^28 (two to the twenty-eighth power). Approximately 64 MB could be left for graphics memory and as such the start range for the swap usage of graphics memory would be calculated with the formula 2^26.
[http://www.linux-mtd.infradead.org MTD website]
+
 
[http://gentoo-wiki.com/TIP_Use_memory_on_video_card_as_swap Gentoo Wiki]
+
Using the numbers above, you can take the difference and determine a reseasonable range for usage as swap memory.
 +
leaving 2^24 (32M) for the normal function (less will work fine)
 +
 
 +
==Setup==
 +
Load the modules:
 +
{{hc|# /etc/rc.conf|<nowiki>
 +
MODULES=(otherModulesYouNeed '''slram mtdblock''')</nowiki>}}
 +
 
 +
{{hc|# /etc/rc.local|
 +
mkswap /dev/mtdblock0 && swapon /dev/mtdblock0 -p 10 #higher priority}}
 +
 
 +
Add the following.
 +
{{hc|# /etc/modprobe.d/modprobe.conf|<nowiki>
 +
options slram map=VRAM,0xStartRange,+0xUsedAmount</nowiki>}}
 +
 
 +
===Xorg driver config===
 +
To keep X stable, your video driver needs to be told to use less than the detected videoram.
 +
 
 +
{{hc|# /etc/X11/xorg.conf|
 +
Section "Device"
 +
    Driver "radeon" # or whichever other driver you use
 +
    VideoRam 32768
 +
#other stuff
 +
EndSection}}
 +
The above example specifies that you use 32 MB of graphics memory.
 +
 
 +
{{Note|Some drivers might take the number for videoram as being in MiB. See relevant manpages.}}
 +
 
 +
==Troubleshooting==
 +
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
 +
 
 +
{{bc|swapon -s}}
 +
 
 +
==See also==
 +
* [http://www.gentoo-wiki.info/TIP_Use_memory_on_video_card_as_swap Archived Gentoo Wiki articles. Note the warnings.]
 +
* [http://www.linux-mtd.infradead.org MTD website]
 +
* [http://en.gentoo-wiki.com/wiki/Using_Graphics_Card_Memory_as_Swap Gentoo Wiki]{{linkrot|2013|08|17}}

Revision as of 04:30, 18 August 2013

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: This article may need to be expanded or revised for contemporary hardware. (Discuss in Talk:Swap on video ram#)

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

Reason: Graphics hardware referenced is quite old at this point. rconf is referenced instead of systemd. This article primarily references a now archived article from Gentoo's wiki. (Discuss in Talk:Swap on video ram#)
Template:Article summary start

Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary end

Warning: This will not work with binary drivers.
Warning: Unless your graphics driver can be made to use less ram than is detected, Xorg may crash when you try to use the same section of RAM to store textures as swap. Using a video driver that allows you to override videoram should increase stability.

Potential benefits

A graphics card with GDDR SDRAM or DDR SDRAM may be used as swap by using the MTD subsystem of the kernel. Systems with dedicated graphics memory of 256 MB or greater which also have limited amounts of system memory (DDR SDRAM) may benefit the most from this type of setup.

Warning: The accelerated graphics bus (AGP) is a legacy bus and has a limited amount of bus bandwidth. This may limit reads to approximately 8 MB per second.

Kernel requirements

MTD is in the mainline kernel since version 2.6.23.

Pre-setup

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.

To find the available memory ranges run the following command and look for the VGA compatible controller section (see the example below).

$ lspci -vvv
01:00.0 VGA compatible controller: NVIDIA Corporation GK104 [GeForce GTX 670] (rev a1) (prog-if 00 [VGA controller])
	Subsystem: ASUSTeK Computer Inc. Device 8405
	Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
	Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
	Latency: 0
	Interrupt: pin A routed to IRQ 57
	Region 0: Memory at f5000000 (32-bit, non-prefetchable) [size=16M]
	Region 1: Memory at e8000000 (64-bit, prefetchable) [size=128M]
	Region 3: Memory at f0000000 (64-bit, prefetchable) [size=32M]
	Region 5: I/O ports at e000 [size=128]
	[virtual] Expansion ROM at f6000000 [disabled] [size=512K]
	Capabilities: <access denied>
	Kernel driver in use: nvidia
	Kernel modules: nouveau, nvidia
Note: Systems with multiple GPUs will likely have multiple entries here.

Of most potential benefit is a region that is prefectable, 64-bit, and the largest in size.

Note: The graphics card used above has 2 GB of GDDR5 SDRAM, though as indicated above the full amount is not exposed or listed by the command provided above.

A video card needs some of its memory to function, as such some calculations are needed. The offsets are easy to calculate as powers of 2. The card should use the beginning of the address range as a framebuffer for textures and such. However, if limited or as indicated in the beginning of this article, if two programs try to write to the same sectors, stability issues are likely to occur.

Warning: The following example is dated and may no longer be accurate.

As an example: For a total of 256 MB of graphics memory, the forumla is 2^28 (two to the twenty-eighth power). Approximately 64 MB could be left for graphics memory and as such the start range for the swap usage of graphics memory would be calculated with the formula 2^26.

Using the numbers above, you can take the difference and determine a reseasonable range for usage as swap memory. leaving 2^24 (32M) for the normal function (less will work fine)

Setup

Load the modules:

# /etc/rc.conf
 MODULES=(otherModulesYouNeed '''slram mtdblock''')
# /etc/rc.local
 mkswap /dev/mtdblock0 && swapon /dev/mtdblock0 -p 10 #higher priority

Add the following.

# /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.

# /etc/X11/xorg.conf
Section "Device"
    Driver "radeon" # or whichever other driver you use
    VideoRam 32768
	#other stuff
EndSection

The above example specifies that you use 32 MB of graphics memory.

Note: Some drivers might take the number for videoram as being in MiB. See relevant manpages.

Troubleshooting

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

See also