public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] swsusp: simpler calculation of number of pages in PBE list
@ 2005-07-29 19:46 Michal Schmidt
  2005-07-29 20:43 ` [linux-pm] " Rafael J. Wysocki
  2005-07-30 13:20 ` Pavel Machek
  0 siblings, 2 replies; 11+ messages in thread
From: Michal Schmidt @ 2005-07-29 19:46 UTC (permalink / raw)
  To: Pavel Machek; +Cc: linux-kernel, linux-pm

[-- Attachment #1: Type: text/plain, Size: 251 bytes --]

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.

Signed-off-by: Michal Schmidt <xschmi00@stud.feec.vutbr.cz>

[-- Attachment #2: swsusp-simpler-calc_nr.diff --]
[-- Type: text/x-patch, Size: 690 bytes --]

diff -Nurp -X dontdiff.new linux-mm/kernel/power/swsusp.c linux-mm.mich/kernel/power/swsusp.c
--- linux-mm/kernel/power/swsusp.c	2005-07-28 13:57:53.000000000 +0200
+++ linux-mm.mich/kernel/power/swsusp.c	2005-07-29 21:01:46.000000000 +0200
@@ -737,18 +737,7 @@ static void copy_data_pages(void)
 
 static int calc_nr(int nr_copy)
 {
-	int extra = 0;
-	int mod = !!(nr_copy % PBES_PER_PAGE);
-	int diff = (nr_copy / PBES_PER_PAGE) + mod;
-
-	do {
-		extra += diff;
-		nr_copy += diff;
-		mod = !!(nr_copy % PBES_PER_PAGE);
-		diff = (nr_copy / PBES_PER_PAGE) + mod - extra;
-	} while (diff > 0);
-
-	return nr_copy;
+	return nr_copy + (nr_copy+PBES_PER_PAGE-2)/(PBES_PER_PAGE-1);
 }
 
 /**

^ permalink raw reply	[flat|nested] 11+ messages in thread
* [PATCH] swsusp: simpler calculation of number of pages in PBE list
@ 2005-07-30 13:33 Pavel Machek
  0 siblings, 0 replies; 11+ messages in thread
From: Pavel Machek @ 2005-07-30 13:33 UTC (permalink / raw)
  To: Andrew Morton, kernel list, xschmi00

From: Michal Schmidt <xschmi00@stud.feec.vutbr.cz>

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.

Note that this was even proved correct ;-).

Signed-off-by: Michal Schmidt <xschmi00@stud.feec.vutbr.cz>
Signed-off-by: Pavel Machek <pavel@suse.cz>

---
commit 06695555bdbe1a5ac3b7926867abfdc9e560121f
tree 3be140250bf556a51261ea75b908906e64182ec3
parent 42b960c2ed61b623d5e84b67f95c7f0ddad0565f
author <pavel@amd.(none)> Sat, 30 Jul 2005 15:19:56 +0200
committer <pavel@amd.(none)> Sat, 30 Jul 2005 15:19:56 +0200

 kernel/power/swsusp.c |   13 +------------
 1 files changed, 1 insertions(+), 12 deletions(-)

diff --git a/kernel/power/swsusp.c b/kernel/power/swsusp.c
--- a/kernel/power/swsusp.c
+++ b/kernel/power/swsusp.c
@@ -591,18 +591,7 @@ static void copy_data_pages(void)
 
 static int calc_nr(int nr_copy)
 {
-	int extra = 0;
-	int mod = !!(nr_copy % PBES_PER_PAGE);
-	int diff = (nr_copy / PBES_PER_PAGE) + mod;
-
-	do {
-		extra += diff;
-		nr_copy += diff;
-		mod = !!(nr_copy % PBES_PER_PAGE);
-		diff = (nr_copy / PBES_PER_PAGE) + mod - extra;
-	} while (diff > 0);
-
-	return nr_copy;
+	return nr_copy + (nr_copy+PBES_PER_PAGE-2)/(PBES_PER_PAGE-1);
 }
 
 /**

-- 
teflon -- maybe it is a trademark, but it should not be.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2005-07-30 14:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
  -- strict thread matches above, loose matches on Subject: below --
2005-07-30 13:33 Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox