Difference between revisions of "Swap on video ram"

From ArchWiki
Jump to: navigation, search
m (del irrelevant remark)
 
(15 intermediate revisions by 9 users not shown)
Line 1: Line 1:
{{out of date}}
 
{{accuracy}}
 
 
[[Category:Graphics]]
 
[[Category:Graphics]]
'''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).
+
[[ja:ビデオメモリにスワップ]]
 +
{{Expansion|This article may need to be expanded or revised for contemporary hardware.}}
 +
{{Out of date|Graphics hardware referenced is quite old at this point. This article primarily references a now archived article from Gentoo's wiki.}}
 +
{{Related articles start}}
 +
{{Related|Improving performance}}
 +
{{Related articles end}}
 +
Article on utilizing video memory for system swap.
  
==Why Do it==
+
{{Warning|This will not work with binary drivers.}}
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 :).
+
{{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.}}
  
Agp has slow reads; ~8 M/s. Making this less desirable.
+
==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==
+
{{Note|Using legacy AGP (Accelerated Graphics Bus) card may limit reads to approximately 8 MB per second. AGP bus has a limited amount of bus bandwidth.}}
===Kernel Stuff===
+
MTD is now included in the kernel as of 2.6.23.1-6.
+
  
===Post-Kernel Stuff===
+
==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.
 
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
+
To find the available memory ranges run the following command and look for the VGA compatible controller section (see the example below).
lspci -vvv
+
  
Then you look for the sections that name your video card as an example mine is here:
+
{{hc|$ lspci -vvv|<nowiki>
 
+
01:00.0 VGA compatible controller: NVIDIA Corporation GK104 [GeForce GTX 670] (rev a1) (prog-if 00 [VGA controller])
<pre>
+
Subsystem: ASUSTeK Computer Inc. Device 8405
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-
 
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-
+
Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
Latency: 64 (2000ns min), Cache Line Size: 32 bytes
+
Latency: 0
Region 0: Memory at d0000000 (32-bit, prefetchable) [size=256M]
+
Interrupt: pin A routed to IRQ 57
Region 1: Memory at ff8e0000 (32-bit, non-prefetchable) [size=64K]
+
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>
 
Capabilities: <access denied>
</pre>
+
Kernel driver in use: nvidia
 +
Kernel modules: nouveau, nvidia</nowiki>}}
  
What's important is Region 0, (the biggest one)
+
{{Note|Systems with multiple GPUs will likely have multiple entries here.}}
  
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).
+
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.}}
  
Example: total 2^28 bytes (256M) videoram, leaving 2^24 (32M) for the normal function (less will work fine)
+
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.
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.  
+
{{Warning|The following example is dated and may no longer be accurate.}}
  
Load the modules in /etc/rc.conf
+
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.
MODULES=(otherModulesYouNeed '''slram mtdblock''')  
+
  
In /etc/rc.local
+
Using the numbers above, you can take the difference and determine a reseasonable range for usage as swap memory.
mkswap /dev/mtdblock0 && swapon /dev/mtdblock0 -p 10 #higher priority
+
leaving 2^24 (32M) for the normal function (less will work fine)
  
Add this to /etc/modprobe.d/modprobe.conf
+
==Setup==
options slram map=VRAM,0xStartRange,+0xUsedAmount
+
Load the modules:
 +
{{hc|# /etc/modules-load.d/vramswap.conf|<nowiki>
 +
slram
 +
mtdblock
 +
</nowiki>}}
  
===Xorg Driver Config===
+
systemd service:
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
+
{{hc|# /usr/lib/systemd/system/vramswap.service|<nowiki>
<pre>
+
[Unit]
 +
Description=Swap on Video RAM
 +
 
 +
[Service]
 +
Type=oneshot
 +
ExecStart=/usr/bin/bash -c "mkswap /dev/mtdblock0 && swapon /dev/mtdblock0 -p 10"
 +
ExecStop=/usr/bin/bash -c "swapoff /dev/mtdblock0"
 +
RemainAfterExit=yes
 +
 
 +
[Install]
 +
WantedBy=multi-user.target
 +
</nowiki>}}
 +
 
 +
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.d/vramswap.conf|
 
Section "Device"
 
Section "Device"
 
     Driver "radeon" # or whichever other driver you use
 
     Driver "radeon" # or whichever other driver you use
 
     VideoRam 32768
 
     VideoRam 32768
 
#other stuff
 
#other stuff
EndSection
+
EndSection}}
</pre>
+
The above example specifies that you use 32 MB of graphics memory.
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.
+
 
 +
{{Note|Some drivers might take the number for videoram as being in MiB. See relevant manpages.}}
  
==Checking the Swap space being used==
+
==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
 
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>
+
{{bc|swapon -s}}
swapon -s  
+
</pre>
+
  
==External Links==
+
==See also==
*[http://www.linux-mtd.infradead.org MTD website]
+
* [http://www.gentoo-wiki.info/TIP_Use_memory_on_video_card_as_swap Archived Gentoo Wiki articles. Note the warnings.]
*[http://en.gentoo-wiki.com/wiki/Using_Graphics_Card_Memory_as_Swap Gentoo Wiki]
+
* [http://www.linux-mtd.infradead.org MTD website]

Latest revision as of 14:17, 30 October 2016

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. This article primarily references a now archived article from Gentoo's wiki. (Discuss in Talk:Swap on video ram#)

Related articles

Article on utilizing video memory for system swap.

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.

Note: Using legacy AGP (Accelerated Graphics Bus) card may limit reads to approximately 8 MB per second. AGP bus has a limited amount of bus bandwidth.

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/modules-load.d/vramswap.conf
slram
mtdblock

systemd service:

# /usr/lib/systemd/system/vramswap.service
[Unit]
Description=Swap on Video RAM

[Service]
Type=oneshot
ExecStart=/usr/bin/bash -c "mkswap /dev/mtdblock0 && swapon /dev/mtdblock0 -p 10"
ExecStop=/usr/bin/bash -c "swapoff /dev/mtdblock0"
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

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.d/vramswap.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