Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756214AbbEUPst (ORCPT ); Thu, 21 May 2015 11:48:49 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:30858 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756102AbbEUPsr (ORCPT ); Thu, 21 May 2015 11:48:47 -0400 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Dave Hansen , Naoya Horiguchi , David Rientjes , Hugh Dickins , Davidlohr Bueso , Aneesh Kumar , Hillf Danton , Christoph Hellwig , Mike Kravetz Subject: [RFC v3 PATCH 01/10] mm/hugetlb: compute/return the number of regions added by region_add() Date: Thu, 21 May 2015 08:47:35 -0700 Message-Id: <1432223264-4414-2-git-send-email-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1432223264-4414-1-git-send-email-mike.kravetz@oracle.com> References: <1432223264-4414-1-git-send-email-mike.kravetz@oracle.com> X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2320 Lines: 82 Modify region_add() to keep track of regions(pages) added to the reserve map and return this value. The return value can be compared to the return value of region_chg() to determine if the map was modified between calls. Make vma_commit_reservation() also pass along the return value of region_add(). The special case return values of vma_needs_reservation() should also be taken into account when determining the return value of vma_commit_reservation(). Signed-off-by: Mike Kravetz --- mm/hugetlb.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index c41b2a0..7f64034 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -156,6 +156,7 @@ static long region_add(struct resv_map *resv, long f, long t) { struct list_head *head = &resv->regions; struct file_region *rg, *nrg, *trg; + long chg = 0; spin_lock(&resv->lock); /* Locate the region we are either in or before. */ @@ -181,14 +182,17 @@ static long region_add(struct resv_map *resv, long f, long t) if (rg->to > t) t = rg->to; if (rg != nrg) { + chg -= (rg->to - rg->from); list_del(&rg->link); kfree(rg); } } + chg += (nrg->from - f); nrg->from = f; + chg += t - nrg->to; nrg->to = t; spin_unlock(&resv->lock); - return 0; + return chg; } static long region_chg(struct resv_map *resv, long f, long t) @@ -1349,18 +1353,25 @@ static long vma_needs_reservation(struct hstate *h, else return chg < 0 ? chg : 0; } -static void vma_commit_reservation(struct hstate *h, + +static long vma_commit_reservation(struct hstate *h, struct vm_area_struct *vma, unsigned long addr) { struct resv_map *resv; pgoff_t idx; + long add; resv = vma_resv_map(vma); if (!resv) - return; + return 1; idx = vma_hugecache_offset(h, vma, addr); - region_add(resv, idx, idx + 1); + add = region_add(resv, idx, idx + 1); + + if (vma->vm_flags & VM_MAYSHARE) + return add; + else + return 0; } static struct page *alloc_huge_page(struct vm_area_struct *vma, -- 2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/