All of lore.kernel.org
 help / color / mirror / Atom feed
* Fw: Re: [PATCH] fix page aging (2.4.9-ac12)
@ 2001-09-20 13:48 Stephan von Krawczynski
  2001-09-20 14:03 ` Ville Herva
  2001-09-20 19:29 ` Oliver Xymoron
  0 siblings, 2 replies; 5+ messages in thread
From: Stephan von Krawczynski @ 2001-09-20 13:48 UTC (permalink / raw)
  To: linux-kernel

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.
So you just made Linus' max/min/cast point of view _very_ clear, I guess it was
something like "people don't really think about using max/min and related
problems".

;-))

I guess you meant:

page->age = max(((int)age - (int)PAGE_AGE_DECL),0);

Written without actually caring about the real definition of PAGE_AGE_DECL.

Regards,
Stephan

PS: please anyone don't tell me what gnu c actually thinks about this, I don't
care, I read K&R.
And, of course, the whole thing is not worth discussing, it just hit me ...


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-09-20 19:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-09-20 13:48 Fw: Re: [PATCH] fix page aging (2.4.9-ac12) Stephan von Krawczynski
2001-09-20 14:03 ` Ville Herva
2001-09-20 14:20   ` Stephan von Krawczynski
2001-09-20 14:57     ` Ville Herva
2001-09-20 19:29 ` Oliver Xymoron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.