mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hugh Dickins <hugh@veritas.com>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 05/13] show span of swap extents
Date: Sat, 9 Jul 2005 01:04:42 +0100 (BST)	[thread overview]
Message-ID: <Pine.LNX.4.61.0507090103530.13391@goblin.wat.veritas.com> (raw)
In-Reply-To: <Pine.LNX.4.61.0507090057340.13391@goblin.wat.veritas.com>

The "Adding %dk swap" message shows the number of swap extents, as a guide
to how fragmented the swapfile may be.  But a useful further guide is what
total extent they span across (sometimes scarily large).

And there's no need to keep nr_extents in swap_info: it's unused after
the initial message, so save a little space by keeping it on stack.

Signed-off-by: Hugh Dickins <hugh@veritas.com>
---

 include/linux/swap.h |    1 -
 mm/swapfile.c        |   44 ++++++++++++++++++++++++++++++--------------
 2 files changed, 30 insertions(+), 15 deletions(-)

--- swap4/include/linux/swap.h	2005-07-08 19:14:00.000000000 +0100
+++ swap5/include/linux/swap.h	2005-07-08 19:14:12.000000000 +0100
@@ -122,7 +122,6 @@ struct swap_info_struct {
 	struct file *swap_file;
 	struct block_device *bdev;
 	struct list_head extent_list;
-	int nr_extents;
 	struct swap_extent *curr_swap_extent;
 	unsigned old_block_size;
 	unsigned short * swap_map;
--- swap4/mm/swapfile.c	2005-07-08 19:14:00.000000000 +0100
+++ swap5/mm/swapfile.c	2005-07-08 19:14:12.000000000 +0100
@@ -852,7 +852,6 @@ static void destroy_swap_extents(struct 
 		list_del(&se->list);
 		kfree(se);
 	}
-	sis->nr_extents = 0;
 }
 
 /*
@@ -891,8 +890,7 @@ add_swap_extent(struct swap_info_struct 
 	new_se->start_block = start_block;
 
 	list_add_tail(&new_se->list, &sis->extent_list);
-	sis->nr_extents++;
-	return 0;
+	return 1;
 }
 
 /*
@@ -926,7 +924,7 @@ add_swap_extent(struct swap_info_struct 
  * This is extremely effective.  The average number of iterations in
  * map_swap_page() has been measured at about 0.3 per page.  - akpm.
  */
-static int setup_swap_extents(struct swap_info_struct *sis)
+static int setup_swap_extents(struct swap_info_struct *sis, sector_t *span)
 {
 	struct inode *inode;
 	unsigned blocks_per_page;
@@ -934,11 +932,15 @@ static int setup_swap_extents(struct swa
 	unsigned blkbits;
 	sector_t probe_block;
 	sector_t last_block;
+	sector_t lowest_block = -1;
+	sector_t highest_block = 0;
+	int nr_extents = 0;
 	int ret;
 
 	inode = sis->swap_file->f_mapping->host;
 	if (S_ISBLK(inode->i_mode)) {
 		ret = add_swap_extent(sis, 0, sis->max, 0);
+		*span = sis->pages;
 		goto done;
 	}
 
@@ -983,19 +985,28 @@ static int setup_swap_extents(struct swa
 			}
 		}
 
+		first_block >>= (PAGE_SHIFT - blkbits);
+		if (page_no) {	/* exclude the header page */
+			if (first_block < lowest_block)
+				lowest_block = first_block;
+			if (first_block > highest_block)
+				highest_block = first_block;
+		}
+
 		/*
 		 * We found a PAGE_SIZE-length, PAGE_SIZE-aligned run of blocks
 		 */
-		ret = add_swap_extent(sis, page_no, 1,
-				first_block >> (PAGE_SHIFT - blkbits));
-		if (ret)
+		ret = add_swap_extent(sis, page_no, 1, first_block);
+		if (ret < 0)
 			goto out;
+		nr_extents += ret;
 		page_no++;
 		probe_block += blocks_per_page;
 reprobe:
 		continue;
 	}
-	ret = 0;
+	ret = nr_extents;
+	*span = 1 + highest_block - lowest_block;
 	if (page_no == 0)
 		page_no = 1;	/* force Empty message */
 	sis->max = page_no;
@@ -1263,6 +1274,8 @@ asmlinkage long sys_swapon(const char __
 	union swap_header *swap_header = NULL;
 	int swap_header_version;
 	int nr_good_pages = 0;
+	int nr_extents;
+	sector_t span;
 	unsigned long maxpages = 1;
 	int swapfilesize;
 	unsigned short *swap_map;
@@ -1298,7 +1311,6 @@ asmlinkage long sys_swapon(const char __
 		nr_swapfiles = type+1;
 	INIT_LIST_HEAD(&p->extent_list);
 	p->flags = SWP_USED;
-	p->nr_extents = 0;
 	p->swap_file = NULL;
 	p->old_block_size = 0;
 	p->swap_map = NULL;
@@ -1475,9 +1487,11 @@ asmlinkage long sys_swapon(const char __
 		p->swap_map[0] = SWAP_MAP_BAD;
 		p->max = maxpages;
 		p->pages = nr_good_pages;
-		error = setup_swap_extents(p);
-		if (error)
+		nr_extents = setup_swap_extents(p, &span);
+		if (nr_extents < 0) {
+			error = nr_extents;
 			goto bad_swap;
+		}
 		nr_good_pages = p->pages;
 	}
 	if (!nr_good_pages) {
@@ -1492,9 +1506,11 @@ asmlinkage long sys_swapon(const char __
 	p->flags = SWP_ACTIVE;
 	nr_swap_pages += nr_good_pages;
 	total_swap_pages += nr_good_pages;
-	printk(KERN_INFO "Adding %dk swap on %s.  Priority:%d extents:%d\n",
-		nr_good_pages<<(PAGE_SHIFT-10), name,
-		p->prio, p->nr_extents);
+
+	printk(KERN_INFO "Adding %dk swap on %s.  "
+			"Priority:%d extents:%d across:%lluk\n",
+		nr_good_pages<<(PAGE_SHIFT-10), name, p->prio,
+		nr_extents, (unsigned long long)span<<(PAGE_SHIFT-10));
 
 	/* insert swap space into swap_list: */
 	prev = -1;

  parent reply	other threads:[~2005-07-09  0:08 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-09  0:00 [PATCH 00/13] some swapfile patches Hugh Dickins
2005-07-09  0:01 ` [PATCH 01/13] update swapfile i_sem comment Hugh Dickins
2005-07-09  0:01 ` [PATCH 02/13] correct swapfile nr_good_pages Hugh Dickins
2005-07-09  0:02 ` [PATCH 03/13] move destroy_swap_extents calls Hugh Dickins
2005-07-09  0:03 ` [PATCH 04/13] swap extent list is ordered Hugh Dickins
2005-07-09  0:04 ` Hugh Dickins [this message]
2005-07-09  0:05 ` [PATCH 06/13] swap unsigned int consistency Hugh Dickins
2005-07-09  0:06 ` [PATCH 07/13] freeing update swap_list.next Hugh Dickins
2005-07-09  0:07 ` [PATCH 08/13] get_swap_page drop swap_list_lock Hugh Dickins
2005-07-09  0:08 ` [PATCH 09/13] scan_swap_map restyled Hugh Dickins
2005-07-09  0:09 ` [PATCH 10/13] scan_swap_map drop swap_device_lock Hugh Dickins
2005-07-09  0:10 ` [PATCH 11/13] scan_swap_map latency breaks Hugh Dickins
2005-07-09  0:11 ` [PATCH 12/13] swap_lock replace list+device Hugh Dickins
2005-07-09  0:15 ` [PATCH 13/13] update swsusp use of swap_info Hugh Dickins
2005-07-09 11:13   ` [PATCH 14/13] swsusp mod needed parentheses Hugh Dickins

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.61.0507090103530.13391@goblin.wat.veritas.com \
    --to=hugh@veritas.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®