Re: free_memory_available()

H. Peter Anvin (hpa@transmeta.com)
28 Dec 1998 01:52:09 GMT


Followup to: <19981228024700.A315@braindamage.linux.bogus>
By author: Erik Elmgren <erik.elmgren@swipnet.se>
In newsgroup: linux.dev.kernel
>
> Reading through the sources, trying to understand them, I find:
>
> page_alloc.c, line 103
> : int free_memory_available(void)
> : {
> : static int available = 1;
> :
> : if (nr_free_pages < freepages.low) {
> : available = 0;
> : return 0;
> : }
> :
> : if (nr_free_pages > freepages.high) {
> : available = 1;
> : return 2;
> : }
> :
> : return available;
> : }
>
> Have I gone mad (unlikely but possible) and there /is/ a reason to assign
> a value to a local var and then immediately, unconditionally return?!

Yes. The variable is static, which means it is initialized to 1 only
at the very start. If neither of the if statements is activated,
"available" returns whatever it was last set to.

-hpa

-- 
    PGP: 2047/2A960705 BA 03 D3 2C 14 A8 A8 BD  1E DF FE 69 EE 35 BD 74
    See http://www.zytor.com/~hpa/ for web page and full PGP public key
        I am Bahá'í -- ask me about it or see http://www.bahai.org/
   "To love another person is to see the face of God." -- Les Misérables

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/