Swap file suggestion

Using applications, configuring, problems
Message
Author
superchook
Posts: 117
Joined: Mon 13 Mar 2006, 07:39
Location: Sydney, Australia

Swap file suggestion

#1 Post by superchook »

I was wondering if there was a way to run Puppy from a CD or USB stick _and_ have the benefit of a swap file without creating a new file on a "borrowed" computer. It occurred to me that if the computer in question normally runs Windows XP there will be a file C:\pagefile.sys that windows uses as a swap file. The default size of this file is 1.5xRAM. My idea is to mount the "C:\" drive which will probably be hda1 and run mkswap on pagefile.sys followed by swapon.

I have tried this idea on one computer and it booted back into XP all right when I had finished but I don't know if there might be problems with this idea that I have not struck yet. Does anyone on this list know enough about how Windows XP works to comment?

Sage
Posts: 5536
Joined: Tue 04 Oct 2005, 08:34
Location: GB

#2 Post by Sage »

Messing with 'doze needs bravery, some would say foolhardiness!
There are (at least) two easier solutions.
1. GPartED allows creation of a small swap partition tacked on the end of the drive.
2. Use a junk HD drive ~200-500Mb as a discrete swap drive.

Everitt
Posts: 331
Joined: Tue 19 Dec 2006, 21:59
Location: Leeds,UK or Birmingham, UK

#3 Post by Everitt »

In theory this should be fine. AFAIK the pagefile is tempory data. It contains 'pages', which in basic terms are address', giving the location of other data in RAM (Or possibly in the pagefile, if the system is low on memory). Either way, the file is only concerned with tempory infomation. When the machine is powered down the ram is cleared, so this infomation is totally useless once the machine has been power cycled. That means that it's ok for us to overwrite it just as much as we like.
If it worked once, then it should work fine time after time. The question really is wither Windoze can cope with booting to find it's swap file is 'corrupt' (has been formatted as an alien filesystem). If it coped once, it should cope again.

One thing I feel needs to be said. Be VERY careful with 'hibernated' machines. when a machine is hibernated the contents of the RAM is preserved, so overwriting the page file could lead no no end of errors. Potentially system file corruption too. Avoid!

Bruce B

#4 Post by Bruce B »

I wouldn't even mount an NTFS partition read/write on a borrowed computer, depending of course on how much you dislike the owner of the computer, combined with how little responsibility you intend take for any damage that may follow.

Everitt
Posts: 331
Joined: Tue 19 Dec 2006, 21:59
Location: Leeds,UK or Birmingham, UK

#5 Post by Everitt »

Bruce B wrote:I wouldn't even mount an NTFS partition read/write on a borrowed computer, depending of course on how much you dislike the owner of the computer, combined with how little responsibility you intend take for any damage that may follow.
Yeah, I wouldn't be all that happy either. Read only maybe...
Each to their own though.

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#6 Post by Flash »

Could you put a file in the Windows page file which is internally a Linux swap file? Windows would ignore such a file and overwrite it. Doesn't Puppy already do such a thing so that it can run from a Windows machine without formatting the HD for Linux?

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

Re: Swap file suggestion

#7 Post by BarryK »

superchook wrote:I was wondering if there was a way to run Puppy from a CD or USB stick _and_ have the benefit of a swap file without creating a new file on a "borrowed" computer. It occurred to me that if the computer in question normally runs Windows XP there will be a file C:\pagefile.sys that windows uses as a swap file. The default size of this file is 1.5xRAM. My idea is to mount the "C:" drive which will probably be hda1 and run mkswap on pagefile.sys followed by swapon.
GuestTwo suggested this a couple of years ago. He reported the same as you, that XP didn't mind finding a corrupted swap file. But, I never had the nerve to implement it. Sure would be convenient though.

Bruce B

#8 Post by Bruce B »

For information sake: When running Windows 9x I'd set it up for a static swap file size. Periodically, I'd run a DOS utility on it called ZAP, which would write zeros to the entire file.

It worked fine as a swap file even after being zeroed out. It could be for all intents the Windows swap file in nothing more than a file with no special characteristics. As for XP, I never took an interest in it.

User avatar
ecomoney
Posts: 2178
Joined: Fri 25 Nov 2005, 07:00
Location: Lincolnshire, England
Contact:

Swap File

#9 Post by ecomoney »

Since puppy makes such an excellent linux starter distro, it would be a greatif this were possible. Most people want to run xp but are so paranoid about changes to their system (rightly so!). If this system were implemented it would need heavy testing as one of puppy's great benefits is its ability to install itself without even booting into xp. This incedently is how I install in peopls houses ("frugal" install boot from cd). I dont even need to boot xp to install so I can say to them "When windows xp balks out, it was nothing to do with me, I diidnt even start it up. When it does puppy will still work though". What tends to happen is next time windows corrupts itself they dont bother re-installing :-)
Puppy Linux's [url=http://www.murga-linux.com/puppy/viewtopic.php?p=296352#296352]Mission[/url]

Sorry, my server is down atm!

Bruce B

Re: Swap File

#10 Post by Bruce B »

ecomoney,

I don't look at the subject at hand as much of an XP system change. My concern is how safe is it to write to NTFS, I tend to be a bit conservative in erroring in on the side of caution.

The reason for my concern is only because the Linux write to NTFS as a common thing to do is fairly new technology.

Bruce

PaulBx1
Posts: 2312
Joined: Sat 17 Jun 2006, 03:11
Location: Wyoming, USA

#11 Post by PaulBx1 »

Usually these machines are not short of disk space! Maybe the safest thing to do would be, in Windows, copy pagefile.sys to a file called pupswap.swp; then when you boot Puppy it will use it and you don't have to worry about messing with XP at all.

Better yet, often these machines have plenty of memory as well, so swap is not needed. If we had a "noswap" boot parameter we'd be able to avoid creating a swap file on that NTFS volume...

But then, the zdrv file gets copied there too so maybe we should just trust Puppy not to trash anything.

As always, don't use swap when you are running a heavy-encrypted pup_save.

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#12 Post by Flash »

There's a Wikipedia article on Virtual Memory that might be worth reading for deep background on the subject. It has lots of external links at the bottom of the article.

User avatar
ecomoney
Posts: 2178
Joined: Fri 25 Nov 2005, 07:00
Location: Lincolnshire, England
Contact:

Hi Bruce

#13 Post by ecomoney »

Hi Bruce, I know that writing to NTFS is a fairly new thing. I was of the impression (and Im certainly no expert) that the ntfs driver was was able to *reasonably* reliably write to a file that was already there (like the xp swap file), but it was creating new ones that caused it problems until recently.

I have recently changed the initrd.gz init script to create a swapfile on ntfs partitions as well as the other types. Am looking for an xp computer to test it on. Am I likely any luck?

P.S. Just an idea, would it be possible to create a swap file *inside* pup_save.2fs?
Puppy Linux's [url=http://www.murga-linux.com/puppy/viewtopic.php?p=296352#296352]Mission[/url]

Sorry, my server is down atm!

Bruce B

#14 Post by Bruce B »

ecomoney,

In thinking it through and noticing that I've never see a complaint on the forum that could trace to Linux messing up writes, such as installations on NTFS, there probably is nothing to worry about.

Except worry itself, which would be overcome upon seeing that it does work after several sessions, with no problems or errors.

Bruce

User avatar
Bluedogruns
Posts: 38
Joined: Wed 12 Sep 2007, 23:31

Hum

#15 Post by Bluedogruns »

Although I am new at Puppy, I've been playing with it a lot and have discovered a couple things testing other Linux distros on a small hard drive with my main Redmond Drive pulled from the machine.

I may be way off base here but sometimes new users have different ways to look at things because they are not totally informed yet and sometimes that can lead to discovery and sometimes that can lead to disaster. So take caution and please do not try what I am suggesting unless you are brave or know enough to know if this would work.

What I found as I think confirmed by Bruce B (think it was Bruce anyway) When I install any Linux distro to the drive when Puppy boots up it finds the swap file created by that distro and uses it. So here is what I am thinking. On ones personal machine at home even if you don't normally do a pupsave to the hard drive you could run Puppy once without your pupsave file flash drive and then shut down and let it do a save to the hard drive. When doing a pup save to the hard drive it does create a swap file, it did on mine anyway (I think) but it does not seem to do this when doing a pupsave to a flash drive.

Once you shut the machine down you could restart the computer with another os or maybe even Puppy and copy the swap file created on the hard drive to an empty flash drive. Then remove the other files Puppy created on the hard drive so you can go back to using your normal pup save file and not the new files on the hard drive.

Now when you go to the next borrowed computer you could insert your flash drive with the swap file on it and then boot Puppy from the cd or you main Puppy flash drive. When Puppy scans the hardware it should find this swap file and use it.

Please someone with experience comment on this and tell me if it is a pipe dream or if it may have any merit at all.

Thanks
Blue

Everitt
Posts: 331
Joined: Tue 19 Dec 2006, 21:59
Location: Leeds,UK or Birmingham, UK

#16 Post by Everitt »

That's a nice idea but, I'm afraid, a very bad one. :P
The problem is the flash memory has a very limited lifespan. This a time limit, it's a number of read/write operations. Swap is very IO (read/write) intensive, so putting a swap file or partition on a flash disk will soon lead to the disk failing.
So yes, it would be fantastic if we could do that, but it just isn't sensible, unless you like spending all your money on new flash disks :)

User avatar
Bluedogruns
Posts: 38
Joined: Wed 12 Sep 2007, 23:31

Flash Drive Life

#17 Post by Bluedogruns »

I do understand the life limits of a flash drive and I know using one as a swap file would reduce the life greatly. I do know some people that could care less (not me) how much money they spend and even if they had to replace the flash drive with the swap file once a month so long as fit their needs they would do it.

For limited use when there is no other choice would putting the swap on the flash work? Or if necessary how about using an external hard drive for the swap file in those rare cases when you need to.

Blue

Bruce B

#18 Post by Bruce B »

Some of the flash sticks are very cheap. I suppose the write limits are more on a per section of the stick, rather than for the stick. (Supposition only)

Use the swap file for a short while, rename it, then write another swap file so the same sections of the stick are not being constantly used.

User avatar
Bluedogruns
Posts: 38
Joined: Wed 12 Sep 2007, 23:31

Flash Drive Writes

#19 Post by Bluedogruns »

When I first started using flash drives several years ago 4 to be exact I read the details on how my drive worked from either the manufacturer site or the manual which you once got way back when got in the package with the drive, this is when they still supplied W98 driver cd with the flash drive.

Anyway in that reading I learned that the PNY Brand not sure the others are this way are programed not to use the same portion of the memory all of the time. My understanding is each time you write to the drive it writes to a new place so that all of the space will get evenly used so that it does not destroy a portion of the drive be writing to the same place over and over.

Since it is actually memory and not sectors on a hard drive the fragmentation is not such an issue, that is why they do this.

My first drives purchased 4 years ago are used as temporary backup drives. Every day I write and erase and overwrite files to those drives. Have done so for 4 years. At the end of each month when make a complete total hard drive backup I clear the flash drives. 4 years and still running. I think the paper stated each sector of the memory has either a 1,000,000 or 10,000,000 write erase cycle before it starts failing.

Blue

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#20 Post by Flash »

Thank you. Most people seem to avoid writing to a flash drive for fear of wearing it out. You are the first Puppy forum member I can remember who has reported the results of writing a lot to a flash drive. :)

The following is exerpted from this article.
Using a swap file(s) also allows you to share swap space with other
OSes as described in the Linux Swap Space Mini-HOWTO [3] and on the
linux-kernel mailing list [4].

To use a file in a filesystem for swap space, choose the swap space
size that you want for this swap area (up to 2 GiB on x86) and then
enter (as described in 'man mkswap'):
dd bs=1024 count=1M if=/dev/zero of=/path/to/swapfile.n
This writes a 1 GiB file (1 MiB * 1024) to "/path/to/swapfile.n".
You can do this multiple times to use more swap files on large-memory
systems. Swap files cannot be sparse; they must be fully allocated
before using them.

In Linux 2.4 and earlier, swap files are less robust than swap
devices (partitions) because of the need to read metadata from the
filesystem for swap files, making them prone to OOM deadlocks when
allocating pages and buffer_heads to use in swapping.
This has changed in Linux 2.5. Using a swap file has no disadvantage
compared to swapping to a device (partition). The kernel doesn't
need to allocate any memory to get a swapcache page to disk.

This is interesting because swap files are much easier to administer
(add, remove, resize) and easier to stripe. It is now feasible
(in the Linux 2.5.40 timeframe) to eliminate swap devices (partitions)
completely and not be penalized in performance.

But really, if your application is dependent on swap performance, you
need more RAM. Swap should be viewed as a lightweight background
optimization to make unused pages available for other work, rather
than as a cure for an underprovisioned machine.

Swap devices (partitions) can also be used for "software suspend"
(swsusp) in Linux 2.5 and as a destination for saving a kernel crash
dump in versions of Linux which support these features.


3. Swap-Space, Linux Swap Space Mini-HOWTO. Updated: July 2002.
How to share your Linux swap partition with Windows.
URL:: http://www.tldp.org/HOWTO/mini/Swap-Space.html
4. URL:: http://marc.theaimsgroup.com/?l=linux-k ... 324081&w=2
Last edited by Flash on Sun 23 Sep 2007, 15:39, edited 1 time in total.

Post Reply