LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware > Slackware - Installation
User Name
Password
Slackware - Installation This forum is for the discussion of installation issues with Slackware.

Notices

Reply
 
Search this Thread
Old 03-14-2014, 10:06 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,225

Rep: Reputation: 49
Swap partition against swap file: how much performance do I loose?


Hi: That's basically the question if another question can be "can linux be installed on a logical partition?". The partitioning scheme is that with absolute sector 0 being the MBR, also called boot sector in Linux, for short,that found in old IMB PC desktops. I once dedicated a logical partition to an O.S. but don't remember which one.

EDIT: I assume that in the absence of a swap partition Linux transparently uses some space in the filesystem. I mean, without operator intervention. Am I right?

Last edited by stf92; 03-14-2014 at 10:12 PM.
 
Old 03-14-2014, 10:41 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,445

Rep: Reputation: 1068Reputation: 1068Reputation: 1068Reputation: 1068Reputation: 1068Reputation: 1068Reputation: 1068Reputation: 1068
Linux can be installed in a logical partition - I almost never use primary partition (on non-gpt disks)
Swap performance is unaffected by being partition or file based - used to be an issue in (early) 2.4 kernels, but no longer.
Swap must be allocated, and activated - by you.
 
1 members found this post helpful.
Old 03-14-2014, 11:24 PM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,225

Original Poster
Rep: Reputation: 49
That's fine! I had the swap complex.

Last edited by stf92; 03-14-2014 at 11:43 PM.
 
Old 03-15-2014, 02:22 PM   #4
gengisdave
Member
 
Registered: Dec 2013
Location: Turin, Italy
Distribution: slackware
Posts: 287

Rep: Reputation: 59
doesn't a swapfile involve filesystem routines (e.g jbd2 on ext4)? isn't a swap partition faster as it's more simple? i can't answer them without a deep studies about
 
Old 03-15-2014, 03:20 PM   #5
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,225

Original Poster
Rep: Reputation: 49
gengisdave, if you use dd to make it, it certainly does. But just after running mkswap, it is a mare collection of sectors with no organization at all (it is not ext4, not cramfs not nothing). mkswap just destroys this organization, and makes it imposible for your filesystem to allocate it for its use.

The kernel is just passing the controller sector numbers. An increase in complexity because now the kernel must know where the sectors are? He must know it all the same for access to a swap partition.

Last edited by stf92; 03-15-2014 at 03:31 PM.
 
Old 03-15-2014, 03:31 PM   #6
gengisdave
Member
 
Registered: Dec 2013
Location: Turin, Italy
Distribution: slackware
Posts: 287

Rep: Reputation: 59
if i write an amount of memory on my swapfile, it'll be handled by swap routines, in a simple way like the physical RAM; but the "physic" swapfile it's on a partition which has a filesystem, and this write event will be handled as any other file write; swap partition doesn't have this, but it's more difficult change its size; third way to handle swap is making a tmpfs on RAM
 
Old 03-15-2014, 03:45 PM   #7
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,225

Original Poster
Rep: Reputation: 49
If you do 'file <the swap file>' you'll read plenty of output. So it has some organization after all! True, but for the kernel it only matters at boot time (it is only a little header). Once it has got the file location in the filesystem, it has the disk absolute first sector number of the swap file. From now all, the kernel does not care for filesystem structure.

Last edited by stf92; 03-15-2014 at 04:16 PM.
 
Old 03-15-2014, 03:49 PM   #8
gengisdave
Member
 
Registered: Dec 2013
Location: Turin, Italy
Distribution: slackware
Posts: 287

Rep: Reputation: 59
absolutely true, but how the swapfile is written on the disk? think about if your swapfile is on a remote filesystem
 
Old 03-15-2014, 04:24 PM   #9
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,225

Original Poster
Rep: Reputation: 49
Quote:
Originally Posted by gengisdave View Post
absolutely true, but how the swapfile is written on the disk? think about if your swapfile is on a remote filesystem
I'm not a specialist on the matter, I'll tell you. Do not think of it as a file. You see it as such, and so does the filesystem. But not the kernel. It's not a mystery. How does fdisk deal with the hard disk. Does it look for filesystems? How does it write the disk. Think of it.

Last edited by stf92; 03-15-2014 at 06:56 PM.
 
Old 03-15-2014, 05:31 PM   #10
gengisdave
Member
 
Registered: Dec 2013
Location: Turin, Italy
Distribution: slackware
Posts: 287

Rep: Reputation: 59
Code:
# swapon -s
Filename                                Type            Size    Used    Priority
/dev/sda6                               partition       4194300 32      -1

# dd if=/dev/zero of=swapfile count=512K
524288+0 record dentro
524288+0 record fuori
268435456 byte (268 MB) copiati, 5,59883 s, 47,9 MB/s

# file swapfile
swapfile: data

# mkswap swapfile
Setting up swapspace version 1, size = 262140 KiB
nessuna etichetta, UUID=53175caf-cacf-4002-96e8-9520a1ac311e

# file swapfile
swapfile: Linux/i386 swap file (new style), version 1 (4K pages), size 65535 pages, no label, UUID=53175caf-cacf-4002-96e8-9520a1ac311e

# swapon -a swapfile

# swapon -s
Filename                                Type            Size    Used    Priority
/dev/sda6                               partition       4194300 32      -1
/mnt/archivio/work/swapfile             file            262140  0       -2
i added a little swap to my system; swapfile is located on a ext4 filesystem (/mnt/archivio);

when kernel need to write/read on swapfile, it does like he knows, there are no differences how he access on swapfile or /dev/sda6 (my swap partition); how data are physically written on disk on both swap area?

partition case: is a swap partition, no filesystem, just direct access, "swap manager" asks "disk manager" to write on the disk;

file case: "swap manager" wants to write some sectors, but these sectors belongs to a file in an ext4 filesystem, so the write system call is handled by the "ext4 file manager" who calls the "disk manager" to write the sectors;

what's best? partition or file? the difference is in performance of ext4 fs (in that case); on a modern system there should be no difference (almost), and a swap file is easier to resize, while a partition is a nightmare

everything that happens in an operating system should be seen in layers, processes don't know what's outside of their area

i know it's not an easy subject and i beg your pardon, but my english is getting worse

Last edited by gengisdave; 03-15-2014 at 05:32 PM.
 
Old 03-15-2014, 06:04 PM   #11
273
Senior Member
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 3,508

Rep: Reputation: 800Reputation: 800Reputation: 800Reputation: 800Reputation: 800Reputation: 800Reputation: 800
Quote:
Originally Posted by gengisdave View Post
file case: "swap manager" wants to write some sectors, but these sectors belongs to a file in an ext4 filesystem, so the write system call is handled by the "ext4 file manager" who calls the "disk manager" to write the sectors;

what's best? partition or file? the difference is in performance of ext4 fs (in that case); on a modern system there should be no difference (almost), and a swap file is easier to resize, while a partition is a nightmare
As I understand it the kernel does not access the swap file using the file system but does so directly using low level system calls (likely the ones the file system itself uses). This man page seems to back that up:
http://man7.org/linux/man-pages/man8/swapon.8.html
Pay attention to the notes section where it is noted that btrfs and swap files do not mix:
Quote:
swapon may not work correctly when using a swap file with some
versions of btrfs. This is due to the swap file implementation in
the kernel expecting to be able to write to the file directly,
without the assistance of the file system.
 
Old 03-15-2014, 06:18 PM   #12
gengisdave
Member
 
Registered: Dec 2013
Location: Turin, Italy
Distribution: slackware
Posts: 287

Rep: Reputation: 59
theory and application: newer kernel (at least 2.6+) have direct access to write swapfile on the disk, so there are no differences between swap file and swap partitions; all i said belongs to history
 
Old 03-15-2014, 06:48 PM   #13
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,225

Original Poster
Rep: Reputation: 49
On the contrary. Things yesterday were done directly, today by infinitely indirect methods. Think of USB instead of RS-232. Machine code was handwritten until the appearance of the first assemblers. Today the process is usually much more complicated. Programs wrote directly to devices, today we have stacks of drivers doing that. And in the 1980's, there directly were no swap disks. Because the concept of virtual memory had not yet been born

Disk swapping is all about virtual memory management, which is a method by which a program seems to have lots of RAM though the real RAM is limited. A processor with 30 address lines can access 2**30 memory locations (1 GB). But a hard disk can hold many time that amount of data. Virtual memory takes advantage of that fact and of the large speed of modern disk drives.

Last edited by stf92; 03-15-2014 at 06:52 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Would a Linux swap partition work as a FreeBSD swap partition? Froggy192 *BSD 11 07-27-2013 03:06 PM
swap file vs. swap partition verndog Ubuntu 16 07-09-2012 09:49 PM
Swap Partition Ruining PC Performance? FredJones Linux - Desktop 34 02-22-2012 09:43 AM
swap file or swap partition? What is better? zemir Linux - Newbie 28 08-19-2011 10:15 PM
Can swap file or a swap partition be mounted and read? Mr-Bisquit Linux - General 3 06-08-2009 03:16 PM


All times are GMT -5. The time now is 10:27 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration