public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Michal Schmidt <xschmi00@stud.feec.vutbr.cz>,
	linux-pm@lists.osdl.org, linux-kernel@vger.kernel.org,
	Pavel Machek <pavel@ucw.cz>
Subject: Re: [linux-pm] [PATCH] swsusp: simpler calculation of number of pages in PBE list
Date: Sat, 30 Jul 2005 15:16:31 +0200	[thread overview]
Message-ID: <200507301516.32003.rjw@sisk.pl> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0507292126390.16749-100000@netrider.rowland.org>

On Saturday, 30 of July 2005 03:35, Alan Stern wrote:
> On Fri, 29 Jul 2005, Michal Schmidt wrote:
> 
> > Rafael J. Wysocki wrote:
> > > On Friday, 29 of July 2005 21:46, Michal Schmidt wrote:
> > > 
> > >>The function calc_nr uses an iterative algorithm to calculate the number 
> > >>of pages needed for the image and the pagedir. Exactly the same result 
> > >>can be obtained with a one-line expression.
> > > 
> > > 
> > > Could you please post the proof?
> > > 
> > > Rafael
> > 
> > OK, attached is a proof-by-brute-force program. It compares the results 
> > of the original function and the simplified one.
> 
> Here's a more general proof.
> 
> As I understand it, calc_nr is given nr_copy, the number of data pages
> that need to be written out, and it has to return the number of pages
> needed to hold the image data plus a bunch of PBE pagedir indexes, where
> each page gets one index (and pages containing PBEs need their own indexes
> as well).
> 
> For brevity, let n = nr_copy, let p = PBES_PER_PAGE, and let x be the 
> number of pagdir pages needed.  Since each page can hold p PBEs, there 
> will be room to store px PBEs.  The total number of pages is n + x, so 
> the routine needs to find the smallest value of x for which
> 
> 	px >= n + x
> 
> or
> 
> 	(p-1)x >= n
> 
> or
> 
> 	x >= n / (p-1).
> 
> The obvious solution is
> 
> 	x = ceiling(n / (p-1)),
> 
> so calc_nr should return n + ceiling(n / (p-1)), which is exactly what 
> Michal's patch computes.

Nice. :-)

Could we perhaps add your proof to the Michal's patch as a comment,
for reference?

Rafael


-- 
- Would you tell me, please, which way I ought to go from here?
- That depends a good deal on where you want to get to.
		-- Lewis Carroll "Alice's Adventures in Wonderland"

  reply	other threads:[~2005-07-30 13:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-29 19:46 [PATCH] swsusp: simpler calculation of number of pages in PBE list Michal Schmidt
2005-07-29 20:43 ` [linux-pm] " Rafael J. Wysocki
2005-07-29 21:14   ` Michal Schmidt
2005-07-29 21:53     ` Rafael J. Wysocki
2005-07-30  1:35     ` Alan Stern
2005-07-30 13:16       ` Rafael J. Wysocki [this message]
2005-07-30 13:13         ` Pavel Machek
2005-07-30 13:32           ` Rafael J. Wysocki
2005-07-30 14:37             ` Alan Stern
2005-07-30 13:20 ` Pavel Machek

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=200507301516.32003.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@lists.osdl.org \
    --cc=pavel@ucw.cz \
    --cc=stern@rowland.harvard.edu \
    --cc=xschmi00@stud.feec.vutbr.cz \
    /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