Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1334848
| Path | csiph.com!feeder.erje.net!2.us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!news.mixmin.net!aioe.org!gothmog.csi.it!bofh.it!news.nic.it!robomod |
|---|---|
| From | Grazvydas Ignotas <notasas@gmail.com> |
| Newsgroups | linux.kernel |
| Subject | Re: remap_file_pages regression |
| Date | Mon, 15 Feb 2016 23:10:01 +0100 |
| Message-ID | <r2zvb-794-9@gated-at.bofh.it> (permalink) |
| References | <r2giS-2rc-11@gated-at.bofh.it> <r2ozM-824-31@gated-at.bofh.it> |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=xX2o+dT6LmeVya6nb92LPFd8nAnBiF70Blwt1VPwnnc=; b=Q7I3gajU0ox/I4OtY9g+UVkgIhaqg8qri00ZJqIvCZRNxLeq4m6Sf8qmBffWQaRWVk TsMiHFEY2Kk4TPOUjzdK8UxtcB5J9dEHP6hw5W49gFtT2rCRYSkPdxgPLpdGsjPlGjBj 1+FYeoMBuwsbR47RQvpS/u8a7E2xLUVSTfJQMp+OPbrIQjZxCuLoaBYO4h6I9XWw+9f3 60d1/41bqM8gzKC7C4yTugv9BK2eQGX5727m86MJ9MW18WGGzSbOv8DRDoQImvGNzONf xAzu8wxxOiXxhN1BzZ4eOVZuUDUtIfWCisxDy2oXlYYQjXdzIcPi6j+Pg/rTG74ZtbXO M/NQ== |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=xX2o+dT6LmeVya6nb92LPFd8nAnBiF70Blwt1VPwnnc=; b=ZZVp8qWd6JwHe3BzdZ6BVCXNP8Taibm/RMPLK+x5xIBa+6/vxpgHGO8VGhioZh9A9F d2NmICyT+iXmMcPXqb1E68rll9VEocwMOwlQqOayyQ9lxQfAkffzRvS3ggy+E91R2zz4 k2+g8ed49Blzf8OF9GWYac1lWAOYNcnOS2f5IPEmETF4hfOhjsxpUzyTw3ib8X0ywyk0 NzT+Zp0y6waiTzicP/vqPzXX05TuvarfqvTxKKm8sVzI+pp7ob7qlGKyML+EQTAk9zJr l4bz+/KpDxTnnRI83uj7HqZ3kCeSkR4uNB3ZC8MA+KrzQ9xcnU30e7KLT5UOHSNk6ZDg X2xg== |
| X-Gm-Message-State | AG10YOQRDy6GhUZWbiya5gHE7FZbSPmiOyiBUxDZM/Bt23c8xs8uKpnwYcSOB5PCzfXw9Ub/Sn6c4fv0lXRH7w== |
| MIME-Version | 1.0 |
| X-Received | by 10.37.20.195 with SMTP id 186mr11052745ybu.60.1455574114395; Mon, 15 Feb 2016 14:08:34 -0800 (PST) |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8BIT |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 117 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>, Andrew Morton <akpm@linux-foundation.org> |
| X-Original-Date | Tue, 16 Feb 2016 00:08:34 +0200 |
| X-Original-Message-ID | <CANOLnOObzMk7YQACtWz8rEKgP0DYVgvk0g9JViK1v7sP9n0Xeg@mail.gmail.com> |
| X-Original-References | <1455499975-8390-1-git-send-email-notasas@gmail.com> <20160215102628.GA53150@black.fi.intel.com> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1334848 |
Show key headers only | View raw
On Mon, Feb 15, 2016 at 12:26 PM, Kirill A. Shutemov
<kirill.shutemov@linux.intel.com> wrote:
> On Mon, Feb 15, 2016 at 03:32:55AM +0200, Grazvydas Ignotas wrote:
>> Hi,
>>
>> since remap_file_pages() rework the following simple program fails.
>> I haven't actually bisected this, only know it worked on 3.19 at least
>> (I bought a new system now and need 4.2+ for hardware support).
>
> The patch below should fix the issue. Please test.
It works, thanks.
Tested-by: Grazvydas Ignotas <notasas@gmail.com>
>
>> If you are curious, the program is an emulator and is using
>> remap_file_pages() to implement memory mirroring efficiently (and to
>> remap things during run time).
>
> Could you elaborate on this?
>
> Why creating file on tmpfs/shmem (using memfd_create() for example) plus
> plain mmap()s wouldn't work for you?
It works, but remap_file_pages() is just more convenient, you don't
need many mmap()/munmap() calls (less syscalls), and as the emulator
needs to reconfigure the mappings during runtime (it's not a one time
init thing), remap_file_pages() makes more sense. The reduced number
of VMAs of the past was also a benefit I guess.
Actually I'm not the author of the emulator in question, so I've asked
the author to comment:
--- quote ---
One of the things we do with remap_file_pages is a mapping for the
emulated system's VRAM. The system allows many different
configurations of several differently sized VRAM banks to a 16MB area
of address space. The banks are multiples of 16KB in size and their
allocations are also 16KB aligned. With remap_file_pages we can map
that entire space to an (in-memory) file and then arbitrarily map
chunks of it as desired. We have an mmap-based fallback, but it
requires us to manage a separate mmap for each 16KB region."
--- end of quote ---
Apparently the mentioned fallback was a compile time option, so I was
hit with the issue after upgrading my machine.
> <snip>
>
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: stable?
Fixes: c8d78c182 (I guess?)
> Reported-by: Grazvydas Ignotas <notasas@gmail.com>
> ---
> mm/mmap.c | 34 +++++++++++++++++++++++++++++-----
> 1 file changed, 29 insertions(+), 5 deletions(-)
>
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 2f2415a7a688..76d1ec29149b 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -2664,12 +2664,29 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
> if (!vma || !(vma->vm_flags & VM_SHARED))
> goto out;
>
> - if (start < vma->vm_start || start + size > vma->vm_end)
> + if (start < vma->vm_start)
> goto out;
>
> - if (pgoff == linear_page_index(vma, start)) {
> - ret = 0;
> - goto out;
> + if (start + size > vma->vm_end) {
> + struct vm_area_struct *next;
> +
> + for (next = vma->vm_next; next; next = next->vm_next) {
> + /* hole between vmas ? */
> + if (next->vm_start != next->vm_prev->vm_end)
> + goto out;
> +
> + if (next->vm_file != vma->vm_file)
> + goto out;
> +
> + if (next->vm_flags != vma->vm_flags)
> + goto out;
> +
> + if (start + size <= next->vm_end)
> + break;
> + }
> +
> + if (!next)
> + goto out;
> }
>
> prot |= vma->vm_flags & VM_READ ? PROT_READ : 0;
> @@ -2679,9 +2696,16 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
> flags &= MAP_NONBLOCK;
> flags |= MAP_SHARED | MAP_FIXED | MAP_POPULATE;
> if (vma->vm_flags & VM_LOCKED) {
> + struct vm_area_struct *tmp;
> flags |= MAP_LOCKED;
> +
> /* drop PG_Mlocked flag for over-mapped range */
> - munlock_vma_pages_range(vma, start, start + size);
> + for (tmp = vma; tmp->vm_start >= start + size;
> + tmp = tmp->vm_next) {
> + munlock_vma_pages_range(tmp,
> + max(tmp->vm_start, start),
> + min(tmp->vm_end, start + size));
> + }
> }
>
> file = get_file(vma->vm_file);
> --
> Kirill A. Shutemov
GraÅžvydas
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
remap_file_pages regression Grazvydas Ignotas <notasas@gmail.com> - 2016-02-15 02:40 +0100
Re: remap_file_pages regression "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-02-15 11:30 +0100
Re: remap_file_pages regression Grazvydas Ignotas <notasas@gmail.com> - 2016-02-15 23:10 +0100
Re: remap_file_pages regression "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-02-15 23:20 +0100
csiph-web