mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ville Herva <vherva@mail.niksula.cs.hut.fi>
To: Stephan von Krawczynski <skraw@ithnet.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: Fw: Re: [PATCH] fix page aging (2.4.9-ac12)
Date: Thu, 20 Sep 2001 17:03:49 +0300	[thread overview]
Message-ID: <20010920170349.E22640@niksula.cs.hut.fi> (raw)
In-Reply-To: <20010920154806.75d7da23.skraw@ithnet.com>
In-Reply-To: <20010920154806.75d7da23.skraw@ithnet.com>; from skraw@ithnet.com on Thu, Sep 20, 2001 at 03:48:06PM +0200

On Thu, Sep 20, 2001 at 03:48:06PM +0200, you [Stephan von Krawczynski] claimed:
> On Thu, 20 Sep 2001 15:32:26 +0200 Daniel Phillips <phillips@bonn-fries.net>
> wrote:
> 
> >      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".

age - PAGE_AGE_DECL may be a 2^32-1 or so, but when you cast it back to int,
it is at most 2^31 again. It rolls over, so you get the sign bit back.
Witness:

vherva@linux:/home/vherva>cat n.c
#define FOUR 4
void main()
{
   unsigned three = 3;
   printf("%u\n", three - FOUR);
   printf("%i\n", (int)(three - FOUR));
   printf("%i\n", (int)three - (int)FOUR);
}

vherva@linux:/home/vherva>./a.out
4294967295
-1
-1

Perhaps a lucky incidence, but it works as Daniel wrote it. (At least on
32-bit architecture.)

I agree that Rik's variant is much more readable.


-- v --

v@iki.fi

  reply	other threads:[~2001-09-20 14:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-20 13:48 Stephan von Krawczynski
2001-09-20 14:03 ` Ville Herva [this message]
2001-09-20 14:20 ` Stephan von Krawczynski
2001-09-20 14:57   ` Ville Herva
2001-09-20 19:29 ` Oliver Xymoron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010920170349.E22640@niksula.cs.hut.fi \
    --to=vherva@mail.niksula.cs.hut.fi \
    --cc=linux-kernel@vger.kernel.org \
    --cc=skraw@ithnet.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®