mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@suse.cz>
To: riel@conectiva.com.br, kernel list <linux-kernel@vger.kernel.org>
Subject: Out of memory handling broken
Date: Tue, 25 Sep 2001 00:34:16 +0200	[thread overview]
Message-ID: <20010925003416.A151@bug.ucw.cz> (raw)

Hi!

I need to allocate as much memory as possible (but not more). Okay, so
I use out_of_memory, right?

Does this code look sane?

static void eat_memory(void)
{
        int i = 0;
        void **c= eaten_memory, *m;

        printk("Eating pages ");
        while ((m = (void *) get_free_page(GFP_USER))) {
                memset(m, 0, PAGE_SIZE);
                eaten_memory = m;
                if (!(i%5000))
                        printk( "." );
                *eaten_memory = c;
                c = eaten_memory;
                i++;
                if (out_of_memory())
                        break;
        }
        printk("(%dK)\n", i*4);
}

[if not, how should I code it?]

But, when I looked into out_of_memory... Of course its
wrong. out_of_memory() contains

        if (nr_swap_pages > 0)
                return 0;

...which is obviously wrong. It is well possible to have free swap
_and_ be out of memory -- eat_memory() loop gets system to this state
easily.
								Pavel
-- 
I'm pavel@ucw.cz. "In my country we have almost anarchy and I don't care."
Panos Katsaloulis describing me w.r.t. patents at discuss@linmodems.org

             reply	other threads:[~2001-09-25 19:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-24 22:34 Pavel Machek [this message]
2001-09-25 20:05 ` Rik van Riel
2001-09-26 14:03   ` Pavel Machek
2001-09-26 14:08     ` Rik van Riel
2001-09-26 14:25       ` Pavel Machek

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=20010925003416.A151@bug.ucw.cz \
    --to=pavel@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=riel@conectiva.com.br \
    /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®