Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4247769ybl; Mon, 3 Feb 2020 15:24:36 -0800 (PST) X-Google-Smtp-Source: APXvYqzNXyg7+FY+QTD7r5RkjupPaHeWxASdq30eCoMLZsgwnTQOCAsgO2OJMW7KW+1tc3rLkg6Q X-Received: by 2002:aca:5d57:: with SMTP id r84mr1200864oib.42.1580772275891; Mon, 03 Feb 2020 15:24:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580772275; cv=none; d=google.com; s=arc-20160816; b=PCyvoFjEr/nlvz8wo3zMuVcEZ7scv4T9F54kTLPfybJEVoOlm0xBAmgQnUz8ca1vxY RB3SFFGlzyTvVjsxypcYNUmDcm7QRuzUvjdeZCjF4sRunEFjClShEm7bicjlJxjI0Xq0 CVZ82g4Oi0WRmMINLMdS+zSVZl2qdc2/oWhT1COLCjsEIUsQYTirq0b0o9RJUInj44Sj 1lJPmlJksE5zJxNd3ZFzdZyFkcoB2WOLezJ4hBlZNmFU1Qn0uC0SVynyviywsSKd/kVH SQWgiyqIYr6408tbHronUTjBKp5dEWVMLOaEpRYI6665MX4wetNvO9mTLlmawuV/Gt/3 sy7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=gTAQ6DpOvbk9aFAmz/RHl3R2aBxncgiEKbaGpA5frS0=; b=WP15qCUfyQxmYNrWZJ5jK3DaY/aPPx8nWGM1J+jRlKOBNNLFUuup7boisgF03/QbiZ nnmKnruiWDHEyvjpXfpMqTnQ5F5TVbX2txlD5UnlFMFOyf0F3C708Lvq0LyuXfbZwbeJ ZNQht+vDJvLh+TmA9fk3W9IyjbB54QdjcymSBgj+5pgc8ai1PODrI7sMAjIDMYs+a5ml fe2gp/yVMdcsHTzabp/qMPEBjDpjLJQFAYRG7PV8IkP7OPItfAlJTafmNWXdmH8XlQJ+ /A4NBgDBsqBTZPYIjzIT0kGFGYEEeh+LdeB3xusKHmzwMKLefqgF7x9Nm/bVXz54Wpwd jtoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=lawWGfNg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m24si10191358otf.101.2020.02.03.15.24.24; Mon, 03 Feb 2020 15:24:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=lawWGfNg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727253AbgBCXXW (ORCPT + 99 others); Mon, 3 Feb 2020 18:23:22 -0500 Received: from mail-qk1-f201.google.com ([209.85.222.201]:43429 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726369AbgBCXXV (ORCPT ); Mon, 3 Feb 2020 18:23:21 -0500 Received: by mail-qk1-f201.google.com with SMTP id f22so10612609qka.10 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=FY+01a1DTor3bKcakNJPSRWAgQZCSgETK2g4M2cDWwl+cHnu4nggyPCubCOQg8qSL6 gHqELYISpuXn1w6IRHhFK3yXPv7X6HvE1HTn/KNmv05c+9mrNUnehktJDudnVdH9/Yhh W6Dlej2296zJCIQNeyeIfkKDiX8ZlIpSkirPRKlhdEAj12noZHWwuFrFtgfoaYhhAf01 x6SyA4NXLu4l4cdDlZONjNLaFe0TIpEiio6Y6qEAKZm4k44WUCCQwkBWi5sJm1WlkY/k FNGT42dWqzw2srUz8Xd3Ur9c/9sYJzRDWCP+aHE05UVSVzu5JGYDEvO/uUut1IHa/J0i TFNA== X-Gm-Message-State: APjAAAXDbgfd5X8BE3V8VpFLuZlFVqA9aSivq2Nba/pV9RPucAwkrH0D D/VOyvfc0XKgS3d1gHzU07pKFLfIMY56GIblsg== 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) 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); -- 2.25.0.341.g760bfbb309-goog