mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hugh Dickins <hughd@google.com>
To: Kenny Simpson <theonetruekenny@yahoo.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: remap_file_pages doesn't like MAP_ANONYMOUS (but used to?)
Date: Sat, 19 Mar 2011 15:52:57 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LSU.2.00.1103191525180.1609@sister.anvils> (raw)
In-Reply-To: <11649.19421.qm@web39421.mail.mud.yahoo.com>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1654 bytes --]

On Wed, 16 Mar 2011, Kenny Simpson wrote:
> Hello,
>   In older kernels (2.6.15-2.6.18?) I was able to make an anonymous mapping and remap part of it back over itself to create a circular buffer:
>   p = mmap(0, sz, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0)
>   remap_file_pages(p + sz/2, sz/2, 0/*prot*/, 0/*offset*/, 0/*flags*/)
> 
> I find the same method fails with EINVAL on the remap_file_pages call in 2.6.35/38.  Making a dummy file or shared memory object works, but seems a bit more messy.
> 
> Why drop support for ANONYMOUS?  Is there another way to get the same effect?

Thanks for reporting.  It was a simple oversight: and until you came
along, nobody noticed.  Here's the patch, I'll pass it upstream shortly.

[PATCH] shmem: let shared anonymous be nonlinear again

Up to 2.6.22, you could use remap_file_pages(2) on a tmpfs file or a
shared mapping of /dev/zero or a shared anonymous mapping.  In 2.6.23
we disabled it by default, but set VM_CAN_NONLINEAR to enable it on
safe mappings.  We made sure to set it in shmem_mmap() for tmpfs files,
but missed it in shmem_zero_setup() for the others.  Fix that at last.

Reported-by: Kenny Simpson <theonetruekenny@yahoo.com>
Signed-off-by: Hugh Dickins <hughd@google.com>
---

 mm/shmem.c |    1 +
 1 file changed, 1 insertion(+)

--- 2.6.38/mm/shmem.c	2011-03-14 18:20:32.000000000 -0700
+++ linux/mm/shmem.c	2011-03-19 15:09:26.000000000 -0700
@@ -2791,5 +2791,6 @@ int shmem_zero_setup(struct vm_area_stru
 		fput(vma->vm_file);
 	vma->vm_file = file;
 	vma->vm_ops = &shmem_vm_ops;
+	vma->vm_flags |= VM_CAN_NONLINEAR;
 	return 0;
 }

  reply	other threads:[~2011-03-19 22:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-17  5:54 Kenny Simpson
2011-03-19 22:52 ` Hugh Dickins [this message]
2011-03-20 17:51   ` Kenny Simpson
2011-03-21  1:57     ` Hugh Dickins

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=alpine.LSU.2.00.1103191525180.1609@sister.anvils \
    --to=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=theonetruekenny@yahoo.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

all inboxes | Powered by JetHome®