All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Garzik <jgarzik@mandrakesoft.com>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: Linux-Kernel list <linux-kernel@vger.kernel.org>
Subject: [BK PATCH] remove swap_device from swap_info_struct
Date: Fri, 08 Feb 2002 19:25:57 -0500	[thread overview]
Message-ID: <3C646C95.3978AE16@mandrakesoft.com> (raw)

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

 

[-- Attachment #2: vm-2.5.txt --]
[-- Type: text/plain, Size: 914 bytes --]



Pull from:  http://gkernel.bkbits.net/vm-2.5


---------------------------------------------------------------------------
ChangeSet@1.230, 2002-02-08 18:11:31-05:00, jgarzik@rum.normnet.org
  After Al Viro's recent swapfile cleanup, the swap_device member of
  swap_info_struct became pretty much superfluous.  As we are minimizing
  kdev_t usage anyway, I took the opportunity to remove swap_device
  member, and replace the remaining usages with SWP_BLOCKDEV bit flag.
  
  Adding SWP_BLOCKDEV in turn motivated a small cleanup of the
  SWP_xxx bit flags and their usage.
  
  Patch has been in light testing for a couple weeks, and
  has been glanced at by Al.  "looks sane"

 include/linux/swap.h |    9 ++++++---
 mm/swapfile.c        |   33 ++++++++++++++++++---------------
 2 files changed, 24 insertions(+), 18 deletions(-)

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


[-- Attachment #3: rm-swapdev-swapinfo-2.5.4.3.patch --]
[-- Type: text/plain, Size: 4022 bytes --]

diff -Nru a/include/linux/swap.h b/include/linux/swap.h
--- a/include/linux/swap.h	Fri Feb  8 19:10:16 2002
+++ b/include/linux/swap.h	Fri Feb  8 19:10:16 2002
@@ -50,8 +50,12 @@
 
 #include <asm/atomic.h>
 
-#define SWP_USED	1
-#define SWP_WRITEOK	3
+enum {
+	SWP_USED	= (1 << 0),	/* is slot in swap_info[] used? */
+	SWP_WRITEOK	= (1 << 1),	/* ok to write to this swap?	*/
+	SWP_BLOCKDEV	= (1 << 2),	/* is this swap a block device? */
+	SWP_ACTIVE	= (SWP_USED | SWP_WRITEOK),
+};
 
 #define SWAP_CLUSTER_MAX 32
 
@@ -63,7 +67,6 @@
  */
 struct swap_info_struct {
 	unsigned int flags;
-	kdev_t swap_device;
 	spinlock_t sdev_lock;
 	struct file *swap_file;
 	unsigned short * swap_map;
diff -Nru a/mm/swapfile.c b/mm/swapfile.c
--- a/mm/swapfile.c	Fri Feb  8 19:10:16 2002
+++ b/mm/swapfile.c	Fri Feb  8 19:10:16 2002
@@ -114,7 +114,7 @@
 
 	while (1) {
 		p = &swap_info[type];
-		if ((p->flags & SWP_WRITEOK) == SWP_WRITEOK) {
+		if ((p->flags & SWP_ACTIVE) == SWP_ACTIVE) {
 			swap_device_lock(p);
 			offset = scan_swap_map(p);
 			swap_device_unlock(p);
@@ -729,7 +729,7 @@
 	swap_list_lock();
 	for (type = swap_list.head; type >= 0; type = swap_info[type].next) {
 		p = swap_info + type;
-		if ((p->flags & SWP_WRITEOK) == SWP_WRITEOK) {
+		if ((p->flags & SWP_ACTIVE) == SWP_ACTIVE) {
 			if (p->swap_file->f_dentry == nd.dentry)
 				break;
 		}
@@ -752,7 +752,7 @@
 	}
 	nr_swap_pages -= p->pages;
 	total_swap_pages -= p->pages;
-	p->flags = SWP_USED;
+	p->flags &= ~SWP_WRITEOK;
 	swap_list_unlock();
 	unlock_kernel();
 	err = try_to_unuse(type);
@@ -770,7 +770,7 @@
 			swap_info[prev].next = p - swap_info;
 		nr_swap_pages += p->pages;
 		total_swap_pages += p->pages;
-		p->flags = SWP_WRITEOK;
+		p->flags |= SWP_WRITEOK;
 		swap_list_unlock();
 		goto out_dput;
 	}
@@ -778,7 +778,6 @@
 	swap_device_lock(p);
 	swap_file = p->swap_file;
 	p->swap_file = NULL;
-	p->swap_device = NODEV;
 	p->max = 0;
 	swap_map = p->swap_map;
 	p->swap_map = NULL;
@@ -822,7 +821,8 @@
 				}
 			len += sprintf(buf + len, "%-39s %s\t%d\t%d\t%d\n",
 				       path,
-				       !kdev_none(ptr->swap_device) ? "partition" : "file\t",
+				       (ptr->flags & SWP_BLOCKDEV) ?
+				       		"partition" : "file\t",
 				       ptr->pages << (PAGE_SHIFT - 10),
 				       usedswap << (PAGE_SHIFT - 10),
 				       ptr->prio);
@@ -837,9 +837,10 @@
 	int i;
 
 	for (i = 0 ; i < nr_swapfiles ; i++, ptr++) {
-		if (ptr->flags & SWP_USED)
-			if (kdev_same(ptr->swap_device, dev))
-				return 1;
+		if ((ptr->flags & SWP_USED) &&
+		    (ptr->flags & SWP_BLOCKDEV) &&
+		    (kdev_same(ptr->swap_file->f_dentry->d_inode->i_rdev, dev)))
+			return 1;
 	}
 	return 0;
 }
@@ -883,7 +884,6 @@
 		nr_swapfiles = type+1;
 	p->flags = SWP_USED;
 	p->swap_file = NULL;
-	p->swap_device = NODEV;
 	p->swap_map = NULL;
 	p->lowest_bit = 0;
 	p->highest_bit = 0;
@@ -911,8 +911,10 @@
 
 	error = -EINVAL;
 	if (S_ISBLK(swap_file->f_dentry->d_inode->i_mode)) {
-		p->swap_device = swap_file->f_dentry->d_inode->i_rdev;
-		set_blocksize(p->swap_device, PAGE_SIZE);
+		error = set_blocksize(swap_file->f_dentry->d_inode->i_rdev,
+				      PAGE_SIZE);
+		if (error < 0)
+			goto bad_swap;
 	} else if (!S_ISREG(swap_file->f_dentry->d_inode->i_mode))
 		goto bad_swap;
 
@@ -1035,7 +1037,9 @@
 	swap_list_lock();
 	swap_device_lock(p);
 	p->max = maxpages;
-	p->flags = SWP_WRITEOK;
+	p->flags = SWP_ACTIVE;
+	if (S_ISBLK(swap_file->f_dentry->d_inode->i_mode))
+		p->flags |= SWP_BLOCKDEV;
 	p->pages = nr_good_pages;
 	nr_swap_pages += nr_good_pages;
 	total_swap_pages += nr_good_pages;
@@ -1064,7 +1068,6 @@
 bad_swap_2:
 	swap_list_lock();
 	swap_map = p->swap_map;
-	p->swap_device = NODEV;
 	p->swap_file = NULL;
 	p->swap_map = NULL;
 	p->flags = 0;
@@ -1090,7 +1093,7 @@
 	swap_list_lock();
 	for (i = 0; i < nr_swapfiles; i++) {
 		unsigned int j;
-		if (swap_info[i].flags != SWP_USED)
+		if (!(swap_info[i].flags & SWP_USED))
 			continue;
 		for (j = 0; j < swap_info[i].max; ++j) {
 			switch (swap_info[i].swap_map[j]) {

                 reply	other threads:[~2002-02-09  0:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=3C646C95.3978AE16@mandrakesoft.com \
    --to=jgarzik@mandrakesoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.