From patchwork Mon Feb 3 23:22:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 11363649 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 629C1921 for ; Mon, 3 Feb 2020 23:23:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2F55D20732 for ; Mon, 3 Feb 2020 23:23:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="lawWGfNg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2F55D20732 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 21DBB6B000D; Mon, 3 Feb 2020 18:23:22 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1A68E6B000E; Mon, 3 Feb 2020 18:23:22 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 071B96B0010; Mon, 3 Feb 2020 18:23:22 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0136.hostedemail.com [216.40.44.136]) by kanga.kvack.org (Postfix) with ESMTP id E24B36B000D for ; Mon, 3 Feb 2020 18:23:21 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 8FCAF180AD804 for ; Mon, 3 Feb 2020 23:23:21 +0000 (UTC) X-FDA: 76450394202.18.pets76_1d49ea8adaf1d X-Spam-Summary: 2,0,0,26ad9770ca93d84c,d41d8cd98f00b204,3aks4xgskcjk3ef3lkrfbg39hh9e7.5hfebgnq-ffdo35d.hk9@flex--almasrymina.bounces.google.com,:mike.kravetz@oracle.com:shuah@kernel.org:almasrymina@google.com:rientjes@google.com:shakeelb@google.com:gthelen@google.com:akpm@linux-foundation.org:linux-kernel@vger.kernel.org::linux-kselftest@vger.kernel.org:cgroups@vger.kernel.org,RULES_HIT:41:152:355:379:541:800:960:966:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2890:3138:3139:3140:3141:3142:3152:3354:3865:3866:3867:3868:3870:3871:3872:4042:4385:4605:5007:6261:6653:7875:9969:10004:10400:11026:11232:11658:11914:12043:12291:12296:12297:12438:12555:12895:13161:13229:14096:14097:14181:14394:14659:14721:21080:21444:21450:21627:30054:30070,0,RBL:209.85.160.202:@flex--almasrymina.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,Domain Cache:0, X-HE-Tag: pets76_1d49ea8adaf1d X-Filterd-Recvd-Size: 5844 Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Mon, 3 Feb 2020 23:23:21 +0000 (UTC) Received: by mail-qt1-f202.google.com with SMTP id d16so2656237qtr.2 for ; Mon, 03 Feb 2020 15:23:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=gTAQ6DpOvbk9aFAmz/RHl3R2aBxncgiEKbaGpA5frS0=; b=lawWGfNg3coqzUxzW5tdwnM7JzKsxWVWyd9ZXeZ6oVEfozYZYeEfuerRe1iAJjbD3B nFZ22Sr44cgnTCoY2qCi8yFTrjm5FUtbXALgxMYmqHg5mrNGujJPgYVENxnn010VAOdz ajYKoq1V3qmlRxmoKlcyAB99zGipHVX3cVZ29iRJ8hRAPI5gz8qn1RA8u1YKfpxUJXHf y6bdAw5mzejzeuWC7XPEFxucoppFAm+GhlSUmtBSVtXgmSIX9fQasyqBikW8UNtiazuG eQcX3OuLuEv4OH19GaD7s/KkHqIpbuTaMm0pzHTn/9uVPCR6qtK3hWmd748N4Vtj1Z+Z ozJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=gTAQ6DpOvbk9aFAmz/RHl3R2aBxncgiEKbaGpA5frS0=; b=XWWztBxVTnXG4fQeLNXKxqO+advvOQL32nkC1atsh1P2/N29wBwxMAGJDcx3+4ANkl utE+VvXLVCWig+k/mIHlnHOxZRUHq3rPGcVBby1LtGaiHe717vof4KgPyPUSjCYP9sXt ZdulFqdBd6geithDtGOwNR+3hoYniuKvQMi+9Glxe2N+vHC8aSPOWKh8L/H5nVnBo48k 6CEUrnfbJwrubrH4l+pR6YlJAHceL5N2ULKwgR7mSTu5NtkfT/x8QCt+lcII/aMjVbVW vocHKB7jeSb0EWoIqQzGfVzqKW4QyQ4n7cuwdqUxTiOiYktonWZK1WRIT/BjKZ7NiHPw zmMg== X-Gm-Message-State: APjAAAVMjoOXs8pdRfpwbo1+RXFRqpbp0OwUgJ46mdwmO6DxXDnzZNM5 sDcihTn/P+Uj/VtW0tOHj8u3yanyynsrhkz98w== X-Google-Smtp-Source: APXvYqyZFRK2nwPrxgIM0lMsOI9GD3u259sj/EVTiSp7XQoeYTs2EoceYp2yKqu7UzsKjbmj74yv/rUcqDITUWzAXA== X-Received: by 2002:a37:4d85:: with SMTP id a127mr7298741qkb.267.1580772200586; Mon, 03 Feb 2020 15:23:20 -0800 (PST) Date: Mon, 3 Feb 2020 15:22:45 -0800 In-Reply-To: <20200203232248.104733-1-almasrymina@google.com> Message-Id: <20200203232248.104733-6-almasrymina@google.com> Mime-Version: 1.0 References: <20200203232248.104733-1-almasrymina@google.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog Subject: [PATCH v11 6/9] hugetlb_cgroup: support noreserve mappings From: Mina Almasry To: mike.kravetz@oracle.com Cc: shuah@kernel.org, almasrymina@google.com, rientjes@google.com, shakeelb@google.com, gthelen@google.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, cgroups@vger.kernel.org X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Support MAP_NORESERVE accounting as part of the new counter. For each hugepage allocation, at allocation time we check if there is a reservation for this allocation or not. If there is a reservation for this allocation, then this allocation was charged at reservation time, and we don't re-account it. If there is no reserevation for this allocation, we charge the appropriate hugetlb_cgroup. The hugetlb_cgroup to uncharge for this allocation is stored in page[3].private. We use new APIs added in an earlier patch to set this pointer. Signed-off-by: Mina Almasry --- Changes in v10: - Refactored deferred_reserve check. --- mm/hugetlb.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) -- 2.25.0.341.g760bfbb309-goog diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 33818ccaf7e89..ec0b55ea1506e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1339,6 +1339,9 @@ static void __free_huge_page(struct page *page) clear_page_huge_active(page); hugetlb_cgroup_uncharge_page(hstate_index(h), pages_per_huge_page(h), page, false); + hugetlb_cgroup_uncharge_page(hstate_index(h), pages_per_huge_page(h), + page, true); + if (restore_reserve) h->resv_huge_pages++; @@ -2172,6 +2175,7 @@ struct page *alloc_huge_page(struct vm_area_struct *vma, long gbl_chg; int ret, idx; struct hugetlb_cgroup *h_cg; + bool deferred_reserve; idx = hstate_index(h); /* @@ -2209,10 +2213,20 @@ struct page *alloc_huge_page(struct vm_area_struct *vma, gbl_chg = 1; } + /* If this allocation is not consuming a reservation, charge it now. + */ + deferred_reserve = map_chg || avoid_reserve || !vma_resv_map(vma); + if (deferred_reserve) { + ret = hugetlb_cgroup_charge_cgroup(idx, pages_per_huge_page(h), + &h_cg, true); + if (ret) + goto out_subpool_put; + } + ret = hugetlb_cgroup_charge_cgroup(idx, pages_per_huge_page(h), &h_cg, false); if (ret) - goto out_subpool_put; + goto out_uncharge_cgroup_reservation; spin_lock(&hugetlb_lock); /* @@ -2236,6 +2250,14 @@ struct page *alloc_huge_page(struct vm_area_struct *vma, } hugetlb_cgroup_commit_charge(idx, pages_per_huge_page(h), h_cg, page, false); + /* If allocation is not consuming a reservation, also store the + * hugetlb_cgroup pointer on the page. + */ + if (deferred_reserve) { + hugetlb_cgroup_commit_charge(idx, pages_per_huge_page(h), h_cg, + page, true); + } + spin_unlock(&hugetlb_lock); set_page_private(page, (unsigned long)spool); @@ -2261,6 +2283,10 @@ struct page *alloc_huge_page(struct vm_area_struct *vma, out_uncharge_cgroup: hugetlb_cgroup_uncharge_cgroup(idx, pages_per_huge_page(h), h_cg, false); +out_uncharge_cgroup_reservation: + if (deferred_reserve) + hugetlb_cgroup_uncharge_cgroup(idx, pages_per_huge_page(h), + h_cg, true); out_subpool_put: if (map_chg || avoid_reserve) hugepage_subpool_put_pages(spool, 1);