lkml.org 
[lkml]   [2002]   [Dec]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH] Make `hash_long' function work if bits parameter is 0.
From
On Fri, Dec 06, 2002 at 08:37:26AM -0800, Linus Torvalds wrote:
> > If the bits parameter of hash_long (in <linux/hash.h>) is 0, then it
> > ends up right-shifting by BITS_PER_LONG, which is undefined in C (and
> > often is a nop).
>
> I would much rather just add a comment saying that "bits" had better be in
> a valid range. There are no valid uses for a 0-bit hash table that I can
> see, and undefined behaviour for undefined operations is fine with me.

The reason I sent the patch is because I ran into a case where the return
value _should_ be zero -- on a machine with very little memory (1MB), the
page wait-queue hash-table ends up having only one bucket (it has 256 pages,
and the code tries to make a wait-queue for every 256 pages....). The 0 is
returned by the `wait_table_bits' function in mm/page_alloc.c.

I suppose an alternative in this case is to special-case above calculation to
peg the minimum at 1.

-Miles
--
`...the Soviet Union was sliding in to an economic collapse so comprehensive
that in the end its factories produced not goods but bads: finished products
less valuable than the raw materials they were made from.' [The Economist]
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:31    [W:0.468 / U:0.000 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site