From patchwork Tue Oct 1 18:38:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 20737 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vb0-f71.google.com (mail-vb0-f71.google.com [209.85.212.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A4D9B23920 for ; Tue, 1 Oct 2013 18:39:18 +0000 (UTC) Received: by mail-vb0-f71.google.com with SMTP id g17sf8305744vbg.6 for ; Tue, 01 Oct 2013 11:39:18 -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=kfwcSHqyWWVuRAAO8d1Xhu64NVc2MAh8ovapTNK7OwU=; b=cLT2CUMkz3UTxeP0Hwy1RbsjMqA0bZpKfQSBf3v/HCne3XrjhhltBTrBSBodM+4fF1 N1FS4vL2RVhFzA1Xf4i/Uk23D9+AlB05W3/Y6La1et9Q1KvNGV+xXZo+f0DWOgRoqyzl 9Bv4OUYTXerbCfBs5YBmmJ2DkIa5Y5o4iJvMuX5lmrRj6T96pUeTEPY0+DQILRcApyZK zys2D6MjnBCD7gxyOnDrbNEAew80fduoagerbFOfTSWllYtq19DkfpkYGV3HXE9AP8+Y erkSuPC7RPI3t0XW+jqXjoE4WRMuo5OiMD1616qMhD8fo+bNqsukb2ywbfdI510LF01D BVfw== X-Received: by 10.58.206.33 with SMTP id ll1mr2315354vec.10.1380652758530; Tue, 01 Oct 2013 11:39:18 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.119.9 with SMTP id kq9ls201979qeb.48.gmail; Tue, 01 Oct 2013 11:39:18 -0700 (PDT) X-Received: by 10.220.145.75 with SMTP id c11mr1289865vcv.30.1380652758419; Tue, 01 Oct 2013 11:39:18 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id l1si1607835vcl.139.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Oct 2013 11:39:18 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.170 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.170; Received: by mail-vc0-f170.google.com with SMTP id lc6so4812898vcb.15 for ; Tue, 01 Oct 2013 11:39:18 -0700 (PDT) X-Gm-Message-State: ALoCoQnGZ455zSi/cRFufSJ/Cg8Yk1cjVBqzNjgMMFwUMFxS03pwJNCNf3a3vSJ/a2Dq9vO2j4dO X-Received: by 10.58.229.41 with SMTP id sn9mr29241988vec.11.1380652758315; Tue, 01 Oct 2013 11:39:18 -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 u4csp38617vcz; Tue, 1 Oct 2013 11:39:17 -0700 (PDT) X-Received: by 10.66.132.69 with SMTP id os5mr34718758pab.114.1380652756943; Tue, 01 Oct 2013 11:39:16 -0700 (PDT) Received: from mail-pa0-f43.google.com (mail-pa0-f43.google.com [209.85.220.43]) by mx.google.com with ESMTPS id ar2si5539929pbc.142.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Oct 2013 11:39:16 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.43 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.220.43; Received: by mail-pa0-f43.google.com with SMTP id hz1so7866079pad.2 for ; Tue, 01 Oct 2013 11:39:16 -0700 (PDT) X-Received: by 10.66.163.164 with SMTP id yj4mr35687602pab.91.1380652756519; Tue, 01 Oct 2013 11:39:16 -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:15 -0700 (PDT) From: John Stultz To: Minchan Kim , Dhaval Giani Subject: [PATCH 12/14] vrange: Support background purging for vrange-file Date: Tue, 1 Oct 2013 11:38:56 -0700 Message-Id: <1380652738-8000-13-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.170 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: , From: Minchan Kim Add support to purge vrange file pages via the shrinker interface. This is useful, since some filesystems like shmem/tmpfs use anonymous pages, which won't be aged off the page LRU if swap is disabled. 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: Minchan Kim [jstultz: Commit message tweaks] Signed-off-by: John Stultz --- mm/vrange.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/mm/vrange.c b/mm/vrange.c index 7e55ff3..be63f0a 100644 --- a/mm/vrange.c +++ b/mm/vrange.c @@ -13,6 +13,7 @@ #include #include #include +#include static struct kmem_cache *vrange_cachep; @@ -854,21 +855,62 @@ out: return ret; } +static int __discard_vrange_file(struct address_space *mapping, + struct vrange *vrange, unsigned int *ret_discard) +{ + struct pagevec pvec; + pgoff_t index; + int i; + unsigned int nr_discard = 0; + unsigned long start_idx = vrange->node.start; + unsigned long end_idx = vrange->node.last; + const pgoff_t start = start_idx >> PAGE_CACHE_SHIFT; + pgoff_t end = end_idx >> PAGE_CACHE_SHIFT; + LIST_HEAD(pagelist); + + pagevec_init(&pvec, 0); + index = start; + while (index <= end && pagevec_lookup(&pvec, mapping, index, + min(end - index, (pgoff_t)PAGEVEC_SIZE - 1) + 1)) { + for (i = 0; i < pagevec_count(&pvec); i++) { + struct page *page = pvec.pages[i]; + index = page->index; + if (index > end) + break; + if (isolate_lru_page(page)) + continue; + list_add(&page->lru, &pagelist); + inc_zone_page_state(page, NR_ISOLATED_ANON); + } + pagevec_release(&pvec); + cond_resched(); + index++; + } + + if (!list_empty(&pagelist)) + nr_discard = discard_vrange_pagelist(&pagelist); + + *ret_discard = nr_discard; + putback_lru_pages(&pagelist); + + return 0; +} + static int discard_vrange(struct vrange *vrange) { int ret = 0; - struct mm_struct *mm; struct vrange_root *vroot; unsigned int nr_discard = 0; vroot = vrange->owner; - /* TODO : handle VRANGE_FILE */ - if (vroot->type != VRANGE_MM) - goto out; + if (vroot->type == VRANGE_MM) { + struct mm_struct *mm = vroot->object; + ret = __discard_vrange_anon(mm, vrange, &nr_discard); + } else if (vroot->type == VRANGE_FILE) { + struct address_space *mapping = vroot->object; + ret = __discard_vrange_file(mapping, vrange, &nr_discard); + } - mm = vroot->object; - ret = __discard_vrange_anon(mm, vrange, &nr_discard); -out: return nr_discard; }