From patchwork Tue Oct 1 18:38: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: 20727 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f200.google.com (mail-ve0-f200.google.com [209.85.128.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4A44223920 for ; Tue, 1 Oct 2013 18:39:08 +0000 (UTC) Received: by mail-ve0-f200.google.com with SMTP id oy12sf8808142veb.7 for ; Tue, 01 Oct 2013 11:39:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:x-gm-message-state:delivered-to:from:to:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=jbSHripK3+lzdlqwc84UXMlXjFExP3X4oc/OXJry33A=; b=m368YNzfLVX3Of3SMvP/HuV40r3/Oy8j5nVwTbtiI76qraSaDyb918ZZILJsd3n87D zthWkuZTCHS3+C+mLUVTl+hd5op6lWyQFDuYxEecFi9JWANzbSPvj/18NpvokqwV4TBy xJaDDVV3U+V82i2BeiRK6anpBI/TD8KnBsY0LEpkucx+XK+Dik+Pq1vNF7/cAPW6gfqr uDcUf08mPHi2DcpVH4jdinmshFHK5ZtRHUIXROiIlJjJEnMiS0SDQJfRplX+Sn6MjEDc Gas4FDZ7JsUKfDig+ld5vwlOhBd3gNQMIWXjg4MjsGZPMfKeMfZOgT5Yedl6y9lAfk6v lCXQ== X-Received: by 10.58.181.103 with SMTP id dv7mr2419435vec.15.1380652748018; Tue, 01 Oct 2013 11:39:08 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.6.73 with SMTP id y9ls189991qey.60.gmail; Tue, 01 Oct 2013 11:39:07 -0700 (PDT) X-Received: by 10.221.32.133 with SMTP id sk5mr1580541vcb.27.1380652747887; Tue, 01 Oct 2013 11:39:07 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id rz3si1615501vdc.33.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Oct 2013 11:39:07 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.180 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id ld13so5004744vcb.39 for ; Tue, 01 Oct 2013 11:39:07 -0700 (PDT) X-Gm-Message-State: ALoCoQmGGXwDRogdABTqq0dmMTuvGLbytatGGsW2bAU/9WlxYYjPiWle8W1SbnN0pGBO/XlF9Ssv X-Received: by 10.220.91.16 with SMTP id k16mr2260805vcm.21.1380652747755; Tue, 01 Oct 2013 11:39:07 -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.220.174.196 with SMTP id u4csp38602vcz; Tue, 1 Oct 2013 11:39:07 -0700 (PDT) X-Received: by 10.66.158.72 with SMTP id ws8mr35708025pab.39.1380652746837; Tue, 01 Oct 2013 11:39:06 -0700 (PDT) Received: from mail-pb0-f45.google.com (mail-pb0-f45.google.com [209.85.160.45]) by mx.google.com with ESMTPS id gg2si5748915pac.43.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Oct 2013 11:39:06 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.45 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.160.45; Received: by mail-pb0-f45.google.com with SMTP id mc17so7511802pbc.18 for ; Tue, 01 Oct 2013 11:39:06 -0700 (PDT) X-Received: by 10.66.163.164 with SMTP id yj4mr35686927pab.91.1380652746365; Tue, 01 Oct 2013 11:39:06 -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 ed3sm8282606pbc.6.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Oct 2013 11:39:05 -0700 (PDT) From: John Stultz To: Minchan Kim , Dhaval Giani Subject: [PATCH 03/14] vrange: Clear volatility on new mmaps Date: Tue, 1 Oct 2013 11:38:47 -0700 Message-Id: <1380652738-8000-4-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1380652738-8000-1-git-send-email-john.stultz@linaro.org> References: <1380652738-8000-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.180 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, specifically 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 volitility 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. Minchan does have an alternative solution, but I'm not a big fan of it yet, so this simpler approach is a placeholder for now. 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: Rob Clark 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 2b96ee1..ef153c8 100644 --- a/include/linux/vrange.h +++ b/include/linux/vrange.h @@ -36,6 +36,8 @@ static inline int vrange_type(struct vrange *vrange) return vrange->owner->type; } +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 f9c97d1..ed7056f 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -1502,6 +1503,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 c590198..10c736f 100644 --- a/mm/vrange.c +++ b/mm/vrange.c @@ -166,6 +166,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;