lkml.org 
[lkml]   [2001]   [Sep]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Fw: Re: [PATCH] fix page aging (2.4.9-ac12)
On Thu, 20 Sep 2001, Stephan von Krawczynski wrote:

> On Thu, 20 Sep 2001 15:32:26 +0200 Daniel Phillips <phillips@bonn-fries.net>
> wrote:
>
> > > Perhaps the following would be better, just in case anyone sets
> > > PAGE_AGE_DECL to something other than 1.
> > >
> > > static inline void age_page_down(struct page *page)
> > > {
> > > unsigned long age = page->age;
> > > if (age > PAGE_AGE_DECL)
> > > age -= PAGE_AGE_DECL;
> > > else
> > > age = 0;
> > > page->age = age;
> > > }
> >
> >
> > static inline void age_page_down(struct page *page)
> > {
> > page->age = max((int) (age - PAGE_AGE_DECL), 0);
> > }
> >
> > ;-)
>
> Aehm, Daniel. Just for a hint of what I know about C:
>
> IF age is unsigned long (like declared above) and PAGE_AGE_DECL is a define,
> then age-PAGE_AGE_DECL is of type unsigned long, which means it will not go
> below 0 but instead be huge positive, so your cast (int) before will not do any
> good, and you will not end up with 0 but somewhere above the clouds.

Bzzt. Conversion from unsigned to signed where the value won't fit is
implementation defined. In practice it's done by truncation which in the
case of twos-complement arithmetic means it becomes negative again, and it
all works. More problematic is when age is just above 2^31 and suddenly
becomes zero - not likely to show up though.

A better paradigm:

age = max(age, PAGE_AGE_DECL) - PAGE_AGE_DECL;
age -= min(age, PAGE_AGE_DECL);

--
"Love the dolphins," she advised him. "Write by W.A.S.T.E.."

-
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:03    [W:0.069 / U:0.196 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site