Re: [PATCH -mm] page-writeback: fine-grained dirty_ratio and dirty_background_ratio

From: Andrea Righi
Date: Fri Oct 10 2008 - 05:32:40 EST


KAMEZAWA Hiroyuki wrote:
> <snip>
>
>> -int dirty_background_ratio = 5;
>> +int dirty_background_ratio = 5 * PERCENT_PCM;
>>
>> /*
>> * free highmem will not be subtracted from the total free memory
>> @@ -77,7 +77,7 @@ int vm_highmem_is_dirtyable;
>> /*
>> * The generator of dirty data starts writeback at this percentage
>> */
>> -int vm_dirty_ratio = 10;
>> +int vm_dirty_ratio = 10 * PERCENT_PCM;
>>
>> /*
>> * The interval between `kupdate'-style writebacks, in jiffies
>> @@ -135,7 +135,8 @@ static int calc_period_shift(void)
>> {
>> unsigned long dirty_total;
>>
>> - dirty_total = (vm_dirty_ratio * determine_dirtyable_memory()) / 100;
>> + dirty_total = (vm_dirty_ratio * determine_dirtyable_memory())
>> + / ONE_HUNDRED_PCM;
>> return 2 + ilog2(dirty_total - 1);
>> }
>>
> I wonder...isn't this overflow in 32bit system ?

Correct! the worst case is (in pages):

4GB = 100,000 * determine_dirtyable_memory()

that means 42950 pages (~168MB) of dirtyable memory is enough to overflow :(.
Using an u64 for dirty_total should resolve.

Delta patch is below.

Unfortunately I have all 64-bit machines right now. Maybe tomorrow I'll
be able to get a 32-bit box, if someone doesn't test this before.

Thanks!
-Andrea

---
Subject: fix overflow in 32-bit systems using fine-grained dirty_ratio

Signed-off-by: Andrea Righi <righi.andrea@xxxxxxxxx>
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx>
---
mm/page-writeback.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 6bc8c9b..29913e5 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -133,7 +133,7 @@ static struct prop_descriptor vm_dirties;
*/
static int calc_period_shift(void)
{
- unsigned long dirty_total;
+ u64 dirty_total;

dirty_total = (vm_dirty_ratio * determine_dirtyable_memory())
/ ONE_HUNDRED_PCM;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/