From patchwork Wed Jun 12 04:22:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 17807 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ye0-f198.google.com (mail-ye0-f198.google.com [209.85.213.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1F03625DFB for ; Wed, 12 Jun 2013 04:23:23 +0000 (UTC) Received: by mail-ye0-f198.google.com with SMTP id m13sf8240222yen.5 for ; Tue, 11 Jun 2013 21:23:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=WRzZaYwy2WPWhcUgQLt0YnSqWi4L7diQk9Il/hkAjk0=; b=lvbkN1JUKXBfRB04+vZ7yu/+UQh3UIrN3H78257WVLx6/GYCX5d5lo6kQDv4k2OMwJ umYIiuty1m2Ejqz17PH1uaGwGX1VV1nBOy6Ft2H3mmPMNmGo0x3x2Wrn75mHvnFQ4J1H fzJW7d9oaVm+m8bz+8nywCmX+Rd2n6J7/QBJp6liWn01bBFL6qkqT9Li2zy7lxkpiNOK CzxaE7VnWacG/AQrV5QqnsYlM7gZIhFt7nEN5MpjDbXU2dk3d+7BDiDUBvyGpmFeky0V pbjmoZ34HtOg9EiJZpMTLtz/67MBu84JVnNx542KphL7Xu6Ac3SdC3rHgNvzKTAcAw7f B+2A== X-Received: by 10.224.205.138 with SMTP id fq10mr12508787qab.1.1371011002888; Tue, 11 Jun 2013 21:23:22 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.36.40 with SMTP id n8ls1310469qej.79.gmail; Tue, 11 Jun 2013 21:23:22 -0700 (PDT) X-Received: by 10.220.59.8 with SMTP id j8mr9037236vch.74.1371011002582; Tue, 11 Jun 2013 21:23:22 -0700 (PDT) Received: from mail-vb0-x235.google.com (mail-vb0-x235.google.com [2607:f8b0:400c:c02::235]) by mx.google.com with ESMTPS id tq4si8051831vdc.1.2013.06.11.21.23.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Jun 2013 21:23:22 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c02::235 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c02::235; Received: by mail-vb0-f53.google.com with SMTP id p12so5713864vbe.40 for ; Tue, 11 Jun 2013 21:23:22 -0700 (PDT) X-Received: by 10.52.170.148 with SMTP id am20mr7768568vdc.75.1371011002443; Tue, 11 Jun 2013 21:23:22 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.191.99 with SMTP id gx3csp130071vec; Tue, 11 Jun 2013 21:23:21 -0700 (PDT) X-Received: by 10.68.196.231 with SMTP id ip7mr17596418pbc.61.1371011001061; Tue, 11 Jun 2013 21:23:21 -0700 (PDT) Received: from mail-pb0-x230.google.com (mail-pb0-x230.google.com [2607:f8b0:400e:c01::230]) by mx.google.com with ESMTPS id kx5si8485527pbc.260.2013.06.11.21.23.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Jun 2013 21:23:21 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400e:c01::230 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=2607:f8b0:400e:c01::230; Received: by mail-pb0-f48.google.com with SMTP id ma3so3775463pbc.7 for ; Tue, 11 Jun 2013 21:23:20 -0700 (PDT) X-Received: by 10.68.239.228 with SMTP id vv4mr17910961pbc.5.1371011000615; Tue, 11 Jun 2013 21:23:20 -0700 (PDT) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id xe9sm17439221pbc.21.2013.06.11.21.23.19 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Jun 2013 21:23:20 -0700 (PDT) From: John Stultz To: LKML Cc: John Stultz , Andrew Morton , Android Kernel Team , Robert Love , Mel Gorman , Hugh Dickins , Dave Hansen , Rik van Riel , Dmitry Adamushko , Dave Chinner , Neil Brown , Andrea Righi , Andrea Arcangeli , "Aneesh Kumar K.V" , Mike Hommey , Taras Glek , Dhaval Giani , Jan Kara , KOSAKI Motohiro , Michel Lespinasse , Minchan Kim , "linux-mm@kvack.org" Subject: [PATCH 4/8] vrange: Clear volatility on new mmaps Date: Tue, 11 Jun 2013 21:22:47 -0700 Message-Id: <1371010971-15647-5-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1371010971-15647-1-git-send-email-john.stultz@linaro.org> References: <1371010971-15647-1-git-send-email-john.stultz@linaro.org> X-Gm-Message-State: ALoCoQlu8E+zRHiMe5B7U77VqiPjtMlTqfqFKRqPMUsyvtX9gV+MozFLdCy6WyvuvTTp4rV7StTR X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c02::235 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , At lsf-mm, the issue was brought up that there is a precedence with interfaces like mlock, such that new mappings in a pre-existing range do no inherit the mlock state. This is mostly because mlock only modifies the existing vmas, and so any new mmaps create new vmas, which won't be mlocked. Since volatility is not stored in the vma (for good cause, specfically as we'd have to have manage file volatility differently from anonymous and we're likely to manage volatility on small chunks of memory, which would cause lots of vma splitting and churn), this patch clears volatilty on new mappings, to ensure that we don't inherit volatility if memory in an existing volatile range is unmapped and then re-mapped with something else. Thus, this patch forces any volatility to be cleared on mmap. XXX: We expect this patch to be not well loved by mm folks, and are open to alternative methods here. Its more of a place holder to address the issue from lsf-mm and hopefully will spur some further discussion. Cc: Andrew Morton Cc: Android Kernel Team Cc: Robert Love Cc: Mel Gorman Cc: Hugh Dickins Cc: Dave Hansen Cc: Rik van Riel Cc: Dmitry Adamushko Cc: Dave Chinner Cc: Neil Brown Cc: Andrea Righi Cc: Andrea Arcangeli Cc: Aneesh Kumar K.V Cc: Mike Hommey Cc: Taras Glek Cc: Dhaval Giani Cc: Jan Kara Cc: KOSAKI Motohiro Cc: Michel Lespinasse Cc: Minchan Kim Cc: linux-mm@kvack.org Signed-off-by: John Stultz --- include/linux/vrange.h | 2 ++ mm/mmap.c | 5 +++++ mm/vrange.c | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/include/linux/vrange.h b/include/linux/vrange.h index 13f4887..a97ac25 100644 --- a/include/linux/vrange.h +++ b/include/linux/vrange.h @@ -32,6 +32,8 @@ static inline int vrange_type(struct vrange *vrange) } void vrange_init(void); +extern int vrange_clear(struct vrange_root *vroot, + unsigned long start, unsigned long end); extern void vrange_root_cleanup(struct vrange_root *vroot); extern int vrange_fork(struct mm_struct *new, struct mm_struct *old); diff --git a/mm/mmap.c b/mm/mmap.c index f681e18..80d3676 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -1500,6 +1501,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr, /* Clear old maps */ error = -ENOMEM; munmap_back: + + /* zap any volatile ranges */ + vrange_clear(&mm->vroot, addr, addr + len); + if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) { if (do_munmap(mm, addr, len)) return -ENOMEM; diff --git a/mm/vrange.c b/mm/vrange.c index bbaa184..5ca8853 100644 --- a/mm/vrange.c +++ b/mm/vrange.c @@ -164,6 +164,14 @@ static int vrange_remove(struct vrange_root *vroot, return 0; } +int vrange_clear(struct vrange_root *vroot, + unsigned long start, unsigned long end) +{ + int purged; + + return vrange_remove(vroot, start, end-1, &purged); +} + void vrange_root_cleanup(struct vrange_root *vroot) { struct vrange *range;