Re: free_memory_available()

Brandon S. Allbery KF8NH (allbery@kf8nh.apk.net)
Sun, 27 Dec 1998 20:53:07 -0500


In message <19981228024700.A315@braindamage.linux.bogus>, Erik Elmgren
writes:
+-----
| 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?!
+--->8

It's a static variable. As such, it constitutes saved state. Your proposed
alternative doesn't do the same thing:

| return 1
+--->8

Causes it to report that a low-memory condition has been exited as soon as
there are more than a minimum number available; the code above remembers "we
ran out of memory" until the available memory reaches a high-water mark,
avoiding serious thrashing where the available memory drops to the low-water
mark and stays there, causing a low-memory condition on virtually every
successive memory allocation.

-- 
brandon s. allbery	[os/2][linux][solaris][japh]	 allbery@kf8nh.apk.net
system administrator	     [WAY too many hats]	   allbery@ece.cmu.edu
carnegie mellon / electrical and computer engineering			 KF8NH
     We are Linux. Resistance is an indication that you missed the point.

- 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/