linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Hugh Dickins <hugh.dickins@tiscali.co.uk>
Cc: Jens Axboe <jens.axboe@oracle.com>,
	Matthew Wilcox <matthew@wil.cx>,
	linux-mm@kvack.org, linux-scsi@vger.kernel.org
Subject: [PATCH] mm: don't discard unused swap slots by default
Date: Mon, 30 Nov 2009 18:22:44 +0100	[thread overview]
Message-ID: <20091130172243.GA30779@lst.de> (raw)
In-Reply-To: <20091118171232.GB25541@lst.de>

Current TRIM/UNMAP/etc implementation are slow enough that discarding
small chunk during run time is a bad idea.  So only discard the whole
swap space on swapon by default, but require the admin to enable it
for run-time discards using the new vm.discard_swapspace sysctl.


Signed-off-by: Christoph Hellwig <hch@lst.de>

Index: linux-2.6/include/linux/swap.h
===================================================================
--- linux-2.6.orig/include/linux/swap.h	2009-11-27 11:50:47.319003920 +0100
+++ linux-2.6/include/linux/swap.h	2009-11-27 11:51:55.617286868 +0100
@@ -247,6 +247,7 @@ extern unsigned long mem_cgroup_shrink_n
 extern int __isolate_lru_page(struct page *page, int mode, int file);
 extern unsigned long shrink_all_memory(unsigned long nr_pages);
 extern int vm_swappiness;
+extern int vm_discard_swapspace;
 extern int remove_mapping(struct address_space *mapping, struct page *page);
 extern long vm_total_pages;
 
Index: linux-2.6/kernel/sysctl.c
===================================================================
--- linux-2.6.orig/kernel/sysctl.c	2009-11-27 11:49:02.935254088 +0100
+++ linux-2.6/kernel/sysctl.c	2009-11-27 11:53:10.333006621 +0100
@@ -1163,6 +1163,16 @@ static struct ctl_table vm_table[] = {
 		.extra1		= &zero,
 		.extra2		= &one_hundred,
 	},
+	{
+		.ctl_name	= CTL_UNNUMBERED,
+		.procname	= "discard_swapspace",
+		.data		= &vm_discard_swapspace,
+		.maxlen		= sizeof(vm_discard_swapspace),
+		.mode		= 0644,
+		.proc_handler	= &proc_dointvec_minmax,
+		.extra1		= &zero,
+		.extra2		= &one,
+	},
 #ifdef CONFIG_HUGETLB_PAGE
 	 {
 		.procname	= "nr_hugepages",
Index: linux-2.6/mm/swapfile.c
===================================================================
--- linux-2.6.orig/mm/swapfile.c	2009-11-27 11:53:19.449254088 +0100
+++ linux-2.6/mm/swapfile.c	2009-11-27 11:54:07.883255931 +0100
@@ -41,6 +41,7 @@ long nr_swap_pages;
 long total_swap_pages;
 static int swap_overflow;
 static int least_priority;
+int vm_discard_swapspace;
 
 static const char Bad_file[] = "Bad swap file entry ";
 static const char Unused_file[] = "Unused swap file entry ";
@@ -1978,7 +1979,7 @@ SYSCALL_DEFINE2(swapon, const char __use
 			p->flags |= SWP_SOLIDSTATE;
 			p->cluster_next = 1 + (random32() % p->highest_bit);
 		}
-		if (discard_swap(p) == 0)
+		if (discard_swap(p) == 0 && vm_discard_swapspace)
 			p->flags |= SWP_DISCARDABLE;
 	}
 

--
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:[~2009-11-30 17:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-30  6:51 unconditional discard calls in the swap code Christoph Hellwig
2009-10-30 17:26 ` Hugh Dickins
2009-11-18 17:12   ` Christoph Hellwig
2009-11-30 17:22     ` Christoph Hellwig [this message]
2009-11-30 18:28       ` [PATCH] mm: don't discard unused swap slots by default Hugh Dickins
2009-11-30 18:58         ` Martin K. Petersen
2009-12-31  0:33         ` 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=20091130172243.GA30779@lst.de \
    --to=hch@lst.de \
    --cc=hugh.dickins@tiscali.co.uk \
    --cc=jens.axboe@oracle.com \
    --cc=linux-mm@kvack.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=matthew@wil.cx \
    /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