linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@redhat.com>
To: ext4 development <linux-ext4@vger.kernel.org>
Subject: [PATCH] use for_each_possible_cpu for reservation slots
Date: Tue, 27 Feb 2007 14:52:48 -0600	[thread overview]
Message-ID: <45E49A20.5080604@redhat.com> (raw)

NR_CPUS is a config-time option that may be much more than your actual
count of runtime possible CPUs... 

compile-tested.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>

Index: linux-2.6-ext4/fs/ext4/balloc.c
===================================================================
--- linux-2.6-ext4.orig/fs/ext4/balloc.c
+++ linux-2.6-ext4/fs/ext4/balloc.c
@@ -1895,16 +1895,17 @@ void ext4_rebalance_reservation(struct e
 	__u64 chunk;
 
 	/* let's know what slots have been used */
-	for (i = 0; i < NR_CPUS; i++)
+	for_each_possible_cpu(i) {
 		if (rs[i].rs_reserved || i == smp_processor_id())
 			used_slots++;
+	}
 
 	/* chunk is a number of block every used
 	 * slot will get. make sure it isn't 0 */
 	chunk = free + used_slots - 1;
 	do_div(chunk, used_slots);
 
-	for (i = 0; i < NR_CPUS; i++) {
+	for_each_possible_cpu(i) {
 		if (free < chunk)
 			chunk = free;
 		if (rs[i].rs_reserved || i == smp_processor_id()) {
@@ -1926,7 +1927,7 @@ int ext4_reserve_global(struct super_blo
 	rs = sbi->s_reservation_slots;
 
 	/* lock all slots */
-	for (i = 0; i < NR_CPUS; i++) {
+	for_each_possible_cpu(i) {
 		spin_lock(&rs[i].rs_lock);
 		free += rs[i].rs_reserved;
 	}
@@ -1937,8 +1938,9 @@ int ext4_reserve_global(struct super_blo
 		rc = 0;
 	}
 
-	for (i = 0; i < NR_CPUS; i++)
+	for_each_possible_cpu(i) {
 		spin_unlock(&rs[i].rs_lock);
+	}
 
 	return rc;
 }
@@ -1979,12 +1981,14 @@ int ext4_reserve_init(struct super_block
 	struct ext4_reservation_slot *rs;
 	int i;
 
-	rs = kmalloc(sizeof(struct ext4_reservation_slot) * NR_CPUS, GFP_KERNEL);
+	rs = kmalloc(sizeof(struct ext4_reservation_slot) * 
+			highest_possible_processor_id()+1,
+		     GFP_KERNEL);
 	if (rs == NULL)
 		return -ENOMEM;
 	sbi->s_reservation_slots = rs;
 
-	for (i = 0; i < NR_CPUS; i++) {
+	for_each_possible_cpu(i) {
 		spin_lock_init(&rs[i].rs_lock);
 		rs[i].rs_reserved = 0;
 	}

             reply	other threads:[~2007-02-27 20:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-27 20:52 Eric Sandeen [this message]
2007-03-12 17:16 ` [PATCH] use for_each_possible_cpu for reservation slots Eric Sandeen

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=45E49A20.5080604@redhat.com \
    --to=sandeen@redhat.com \
    --cc=linux-ext4@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;
as well as URLs for NNTP newsgroup(s).