From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Morton Subject: + mm-gup-proc-vmstat-pin_user_pages-foll_pin-reporting.patch added to -mm tree Date: Mon, 10 Feb 2020 21:50:49 -0800 Message-ID: <20200211055049.8ZOhxhPhl%akpm@linux-foundation.org> References: <20200203173311.6269a8be06a05e5a4aa08a93@linux-foundation.org> Reply-To: linux-kernel@vger.kernel.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from mail.kernel.org ([198.145.29.99]:60454 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726942AbgBKFuv (ORCPT ); Tue, 11 Feb 2020 00:50:51 -0500 In-Reply-To: <20200203173311.6269a8be06a05e5a4aa08a93@linux-foundation.org> Sender: mm-commits-owner@vger.kernel.org List-Id: mm-commits@vger.kernel.org To: corbet@lwn.net, dan.j.williams@intel.com, david@fromorbit.com, hch@infradead.org, ira.weiny@intel.com, jack@suse.cz, jgg@ziepe.ca, jglisse@redhat.com, jhubbard@nvidia.com, kirill.shutemov@linux.intel.com, mhocko@suse.com, mike.kravetz@oracle.com, mm-commits@vger.kernel.org, shuah@kernel.org, vbabka@suse.cz, viro@zeniv.linux.org.uk, willy@infradead.org The patch titled Subject: mm/gup: /proc/vmstat: pin_user_pages (FOLL_PIN) reporting has been added to the -mm tree. Its filename is mm-gup-proc-vmstat-pin_user_pages-foll_pin-reporting.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/mm-gup-proc-vmstat-pin_user_pa= ges-foll_pin-reporting.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/mm-gup-proc-vmstat-pin_user_pa= ges-foll_pin-reporting.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing= your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ =46rom: John Hubbard Subject: mm/gup: /proc/vmstat: pin_user_pages (FOLL_PIN) reporting Now that pages are "DMA-pinned" via pin_user_page*(), and unpinned via unpin_user_pages*(), we need some visibility into whether all of this is working correctly. Add two new fields to /proc/vmstat: nr_foll_pin_acquired nr_foll_pin_released These are documented in Documentation/core-api/pin_user_pages.rst. They represent the number of pages (since boot time) that have been pinned ("nr_foll_pin_acquired") and unpinned ("nr_foll_pin_released"), via pin_user_pages*() and unpin_user_pages*(). In the absence of long-running DMA or RDMA operations that hold pages pinned, the above two fields will normally be equal to each other. Also: update Documentation/core-api/pin_user_pages.rst, to remove an earlier (now confirmed untrue) claim about a performance problem with /proc/vmstat. Also: update Documentation/core-api/pin_user_pages.rst to rename the new /proc/vmstat entries, to the names listed here. Link: http://lkml.kernel.org/r/20200211001536.1027652-9-jhubbard@nvidia.com Signed-off-by: John Hubbard Acked-by: Kirill A. Shutemov Cc: Ira Weiny Cc: Jan Kara Cc: J=C3=A9r=C3=B4me Glisse Cc: "Matthew Wilcox (Oracle)" Cc: Al Viro Cc: Christoph Hellwig Cc: Dan Williams Cc: Dave Chinner Cc: Jason Gunthorpe Cc: Jonathan Corbet Cc: Michal Hocko Cc: Mike Kravetz Cc: Shuah Khan Cc: Vlastimil Babka Signed-off-by: Andrew Morton --- Documentation/core-api/pin_user_pages.rst | 33 ++++++++++++++++---- include/linux/mmzone.h | 2 + mm/gup.c | 13 +++++++ mm/vmstat.c | 2 + 4 files changed, 45 insertions(+), 5 deletions(-) --- a/Documentation/core-api/pin_user_pages.rst~mm-gup-proc-vmstat-pin_user= _pages-foll_pin-reporting +++ a/Documentation/core-api/pin_user_pages.rst @@ -208,12 +208,35 @@ has the following new calls to exercise You can monitor how many total dma-pinned pages have been acquired and rel= eased since the system was booted, via two new /proc/vmstat entries: :: =20 - /proc/vmstat/nr_foll_pin_requested - /proc/vmstat/nr_foll_pin_requested + /proc/vmstat/nr_foll_pin_acquired + /proc/vmstat/nr_foll_pin_released =20 -Those are both going to show zero, unless CONFIG_DEBUG_VM is set. This is -because there is a noticeable performance drop in unpin_user_page(), when = they -are activated. +Under normal conditions, these two values will be equal unless there are a= ny +long-term [R]DMA pins in place, or during pin/unpin transitions. + +* nr_foll_pin_acquired: This is the number of logical pins that have been + acquired since the system was powered on. For huge pages, the head page = is + pinned once for each page (head page and each tail page) within the huge= page. + This follows the same sort of behavior that get_user_pages() uses for hu= ge + pages: the head page is refcounted once for each tail or head page in th= e huge + page, when get_user_pages() is applied to a huge page. + +* nr_foll_pin_released: The number of logical pins that have been released= since + the system was powered on. Note that pages are released (unpinned) on a + PAGE_SIZE granularity, even if the original pin was applied to a huge pa= ge. + Becaused of the pin count behavior described above in "nr_foll_pin_acqui= red", + the accounting balances out, so that after doing this:: + + pin_user_pages(huge_page); + for (each page in huge_page) + unpin_user_page(page); + +...the following is expected:: + + nr_foll_pin_released =3D=3D nr_foll_pin_acquired + +(...unless it was already out of balance due to a long-term RDMA pin being= in +place.) =20 References =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- a/include/linux/mmzone.h~mm-gup-proc-vmstat-pin_user_pages-foll_pin-rep= orting +++ a/include/linux/mmzone.h @@ -243,6 +243,8 @@ enum node_stat_item { NR_DIRTIED, /* page dirtyings since bootup */ NR_WRITTEN, /* page writings since bootup */ NR_KERNEL_MISC_RECLAIMABLE, /* reclaimable non-slab kernel pages */ + NR_FOLL_PIN_ACQUIRED, /* via: pin_user_page(), gup flag: FOLL_PIN */ + NR_FOLL_PIN_RELEASED, /* pages returned via unpin_user_page() */ NR_VM_NODE_STAT_ITEMS }; =20 --- a/mm/gup.c~mm-gup-proc-vmstat-pin_user_pages-foll_pin-reporting +++ a/mm/gup.c @@ -86,6 +86,8 @@ static __maybe_unused struct page *try_g if (flags & FOLL_GET) return try_get_compound_head(page, refs); else if (flags & FOLL_PIN) { + int orig_refs =3D refs; + /* * When pinning a compound page of order > 1 (which is what * hpage_pincount_available() checks for), use an exact count to @@ -104,6 +106,9 @@ static __maybe_unused struct page *try_g if (hpage_pincount_available(page)) hpage_pincount_add(page, refs); =20 + mod_node_page_state(page_pgdat(page), NR_FOLL_PIN_ACQUIRED, + orig_refs); + return page; } =20 @@ -158,6 +163,8 @@ bool __must_check try_grab_page(struct p * once, so that the page really is pinned. */ page_ref_add(page, refs); + + mod_node_page_state(page_pgdat(page), NR_FOLL_PIN_ACQUIRED, 1); } =20 return true; @@ -178,6 +185,7 @@ static bool __unpin_devmap_managed_user_ =20 count =3D page_ref_sub_return(page, refs); =20 + mod_node_page_state(page_pgdat(page), NR_FOLL_PIN_RELEASED, 1); /* * devmap page refcounts are 1-based, rather than 0-based: if * refcount is 1, then the page is free and the refcount is @@ -228,6 +236,8 @@ void unpin_user_page(struct page *page) =20 if (page_ref_sub_and_test(page, refs)) __put_page(page); + + mod_node_page_state(page_pgdat(page), NR_FOLL_PIN_RELEASED, 1); } EXPORT_SYMBOL(unpin_user_page); =20 @@ -2259,6 +2269,9 @@ static int record_subpages(struct page * static void put_compound_head(struct page *page, int refs, unsigned int fl= ags) { if (flags & FOLL_PIN) { + mod_node_page_state(page_pgdat(page), NR_FOLL_PIN_RELEASED, + refs); + if (hpage_pincount_available(page)) hpage_pincount_sub(page, refs); else --- a/mm/vmstat.c~mm-gup-proc-vmstat-pin_user_pages-foll_pin-reporting +++ a/mm/vmstat.c @@ -1168,6 +1168,8 @@ const char * const vmstat_text[] =3D { "nr_dirtied", "nr_written", "nr_kernel_misc_reclaimable", + "nr_foll_pin_acquired", + "nr_foll_pin_released", =20 /* enum writeback_stat_item counters */ "nr_dirty_threshold", _ Patches currently in -mm which might be from jhubbard@nvidia.com are mm-gup-split-get_user_pages_remote-into-two-routines.patch mm-gup-pass-a-flags-arg-to-__gup_device_-functions.patch mm-introduce-page_ref_sub_return.patch mm-gup-pass-gup-flags-to-two-more-routines.patch mm-gup-require-foll_get-for-get_user_pages_fast.patch mm-gup-track-foll_pin-pages.patch mm-gup-page-hpage_pinned_refcount-exact-pin-counts-for-huge-pages.patch mm-gup-proc-vmstat-pin_user_pages-foll_pin-reporting.patch mm-gup_benchmark-support-pin_user_pages-and-related-calls.patch selftests-vm-run_vmtests-invoke-gup_benchmark-with-basic-foll_pin-coverage.= patch mm-dump_page-additional-diagnostics-for-huge-pinned-pages.patch