All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Lameter <clameter@sgi.com>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org
Cc: dgc@sgi.com
Subject: [patch 07/12] Slab defragmentation: Support for buffer_head defrag
Date: Sat, 07 Jul 2007 20:05:45 -0700	[thread overview]
Message-ID: <20070708030845.032023558@sgi.com> (raw)
In-Reply-To: 20070708030538.729027694@sgi.com

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

Limited defragmentation support for buffer heads. Simply try to free the
buffers in a sparsely populated slab page.

Signed-off-by: Christoph Lameter <clameter@sgi.com>

---
 fs/buffer.c |   67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 65 insertions(+), 2 deletions(-)

Index: linux-2.6.22-rc6-mm1/fs/buffer.c
===================================================================
--- linux-2.6.22-rc6-mm1.orig/fs/buffer.c	2007-07-04 11:14:01.000000000 -0700
+++ linux-2.6.22-rc6-mm1/fs/buffer.c	2007-07-04 17:23:02.000000000 -0700
@@ -3078,12 +3078,75 @@ static int buffer_cpu_notify(struct noti
 	return NOTIFY_OK;
 }
 
+/*
+ * Get references on buffers.
+ *
+ * We obtain references on the page that uses the buffer. v[i] will point to
+ * the corresponding page after get_buffers() is through.
+ *
+ * We are safe from the underlying page being removed simply by doing
+ * a get_page_unless_zero. The buffer head removal may race at will.
+ * try_to_free_buffes will later take appropriate locks to remove the
+ * buffers if they are still there.
+ *
+ * TODO: Write out dirty buffers to increase the chance of kick_buffers
+ * to be successful.
+ */
+static void *get_buffers(struct kmem_cache *s, int nr, void **v)
+{
+	struct page *page;
+	struct buffer_head *bh;
+	int i;
+
+	for (i = 0; i < nr; i++) {
+		bh = v[i];
+		page = bh->b_page;
+		if (page && PagePrivate(page) && get_page_unless_zero(page))
+			v[i] = page;
+		else
+			v[i] = NULL;
+	}
+	return NULL;
+}
+
+/*
+ * Despite its name: kick_buffers operates on a list of pointers to
+ * page structs that was setup by get_buffer
+ */
+static void kick_buffers(struct kmem_cache *s, int nr, void **v,
+							void *private)
+{
+	struct page *page;
+	int i;
+
+	for (i = 0; i < nr; i++) {
+		page = v[i];
+
+		if (!page)
+			continue;
+
+		if (!TestSetPageLocked(page)) {
+			if (PagePrivate(page))
+				try_to_free_buffers(page);
+			unlock_page(page);
+		}
+		put_page(page);
+	}
+}
+
+static struct kmem_cache_ops buffer_head_kmem_cache_ops = {
+	.get = get_buffers,
+	.kick = kick_buffers,
+};
+
+
 void __init buffer_init(void)
 {
 	int nrpages;
 
-	bh_cachep = KMEM_CACHE(buffer_head,
-			SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD);
+	bh_cachep = KMEM_CACHE_OPS(buffer_head,
+			SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD,
+			&buffer_head_kmem_cache_ops);
 
 	/*
 	 * Limit the bh occupancy to 10% of ZONE_NORMAL

-- 

WARNING: multiple messages have this Message-ID (diff)
From: Christoph Lameter <clameter@sgi.com>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, dgc@sgi.com
Subject: [patch 07/12] Slab defragmentation: Support for buffer_head defrag
Date: Sat, 07 Jul 2007 20:05:45 -0700	[thread overview]
Message-ID: <20070708030845.032023558@sgi.com> (raw)
In-Reply-To: 20070708030538.729027694@sgi.com

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

Limited defragmentation support for buffer heads. Simply try to free the
buffers in a sparsely populated slab page.

Signed-off-by: Christoph Lameter <clameter@sgi.com>

---
 fs/buffer.c |   67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 65 insertions(+), 2 deletions(-)

Index: linux-2.6.22-rc6-mm1/fs/buffer.c
===================================================================
--- linux-2.6.22-rc6-mm1.orig/fs/buffer.c	2007-07-04 11:14:01.000000000 -0700
+++ linux-2.6.22-rc6-mm1/fs/buffer.c	2007-07-04 17:23:02.000000000 -0700
@@ -3078,12 +3078,75 @@ static int buffer_cpu_notify(struct noti
 	return NOTIFY_OK;
 }
 
+/*
+ * Get references on buffers.
+ *
+ * We obtain references on the page that uses the buffer. v[i] will point to
+ * the corresponding page after get_buffers() is through.
+ *
+ * We are safe from the underlying page being removed simply by doing
+ * a get_page_unless_zero. The buffer head removal may race at will.
+ * try_to_free_buffes will later take appropriate locks to remove the
+ * buffers if they are still there.
+ *
+ * TODO: Write out dirty buffers to increase the chance of kick_buffers
+ * to be successful.
+ */
+static void *get_buffers(struct kmem_cache *s, int nr, void **v)
+{
+	struct page *page;
+	struct buffer_head *bh;
+	int i;
+
+	for (i = 0; i < nr; i++) {
+		bh = v[i];
+		page = bh->b_page;
+		if (page && PagePrivate(page) && get_page_unless_zero(page))
+			v[i] = page;
+		else
+			v[i] = NULL;
+	}
+	return NULL;
+}
+
+/*
+ * Despite its name: kick_buffers operates on a list of pointers to
+ * page structs that was setup by get_buffer
+ */
+static void kick_buffers(struct kmem_cache *s, int nr, void **v,
+							void *private)
+{
+	struct page *page;
+	int i;
+
+	for (i = 0; i < nr; i++) {
+		page = v[i];
+
+		if (!page)
+			continue;
+
+		if (!TestSetPageLocked(page)) {
+			if (PagePrivate(page))
+				try_to_free_buffers(page);
+			unlock_page(page);
+		}
+		put_page(page);
+	}
+}
+
+static struct kmem_cache_ops buffer_head_kmem_cache_ops = {
+	.get = get_buffers,
+	.kick = kick_buffers,
+};
+
+
 void __init buffer_init(void)
 {
 	int nrpages;
 
-	bh_cachep = KMEM_CACHE(buffer_head,
-			SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD);
+	bh_cachep = KMEM_CACHE_OPS(buffer_head,
+			SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD,
+			&buffer_head_kmem_cache_ops);
 
 	/*
 	 * Limit the bh occupancy to 10% of ZONE_NORMAL

-- 

  parent reply	other threads:[~2007-07-08  3:11 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-08  3:05 [patch 00/12] Slab defragmentation V4 Christoph Lameter
2007-07-08  3:05 ` Christoph Lameter
2007-07-08  3:05 ` [patch 01/12] Slab defragmentation: Add support for kmem_cache_ops Christoph Lameter
2007-07-08  3:05   ` Christoph Lameter
2007-07-08  3:05 ` [patch 02/12] Slab defragmentation: Core piece Christoph Lameter
2007-07-08  3:05   ` Christoph Lameter
2007-07-08  3:05 ` [patch 03/12] Slab defragmentation: Updates to slabinfo.c Christoph Lameter
2007-07-08  3:05   ` Christoph Lameter
2007-07-08  3:05 ` [patch 04/12] Slab defragmentation: Logic to trigger defragmentation from memory reclaim Christoph Lameter
2007-07-08  3:05   ` Christoph Lameter
2007-07-08  3:05 ` [patch 05/12] Slab defragmentation: Log information to the syslog to show defrag operations Christoph Lameter
2007-07-08  3:05   ` Christoph Lameter
2007-07-08  3:05 ` [patch 06/12] Slab defragmentation: Support dentry defragmentation Christoph Lameter
2007-07-08  3:05   ` Christoph Lameter
2007-07-08  3:05 ` Christoph Lameter [this message]
2007-07-08  3:05   ` [patch 07/12] Slab defragmentation: Support for buffer_head defrag Christoph Lameter
2007-07-08  3:05 ` [patch 08/12] Slab defragmentation: Support generic defragmentation for inode slab caches Christoph Lameter
2007-07-08  3:05   ` Christoph Lameter
2007-07-08  3:05 ` [patch 09/12] Slab defragmentation: Support defragmentation for extX filesystem inodes Christoph Lameter
2007-07-08  3:05   ` Christoph Lameter
2007-07-08  3:05 ` [patch 10/12] Slab defragmentation: Support inode defragmentation for xfs Christoph Lameter
2007-07-08  3:05   ` Christoph Lameter
2007-07-08  3:05 ` [patch 11/12] Slab defragmentation: Support reiserfs inode defragmentation Christoph Lameter
2007-07-08  3:05   ` Christoph Lameter
2007-07-08  3:05 ` [patch 12/12] Slab defragmentation: kmem_cache_vacate for antifrag / memory compaction Christoph Lameter
2007-07-08  3:05   ` Christoph Lameter

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=20070708030845.032023558@sgi.com \
    --to=clameter@sgi.com \
    --cc=akpm@linux-foundation.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 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.