Swap on SSD

57 views
Skip to first unread message

@lbutlr

unread,
Feb 4, 2018, 8:16:59 AM2/4/18
to Freebsd Questions
I have a machine that has dual SSDs in it and no spinning disks. FreeBSD has a 4GB (or so) swap partition that it created on the installation of FreeBSD 11.1.

Isn't this going to cause problems for the SSD to have swap constantly working the drive?


_______________________________________________
freebsd-...@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questi...@freebsd.org"

Ralf Mardorf via freebsd-questions

unread,
Feb 4, 2018, 11:57:45 AM2/4/18
to freebsd-...@freebsd.org
On Sun, 4 Feb 2018 04:19:25 -0700, @lbutlr wrote:
>Isn't this going to cause problems for the SSD to have swap constantly
>working the drive?

Assuming that swap is constantly needed, why should this be a problem?
However, why is swap constantly used at all?

Manish Jain

unread,
Feb 4, 2018, 11:58:00 AM2/4/18
to @lbutlr, Freebsd Questions
On 02/04/18 16:49, @lbutlr wrote:
> I have a machine that has dual SSDs in it and no spinning disks. FreeBSD has a 4GB (or so) swap partition that it created on the installation of FreeBSD 11.1.
>
> Isn't this going to cause problems for the SSD to have swap constantly working the drive?
I have a 1 GB swap partition on an SSD under my FreeBSD box (shared with
Linux as swap). I have never had any issue with swapping under FreeBSD
or Linux.

--
Regards,
Manish Jain

John Levine

unread,
Feb 4, 2018, 12:53:03 PM2/4/18
to freebsd-...@freebsd.org, jude.o...@yandex.com
In article <d84a4c7e-f311-3d13...@yandex.com> you write:
>On 02/04/18 16:49, @lbutlr wrote:
>> I have a machine that has dual SSDs in it and no spinning disks. FreeBSD has a 4GB (or so) swap partition that it created on the installation of FreeBSD 11.1.
>>
>> Isn't this going to cause problems for the SSD to have swap constantly working the drive?

In my experience FreeBSD hardly swaps at all unless it's horribly
overloaded. Remember that the only page frames that get written to
swap are ones that don't have a home somewhere else. A large amount
of any process image is program and data mapped in from disk files,
and they don't get swapped, they just get deleted from memory and
reloaded from the disk if needed.

Do a "systat -vm" and you'll see how much swapping your system is doing.

Erich Dollansky

unread,
Feb 4, 2018, 2:47:00 PM2/4/18
to @lbutlr, Freebsd Questions
Hi,

On Sun, 4 Feb 2018 04:19:25 -0700
"@lbutlr" <kre...@kreme.com> wrote:

> I have a machine that has dual SSDs in it and no spinning disks.
> FreeBSD has a 4GB (or so) swap partition that it created on the
> installation of FreeBSD 11.1.
>
> Isn't this going to cause problems for the SSD to have swap
> constantly working the drive?
>
it depends on the amount of RAM the machine has. In case of, you just
need more RAM.

Erich

Steve O'Hara-Smith

unread,
Feb 5, 2018, 6:50:16 AM2/5/18
to freebsd-...@freebsd.org
On Sun, 4 Feb 2018 04:19:25 -0700
"@lbutlr" <kre...@kreme.com> wrote:

> I have a machine that has dual SSDs in it and no spinning disks. FreeBSD
> has a 4GB (or so) swap partition that it created on the installation of
> FreeBSD 11.1.
>
> Isn't this going to cause problems for the SSD to have swap constantly
> working the drive?

If swap activity is constantly working the drive then you have a
problem (add RAM or reduce workload) anyway. With an SSD the performance
problem will be less painful than with a hard disc so for a system that is
well sized to its load an SSD is a great solution for swap, rarely used but
fast when needed.

--
Steve O'Hara-Smith <st...@sohara.org>

Frank Leonhardt

unread,
Feb 5, 2018, 11:14:39 AM2/5/18
to freebsd-...@freebsd.org
On 2018-02-04 11:19, @lbutlr wrote:
> I have a machine that has dual SSDs in it and no spinning disks.
> FreeBSD has a 4GB (or so) swap partition that it created on the
> installation of FreeBSD 11.1.
>
> Isn't this going to cause problems for the SSD to have swap constantly
> working the drive?

Assuming you have enough RAM, I'd turn it off. "swapoff -a" if you can't
wait and edit fstab if don't mind a reboot.

You could use gpart to return it to normal use.

But there's more to it than that. And all SSDs are definitely NOT
created equal. Some cost 10x as much as others and are designed to be
pounded. Others are cheap and expect to be treated gently. If you're
using an enterprise SSD it probably won't matter, but you'd probably
know it if you were.

FreeBSD doesn't actually swap these days; uses demand paging. This means
that blocks of RAM that are hardly ever used can get copied to disk.
This may include some stuff that's only accessed a few times a year, but
would otherwise be occupying precious RAM that would be much more useful
as a disk cache. That said, FreeBSD tends not to page out except as a
last resort - probably a mistake but I can't prove it.

It's perfectly feasible to run with no swap. I sometimes think the
gradual slow-down due to lack of caching/buffer space is preferable to a
thousand page-faults/second.

But what works for you depends on the workload and available RAM.

LuKreme

unread,
Feb 5, 2018, 12:55:53 PM2/5/18
to freebsd-...@freebsd.org
On Feb 5, 2018, at 09:13, Frank Leonhardt <fra...@fjl.co.uk> wrote:
> FreeBSD doesn't actually swap these days; uses demand paging. This means that blocks of RAM that are hardly ever used can get copied to disk. This may include some stuff that's only accessed a few times a year, but would otherwise be occupying precious RAM that would be much more useful as a disk cache. That said, FreeBSD tends not to page out except as a last resort - probably a mistake but I can't prove it.

Thanks, this is what I didn't know because I know it use to swap a lot, even if RAM was available (albeit, that may behave been v4...).

I think I'll leave it for now, the machine has 8 times as much RAM as the one it replaced and is doing less, so I really shouldn't have any issues. The previous machine was setup to use a swap file instead of a partition.

--
This is my signature. There are many like it, but this one is mine.

Robert Huff

unread,
Feb 5, 2018, 1:57:02 PM2/5/18
to Frank Leonhardt, freebsd-...@freebsd.org

Frank Leonhardt writes:

> FreeBSD doesn't actually swap these days; uses demand paging.

Possible evidence to the contrary:
On a system running:

FreeBSD 12.0-CURRENT #0 r326723: Sat Dec 9 12:30:04 EST 2017 amd64

top shows:

last pid: 57956; load averages: 2.02, 2.01, 1.95 up 57+19:09:04 13:49:29
132 processes: 3 running, 129 sleeping
CPU: 38.7% user, 0.4% nice, 7.9% system, 0.0% interrupt, 53.0% idle
Mem: 2264M Active, 2303M Inact, 1478M Laundry, 1525M Wired, 761M Buf, 115M Free
Swap: 17G Total, 996M Used, 16G Free, 5% Inuse

So ... is "Swap" an incorrect label, or is actual swapping
going on?
(And is there a utility which will list the swap area by owning
process?)


Respectfully,


Robert Huff

John R. Levine

unread,
Feb 5, 2018, 3:09:37 PM2/5/18
to freebsd-...@freebsd.org
In article <24BAEBB4-FAA7-47C8...@kreme.com>, LuKreme <kre...@kreme.com> wrote:
>On Feb 5, 2018, at 09:13, Frank Leonhardt <fra...@fjl.co.uk> wrote:
>> FreeBSD doesn't actually swap these days; uses demand paging. This means that blocks of RAM that are hardly ever used can get
>copied to disk. This may include some stuff that's only accessed a few times a year, but would otherwise be occupying precious
>RAM that would be much more useful as a disk cache. That said, FreeBSD tends not to page out except as a last resort - probably a
>mistake but I can't prove it.

That's right. The swap space is where it pages stuff that doesn't have a
home anywhere else. A great deal of what's in memory is a copy of
something on the disk, so if it's paged out, it goes back to the disk, or
it's just deleted in the common case that it hasn't changed since being
read in.

Unless your system is trying to do something that wants a lot more R/W
address space than is physically available, the system doesn't write much
to the swap space.

On one of my BSD cloud virtual machines I have a server process that
slurps in about a gigabyte of stuff into a very large perl table, then
sits there and answers queries from that table. The system swaps like
crazy for a few seconds while it's loading up the table, then quiets down
and reads a few pages a second from the swap as the queries come in.
That's about the worst case, and only becasue I'm a cheapskate and don't
want to pay for a larger VM where everything would fit in RAM.

--
Regards,
John Levine, jo...@iecc.com, Primary Perpetrator of "The Internet for Dummies",
Please consider the environment before reading this e-mail. https://jl.ly

Trond Endrestøl

unread,
Feb 6, 2018, 3:06:13 AM2/6/18
to FreeBSD questions
On Mon, 5 Feb 2018 13:53-0500, Robert Huff wrote:

> last pid: 57956; load averages: 2.02, 2.01, 1.95 up 57+19:09:04 13:49:29
> 132 processes: 3 running, 129 sleeping
> CPU: 38.7% user, 0.4% nice, 7.9% system, 0.0% interrupt, 53.0% idle
> Mem: 2264M Active, 2303M Inact, 1478M Laundry, 1525M Wired, 761M Buf, 115M Free
> Swap: 17G Total, 996M Used, 16G Free, 5% Inuse
>
> So ... is "Swap" an incorrect label, or is actual swapping
> going on?
> (And is there a utility which will list the swap area by owning
> process?)

Try hitting the w key while running top. Then hit the o key and type
in swap. Hit the enter key and the display should now be sorted by the
most swappy processes. If you read the commit log for top, you'll
notice the VM subsystem doesn't really track swap usage, so the
presented values are only an estimate.

--
Trond.

Erich Dollansky

unread,
Feb 6, 2018, 4:40:41 AM2/6/18
to Robert Huff, Frank Leonhardt, freebsd-...@freebsd.org
Hi,

On Mon, 5 Feb 2018 13:53:07 -0500
Robert Huff <rober...@rcn.com> wrote:

> Frank Leonhardt writes:
>
> > FreeBSD doesn't actually swap these days; uses demand paging.
>
> Possible evidence to the contrary:
> On a system running:
>
> FreeBSD 12.0-CURRENT #0 r326723: Sat Dec 9 12:30:04 EST 2017 amd64
>
> top shows:
>
> last pid: 57956; load averages: 2.02, 2.01, 1.95 up
> 57+19:09:04 13:49:29 132 processes: 3 running, 129 sleeping
> CPU: 38.7% user, 0.4% nice, 7.9% system, 0.0% interrupt, 53.0% idle
> Mem: 2264M Active, 2303M Inact, 1478M Laundry, 1525M Wired, 761M Buf,
> 115M Free Swap: 17G Total, 996M Used, 16G Free, 5% Inuse
>
> So ... is "Swap" an incorrect label, or is actual swapping
> going on?
> (And is there a utility which will list the swap area by
> owning process?)
>
I have the same when putting to much load on my old machine. It is just
a matter of RAM.

Either you spend the money on RAM or on SSD.

Erich

Doug Hardie

unread,
Feb 6, 2018, 2:21:23 PM2/6/18
to Trond Endrestøl, FreeBSD questions

> On 6 February 2018, at 00:04, Trond Endrestøl <Trond.E...@fagskolen.gjovik.no> wrote:
>
> On Mon, 5 Feb 2018 13:53-0500, Robert Huff wrote:
>
>> last pid: 57956; load averages: 2.02, 2.01, 1.95 up 57+19:09:04 13:49:29
>> 132 processes: 3 running, 129 sleeping
>> CPU: 38.7% user, 0.4% nice, 7.9% system, 0.0% interrupt, 53.0% idle
>> Mem: 2264M Active, 2303M Inact, 1478M Laundry, 1525M Wired, 761M Buf, 115M Free
>> Swap: 17G Total, 996M Used, 16G Free, 5% Inuse
>>
>> So ... is "Swap" an incorrect label, or is actual swapping
>> going on?
>> (And is there a utility which will list the swap area by owning
>> process?)
>
> Try hitting the w key while running top. Then hit the o key and type
> in swap. Hit the enter key and the display should now be sorted by the
> most swappy processes. If you read the commit log for top, you'll
> notice the VM subsystem doesn't really track swap usage, so the
> presented values are only an estimate.

What system version does that work on? Running 11.1-RELEASE, I get "Command not understood" for both of those.

-- Doug

John Levine

unread,
Feb 6, 2018, 5:46:54 PM2/6/18
to freebsd-...@freebsd.org
In article <CEE525EA-F22A-4D50...@mail.sermon-archive.info> you write:
>> Try hitting the w key while running top. Then hit the o key and type
>> in swap. Hit the enter key and the display should now be sorted by the
>> most swappy processes. If you read the commit log for top, you'll
>> notice the VM subsystem doesn't really track swap usage, so the
>> presented values are only an estimate.
>
>What system version does that work on? Running 11.1-RELEASE, I get "Command not understood" for both of those.

Works fine for me on 11.1, not in 10.4. The swap info seems to be new in version 11.

rober...@rcn.com

unread,
Feb 6, 2018, 10:53:32 PM2/6/18
to Erich Dollansky, freebsd-...@freebsd.org
Erich Dollansky writes:

> > So ... is "Swap" an incorrect label, or is actual swapping
> > going on?
>
> I have the same when putting to much load on my old machine.
> It is just a matter of RAM.
>
> Either you spend the money on RAM or on SSD.

I'm not complaining, and that machine is maxed out.
I'm trying to determine whether one of my principal diagnostic tools is mis-labeling information.


Respectfully,

Robert Huff

Erich Dollansky

unread,
Feb 6, 2018, 11:43:56 PM2/6/18
to rober...@rcn.com, freebsd-...@freebsd.org
Hi,

On Tue, 6 Feb 2018 22:52:06 -0500 (EST)
rober...@rcn.com wrote:

> Erich Dollansky writes:
>
> > > So ... is "Swap" an incorrect label, or is actual
> > > swapping going on?
> >
> > I have the same when putting to much load on my old machine.
> > It is just a matter of RAM.
> >
> > Either you spend the money on RAM or on SSD.
>
> I'm not complaining, and that machine is maxed out.
> I'm trying to determine whether one of my principal
> diagnostic tools is mis-labeling information.

ok, then everything is as expected.

Erich

Trond Endrestøl

unread,
Feb 7, 2018, 3:07:50 AM2/7/18
to FreeBSD questions
On Tue, 6 Feb 2018 11:12-0800, Doug Hardie wrote:

> > On 6 February 2018, at 00:04, Trond Endrestøl <Trond.E...@fagskolen.gjovik.no> wrote:
> >
> > On Mon, 5 Feb 2018 13:53-0500, Robert Huff wrote:
> >
> >> last pid: 57956; load averages: 2.02, 2.01, 1.95 up 57+19:09:04 13:49:29
> >> 132 processes: 3 running, 129 sleeping
> >> CPU: 38.7% user, 0.4% nice, 7.9% system, 0.0% interrupt, 53.0% idle
> >> Mem: 2264M Active, 2303M Inact, 1478M Laundry, 1525M Wired, 761M Buf, 115M Free
> >> Swap: 17G Total, 996M Used, 16G Free, 5% Inuse
> >>
> >> So ... is "Swap" an incorrect label, or is actual swapping
> >> going on?
> >> (And is there a utility which will list the swap area by owning
> >> process?)
> >
> > Try hitting the w key while running top. Then hit the o key and type
> > in swap. Hit the enter key and the display should now be sorted by the
> > most swappy processes. If you read the commit log for top, you'll
> > notice the VM subsystem doesn't really track swap usage, so the
> > presented values are only an estimate.
>
> What system version does that work on? Running 11.1-RELEASE, I get "Command not understood" for both of those.

It's available in base/head and base/stable/11. It will not be present
in releases until 11.2-RELEASE. I don't know the status for
10.4-RELEASE. I only run 11.1-STABLE and occasionally 12.0-CURRENT on
my systems.

--
Trond.

Frank Leonhardt

unread,
Feb 7, 2018, 10:02:31 AM2/7/18
to Robert Huff, freebsd-...@freebsd.org
On 2018-02-05 18:53, Robert Huff wrote:
> Frank Leonhardt writes:
>
>> FreeBSD doesn't actually swap these days; uses demand paging.
>
> Possible evidence to the contrary:
> On a system running:
>
> FreeBSD 12.0-CURRENT #0 r326723: Sat Dec 9 12:30:04 EST 2017 amd64
>
> top shows:
>
> last pid: 57956; load averages: 2.02, 2.01, 1.95 up 57+19:09:04
> 13:49:29
> 132 processes: 3 running, 129 sleeping
> CPU: 38.7% user, 0.4% nice, 7.9% system, 0.0% interrupt, 53.0% idle
> Mem: 2264M Active, 2303M Inact, 1478M Laundry, 1525M Wired, 761M Buf,
> 115M Free
> Swap: 17G Total, 996M Used, 16G Free, 5% Inuse
>
> So ... is "Swap" an incorrect label, or is actual swapping
> going on?

Yes, it's an incorrect label.

Frank Leonhardt

unread,
Feb 7, 2018, 10:19:40 AM2/7/18
to freebsd-...@freebsd.org
On 2018-02-05 20:08, John R. Levine wrote:
> In article <24BAEBB4-FAA7-47C8...@kreme.com>, LuKreme
> <kre...@kreme.com> wrote:
>> On Feb 5, 2018, at 09:13, Frank Leonhardt <fra...@fjl.co.uk> wrote:
>>> FreeBSD doesn't actually swap these days; uses demand paging. This
>>> means that blocks of RAM that are hardly ever used can get
>> copied to disk. This may include some stuff that's only accessed a few
>> times a year, but would otherwise be occupying precious
>> RAM that would be much more useful as a disk cache. That said, FreeBSD
>> tends not to page out except as a last resort - probably a
>> mistake but I can't prove it.
>
<snip>

> On one of my BSD cloud virtual machines I have a server process that
> slurps in about a gigabyte of stuff into a very large perl table, then
> sits there and answers queries from that table. The system swaps like
> crazy for a few seconds while it's loading up the table, then quiets
> down and reads a few pages a second from the swap as the queries come
> in. That's about the worst case, and only becasue I'm a cheapskate and
> don't want to pay for a larger VM where everything would fit in RAM.

On a VM you have no idea whether anything is on disk or in RAM - chances
are in this case your swap partition is in the hypervisor's disk cache.

---------------

There seems to be some confusion on this list about swapping and paging.
Swapping is old hat. Basically when doing a context swap you wrote a
non-running process to a swap area to free up RAM space. We don't do
that anymore - we use demand paged virtual memory. All processes
potentially remain resident, but some of their memory map may be paged
out to disk to free up RAM. If the process tries to access such a page
the MMU interrupts the kernel, which loads in the missing page and uses
the MMU to put it back in the process space at the right location before
returning control.

I'm not being pedantic here - the difference between swapped and paged
systems is very significant if you're optimising disk/RAM usage.

Swap areas have been replaced by page areas on disk, but the name stuck.
A bit like core store - I haven't used core store since the 1980's but
we still have "core dumps". Youngsters in the office look at me oddly
when I use terms like core and DASD...

Arthur Chance

unread,
Feb 7, 2018, 1:35:35 PM2/7/18
to Frank Leonhardt, Robert Huff, freebsd-...@freebsd.org
On 07/02/2018 15:01, Frank Leonhardt wrote:
> On 2018-02-05 18:53, Robert Huff wrote:
>> Frank Leonhardt writes:
>>
>>>  FreeBSD doesn't actually swap these days; uses demand paging.
>>
>>     Possible evidence to the contrary:
>>     On a system running:
>>
>> FreeBSD 12.0-CURRENT #0 r326723: Sat Dec  9 12:30:04 EST 2017 amd64
>>
>>     top shows:
>>
>> last pid: 57956;  load averages:  2.02,  2.01,  1.95   up 57+19:09:04 
>> 13:49:29
>> 132 processes: 3 running, 129 sleeping
>> CPU: 38.7% user,  0.4% nice,  7.9% system,  0.0% interrupt, 53.0% idle
>> Mem: 2264M Active, 2303M Inact, 1478M Laundry, 1525M Wired, 761M Buf,
>> 115M Free
>> Swap: 17G Total, 996M Used, 16G Free, 5% Inuse
>>
>>     So ... is "Swap" an incorrect label, or is actual swapping
>> going on?
>
> Yes, it's an incorrect label.

Pretty much like referring to SSD storage as "disk" when it's all
rectangular slabs. The historical name lingers on long after the
technology becomes obsolete.

--
An amusing coincidence: log2(58) = 5.858 (to 0.0003% accuracy).

Christian Weisgerber

unread,
Feb 7, 2018, 2:41:22 PM2/7/18
to freebsd-...@freebsd.org
On 2018-02-07, Frank Leonhardt <fra...@fjl.co.uk> wrote:

> There seems to be some confusion on this list about swapping and paging.
> Swapping is old hat. Basically when doing a context swap you wrote a
> non-running process to a swap area to free up RAM space. We don't do
> that anymore - we use demand paged virtual memory.

Demand paging was introduced in UNIX 32V and entered the BSD line
with 3BSD. That's around 1978-80, so almost forty years ago.

--
Christian "naddy" Weisgerber na...@mips.inka.de

LuKreme

unread,
Feb 8, 2018, 2:39:18 AM2/8/18
to freebsd-...@freebsd.org
On Feb 7, 2018, at 08:18, Frank Leonhardt <fra...@fjl.co.uk> wrote:
> Swap areas have been replaced by page areas on disk, but the name stuck.

Should the installer then be creating a dedicated swap partition? It seems not.

--
This is my signature. There are many like it, but this one is mine.


Steve O'Hara-Smith

unread,
Feb 8, 2018, 2:59:17 AM2/8/18
to freebsd-...@freebsd.org
On Thu, 8 Feb 2018 00:38:02 -0700
LuKreme <kre...@kreme.com> wrote:

> On Feb 7, 2018, at 08:18, Frank Leonhardt <fra...@fjl.co.uk> wrote:
> > Swap areas have been replaced by page areas on disk, but the name stuck.
>
> Should the installer then be creating a dedicated swap partition? It
> seems not.

Yes of course it should, it's the place where pages that aren't
backed by storage can be written to when needed.

--
Steve O'Hara-Smith <st...@sohara.org>

Frank Leonhardt

unread,
Feb 8, 2018, 12:50:36 PM2/8/18
to freebsd-...@freebsd.org
On 2018-02-07 19:38, Christian Weisgerber wrote:
> On 2018-02-07, Frank Leonhardt <fra...@fjl.co.uk> wrote:
>
>> There seems to be some confusion on this list about swapping and
>> paging.
>> Swapping is old hat. Basically when doing a context swap you wrote a
>> non-running process to a swap area to free up RAM space. We don't do
>> that anymore - we use demand paged virtual memory.
>
> Demand paging was introduced in UNIX 32V and entered the BSD line
> with 3BSD. That's around 1978-80, so almost forty years ago.

Yeah, but not everyone could afford an MMU until much later :-)

Did you ever run the UCSD P System? For some reason the keyboard driver
got swapped out (on to 8" Floppy) and every time you hit the keyboard
the drive went <CLUNK>.

Frank Leonhardt

unread,
Feb 8, 2018, 1:00:18 PM2/8/18
to freebsd-...@freebsd.org
On 2018-02-08 07:57, Steve O'Hara-Smith wrote:
> On Thu, 8 Feb 2018 00:38:02 -0700
> LuKreme <kre...@kreme.com> wrote:
>
>> On Feb 7, 2018, at 08:18, Frank Leonhardt <fra...@fjl.co.uk> wrote:
>> > Swap areas have been replaced by page areas on disk, but the name stuck.
>>
>> Should the installer then be creating a dedicated swap partition? It
>> seems not.
>
> Yes of course it should, it's the place where pages that aren't
> backed by storage can be written to when needed.

Possibly not as true today as it once was. You used to have a drive for
swapping and/or paging, not a partition. It could be small and fast
while the FS was on a large and slow drive. Using a partition instead of
a drive doesn't give the same advantage.

When it was swapping the variable length process could be written
sequentially to a slot on the swap file. Not so much with pages; they
get fragmented whatever you put them on (file or partition). At least
with a dedicated partition the head movements are short stroked - except
when they're interleaved with FS accesses because it's all the same head
anyway.

So why not use a page file instead? Or better still multiple page files
spread across all available physical disks?

Some people might not know that you can add and remove multiple paging
spaces even while the system is running. More here:

http://blog.frankleonhardt.com/2011/large-swap-files-on-freebsd-die-with-mystery-killed-howto-add-lots-of-swap-space/

Steve O'Hara-Smith

unread,
Feb 8, 2018, 3:01:01 PM2/8/18
to freebsd-...@freebsd.org
On Thu, 08 Feb 2018 17:58:59 +0000
Frank Leonhardt <fra...@fjl.co.uk> wrote:

> So why not use a page file instead? Or better still multiple page files
> spread across all available physical disks?

You don't want the overhead of going through a file system to get
to the swap pages, but having swap interleaved over all physical discs is a
good thing to do if you actually allow the swap to be used significantly.

--
Steve O'Hara-Smith <st...@sohara.org>

@lbutlr

unread,
Feb 8, 2018, 9:31:03 PM2/8/18
to Freebsd Questions
On 2018-02-08 (00:57 MST), Steve O'Hara-Smith <st...@sohara.org> wrote:
>
> On Thu, 8 Feb 2018 00:38:02 -0700
> LuKreme <kre...@kreme.com> wrote:
>
>> On Feb 7, 2018, at 08:18, Frank Leonhardt <fra...@fjl.co.uk> wrote:
>>> Swap areas have been replaced by page areas on disk, but the name stuck.
>>
>> Should the installer then be creating a dedicated swap partition? It
>> seems not.
>
> Yes of course it should, it's the place where pages that aren't
> backed by storage can be written to when needed.

That seems easily solved (just as well) by a swapfile.

--
They were the observers of the operation of the universe, its clerks,
its auditors. They saw to it that things spun and rocks fell. And they
believed that for a thing to exist it had to have a position in time and
space. Humanity had arrived as a nasty shock. Humanity practically was
things that didn't have a position in time and space, such as
imagination, pity, hope, history and belief. Take those away and all you
had was an ape that fell out of trees a lot. --The Thief of Time

John Levine

unread,
Feb 8, 2018, 10:32:22 PM2/8/18
to freebsd-...@freebsd.org, kre...@kreme.com
In article <99D367C9-ADF4-41EB...@kreme.com> you write:
>>> Should the installer then be creating a dedicated swap partition? It
>>> seems not.
>>
>> Yes of course it should, it's the place where pages that aren't
>> backed by storage can be written to when needed.
>
>That seems easily solved (just as well) by a swapfile.

FreeBSD lets you have either or both, but a swap partition is faster.

If you use a swap partition, block N is at disk location B+N where B
is the base of the partition. If you use a swapfile, you have inodes
and indirect blocks and such, so random access to a large swapfile
might have to read one or two overhead blocks for every swap block.

Scott Bennett

unread,
Feb 9, 2018, 6:12:37 AM2/9/18
to fra...@fjl.co.uk, freebsd-...@freebsd.org
Frank Leonhardt <fra...@fjl.co.uk> wrote:

> On 2018-02-08 13:48, Scott Bennett wrote:
> > On Wed, 07 Feb 2018 15:01:07 +0000 Frank Leonhardt <fra...@fjl.co.uk>
> > wrote
> >> On 2018-02-05 18:53, Robert Huff wrote:
> >>> Frank Leonhardt writes:
> >>>
> >>>> FreeBSD doesn't actually swap these days; uses demand paging.
> >>>
> >>> Possible evidence to the contrary:
> >>> On a system running:
> >>>
> >>> FreeBSD 12.0-CURRENT #0 r326723: Sat Dec 9 12:30:04 EST 2017 amd64
> >>>
> >>> top shows:
> >>>
> >>> last pid: 57956; load averages: 2.02, 2.01, 1.95 up 57+19:09:04
> >>> 13:49:29
> >>> 132 processes: 3 running, 129 sleeping
> >>> CPU: 38.7% user, 0.4% nice, 7.9% system, 0.0% interrupt, 53.0%
> >>> idle
> >>> Mem: 2264M Active, 2303M Inact, 1478M Laundry, 1525M Wired, 761M Buf,
> >>> 115M Free
> >>> Swap: 17G Total, 996M Used, 16G Free, 5% Inuse
> >>>
> >>> So ... is "Swap" an incorrect label, or is actual swapping
> >>> going on?
> >>
> >> Yes, it's an incorrect label.
> >>
> > Well, yes and no. The "swap" space can be used for both paging
> > and
> > swapping in BSD UNIX. Note that to swap a process out does *not*
> > require
> > writing all of its in-memory pages' content to the swap area, but
> > rather
> > enough of them to satisfy the system's need for available page frames
> > at
> > the time, and it also requires marking the process as "swapped out", so
> > that the scheduler knows that the process has been temporarily
> > deactivated.
> > The "swapped out" status also makes any of the process's pages still in
> > memory prime fodder for the pagedaemon to harvest to continue to fill
> > the
> > system's needs.
> > And on Wed, 07 Feb 2018 15:18:15 +0000 he also wrote:
> >> On 2018-02-05 20:08, John R. Levine wrote:
> >>> In article <24BAEBB4-FAA7-47C8...@kreme.com>, LuKreme
> > Quite right.
> >
> >> ---------------
> >>
> >> There seems to be some confusion on this list about swapping and
> >> paging.
> >> Swapping is old hat. Basically when doing a context swap you wrote a
> >> non-running process to a swap area to free up RAM space. We don't do
> >
> > Sort of right. See what I wrote above in response to your other
> > message.
> >
> >> that anymore - we use demand paged virtual memory. All processes
> >
> > Dead wrong. BSD UNIX is still quite capable of doing both
> > swapping
> > and paging. Try loading your system to a load average of, say, at
> > least
> > 15-20 times the number of CPU threads (a.k.a. logical CPUs) with
> > processes
> > that need large working sets relative to the physical memory of the
> > machine
> > and/or are very CPU-bound. You don't typically see any of the BSDs
> > actively
> > swapping, but they can, and they will when any number of pathological
> > loads
> > are bogging the system down, so that the system can recover to get some
> > work
> > done. There is a hysteresis involved, so that the demands on the
> > system's
> > various resources must have returned to much lower levels before
> > swapped-out
> > processes may begin to be swapped back into memory and their execution
> > resumed. Someone else (my apologies for having forgotten who) posted a
> > brief
> > note to this effect in this discussion already, but perhaps you missed
> > it.
> >
> >> potentially remain resident, but some of their memory map may be paged
> >> out to disk to free up RAM. If the process tries to access such a page
> >> the MMU interrupts the kernel, which loads in the missing page and
> >> uses
> >> the MMU to put it back in the process space at the right location
> >> before
> >> returning control.
> >>
> >> I'm not being pedantic here - the difference between swapped and paged
> >> systems is very significant if you're optimising disk/RAM usage.
> >>
> >> Swap areas have been replaced by page areas on disk, but the name
> >> stuck.
> >
> > No, they haven't, but they did become "dual-use" spaces back in
> > 3.0BSD.
> > See above.
> >
> >> A bit like core store - I haven't used core store since the 1980's but
> >> we still have "core dumps". Youngsters in the office look at me oddly
> >> when I use terms like core and DASD...
> >>
> > ...and disk packs, selector channels, cards, line printers, and...
> > :-)
>
> Hi Scott,
>
> Thanks - interesting! I was looking at the FreeBSD VM code several years
> ago, and it rings a bell but I wasn't sure whether what I was looking at
> was actually in use. I was investigating what was happening in low
> memory conditions, and basically concluded that it picked the largest
> process and simply killed it.

I have had swapping happen, from 4.3BSD to maybe FreeBSD 7.3, on a few
occasions, no more than once per release. In all cases, the system was
horribly bogged down and nearly unresponsive interactively until enough
processes had been swapped out. The swapping eventually did allow the system
to resume functioning well enough that I could then figure out what had gone
wrong and how to deal with it. Usually when things get bad enough to trigger
swapping, they are really, really bad, so even with swapping doing its job,
system responsiveness may still be far less than desirable, and corrective
actions may be delayed in actually getting run, but at least they become
possible again because of swapping. The main caveat is that your corrective
commands may also be swapped out before completion, so plan carefully, and
use only commands with very small resource requirements. :-) But one also
quickly learns to avoid most of the ways such situations might develop lest
one suffer such pain again, so most sysadmins don't experience this class of
thrillers very many times.
>
> I like the idea of BSD still swapping on occasion, so I'm glad to hear
> it does. Do you happen to know if Linux can?

No, I don't. I have next to zero experience with LINUX systems.
However, LINUX was originally designed to be a SysV workalike, based
upon SysVR2.3 or SysVR2.4, with several BSDisms grafted on, including a
networking stack and Sun's NFS and NIS, and the BSD FFS (essentially all
UNIXes, except actual AT&T SysV UNIX, ad{o,a}pted the FFS). IIRC, SysVR2.3+
implemented demand paging and kept its swapping mechanism, as modified to
accommodate demand paging. Therefore I would expect LINUX to have followed
that model initially, but I have no knowledge of the matter one way or
another, much less of what may have transpired in LINUX development since
that era. There are many others on this list who would know the answer to
your question, I'm quite sure.
It may be worth noting here that swapping in UNIX predates virtual
memory implementations. Swapping is how many mini-computer operating system,
including UNIX, managed multiple on-line users with very limited memories
(i.e., often much less than 64 KB). Virtual memory support in hardware
at first merely enabled swapping in such systems* to be made less violent and
extreme. BSD UNIX was exceptional because its first virtual memory
implementation included demand paging. *VMS was, IIRC, another exception.
>
> As to disk packs etc - they don't really exist except in reminiscences,
> and then they know I'm talking about the old days. I still use the term
> Winchester (or even mini-Wini) without thinking, and confuse everyone.
>
As long as you don't slip and say, "RAMAC", instead of "Winchester",
you'll probably skate. :-) Otherwise they may search you and your dwelling
for scarabs or coffins, check your latest dental X-rays, see whether your
blood still flows or has dried up, and so forth.


Scott Bennett, Comm. ASMELG, CFIAG
**********************************************************************
* Internet: bennett at sdf.org *xor* bennett at freeshell.org *
*--------------------------------------------------------------------*
* "A well regulated and disciplined militia, is at all times a good *
* objection to the introduction of that bane of all free governments *
* -- a standing army." *
* -- Gov. John Hancock, New York Journal, 28 January 1790 *
**********************************************************************

Christian Weisgerber

unread,
Feb 9, 2018, 3:56:25 PM2/9/18
to Scott Bennett, freebsd-...@freebsd.org
Scott Bennett:

> >Demand paging was introduced in UNIX 32V and entered the BSD line
>
> Are you absolutely certain of that?

Judging from _A Quarter Century of UNIX_, I slightly misrembered.
UNIX/32V was the port to the VAX, but it didn't yet include demand
paging. That feature was added only in 3BSD. That doesn't really
matter, though, for the point I was trying to bring across: Saying
"FreeBSD doesn't actually swap these days; uses demand paging" is
rather misleading because that makes it sound like a recent innovation
when it is in fact almost forty years old.

So, yes, "swap" space is a misnomer, but then again, "electricity"
today isn't really about rubbing ambers together either.

--
Christian "naddy" Weisgerber na...@mips.inka.de

Kevin P. Neal

unread,
Feb 9, 2018, 8:08:09 PM2/9/18
to freebsd-...@freebsd.org
On Fri, Feb 09, 2018 at 03:27:29AM -0600, Scott Bennett wrote:
> wrong and how to deal with it. Usually when things get bad enough to trigger
> swapping, they are really, really bad, so even with swapping doing its job,
> system responsiveness may still be far less than desirable, and corrective
> actions may be delayed in actually getting run, but at least they become
> possible again because of swapping. The main caveat is that your corrective
> commands may also be swapped out before completion, so plan carefully, and
> use only commands with very small resource requirements. :-) But one also
> quickly learns to avoid most of the ways such situations might develop lest
> one suffer such pain again, so most sysadmins don't experience this class of
> thrillers very many times.

Just this week went one further and ran a FreeBSD 11.1 machine out of swap
space. The top command said swap was full but there was still 300-400MB
of memory available. However, the kill -9 command wasn't able to kill the
large processes that were eating all the memory. Oh, the kill command ran
to completion, but it still didn't work.

I do remember "back in the day" on an Ultrix system seeing a guy run "ps"
and have it tell him that that "ps" had been paged out. Woah.

--
Kevin P. Neal http://www.pobox.com/~kpn/

"A pig's gotta fly." - Crimson Pig

Polytropon

unread,
Feb 10, 2018, 5:13:00 AM2/10/18
to Arthur Chance, freebsd-...@freebsd.org
On Wed, 7 Feb 2018 18:31:13 +0000, Arthur Chance wrote:
> Pretty much like referring to SSD storage as "disk" when it's all
> rectangular slabs. The historical name lingers on long after the
> technology becomes obsolete.

So... like /dev/drum or core dumps... :-)


--
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
Reply all
Reply to author
Forward
0 new messages