From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [195.92.253.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7A3A2DDF18 for ; Fri, 12 Dec 2008 07:28:16 +1100 (EST) Date: Thu, 11 Dec 2008 20:28:00 +0000 From: Al Viro To: Andrew Morton Subject: Re: [PATCH][v2] fork_init: fix division by zero Message-ID: <20081211202800.GQ28946@ZenIV.linux.org.uk> References: <200812101950.51958.yur@emcraft.com> <20081211121635.ff58193f.akpm@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii In-Reply-To: <20081211121635.ff58193f.akpm@linux-foundation.org> Sender: Al Viro Cc: wd@denx.de, dzu@denx.de, linux-kernel@vger.kernel.org, linuxppc-dev@ozlabs.org, miltonm@bga.com, Geert.Uytterhoeven@sonycom.com, yanok@emcraft.com List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On Thu, Dec 11, 2008 at 12:16:35PM -0800, Andrew Morton wrote: > > +#if (8 * THREAD_SIZE) > PAGE_SIZE > > max_threads = mempages / (8 * THREAD_SIZE / PAGE_SIZE); > > +#else > > + max_threads = mempages * (PAGE_SIZE / (8 * THREAD_SIZE)); > > +#endif > > The expression you've chosen here can be quite inacccurate, because > ((PAGE_SIZE / (8 * THREAD_SIZE)) is a small number. The way to > preserve accuracy is > > max_threads = (mempages * PAGE_SIZE) / (8 * THREAD_SIZE); > > so how about avoiding the nasty ifdefs and doing Are you sure? Do they actually cross the page boundaries? From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757890AbYLKU2V (ORCPT ); Thu, 11 Dec 2008 15:28:21 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756929AbYLKU2I (ORCPT ); Thu, 11 Dec 2008 15:28:08 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:60381 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756920AbYLKU2H (ORCPT ); Thu, 11 Dec 2008 15:28:07 -0500 Date: Thu, 11 Dec 2008 20:28:00 +0000 From: Al Viro To: Andrew Morton Cc: Yuri Tikhonov , linux-kernel@vger.kernel.org, linuxppc-dev@ozlabs.org, Geert.Uytterhoeven@sonycom.com, dhowells@redhat.com, miltonm@bga.com, wd@denx.de, dzu@denx.de, yanok@emcraft.com Subject: Re: [PATCH][v2] fork_init: fix division by zero Message-ID: <20081211202800.GQ28946@ZenIV.linux.org.uk> References: <200812101950.51958.yur@emcraft.com> <20081211121635.ff58193f.akpm@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20081211121635.ff58193f.akpm@linux-foundation.org> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 11, 2008 at 12:16:35PM -0800, Andrew Morton wrote: > > +#if (8 * THREAD_SIZE) > PAGE_SIZE > > max_threads = mempages / (8 * THREAD_SIZE / PAGE_SIZE); > > +#else > > + max_threads = mempages * (PAGE_SIZE / (8 * THREAD_SIZE)); > > +#endif > > The expression you've chosen here can be quite inacccurate, because > ((PAGE_SIZE / (8 * THREAD_SIZE)) is a small number. The way to > preserve accuracy is > > max_threads = (mempages * PAGE_SIZE) / (8 * THREAD_SIZE); > > so how about avoiding the nasty ifdefs and doing Are you sure? Do they actually cross the page boundaries?