Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5110281imu; Tue, 29 Jan 2019 13:00:17 -0800 (PST) X-Google-Smtp-Source: ALg8bN6sPXFVQsGdo6+CIMaOJL25O7FiCGCwO72w9cO5mL/HqHYxSl3UNchqmKuq8DkWk/xVeDmK X-Received: by 2002:a63:381c:: with SMTP id f28mr25110475pga.330.1548795617438; Tue, 29 Jan 2019 13:00:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548795617; cv=none; d=google.com; s=arc-20160816; b=Lfo9Dxy+U7Xaal1c5REw4ytPkqyG19/PV8f1vrP7z1jF6EhRbvTgR0DpQF5Aj6VUWC wZ0dhjXuGhB+u9VLmniKw7mMGKmEuhIY7iTJ6+PwEF3Afhq4MtvrjS/hRSB7LR+pv1rx uFIwD06et1/uxxf3ejYPO0dS2+I58AifvqNkC+Pg4Mr4xRMd6YEkxXtv9Cf46nDArCYV AvbcwO6re/I+WrRSyDATtz7+tI75H5vqx3rRhxzqoTNBeGD/ctc8ZYZSFDjzNvH1qF3n pazQ6E3Jm58D5XocEBg31tG8KIZjmmFh4mwlj7M7rRM6sznQYOo/9v0VEzU9UlNMYAwV krmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=+lCxnlIZUJU9pZqCTFE3c/UHyRafPDqnnoPq+cvx5Es=; b=Dn5uNDuV+fBM+SX6no2WdoF8RKTFsDb419hhj97HOOdzrJv6kSgCrDW5UJ8dGfqDv/ xk/HNS3E4cZY8AlrQJ5lE3BqXkK2GyNwvKlJ/W6VWkugFql92ucwjj/ojA39Ub8PafSd MN91Rw1Ptbzl4+EudGtTlx9LUyV433vm1IVYwqJt7V6/r/FvrZAY8cEY+MaRjvuVODLw FDSF/EYP+rVUWzLXsZLoCjTOi/eRR0mMMincLklqFZ4fVO59M5UzRs7rtiWx8y3vLqUY gyQ8FG7HHPqHHImOL9xvThZjr1zFYgFSkRjti/9ZrBIrsrEaN81umsokFEPrpYw5bNWT vhLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chrisdown.name header.s=google header.b=atRWCQe0; 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=NONE sp=NONE dis=NONE) header.from=chrisdown.name Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p14si8705613plq.25.2019.01.29.13.00.01; Tue, 29 Jan 2019 13:00:17 -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=@chrisdown.name header.s=google header.b=atRWCQe0; 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=NONE sp=NONE dis=NONE) header.from=chrisdown.name Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729593AbfA2U6z (ORCPT + 99 others); Tue, 29 Jan 2019 15:58:55 -0500 Received: from mail-yw1-f67.google.com ([209.85.161.67]:45863 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727326AbfA2U6y (ORCPT ); Tue, 29 Jan 2019 15:58:54 -0500 Received: by mail-yw1-f67.google.com with SMTP id d190so8743859ywd.12 for ; Tue, 29 Jan 2019 12:58:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=+lCxnlIZUJU9pZqCTFE3c/UHyRafPDqnnoPq+cvx5Es=; b=atRWCQe0OXSmeZ8tI433nmuVXC9/nf3+BVa2GFc+cDVIopGZtz4CpjFyBmLV5vlmE6 f5YbVCdzOSSXQtZpiK7XBBVdOuoKCkdmprZnxWY0zYoyQYZDgU40xLVWJfPGojBjisSe /K00diZPmknhspvWEuz7lQEQrLtL1JiUXq/nU= 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:message-id:mime-version :content-disposition:user-agent; bh=+lCxnlIZUJU9pZqCTFE3c/UHyRafPDqnnoPq+cvx5Es=; b=tSn2YQX8tIAZmvjM/OOhpuORd5Y5OxNck52sU2yba62E8bNUj0KMb9L3aT/XnE0Tum IOOCKWU+4wdL5XLFGesU3rpqosgp0KkKfaDYsxlSpixjPgvSPDSoci1l1VtxS6d9tXNe /yeqjYC+w0O1GHr9y7EdyOYdoi9DmIBEucahEi8XoOF6RW31ob49t64hb410fbI5O7L0 r4vd0NUpTABW8KBu625LRDlfnIyAqzP3uAI0jZiHWuKwQWMxrR/1rWw6FoPWYhC+/iZ1 pmMjJA+5uOj4EiQ92oF4Pl9Ada8gx+afBmAYxHXyz+MKn7NmRI+zMhDZBhWqIpcyXHRB FszQ== X-Gm-Message-State: AJcUukcw535mEqb7wvkuim9jvJ17AZhAi15P1e6CdRYP0MzYjNXqw7OB 8uw3TJubiM1KHNAjVRZ2PANmgw== X-Received: by 2002:a81:7d0b:: with SMTP id y11mr25566161ywc.442.1548795533500; Tue, 29 Jan 2019 12:58:53 -0800 (PST) Received: from localhost ([2620:10d:c091:200::6:f1fc]) by smtp.gmail.com with ESMTPSA id o14sm27932586ywo.52.2019.01.29.12.58.52 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 29 Jan 2019 12:58:52 -0800 (PST) Date: Tue, 29 Jan 2019 15:58:52 -0500 From: Chris Down To: Andrew Morton Cc: Johannes Weiner , Tejun Heo , Roman Gushchin , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, kernel-team@fb.com Subject: [PATCH] mm: memcontrol: Expose THP events on a per-memcg basis Message-ID: <20190129205852.GA7310@chrisdown.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.11.2 (2019-01-07) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently THP allocation events data is fairly opaque, since you can only get it system-wide. This patch makes it easier to reason about transparent hugepage behaviour on a per-memcg basis. For anonymous THP-backed pages, we already have MEMCG_RSS_HUGE in v1, which is used for v1's rss_huge [sic]. This is reused here as it's fairly involved to untangle NR_ANON_THPS right now to make it per-memcg, since right now some of this is delegated to rmap before we have any memcg actually assigned to the page. It's a good idea to rework that, but let's leave untangling THP allocation for a future patch. Signed-off-by: Chris Down Cc: Andrew Morton Cc: Johannes Weiner Cc: Tejun Heo Cc: Roman Gushchin Cc: linux-kernel@vger.kernel.org Cc: cgroups@vger.kernel.org Cc: linux-mm@kvack.org Cc: kernel-team@fb.com --- Documentation/admin-guide/cgroup-v2.rst | 14 ++++++++++++++ mm/huge_memory.c | 2 ++ mm/khugepaged.c | 2 ++ mm/memcontrol.c | 13 +++++++++++++ 4 files changed, 31 insertions(+) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 7bf3f129c68b..b6989b39ed8e 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1189,6 +1189,10 @@ PAGE_SIZE multiple when read back. Amount of cached filesystem data that was modified and is currently being written back to disk + anon_thp + Amount of memory used in anonymous mappings backed by + transparent hugepages + inactive_anon, active_anon, inactive_file, active_file, unevictable Amount of memory, swap-backed and filesystem-backed, on the internal memory management lists used by the @@ -1248,6 +1252,16 @@ PAGE_SIZE multiple when read back. Amount of reclaimed lazyfree pages + thp_fault_alloc + + Number of transparent hugepages which were allocated to satisfy + a page fault, including COW faults + + thp_collapse_alloc + + Number of transparent hugepages which were allocated to + allow collapsing an existing range of pages + memory.swap.current A read-only single value file which exists on non-root cgroups. diff --git a/mm/huge_memory.c b/mm/huge_memory.c index f5f1d4324fe2..6cb7a748aa33 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -617,6 +617,7 @@ static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf, mm_inc_nr_ptes(vma->vm_mm); spin_unlock(vmf->ptl); count_vm_event(THP_FAULT_ALLOC); + count_memcg_events(memcg, THP_FAULT_ALLOC, 1); } return 0; @@ -1339,6 +1340,7 @@ vm_fault_t do_huge_pmd_wp_page(struct vm_fault *vmf, pmd_t orig_pmd) } count_vm_event(THP_FAULT_ALLOC); + count_memcg_events(memcg, THP_FAULT_ALLOC, 1); if (!page) clear_huge_page(new_page, vmf->address, HPAGE_PMD_NR); diff --git a/mm/khugepaged.c b/mm/khugepaged.c index ceb242ca6ef6..54f3d33f897a 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1075,6 +1075,7 @@ static void collapse_huge_page(struct mm_struct *mm, BUG_ON(!pmd_none(*pmd)); page_add_new_anon_rmap(new_page, vma, address, true); mem_cgroup_commit_charge(new_page, memcg, false, true); + count_memcg_events(memcg, THP_COLLAPSE_ALLOC, 1); lru_cache_add_active_or_unevictable(new_page, vma); pgtable_trans_huge_deposit(mm, pmd, pgtable); set_pmd_at(mm, address, pmd, _pmd); @@ -1503,6 +1504,7 @@ static void collapse_shmem(struct mm_struct *mm, page_ref_add(new_page, HPAGE_PMD_NR - 1); set_page_dirty(new_page); mem_cgroup_commit_charge(new_page, memcg, false, true); + count_memcg_events(memcg, THP_COLLAPSE_ALLOC, 1); lru_cache_add_anon(new_page); /* diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 18f4aefbe0bf..2f4fe2fb9046 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5603,6 +5603,15 @@ static int memory_stat_show(struct seq_file *m, void *v) seq_printf(m, "file_writeback %llu\n", (u64)acc.stat[NR_WRITEBACK] * PAGE_SIZE); + /* + * TODO: We should eventually replace our own MEMCG_RSS_HUGE counter + * with the NR_ANON_THP vm counter, but right now it's a pain in the + * arse because it requires migrating the work out of rmap to a place + * where the page->mem_cgroup is set up and stable. + */ + seq_printf(m, "anon_thp %llu\n", + (u64)acc.stat[MEMCG_RSS_HUGE] * PAGE_SIZE); + for (i = 0; i < NR_LRU_LISTS; i++) seq_printf(m, "%s %llu\n", mem_cgroup_lru_names[i], (u64)acc.lru_pages[i] * PAGE_SIZE); @@ -5634,6 +5643,10 @@ static int memory_stat_show(struct seq_file *m, void *v) seq_printf(m, "pglazyfree %lu\n", acc.events[PGLAZYFREE]); seq_printf(m, "pglazyfreed %lu\n", acc.events[PGLAZYFREED]); + seq_printf(m, "thp_fault_alloc %lu\n", acc.events[THP_FAULT_ALLOC]); + seq_printf(m, "thp_collapse_alloc %lu\n", + acc.events[THP_COLLAPSE_ALLOC]); + return 0; } -- 2.20.1