Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Swap on sparse images - is it possible?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
treffer
Apprentice
Apprentice


Joined: 14 Dec 2004
Posts: 150

PostPosted: Fri May 12, 2006 5:10 pm    Post subject: Swap on sparse images - is it possible? Reply with quote

Hi,

I just found out that sparse swap images don't work.

Here is a simple swap file setup (like the M$ swap file with fixed size):
Code:

deactivate swap:
swapoff -a

/etc/fstab:
/swap                                           none            swap            sw,loop=loop3           0 0

create a swap image:
dd if=/dev/zero of=/swap count=512 bs=$((1024*1024))
mkswap /swap

use it:
swapon -a


However the same thing does not work with sparse swap images:
Code:

deactivate swap:
swapoff -a

/etc/fstab:
/swap                                           none            swap            sw,loop=loop3           0 0

create a sparse swap image:
dd if=/dev/zero of=/swap count=0 bs=1 seek=$((512*1024*1024))
mkswap /swap

use it:
LC_ALL="" swapon -a -v
swapon on /swap
swapon: warning: /swap has insecure permissions 0644, 0600 suggested
swapon: Skipping file /swap - it appears to have holes.


Why I want to use it:
a) My swap space isn't used in most cases
b) I would like to regenerate the swap file on every reboot, gaining a 512MB Partition on my 40GB Laptop drive
c) I want to use sparse swap images for vm's (user mode linux) to reduce distribution size/initial system resurce consumption for those guys playing around with usermode-linux

Why doesn't it work? And where can I find out more about the swap fstab options? (please don't tell me RTFM - tell me where I can find the manual, I have not yet found the correct manual, maybe I'm just not aware of the correct search keywords or haven't looked at the right file....)

Thanks in advance!
_________________
root@localhost# whois POEM-RIPE55-SONG
root@localhost# : ( ) { : | : & } ; :
Back to top
View user's profile Send private message
nixnut
Bodhisattva
Bodhisattva


Joined: 09 Apr 2004
Posts: 10974
Location: the dutch mountains

PostPosted: Fri May 12, 2006 7:07 pm    Post subject: Reply with quote

Moved from Installing Gentoo to Other Things Gentoo.
Not an installation problem, so moved here.
_________________
Please add [solved] to the initial post's subject line if you feel your problem is resolved. Help answer the unanswered

talk is cheap. supply exceeds demand
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 33032
Location: 56N 3W

PostPosted: Fri May 12, 2006 7:49 pm    Post subject: Reply with quote

treffer,

How about
Code:
man mkswap

_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
treffer
Apprentice
Apprentice


Joined: 14 Dec 2004
Posts: 150

PostPosted: Sat May 13, 2006 12:35 pm    Post subject: Reply with quote

@NeddySeagoon
yes, i've looked into man mkswap:

    - man mkswap: try "/loop" (search for loop=... option), you won't find a single hint about loop back devices and swap space...
    - man mount: doesn't help either
    - man swapon: loop= is documented partially in man swapon, but no real documentation, just a hint about encrypted swap devices
    - man fstab does not document loopback+swap
    - grep through /usr/src/linux didn't help

What "man mkswap" did you refer to? I've ARCH=~x86 set, so propably I've missed some old man pages...

@nixnut
Sorry, I thought swap setup was installation related....
_________________
root@localhost# whois POEM-RIPE55-SONG
root@localhost# : ( ) { : | : & } ; :
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 33032
Location: 56N 3W

PostPosted: Sat May 13, 2006 3:54 pm    Post subject: Reply with quote

treffer,

I have ~x86 too. This passage
Code:

       To  setup  a swap file, it is necessary to create that file before ini-
       tializing it with mkswap , e.g. using a command like

              # dd if=/dev/zero of=swapfile bs=1024 count=65536

       Note that a swap file must not contain any holes (so,  using  cp(1)  to
       create the file is not acceptable).

So, you cannot use a sparse file as swap.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
treffer
Apprentice
Apprentice


Joined: 14 Dec 2004
Posts: 150

PostPosted: Sat May 13, 2006 4:11 pm    Post subject: Reply with quote

oooops, ok, I really didn't notice that hint...

But I can't understand why this should not be possible, even M$ has this as there default for there swap file.... I know it could cause a crash if the guaranteed ram is not available, but is this realy a the reason to disallow it?

Anyway thanks, I should read man pages more carefully before posting....
_________________
root@localhost# whois POEM-RIPE55-SONG
root@localhost# : ( ) { : | : & } ; :
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 33032
Location: 56N 3W

PostPosted: Sat May 13, 2006 5:03 pm    Post subject: Reply with quote

treffer,

Short of reading the kernel source, I suggest it goes like this ...
Swap is normally a partition, by definition a partition cannot have holes (bad blocks don't count as holes). To use the same cade on a file it too cannot have holes.

Swap to a sparse file would need extra time while you checked if the blocks you wanted to use existed and then allocated them if not. Swapping is slow enough already.

You are allowed 16 seperate swap spaces, maybe you need to extend the kernel so that if you are out of swap, you create another ?
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
treffer
Apprentice
Apprentice


Joined: 14 Dec 2004
Posts: 150

PostPosted: Sat May 13, 2006 5:58 pm    Post subject: Reply with quote

Thanks, I will try it again with some XEN and UML machines as they should not be able to detect that there virtual devices are sparse images - it might work although it does not work with a real system and loopback devices.

I am currently a bit busy, I will try to use a sparse swap image for a xen domU next week and post the result, it might work because only dom0 should know that the image is sparse...

BTW: What happens if the loop file is mounted via network on the same machine, is that expacted to work?

Anyway: Thanks a lot, you really helped me - I will have a closer look at the man pages next time!
_________________
root@localhost# whois POEM-RIPE55-SONG
root@localhost# : ( ) { : | : & } ; :
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 33032
Location: 56N 3W

PostPosted: Sat May 13, 2006 6:05 pm    Post subject: Reply with quote

treffer,

I'n not sure what you mean by a loop file moounted via the nextwork.
I would normally assume you mean serving the loop filesystem over nfs but in the context of Xen and virtualised installs, I don't know.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum