Skip to contentSkip to conversation

ext4: mballoc avoid use root reserved blocks for non root allocation

PATCH In review Mingming Cao 2 participants 3 messages Jun 1, 2008 – Jun 6, 2008 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: mballoc avoid use root reserved blocks for non root allocation

ext4: mballoc avoid use root reserved blocks for non root allocation

From: Mingming Cao <[email protected]>

mballoc allocation missed check for blocks reserved for root users. Add ext4_has_free_blocks() check before allocation. Also modified ext4_has_free_blocks() to support multiple block allocation request.

---
 fs/ext4/balloc.c  |   50 ++++++++++++++++++++++++++++++++------------------
 fs/ext4/ext4.h    |    2 ++
 fs/ext4/mballoc.c |    7 ++++++-
 3 files changed, 40 insertions(+), 19 deletions(-)
fs/ext4/mballoc.c +6 -1
Index: linux-2.6.26-rc4/fs/ext4/mballoc.c
===================================================================
@@ -4038,6 +4038,12 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t
 					    &(ar->len), errp);
 		return block;
 	}
+	ar->len = ext4_has_free_blocks(sbi, ar->len);
+
+	if (ar->len == 0) {
+		*errp = -ENOSPC;
+		return 0;
+	}
 
 	while (ar->len && DQUOT_ALLOC_BLOCK(ar->inode, ar->len)) {
 		ar->flags |= EXT4_MB_HINT_NOPREALLOC;
@@ -4066,7 +4072,6 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t
 
 	ac->ac_op = EXT4_MB_HISTORY_PREALLOC;
 	if (!ext4_mb_use_preallocated(ac)) {
-
 		ac->ac_op = EXT4_MB_HISTORY_ALLOC;
 		ext4_mb_normalize_request(ac, ar);
 repeat:
fs/ext4/balloc.c +32 -17

82 lines not on this page · raw message

maintainer
#1 lore raw
Quoted 7 lines · Mingming Cao

ext4: mballoc avoid use root reserved blocks for non root allocation

From: Mingming Cao <[email protected]>

mballoc allocation missed check for blocks reserved for root users. Add ext4_has_free_blocks() check before allocation. Also modified ext4_has_free_blocks() to support multiple block allocation request.

This was discovered by a Gentoo user who tried compiling on a UP system.....

fs/ext4/balloc.c out: · line 1629

Quoted 5 lines

Index: linux-2.6.26-rc4/fs/ext4/balloc.c
....

fs/ext4/balloc.c +3 -0
+	if (free_blocks - root_blocks < FBC_BATCH)
+		free_blocks =
+			percpu_counter_sum_positive(&sbi->s_freeblocks_counter);

FBC_BATCH is only defined if CONFIG_SMP is defined. I believe the simplest fix is surround the above if statement with an "#ifdef CONFIG_SMP", since on UP systems, the percpu counters are always exactly correct.

- Ted

#2 lore raw
Quoted 11 lines · Theodore Tso
Quoted 7 lines · Mingming Cao

ext4: mballoc avoid use root reserved blocks for non root allocation

From: Mingming Cao <[email protected]>

mballoc allocation missed check for blocks reserved for root users. Add ext4_has_free_blocks() check before allocation. Also modified ext4_has_free_blocks() to support multiple block allocation request.

This was discovered by a Gentoo user who tried compiling on a UP system.....

Quoted 12 lines

fs/ext4/balloc.c out: · line 1629

Quoted 5 lines

Index: linux-2.6.26-rc4/fs/ext4/balloc.c
....

fs/ext4/balloc.c +3 -0
+	if (free_blocks - root_blocks < FBC_BATCH)
+		free_blocks =
+			percpu_counter_sum_positive(&sbi->s_freeblocks_counter);

FBC_BATCH is only defined if CONFIG_SMP is defined. I believe the simplest fix is surround the above if statement with an "#ifdef CONFIG_SMP", since on UP systems, the percpu counters are always exactly correct.

Works for me. One up system the counter is always accurate.

FBC_BATCH is just some value to trigger sum up from per cpu counters to get the accurate value, we don't need to do this for single UP.

Mingming

Quoted 1 line

- Ted