From: akpm@linux-foundation.org Subject: + mm-munlock-remove-redundant-get_page-put_page-pair-on-the-fast-path.patch added to -mm tree Date: Mon, 19 Aug 2013 15:49:12 -0700 Message-ID: <5212a0e8.RyY0SJlIXRVVRq8E%akpm@linux-foundation.org> Reply-To: linux-kernel@vger.kernel.org Mime-Version: 1.0 Content-Type: application/octet-stream Content-Transfer-Encoding: 8bit Return-path: Received: from mail.linuxfoundation.org ([140.211.169.12]:55174 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751148Ab3HSWtN (ORCPT ); Mon, 19 Aug 2013 18:49:13 -0400 Sender: mm-commits-owner@vger.kernel.org List-Id: mm-commits@vger.kernel.org To: mm-commits@vger.kernel.org, walken@google.com, riel@redhat.com, mhocko@suse.cz, mgorman@suse.de, joern@logfs.org, hughd@google.com, hannes@cmpxchg.org, vbabka@suse.cz Subject: + mm-munlock-remove-redundant-get_page-put_page-pair-on-the-fast-path.patch added to -mm tree To: vbabka@suse.cz,hannes@cmpxchg.org,hughd@google.com,joern@logfs.org,mgorman@suse.de,mhocko@suse.cz,riel@redhat.com,walken@google.com From: akpm@linux-foundation.org Date: Mon, 19 Aug 2013 15:49:12 -0700 The patch titled Subject: mm: munlock: remove redundant get_page/put_page pair on the fast path has been added to the -mm tree. Its filename is mm-munlock-remove-redundant-get_page-put_page-pair-on-the-fast-path.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/mm-munlock-remove-redundant-get_page-put_page-pair-on-the-fast-path.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/mm-munlock-remove-redundant-get_page-put_page-pair-on-the-fast-path.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/SubmitChecklist when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Vlastimil Babka Subject: mm: munlock: remove redundant get_page/put_page pair on the fast path The performance of the fast path in munlock_vma_range() can be further improved by avoiding atomic ops of a redundant get_page()/put_page() pair. When calling get_page() during page isolation, we already have the pin from follow_page_mask(). This pin will be then returned by __pagevec_lru_add(), after which we do not reference the pages anymore. After this patch, an 8% speedup was measured for munlocking a 56GB large memory area with THP disabled. Signed-off-by: Vlastimil Babka Reviewed-by: Jörn Engel Acked-by: Mel Gorman Cc: Michel Lespinasse Cc: Hugh Dickins Cc: Rik van Riel Cc: Johannes Weiner Cc: Michal Hocko Cc: Vlastimil Babka Signed-off-by: Andrew Morton --- mm/mlock.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff -puN mm/mlock.c~mm-munlock-remove-redundant-get_page-put_page-pair-on-the-fast-path mm/mlock.c --- a/mm/mlock.c~mm-munlock-remove-redundant-get_page-put_page-pair-on-the-fast-path +++ a/mm/mlock.c @@ -300,8 +300,10 @@ static void __munlock_pagevec(struct pag if (PageLRU(page)) { lruvec = mem_cgroup_page_lruvec(page, zone); lru = page_lru(page); - - get_page(page); + /* + * We already have pin from follow_page_mask() + * so we can spare the get_page() here. + */ ClearPageLRU(page); del_page_from_lru_list(page, lruvec, lru); } else { @@ -333,25 +335,25 @@ skip_munlock: lock_page(page); if (!__putback_lru_fast_prepare(page, &pvec_putback, &pgrescued)) { - /* Slow path */ + /* + * Slow path. We don't want to lose the last + * pin before unlock_page() + */ + get_page(page); /* for putback_lru_page() */ __munlock_isolated_page(page); unlock_page(page); + put_page(page); /* from follow_page_mask() */ } } } - /* Phase 3: page putback for pages that qualified for the fast path */ + /* + * Phase 3: page putback for pages that qualified for the fast path + * This will also call put_page() to return pin from follow_page_mask() + */ if (pagevec_count(&pvec_putback)) __putback_lru_fast(&pvec_putback, pgrescued); - /* Phase 4: put_page to return pin from follow_page_mask() */ - for (i = 0; i < nr; i++) { - struct page *page = pvec->pages[i]; - - if (page) - put_page(page); - }