linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel Spång" <daniel.spang@gmail.com>
To: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Rik van Riel <riel@redhat.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Marcelo Tosatti <marcelo@kvack.org>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [RFC][PATCH 4/5] memory_pressure_notify() caller
Date: Wed, 16 Jan 2008 12:03:49 +0100	[thread overview]
Message-ID: <cfd9edbf0801160303s53237b81yb9d5e374c16cd006@mail.gmail.com> (raw)
In-Reply-To: <20080116104536.11AE.KOSAKI.MOTOHIRO@jp.fujitsu.com>

[-- Attachment #1: Type: text/plain, Size: 2560 bytes --]

On 1/16/08, KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> wrote:
> Hi Daniel
>
> > > > The notification fires after only ~100 MB allocated, i.e., when page
> > > > reclaim is beginning to nag from page cache. Isn't this a bit early?
> > > > Repeating the test with swap enabled results in a notification after
> > > > ~600 MB allocated, which is more reasonable and just before the system
> > > > starts to swap.
> > >
> > > Your issue may have more to do with the fact that the
> > > highmem zone is 128MB in size and some balancing issues
> > > between __alloc_pages and try_to_free_pages.
> >
> > I don't think so. I ran the test again without highmem and noticed the
> > same behaviour:
>
> Thank you for good point out!
> Could you please post your test program and reproduced method?

Sure:

1. Fill almost all available memory with page cache in a system without swap.
2. Run attached alloc-test program.
3. Notification fires when page cache is reclaimed.

Example:

$ cat /bigfile > /dev/null
$ cat /proc/meminfo
MemTotal:       895876 kB
MemFree:         94272 kB
Buffers:           884 kB
Cached:         782868 kB
SwapCached:          0 kB
Active:          15356 kB
Inactive:       778000 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:       895876 kB
LowFree:         94272 kB
SwapTotal:           0 kB
SwapFree:            0 kB
Dirty:               0 kB
Writeback:           0 kB
AnonPages:        9624 kB
Mapped:           1352 kB
Slab:             4220 kB
SReclaimable:     1168 kB
SUnreclaim:       3052 kB
PageTables:        528 kB
NFS_Unstable:        0 kB
Bounce:              0 kB
CommitLimit:    447936 kB
Committed_AS:    28988 kB
VmallocTotal:   122872 kB
VmallocUsed:       904 kB
VmallocChunk:   121864 kB
$ ./test-alloc
---------
Got notification, allocated 90 MB
$ cat /proc/meminfo
MemTotal:       895876 kB
MemFree:        101960 kB
Buffers:           888 kB
Cached:         775200 kB
SwapCached:          0 kB
Active:          15356 kB
Inactive:       770336 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:       895876 kB
LowFree:        101960 kB
SwapTotal:           0 kB
SwapFree:            0 kB
Dirty:              28 kB
Writeback:           0 kB
AnonPages:        9624 kB
Mapped:           1352 kB
Slab:             4224 kB
SReclaimable:     1168 kB
SUnreclaim:       3056 kB
PageTables:        532 kB
NFS_Unstable:        0 kB
Bounce:              0 kB
CommitLimit:    447936 kB
Committed_AS:    28988 kB
VmallocTotal:   122872 kB
VmallocUsed:       904 kB
VmallocChunk:   121864 kB

[-- Attachment #2: alloc-test.c --]
[-- Type: application/octet-stream, Size: 1738 bytes --]

/*
 * Allocate 10 MB each second. Exit on notification.
 */

#include <sys/mman.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <poll.h>
#include <pthread.h>
#include <errno.h>

int count = 0;
int size = 10;

void *do_alloc() 
{
        for(;;) {
                int *buffer;
                buffer = mmap(NULL,  size*1024*1024,
                              PROT_READ | PROT_WRITE,
                              MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
                if (buffer == MAP_FAILED) {
                        perror("mmap");
                        exit(EXIT_FAILURE);
                }
                memset(buffer, 1 , size*1024*1024);

                printf("-");
                fflush(stdout);

                count++;
                sleep(1);
        }
}

int wait_for_notification(struct pollfd *pfd)
{
        int ret;
        read(pfd->fd, 0, 0);
        ret = poll(pfd, 1, -1);
        if (ret == -1 && errno != EINTR) {
                perror("poll");
                exit(EXIT_FAILURE);
        }
        return ret;
}

void do_free() 
{
        struct pollfd pfd;

        pfd.fd = open("/dev/mem_notify", O_RDONLY);
        if (pfd.fd == -1) {
                perror("open");
                exit(EXIT_FAILURE);
        }
        pfd.events = POLLIN;
        for(;;)
                if (wait_for_notification(&pfd) > 0) {
                        printf("\nGot notification, allocated %d MB\n",
                               size * count);
                        exit(EXIT_SUCCESS);
                }
}

int main(int argc, char *argv[])
{
        pthread_t allocator;

        pthread_create(&allocator, NULL, do_alloc, NULL);
        do_free();
}

  reply	other threads:[~2008-01-16 11:03 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-15  0:52 [RFC][PATCH 0/5] mem notifications v4 KOSAKI Motohiro
2008-01-15  0:59 ` [RFC][PATCH 1/5] introduce poll_wait_exclusive() new API KOSAKI Motohiro
2008-01-15  1:00 ` [RFC][PATCH 2/5] introduce wake_up_locked_nr() " KOSAKI Motohiro
2008-01-15  1:01 ` [RFC][PATCH 3/5] add /dev/mem_notify device KOSAKI Motohiro
2008-01-15  1:08   ` Randy Dunlap
2008-01-15  1:20     ` KOSAKI Motohiro
2008-01-15  1:24       ` KOSAKI Motohiro
2008-01-15  2:10   ` KAMEZAWA Hiroyuki
2008-01-15  2:20     ` KOSAKI Motohiro
2008-01-15  2:56       ` Rik van Riel
2008-01-15 10:46   ` Alan Cox
2008-01-15 10:59     ` KOSAKI Motohiro
2008-01-15 11:20       ` Alan Cox
2008-01-15 11:48         ` KOSAKI Motohiro
2008-01-15 13:42           ` Alan Cox
2008-01-16  2:43             ` KOSAKI Motohiro
2008-01-15 12:05         ` Marcelo Tosatti
2008-01-15 13:42           ` Alan Cox
2008-01-15 22:16   ` Pavel Machek
2008-01-16  1:57     ` KOSAKI Motohiro
2008-01-16  4:13       ` Marcelo Tosatti
2008-01-16 11:42         ` Pavel Machek
2008-01-16 11:51           ` Daniel Spång
2008-01-17  3:04             ` KOSAKI Motohiro
2008-01-15  1:02 ` [RFC][PATCH 4/5] memory_pressure_notify() caller KOSAKI Motohiro
2008-01-15  2:06   ` KAMEZAWA Hiroyuki
2008-01-15  2:37     ` KOSAKI Motohiro
2008-01-15  3:00       ` KAMEZAWA Hiroyuki
2008-01-15  3:08         ` KOSAKI Motohiro
2008-01-15 22:55   ` Daniel Spång
2008-01-15 22:59     ` Rik van Riel
2008-01-15 23:39       ` Daniel Spång
2008-01-16  1:48         ` KOSAKI Motohiro
2008-01-16 11:03           ` Daniel Spång [this message]
2008-01-17  3:26             ` KOSAKI Motohiro
2008-01-18 10:24               ` Daniel Spång
2008-01-18 10:30                 ` KOSAKI Motohiro
2008-01-15  1:03 ` [RFC][PATCH 5/5] /proc/zoneinfo enhancement KOSAKI Motohiro
2008-01-15 10:44   ` Alan Cox
2008-01-15 10:49     ` KOSAKI Motohiro

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=cfd9edbf0801160303s53237b81yb9d5e374c16cd006@mail.gmail.com \
    --to=daniel.spang@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=marcelo@kvack.org \
    --cc=riel@redhat.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