linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hugh Dickins <hugh@veritas.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: dwmw2@infradead.org, jens.axboe@oracle.com, matthew@wil.cx,
	joern@logfs.org, James.Bottomley@HansenPartnership.com,
	djshin90@gmail.com, teheo@suse.de, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 6/9] swapfile: swapon use discard (trim)
Date: Wed, 26 Nov 2008 06:02:46 +0000 (GMT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0811260530570.26081@blonde.site> (raw)
In-Reply-To: <20081125171748.57450cb5.akpm@linux-foundation.org>

On Tue, 25 Nov 2008, Andrew Morton wrote:
> On Tue, 25 Nov 2008 21:44:34 +0000 (GMT)
> Hugh Dickins <hugh@veritas.com> wrote:
> 
> > When adding swap, all the old data on swap can be forgotten: sys_swapon()
> > discard all but the header page of the swap partition (or every extent
> > but the header of the swap file), to give a solidstate swap device the
> > opportunity to optimize its wear-levelling.
> > 
> > If that succeeds, note SWP_DISCARDABLE for later use, and report it
> > with a "D" at the right end of the kernel's "Adding ... swap" message.
> > Perhaps something should be shown in /proc/swaps (swapon -s), but we
> > have to be more cautious before making any addition to that format.
> 
> When reading the above text it's a bit hard to tell whether it's
> talking about "this is how things are at present" or "this is how
> things are after the patch".  This is fairly common with Hugh
> changelogs.

;)  Sorry about that - yes, that's often true.  In this case, it's
all talking about how things are after the patch.  I think it's that
first sentence which bothers you - "all the old data on swap can be
forgotten".  In this case, I'm meaning "it's a good idea to let the
device know that it can forget about all the old data"; but it's easy
to imagine another patch coming from me in which the same sentence
would mean "we've got a terrible data-loss bug, such that all the
data already written to swap gets erased".  Let's hope I didn't
implement the latter.

> > +static int discard_swap(struct swap_info_struct *si)
> > +{
> > +	struct swap_extent *se;
> > +	int err = 0;
> > +
> > +	list_for_each_entry(se, &si->extent_list, list) {
> > +		sector_t start_block = se->start_block << (PAGE_SHIFT - 9);
> > +		pgoff_t nr_blocks = se->nr_pages << (PAGE_SHIFT - 9);
> 
> I trust we don't have any shift overflows here.
> 
> It's a bit dissonant to see a pgoff_t with "blocks" in its name.  But
> swap is like that..

In fact we don't have a shift overflow there, but you've such a good eye.

I noticed that "pgoff_t nr_blocks" line just as I was about to send off
the patches, and had a little worry about it.  By that time I was at
the stage that if I went into the patch and changed a few pgoff_ts
to sector_ts at the last minute, likelihood was I'd screw something
up badly, in one CONFIG combination or another, and if I delayed
it'd be tomorrow.

It would be good to make that change when built and tested,
just for reassurance.  There isn't a shift overflow as it stands,
but the reasons are too contingent for my liking: on 64-bit there
isn't an issue because pgoff_t is as big as sector_t; on 32-bit,
it's because a swp_entry_t is an unsigned long, and it has to
contain five bits for the "type" (which of the 30 or 32 swapfiles
is addressed), and the pages-to-sectors shift is less than 5 on
all 32-bit machines for the foreseeable future.  Oh, and it also
relies on the fact that by the time we're setting up swap extents,
we've already curtailed the size to what's usable by a swp_entry_t,
if that's less than the size given in the swap header.

So, not actually a bug there, but certainly a source of anxiety,
better eliminated.

Hugh

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

      reply	other threads:[~2008-11-26  6:02 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-25 21:35 [PATCH 0/9] swapfile: cleanups and solidstate mods Hugh Dickins
2008-11-25 21:36 ` [PATCH 1/9] swapfile: swapon needs larger size type Hugh Dickins
2008-11-25 21:37 ` [PATCH 2/9] swapfile: remove SWP_ACTIVE mask Hugh Dickins
2008-11-25 21:37 ` [PATCH 3/9] swapfile: remove surplus whitespace Hugh Dickins
2008-11-25 21:39 ` [PATCH 4/9] swapfile: remove v0 SWAP-SPACE message Hugh Dickins
2008-11-25 21:40 ` [PATCH 5/9] swapfile: rearrange scan and swap_info Hugh Dickins
2008-11-25 21:44 ` [PATCH 6/9] swapfile: swapon use discard (trim) Hugh Dickins
2008-11-25 21:46   ` [PATCH 7/9] swapfile: swap allocation use discard Hugh Dickins
2008-12-01  0:29     ` [PATCH 10/9] swapfile: change discard pgoff_t to sector_t Hugh Dickins
2008-12-03  0:47       ` Andrew Morton
2008-12-03 12:52         ` Hugh Dickins
2008-11-25 21:46   ` [PATCH 8/9] swapfile: swapon randomize if nonrot Hugh Dickins
2008-11-26  1:20     ` Andrew Morton
2008-11-26  3:38       ` Matthew Wilcox
2008-12-01  0:32     ` [PATCH 11/9] swapfile: let others seed random Hugh Dickins
2008-11-25 21:47   ` [PATCH 9/9] swapfile: swap allocation cycle if nonrot Hugh Dickins
2008-11-26  1:17   ` [PATCH 6/9] swapfile: swapon use discard (trim) Andrew Morton
2008-11-26  6:02     ` Hugh Dickins [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0811260530570.26081@blonde.site \
    --to=hugh@veritas.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=akpm@linux-foundation.org \
    --cc=djshin90@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=jens.axboe@oracle.com \
    --cc=joern@logfs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=matthew@wil.cx \
    --cc=teheo@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox