From: Andrew Morton <akpm@zip.com.au>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: lkml <linux-kernel@vger.kernel.org>
Subject: [patch 2/21] reduced locking in buffer.c
Date: Sun, 11 Aug 2002 00:38:27 -0700 [thread overview]
Message-ID: <3D561473.40A53C0D@zip.com.au> (raw)
Resend. Replace the buffer lru spinlock protection with
local_irq_disable and a cross-CPU call to invalidate them.
buffer.c | 75 ++++++++++++++++++++++++++++++++++++++++-----------------------
1 files changed, 48 insertions(+), 27 deletions(-)
--- 2.5.31/fs/buffer.c~buffer-lru-lock Sat Aug 10 23:27:26 2002
+++ 2.5.31-akpm/fs/buffer.c Sat Aug 10 23:27:26 2002
@@ -1277,15 +1277,32 @@ __bread_slow(struct block_device *bdev,
*
* This is a transparent caching front-end to sb_bread(), sb_getblk() and
* sb_find_get_block().
+ *
+ * The LRUs themselves only need locking against invalidate_bh_lrus. We use
+ * a local interrupt disable for that.
*/
-#define BH_LRU_SIZE 7
+#define BH_LRU_SIZE 8
static struct bh_lru {
- spinlock_t lock;
struct buffer_head *bhs[BH_LRU_SIZE];
} ____cacheline_aligned_in_smp bh_lrus[NR_CPUS];
+#ifdef CONFIG_SMP
+#define bh_lru_lock() local_irq_disable()
+#define bh_lru_unlock() local_irq_enable()
+#else
+#define bh_lru_lock() preempt_disable()
+#define bh_lru_unlock() preempt_enable()
+#endif
+
+static inline void check_irqs_on(void)
+{
+#ifdef irqs_disabled
+ BUG_ON(irqs_disabled());
+#endif
+}
+
/*
* The LRU management algorithm is dopey-but-simple. Sorry.
*/
@@ -1297,8 +1314,9 @@ static void bh_lru_install(struct buffer
if (bh == NULL)
return;
- lru = &bh_lrus[get_cpu()];
- spin_lock(&lru->lock);
+ check_irqs_on();
+ bh_lru_lock();
+ lru = &bh_lrus[smp_processor_id()];
if (lru->bhs[0] != bh) {
struct buffer_head *bhs[BH_LRU_SIZE];
int in;
@@ -1324,8 +1342,7 @@ static void bh_lru_install(struct buffer
bhs[out++] = NULL;
memcpy(lru->bhs, bhs, sizeof(bhs));
}
- spin_unlock(&lru->lock);
- put_cpu();
+ bh_lru_unlock();
if (evictee) {
touch_buffer(evictee);
@@ -1340,8 +1357,9 @@ lookup_bh(struct block_device *bdev, sec
struct bh_lru *lru;
int i;
- lru = &bh_lrus[get_cpu()];
- spin_lock(&lru->lock);
+ check_irqs_on();
+ bh_lru_lock();
+ lru = &bh_lrus[smp_processor_id()];
for (i = 0; i < BH_LRU_SIZE; i++) {
struct buffer_head *bh = lru->bhs[i];
@@ -1359,8 +1377,7 @@ lookup_bh(struct block_device *bdev, sec
break;
}
}
- spin_unlock(&lru->lock);
- put_cpu();
+ bh_lru_unlock();
return ret;
}
@@ -1407,26 +1424,33 @@ __bread(struct block_device *bdev, secto
EXPORT_SYMBOL(__bread);
/*
- * This is called rarely - at unmount.
+ * invalidate_bh_lrus() is called rarely - at unmount. Because it is only for
+ * unmount it only needs to ensure that all buffers from the target device are
+ * invalidated on return and it doesn't need to worry about new buffers from
+ * that device being added - the unmount code has to prevent that.
*/
-static void invalidate_bh_lrus(void)
+static void invalidate_bh_lru(void *arg)
{
- int cpu_idx;
+ const int cpu = get_cpu();
+ int i;
- for (cpu_idx = 0; cpu_idx < NR_CPUS; cpu_idx++)
- spin_lock(&bh_lrus[cpu_idx].lock);
- for (cpu_idx = 0; cpu_idx < NR_CPUS; cpu_idx++) {
- int i;
-
- for (i = 0; i < BH_LRU_SIZE; i++) {
- brelse(bh_lrus[cpu_idx].bhs[i]);
- bh_lrus[cpu_idx].bhs[i] = NULL;
- }
+ for (i = 0; i < BH_LRU_SIZE; i++) {
+ brelse(bh_lrus[cpu].bhs[i]);
+ bh_lrus[cpu].bhs[i] = NULL;
}
- for (cpu_idx = 0; cpu_idx < NR_CPUS; cpu_idx++)
- spin_unlock(&bh_lrus[cpu_idx].lock);
+ put_cpu();
+}
+
+static void invalidate_bh_lrus(void)
+{
+ preempt_disable();
+ invalidate_bh_lru(NULL);
+ smp_call_function(invalidate_bh_lru, NULL, 1, 1);
+ preempt_enable();
}
+
+
void set_bh_page(struct buffer_head *bh,
struct page *page, unsigned long offset)
{
@@ -2554,9 +2578,6 @@ void __init buffer_init(void)
{
int i;
- for (i = 0; i < NR_CPUS; i++)
- spin_lock_init(&bh_lrus[i].lock);
-
bh_cachep = kmem_cache_create("buffer_head",
sizeof(struct buffer_head), 0,
SLAB_HWCACHE_ALIGN, init_buffer_head, NULL);
.
next reply other threads:[~2002-08-11 7:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-08-11 7:38 Andrew Morton [this message]
2002-08-13 17:34 ` [patch 2/21] reduced locking in buffer.c Linus Torvalds
2002-08-13 17:34 ` David S. Miller
2002-08-13 17:53 ` Andrew Morton
2002-08-13 17:52 ` Christoph Hellwig
2002-08-13 18:09 ` Andrew Morton
2002-08-14 8:36 ` William Lee Irwin III
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=3D561473.40A53C0D@zip.com.au \
--to=akpm@zip.com.au \
--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.