From patchwork Fri May 3 18:27:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 16706 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f71.google.com (mail-yh0-f71.google.com [209.85.213.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 42BA423905 for ; Fri, 3 May 2013 18:27:50 +0000 (UTC) Received: by mail-yh0-f71.google.com with SMTP id a41sf3430414yho.10 for ; Fri, 03 May 2013 11:27:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-beenthere:x-received:received-spf :x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received: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=CXybt3ZdZxuq7LqenqXf9pCyYKSTA8mhBjDhtU8e6V8=; b=MydEfW+hEDfXIC7awLj+uMnLptA9Nvub1W3uWCbl1CzJU1dPJy7F94Ted5DEbaBila JPbiEMxxDksotOiXnLW/KN50W4v0+JQ0Qq91R6l2fRn/4LHMzm87YWYzIFLsvt8+nfSR dF8rvwP921tOQD1EZp4+ZjsrK9F0S9P1J9Z29nncI1GTBVuA3P4Ni7tqa/i96tLTYRHs mSZ0bpnRXQtAblXbEf8MKcuABL/CHAgbpLDpM1ffgoHUgw6uq3mcjQSS7KlqxpscLR9a o57cAQ7Dze/bGWNMlvlKjCcKBOgt2LZ4u4jy/8JYCCX8hy/0UDY3jVljwvhzds8BCe66 rCYA== X-Received: by 10.236.199.198 with SMTP id x46mr9213378yhn.41.1367605659935; Fri, 03 May 2013 11:27:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.51.69 with SMTP id i5ls1879350qeo.89.gmail; Fri, 03 May 2013 11:27:39 -0700 (PDT) X-Received: by 10.58.144.170 with SMTP id sn10mr4001132veb.7.1367605659618; Fri, 03 May 2013 11:27:39 -0700 (PDT) Received: from mail-vb0-x234.google.com (mail-vb0-x234.google.com [2607:f8b0:400c:c02::234]) by mx.google.com with ESMTPS id se7si5540992vec.18.2013.05.03.11.27.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 03 May 2013 11:27:39 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c02::234 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::234; Received: by mail-vb0-f52.google.com with SMTP id p13so1585333vbe.39 for ; Fri, 03 May 2013 11:27:39 -0700 (PDT) X-Received: by 10.58.48.166 with SMTP id m6mr3932681ven.59.1367605659519; Fri, 03 May 2013 11:27:39 -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.127.98 with SMTP id nf2csp34391veb; Fri, 3 May 2013 11:27:39 -0700 (PDT) X-Received: by 10.66.72.3 with SMTP id z3mr15742794pau.125.1367605658350; Fri, 03 May 2013 11:27:38 -0700 (PDT) Received: from mail-da0-x22f.google.com (mail-da0-x22f.google.com [2607:f8b0:400e:c00::22f]) by mx.google.com with ESMTPS id mr7si8056196pbb.257.2013.05.03.11.27.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 03 May 2013 11:27:38 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400e:c00::22f is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=2607:f8b0:400e:c00::22f; Received: by mail-da0-f47.google.com with SMTP id k13so922022dae.20 for ; Fri, 03 May 2013 11:27:38 -0700 (PDT) X-Received: by 10.66.157.195 with SMTP id wo3mr16048697pab.79.1367605657964; Fri, 03 May 2013 11:27:37 -0700 (PDT) Received: from localhost.localdomain (c-24-21-54-107.hsd1.or.comcast.net. [24.21.54.107]) by mx.google.com with ESMTPSA id qh4sm13792406pac.8.2013.05.03.11.27.36 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 03 May 2013 11:27:36 -0700 (PDT) From: John Stultz To: Minchan Kim Cc: John Stultz Subject: [PATCH 11/12] vrange: Enable purging of file backed volatile ranges Date: Fri, 3 May 2013 11:27:15 -0700 Message-Id: <1367605636-18284-12-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1367605636-18284-1-git-send-email-john.stultz@linaro.org> References: <1367605636-18284-1-git-send-email-john.stultz@linaro.org> X-Gm-Message-State: ALoCoQnbd+qeVWL2NYFRHLcTVdGwfLR/Lsl2Cj2PqmwlM2yE2G5T+CrfoMsoa08q0klmhvkrqWVR X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c02::234 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: , Rework the victim range selection to also support file backed volatile ranges. Signed-off-by: John Stultz --- include/linux/vrange.h | 9 ++++ mm/vrange.c | 112 ++++++++++++++++++++++++++++++++++++------------- 2 files changed, 91 insertions(+), 30 deletions(-) diff --git a/include/linux/vrange.h b/include/linux/vrange.h index 0e10fbc..761dca0 100644 --- a/include/linux/vrange.h +++ b/include/linux/vrange.h @@ -40,6 +40,15 @@ static inline struct mm_struct *vrange_get_owner_mm(struct vrange *vrange) return container_of(vrange->owner, struct mm_struct, vroot); } +static inline +struct address_space *vrange_get_owner_mapping(struct vrange *vrange) +{ + if (vrange_type(vrange) != VRANGE_FILE) + return NULL; + return container_of(vrange->owner, struct address_space, vroot); +} + + void vrange_init(void); extern void vrange_root_cleanup(struct vrange_root *vroot); extern int vrange_root_duplicate(struct vrange_root *orig, diff --git a/mm/vrange.c b/mm/vrange.c index 6243983..5590677 100644 --- a/mm/vrange.c +++ b/mm/vrange.c @@ -783,8 +783,9 @@ unsigned int discard_vma_pages(struct zone *zone, struct mm_struct *mm, return ret; } -unsigned int discard_vrange(struct zone *zone, struct vrange *vrange, - int nr_to_discard) +static unsigned int discard_anon_vrange(struct zone *zone, + struct vrange *vrange, + int nr_to_discard) { struct mm_struct *mm; unsigned long start = vrange->node.start; @@ -825,46 +826,91 @@ out: return nr_discarded; } +static unsigned int discard_file_vrange(struct zone *zone, + struct vrange *vrange, + int nr_to_discard) +{ + struct address_space *mapping; + unsigned long start = vrange->node.start; + unsigned long end = vrange->node.last; + unsigned long count = ((end-start) >> PAGE_CACHE_SHIFT); + + mapping = vrange_get_owner_mapping(vrange); + + truncate_inode_pages_range(mapping, start, end); + vrange->purged = true; + + return count; +} + +unsigned int discard_vrange(struct zone *zone, struct vrange *vrange, + int nr_to_discard) +{ + if (vrange_type(vrange) == VRANGE_MM) + return discard_anon_vrange(zone, vrange, nr_to_discard); + return discard_file_vrange(zone, vrange, nr_to_discard); +} + + +/* Take a vrange refcount and depending on the type + * the vrange->owner's mm refcount or inode refcount + */ +static int hold_victim_vrange(struct vrange *vrange) +{ + if (vrange_type(vrange) == VRANGE_MM) { + struct mm_struct *mm = vrange_get_owner_mm(vrange); + + + if (atomic_read(&mm->mm_users) == 0) + return -1; + + + if (!atomic_inc_not_zero(&vrange->refcount)) + return -1; + /* + * we need to access mmap_sem further routine so + * need to get a refcount of mm. + * NOTE: We guarantee mm_count isn't zero in here because + * if we found vrange from LRU list, it means we are + * before exit_vrange or remove_vrange. + */ + atomic_inc(&mm->mm_count); + } else { + struct address_space *mapping; + mapping = vrange_get_owner_mapping(vrange); + + if (!atomic_inc_not_zero(&vrange->refcount)) + return -1; + __iget(mapping->host); + } + + return 0; +} + + + /* - * Get next victim vrange from LRU and hold a vrange refcount - * and vrange->mm's refcount. + * Get next victim vrange from LRU and hold needed refcounts. */ struct vrange *get_victim_vrange(void) { - struct mm_struct *mm; struct vrange *vrange = NULL; struct list_head *cur, *tmp; spin_lock(&lru_lock); list_for_each_prev_safe(cur, tmp, &lru_vrange) { vrange = list_entry(cur, struct vrange, lru); - mm = vrange_get_owner_mm(vrange); - /* the process is exiting so pass it */ - if (atomic_read(&mm->mm_users) == 0) { - list_del_init(&vrange->lru); - vrange = NULL; - continue; - } - /* vrange is freeing so continue to loop */ - if (!atomic_inc_not_zero(&vrange->refcount)) { + if (hold_victim_vrange(vrange)) { list_del_init(&vrange->lru); vrange = NULL; continue; } - /* - * we need to access mmap_sem further routine so - * need to get a refcount of mm. - * NOTE: We guarantee mm_count isn't zero in here because - * if we found vrange from LRU list, it means we are - * before exit_vrange or remove_vrange. - */ - atomic_inc(&mm->mm_count); - /* Isolate vrange */ list_del_init(&vrange->lru); break; + } spin_unlock(&lru_lock); @@ -873,9 +919,18 @@ struct vrange *get_victim_vrange(void) void put_victim_range(struct vrange *vrange) { - struct mm_struct *mm = vrange_get_owner_mm(vrange); put_vrange(vrange); - mmdrop(mm); + + if (vrange_type(vrange) == VRANGE_MM) { + struct mm_struct *mm = vrange_get_owner_mm(vrange); + + mmdrop(mm); + } else { + struct address_space *mapping; + + mapping = vrange_get_owner_mapping(vrange); + iput(mapping->host); + } } unsigned int discard_vrange_pages(struct zone *zone, int nr_to_discard) @@ -884,11 +939,8 @@ unsigned int discard_vrange_pages(struct zone *zone, int nr_to_discard) unsigned int nr_discarded = 0; start_vrange = vrange = get_victim_vrange(); - if (start_vrange) { - struct mm_struct *mm = vrange_get_owner_mm(start_vrange); - atomic_inc(&start_vrange->refcount); - atomic_inc(&mm->mm_count); - } + if (start_vrange) + hold_victim_vrange(start_vrange); while (vrange) { nr_discarded += discard_vrange(zone, vrange, nr_to_discard);