Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4600016ybl; Mon, 13 Jan 2020 16:53:40 -0800 (PST) X-Google-Smtp-Source: APXvYqwiNmxkQ95zzsWVCQLeIJ3KIiInfhYC3J0D8GKqs/sI86MefJ+VVFzwYAc69YT/4OJUbjJv X-Received: by 2002:a9d:3e16:: with SMTP id a22mr16151067otd.259.1578963219978; Mon, 13 Jan 2020 16:53:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578963219; cv=none; d=google.com; s=arc-20160816; b=oWuE4tZIZfBKd2c9q80opOkKF6EYf3E+pyfQjdoN5q8qL9C+MTNQWx2qxHGfEODKnV c2yi0DDqCOvmF8fGJuccPYVA+d56Ecgq/2clDj4BIzczUzVMWwvP6W6b/TQFswNtGV6B Qnn+5KN8zt7W31l3lsbbKXyeXIk4MrPC2dSBpRlQiwOC3tvpPZ7zG93gxrZrEcu3QGd8 poP8UqzeObr99vMqzP7bfF8X4UESb8RM5Pbp8L/MbfBFFJP0wvALMUMzSxpIZj4D7fwG 2BLkXg3bOwBxW8bmHCtTUIcj3ovZzx4kxXn+lI98ow+1aE1RNsxxUPNADD7kb/yPSyZ9 0FqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=ANoh8uEOm+gmkt+50LunFAVjJew2LvqnFtto+wxCdzA=; b=cw9BNM8r1wFktC739OLbrUCe0zaNTo3oY1G4G3Ec7alUpr3MtpIRNLtsHyMOpOsSNJ zVfQ6ImqQMAyay7KmslYHZMsaOgHmt/ZNiSdLDdG3aSOt5n543a0Lz03rrxkaI2lo36l lXFMYi5ZdpD/cfXq6MhzfDbETgyi3q7wrst8OfLVmdPvXCoOV8Zlycc7B1UH0rz4WHp2 HFZN769NG/kHwQ4Vmbx+Ru3hDAFn0uYooQUsSykFQ0ow1ZREIxHEM8qq4BZo0EowtJyh K1mt0cJ2Tk9lBR+Dmm5N+WPqjApxXFDAf1+nxqBzO9PJzkri/n0XhArvR9SwvVaGyMTD tqWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EIJTvGsS; 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 b11si7002131oie.152.2020.01.13.16.53.27; Mon, 13 Jan 2020 16:53:39 -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=EIJTvGsS; 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 S1729030AbgANAsi (ORCPT + 99 others); Mon, 13 Jan 2020 19:48:38 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:40874 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726536AbgANAsh (ORCPT ); Mon, 13 Jan 2020 19:48:37 -0500 Received: by mail-pg1-f195.google.com with SMTP id k25so5537977pgt.7 for ; Mon, 13 Jan 2020 16:48:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=ANoh8uEOm+gmkt+50LunFAVjJew2LvqnFtto+wxCdzA=; b=EIJTvGsSDiqJOKnxxqwUUm7ON/pxRF/Iw9epIVmqhs0PtXyaeT1+6YJNK88D1q3wU1 PGDDHVr/nHr2tKVTneq/1tZK0Lgua6Y3amEdx12flXktjw43k4MPa8GVdezL24+pJuOB 4FzXZvW4Rokk8BUUx9dGu8wxYJkh/Cscc1wpUn3PAcCRKDQ8ZK7KEmRUEmcq67E6AJW9 aU4xYMyBwEKfjvnbLzFzzXt0IJWxZ73lAjk6fdL0NUNBLQEVNSzPoob1CxfbPn9uL+e8 KwDPS/hMnvImDwr5iR+h0E6Q7jyLiG8ZmM9AK3cSlTrvQMnLWltShhFSnRKb4YdORW3S gGeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=ANoh8uEOm+gmkt+50LunFAVjJew2LvqnFtto+wxCdzA=; b=dHHSBkQO68FoEKYoWxLkdfYAK3isq7kfu+AHiWTi0BF+5YweoMt94jlLBWb4SwvWxA vx81d9wW8CUD6RWOpnUYwtOK1i9W1BedGkiMLtFQFoVstwaqNPO39YYt1aHAV3dEPVMV gnWzGG9SiWmnVmSfcpmVDqLk0fY/AJqxoL4aFFoD//lz7iBQxPYgvWTBYthjvxPmApO7 pqlbopTsXdURKWwEsQi6FqdFaq015bfCzrEnaxLJ71/jFWDvga9fJ2X2dW5CH1wpBSr4 1aXd7jOZDirGsnY7Ainju5LLILzzy97oR4C4dQqxZ6wn3OmGWWSAOoLz7jHuHfaTLbOe lJBQ== X-Gm-Message-State: APjAAAVR+A8o8Wqxv77c38RSBPgglR4OKtvDeiX5wBw6EgsCmYXuuh9k h80t7g15yb1AZj4fEwmQv3hXZA== X-Received: by 2002:a65:5788:: with SMTP id b8mr23688309pgr.324.1578962916999; Mon, 13 Jan 2020 16:48:36 -0800 (PST) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id z11sm16093204pfk.96.2020.01.13.16.48.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2020 16:48:36 -0800 (PST) Date: Mon, 13 Jan 2020 16:48:35 -0800 (PST) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Mina Almasry cc: mike.kravetz@oracle.com, shuah@kernel.org, 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, aneesh.kumar@linux.vnet.ibm.com, mkoutny@suse.com Subject: Re: [PATCH v9 6/8] hugetlb_cgroup: support noreserve mappings In-Reply-To: <20191217231615.164161-6-almasrymina@google.com> Message-ID: References: <20191217231615.164161-1-almasrymina@google.com> <20191217231615.164161-6-almasrymina@google.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 17 Dec 2019, Mina Almasry wrote: > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 39eb2fa53a420..3e94f5c2d7cd4 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -1367,6 +1367,9 @@ 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++; > > @@ -2189,10 +2192,19 @@ struct page *alloc_huge_page(struct vm_area_struct *vma, > gbl_chg = 1; > } > > + /* If this allocation is not consuming a reservation, charge it now. > + */ > + if (map_chg || avoid_reserve || !vma_resv_map(vma)) { These conditions are checked three times in this function, maybe better set a bool on the stack and use it throughout the function to guarantee it remains consistent? bool deferred_reserve = !vma_resv_map(vma) || map_chg || avoid_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); > /* > @@ -2216,6 +2228,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 (!vma_resv_map(vma) || map_chg || avoid_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); > @@ -2241,6 +2261,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 (map_chg || avoid_reserve || !vma_resv_map(vma)) > + 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.24.1.735.g03f4e72817-goog >