Re: [PATCH] mm: prevent divide error for small values ofvm_dirty_bytes

From: Peter Zijlstra
Date: Wed Apr 29 2009 - 04:45:12 EST


On Wed, 2009-04-29 at 10:29 +0200, Andrea Righi wrote:
> Avoid to set less than two pages for vm_dirty_byte: this is necessary to avoid
> potential division by 0 (like the following) in get_dirty_limits().

isn't changing the .extra1 in the sysctl table a better fix?

> Signed-off-by: Andrea Righi <righi.andrea@xxxxxxxxx>
> ---
> mm/page-writeback.c | 6 ++++++
> 1 files changed, 6 insertions(+), 0 deletions(-)
>
> diff --git a/mm/page-writeback.c b/mm/page-writeback.c
> index 30351f0..9d6c427 100644
> --- a/mm/page-writeback.c
> +++ b/mm/page-writeback.c
> @@ -213,6 +213,12 @@ int dirty_bytes_handler(struct ctl_table *table, int write,
> int ret;
>
> ret = proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos);
> + /*
> + * Do not allow to set less than two pages for vm_dirty_byte: this is
> + * necessary to avoid division by 0 in get_dirty_limits().
> + */
> + vm_dirty_bytes = max_t(typeof(vm_dirty_bytes),
> + vm_dirty_bytes, 2 * PAGE_SIZE);
> if (ret == 0 && write && vm_dirty_bytes != old_bytes) {
> update_completion_period();
> vm_dirty_ratio = 0;

--
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/