linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Joern Engel <joern@logfs.org>
To: linux-kernel@vger.kernel.org, linux-mm@kvack.org
Cc: Andrew Morton <akpm@linux-foundation.org>, Joern Engel <joern@logfs.org>
Subject: [PATCH 0/2] hugetlb fixes
Date: Tue, 18 Jun 2013 14:47:03 -0400	[thread overview]
Message-ID: <1371581225-27535-1-git-send-email-joern@logfs.org> (raw)

As everyone knows, hugetlbfs sucks.  But it is also necessary for
large memory machines, so we should make it suck less.  Top of my list
were lack of rss accounting and refusing mmap with MAP_HUGETLB when
using hugetlbfs.  The latter generally created a know in every brain I
explained this to.

Test program below is failing before these two patches and passing
after.

Joern Engel (2):
  hugetlb: properly account rss
  mmap: allow MAP_HUGETLB for hugetlbfs files

 mm/hugetlb.c |    4 ++++
 mm/mmap.c    |   12 ++++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

-- 
1.7.10.4

#define _GNU_SOURCE
#include <assert.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

typedef unsigned long long u64;

static size_t length = 1 << 24;

static u64 read_rss(void)
{
	char buf[4096], *s = buf;
	int i, fd;
	u64 rss;

	fd = open("/proc/self/statm", O_RDONLY);
	assert(fd > 2);
	memset(buf, 0, sizeof(buf));
	read(fd, buf, sizeof(buf) - 1);
	for (i = 0; i < 1; i++)
		s = strchr(s, ' ') + 1;
	rss = strtoull(s, NULL, 10);
	return rss << 12; /* assumes 4k pagesize */
}

static void do_mmap(int fd, int extra_flags, int unmap)
{
	int *p;
	int flags = MAP_PRIVATE | MAP_POPULATE | extra_flags;
	u64 before, after;

	before = read_rss();
	p = mmap(NULL, length, PROT_READ | PROT_WRITE, flags, fd, 0);
	assert(p != MAP_FAILED ||
			!"mmap returned an unexpected error");
	after = read_rss();
	assert(llabs(after - before - length) < 0x40000 ||
			!"rss didn't grow as expected");
	if (!unmap)
		return;
	munmap(p, length);
	after = read_rss();
	assert(llabs(after - before) < 0x40000 ||
			!"rss didn't shrink as expected");
}

static int open_file(const char *path)
{
	int fd, err;

	unlink(path);
	fd = open(path, O_CREAT | O_RDWR | O_TRUNC | O_EXCL
			| O_LARGEFILE | O_CLOEXEC, 0600);
	assert(fd > 2);
	unlink(path);
	err = ftruncate(fd, length);
	assert(!err);
	return fd;
}

int main(void)
{
	int hugefd, fd;

	fd = open_file("/dev/shm/hugetlbhog");
	hugefd = open_file("/hugepages/hugetlbhog");

	system("echo 100 > /proc/sys/vm/nr_hugepages");
	do_mmap(-1, MAP_ANONYMOUS, 1);
	do_mmap(fd, 0, 1);
	do_mmap(-1, MAP_ANONYMOUS | MAP_HUGETLB, 1);
	do_mmap(hugefd, 0, 1);
	do_mmap(hugefd, MAP_HUGETLB, 1);
	/* Leak the last one to test do_exit() */
	do_mmap(-1, MAP_ANONYMOUS | MAP_HUGETLB, 0);
	printf("oll korrekt.\n");
	return 0;
}

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

             reply	other threads:[~2013-06-18 20:17 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-18 18:47 Joern Engel [this message]
2013-06-18 18:47 ` [PATCH 1/2] hugetlb: properly account rss Joern Engel
2013-06-28 22:03   ` Andrew Morton
2013-07-03 13:41   ` Steve Capper
2013-07-03 14:55     ` Steve Capper
2013-06-18 18:47 ` [PATCH 2/2] mmap: allow MAP_HUGETLB for hugetlbfs files Joern Engel
2013-06-19  1:22   ` Jianguo Wu
2013-06-19 16:25     ` [PATCH] mmap: allow MAP_HUGETLB for hugetlbfs files v2 Jörn Engel
2013-06-20  1:31       ` Jianguo Wu
2013-06-19 16:25     ` [PATCH 2/2] mmap: allow MAP_HUGETLB for hugetlbfs files Jörn Engel
2013-06-18 18:50 ` [PATCH 0/2] hugetlb fixes Jörn Engel
2013-06-18 20:27   ` Andrew Morton
2013-06-18 20:04     ` Jörn Engel

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=1371581225-27535-1-git-send-email-joern@logfs.org \
    --to=joern@logfs.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /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