From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E52FFC433DB for ; Tue, 23 Feb 2021 16:45:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 52FA764DE9 for ; Tue, 23 Feb 2021 16:45:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 52FA764DE9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C11BD6B0005; Tue, 23 Feb 2021 11:45:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B9A586B0070; Tue, 23 Feb 2021 11:45:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8BB96B0071; Tue, 23 Feb 2021 11:45:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0058.hostedemail.com [216.40.44.58]) by kanga.kvack.org (Postfix) with ESMTP id 947806B0005 for ; Tue, 23 Feb 2021 11:45:17 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 550DC87F6 for ; Tue, 23 Feb 2021 16:45:17 +0000 (UTC) X-FDA: 77850107874.18.5DB0AC8 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) by imf09.hostedemail.com (Postfix) with ESMTP id AE9BF60024A4 for ; Tue, 23 Feb 2021 16:44:55 +0000 (UTC) Received: by mail-ed1-f50.google.com with SMTP id n1so26657242edv.2 for ; Tue, 23 Feb 2021 08:44:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OEmd5FiXkbavQSYegFXdXskGmpLS7zI/goY7LNgK/B4=; b=TDan8xCuEJhqfL/iranz+HfwsGd5+A9H5+KzUnEpWGc21DPUnnovxxG/4uPTOEk4p4 1cKvOnk3NQf9RcC4QFp3dPdVuYVZQnvizCqT31yD4oOJw5Ka57oJDQMbFGsHj1/Y3+Gm +B3lO+6QbBH/nchf5FCdcqhyTYws/r1D8ZE8LCwocmiYAgz+1OuSDE5jwTek5NvUcbij Un9zJvN408BZ+Qe0oZXoYnsQhXfiP+bk8xA6NWSpZgmNdj+ueS3t0r0NP6orwS5UL2r8 xaO6KCJIryMThhOih50U3oTM8IamwtBftv99TF0XWygliGmmkM+t3a4R9RKrnEhjPPXf H36A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OEmd5FiXkbavQSYegFXdXskGmpLS7zI/goY7LNgK/B4=; b=Z5CJ/r72JTRSjaHM8GIjWs3BvW44Z0CzosHGa+GC+4khuuQ0C4ss9g5ijR/jB33srJ ktbNobHhlo6bIwaUkprxcXJ8xTfVa2J7nQ3qoqY3g7thE3hRU1jMZwBpIshvE5gV7CVe 6qU00obs8or6VJc2ABgBvWvGhB1N/2++Sm/7RDfpn5/7qbctNPMKxBPYTpOhxP+8vrUR L4oEIViY2OI86CuQfdUJbf1qetH+wSKq7N+yal6supZab7qHgLPleebmgz982/tJe0qe ROAIIDLkPd7B5UgvGfSrnw3IMqyfnzDOSjR9GjzV3Ymrb6piCmxhMrxLmqIGgQuNvRPI VcUg== X-Gm-Message-State: AOAM532gbzRglNP5HfYE9fMdJre8l01nJFjkMNrObFtCptMJr+CbOsaF MJj/e+jWeCfNq+W5bdW7MI36df34DPzyCceOaIGS+Q== X-Google-Smtp-Source: ABdhPJzyzYUbif39KlLojw9x5+U83YgJIk0AtFDBV59Oa1JNfH+4BvxaoJHD5j7FFRO4K5ND8Uo3oaxaARKH6pgeirc= X-Received: by 2002:a05:6402:b1c:: with SMTP id bm28mr29364796edb.354.1614098696926; Tue, 23 Feb 2021 08:44:56 -0800 (PST) MIME-Version: 1.0 References: <20201208172901.17384-1-joao.m.martins@oracle.com> <6a18179e-65f7-367d-89a9-d5162f10fef0@oracle.com> In-Reply-To: <6a18179e-65f7-367d-89a9-d5162f10fef0@oracle.com> From: Dan Williams Date: Tue, 23 Feb 2021 08:44:52 -0800 Message-ID: Subject: Re: [PATCH RFC 0/9] mm, sparse-vmemmap: Introduce compound pagemaps To: Joao Martins Cc: Linux MM , Ira Weiny , linux-nvdimm , Matthew Wilcox , Jason Gunthorpe , Jane Chu , Muchun Song , Mike Kravetz , Andrew Morton Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: f34hpge6y8yyewrs713bs86sm7e59i8b X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: AE9BF60024A4 Received-SPF: none (intel.com>: No applicable sender policy available) receiver=imf09; identity=mailfrom; envelope-from=""; helo=mail-ed1-f50.google.com; client-ip=209.85.208.50 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614098695-596729 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Feb 23, 2021 at 8:30 AM Joao Martins wrote: > > On 2/20/21 1:18 AM, Dan Williams wrote: > > On Tue, Dec 8, 2020 at 9:32 AM Joao Martins wrote: > >> Patch 6 - 8: Optimize grabbing/release a page refcount changes given that we > >> are working with compound pages i.e. we do 1 increment/decrement to the head > >> page for a given set of N subpages compared as opposed to N individual writes. > >> {get,pin}_user_pages_fast() for zone_device with compound pagemap consequently > >> improves considerably, and unpin_user_pages() improves as well when passed a > >> set of consecutive pages: > >> > >> before after > >> (get_user_pages_fast 1G;2M page size) ~75k us -> ~3.2k ; ~5.2k us > >> (pin_user_pages_fast 1G;2M page size) ~125k us -> ~3.4k ; ~5.5k us > > > > Compelling! > > > > BTW is there any reason why we don't support pin_user_pages_fast() with FOLL_LONGTERM for > device-dax? > Good catch. Must have been an oversight of the conversion. FOLL_LONGTERM collides with filesystem operations, but not device-dax. In fact that's the motivation for device-dax in the first instance, no need to coordinate runtime physical address layout changes because the device is statically allocated. > Looking at the history, I understand that fsdax can't support it atm, but I am not sure > that the same holds for device-dax. I have this small chunk (see below the scissors mark) > which relaxes this for a pgmap of type MEMORY_DEVICE_GENERIC, albeit not sure if there is > a fundamental issue for the other types that makes this an unwelcoming change. > > Joao > > --------------------->8--------------------- > > Subject: [PATCH] mm/gup: allow FOLL_LONGTERM pin-fast for > MEMORY_DEVICE_GENERIC > > The downside would be one extra lookup in dev_pagemap tree > for other pgmap->types (P2P, FSDAX, PRIVATE). But just one > per gup-fast() call. I'd guess a dev_pagemap lookup is faster than a get_user_pages slow path. It should be measurable that this change is at least as fast or faster than falling back to the slow path, but it would be good to measure. Code changes look good to me. > > Signed-off-by: Joao Martins > --- > include/linux/mm.h | 5 +++++ > mm/gup.c | 24 +++++++++++++----------- > 2 files changed, 18 insertions(+), 11 deletions(-) > > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 32f0c3986d4f..c89a049bbd7a 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -1171,6 +1171,11 @@ static inline bool is_pci_p2pdma_page(const struct page *page) > page->pgmap->type == MEMORY_DEVICE_PCI_P2PDMA; > } > > +static inline bool devmap_longterm_available(const struct dev_pagemap *pgmap) > +{ I'd call this devmap_can_longterm(). > + return pgmap->type == MEMORY_DEVICE_GENERIC; > +} > + > /* 127: arbitrary random number, small enough to assemble well */ > #define page_ref_zero_or_close_to_overflow(page) \ > ((unsigned int) page_ref_count(page) + 127u <= 127u) > diff --git a/mm/gup.c b/mm/gup.c > index 222d1fdc5cfa..03e370d360e6 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -2092,14 +2092,18 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned > long end, > goto pte_unmap; > > if (pte_devmap(pte)) { > - if (unlikely(flags & FOLL_LONGTERM)) > - goto pte_unmap; > - > pgmap = get_dev_pagemap(pte_pfn(pte), pgmap); > if (unlikely(!pgmap)) { > undo_dev_pagemap(nr, nr_start, flags, pages); > goto pte_unmap; > } > + > + if (unlikely(flags & FOLL_LONGTERM) && > + !devmap_longterm_available(pgmap)) { > + undo_dev_pagemap(nr, nr_start, flags, pages); > + goto pte_unmap; > + } > + > } else if (pte_special(pte)) > goto pte_unmap; > > @@ -2195,6 +2199,10 @@ static int __gup_device_huge(unsigned long pfn, unsigned long addr, > return 0; > } > > + if (unlikely(flags & FOLL_LONGTERM) && > + !devmap_longterm_available(pgmap)) > + return 0; > + > @@ -2356,12 +2364,9 @@ static int gup_huge_pmd(pmd_t orig, pmd_t *pmdp, unsigned long addr, > if (!pmd_access_permitted(orig, flags & FOLL_WRITE)) > return 0; > > - if (pmd_devmap(orig)) { > - if (unlikely(flags & FOLL_LONGTERM)) > - return 0; > + if (pmd_devmap(orig)) > return __gup_device_huge_pmd(orig, pmdp, addr, end, flags, > pages, nr); > - } > > page = pmd_page(orig) + ((addr & ~PMD_MASK) >> PAGE_SHIFT); > refs = record_subpages(page, addr, end, pages + *nr); > @@ -2390,12 +2395,9 @@ static int gup_huge_pud(pud_t orig, pud_t *pudp, unsigned long addr, > if (!pud_access_permitted(orig, flags & FOLL_WRITE)) > return 0; > > - if (pud_devmap(orig)) { > - if (unlikely(flags & FOLL_LONGTERM)) > - return 0; > + if (pud_devmap(orig)) > return __gup_device_huge_pud(orig, pudp, addr, end, flags, > pages, nr); > - } > > page = pud_page(orig) + ((addr & ~PUD_MASK) >> PAGE_SHIFT); > refs = record_subpages(page, addr, end, pages + *nr); > -- > 2.17.1