Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp614990imm; Fri, 12 Oct 2018 04:01:07 -0700 (PDT) X-Google-Smtp-Source: ACcGV63oE1TzwZYtSPVd818uQaeustYAFqJcULZTDSayBkStFdw98fSVKxHX6MU6pxWvDz/ESt6w X-Received: by 2002:a17:902:768b:: with SMTP id m11-v6mr5437527pll.163.1539342067851; Fri, 12 Oct 2018 04:01:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539342067; cv=none; d=google.com; s=arc-20160816; b=GO6NnRYbf2mjDzYepTP4+R8i6wgFHZPksQWaeablZpBfaVPf7nFKZrfu8kIlCTUBYV ffoBLjvYNFkYUyf2Yx6i1KaGGRNuQymug15CPsoQ9ne2pcWBgcNy7hqriOivgJBiPCgE HY6etOw633DL2s7i1Ika0EFGNKd8YSifM5OioCFvev/rDwDBUNjuT7KmjxIdY6xYAWmL RnPf0rv9b4TI+LLth/QgTwCaPS0eXR3Dvz81S3+XpBzpMHYK9Ec7mSO0CqqvStnWwfzh AFIndh6TU+aYKAnm8+8AUp9FNWUxlcTKl3O3UKg35phLhQUR7TQ6T0FY9+ZO/2KUPGOa 6chg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=GEbrC9WoMx7yLYsqRtPBIyhrSuV+9giyvr/7VnB22LM=; b=Wz9KW/uiQUjcN2RkoF5ELHo0GgLKhwfNf594ZyZg0X4MgS710HHHhCf5SgGomo4Ws0 5kNDnkJYVASu3U6mYSKLUNtWqh+1HA8gKZlYIFHeeGp/vlOunk/EkVewnYJiKzAoioeQ lUHZAEAquo1m42rzeQMcqUBVbvVmRU2LJ06OQNgdML3GwnEq5D33ted19Yv5AdlvnIM/ hND2Vc4WQROVAmTvQo8IjMuUe++Y7sDcOpgeBjBwEerBwJwnoLxguZ2Dr4KlLcixAbiU FCEhp3slpkYVfScgmTcf5r9J7Y9turDx7zyC7W+/MoswNW5k5tugus/Gcz3lMrI3hoBa 5Qgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b="L1Yqe0X/"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f62-v6si1008119plf.288.2018.10.12.04.00.53; Fri, 12 Oct 2018 04:01:07 -0700 (PDT) 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=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b="L1Yqe0X/"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728200AbeJLScT (ORCPT + 99 others); Fri, 12 Oct 2018 14:32:19 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:39424 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727640AbeJLScT (ORCPT ); Fri, 12 Oct 2018 14:32:19 -0400 Received: by mail-pg1-f193.google.com with SMTP id r9-v6so5692457pgv.6 for ; Fri, 12 Oct 2018 04:00:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=GEbrC9WoMx7yLYsqRtPBIyhrSuV+9giyvr/7VnB22LM=; b=L1Yqe0X/Iqbxggpg5gRFq0LOixMi+S3+WUyl1dAahvrs/73UFCbyJB7p7xUNsJCqz2 J/55GuQdzQeSrWw5vmoMEE8bXsjr2xRVwJHTHHWhSP2jbj8b5qLJctFEjk10PIoV/lXH XRGrqfDuXDTB2dTifT9N9Bz0Z3yh9v9PMVqv3dbfw7yAAcEXQ0+UeFCamQfoVqfGxpX2 n0PDkLLD5QlFBx8GJW+Q/DG4bztQIqOGF9zjZnnP60DiSaD8otbMye1DdStyUPUfiJ3Z wv5TAaNIBxLEG/OUwcGmdq6Msj/IPw4Yeu/wLa4P7U2V4G/BGO0bgJ6aChv4zFKsQoIk 1SbA== 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=GEbrC9WoMx7yLYsqRtPBIyhrSuV+9giyvr/7VnB22LM=; b=Ju97LipcNUaNAbCcuH1fNDbslE+ajOWjkl9GMRpakdASRNhbYp72WjimglPI523AgM ZWDmeUVswbfH8Kedop+GMP5ddQXta4wTFavw9awmfn8F9b473Gt/+tgnyPcXzULeaTu7 9HSl+scKBxOIge7QFM3zriIaz6UUQ5nIAhhVr4pcX0emqV5vFc9e3Ldzw8blFklXTj+O 0ju4yb21d20l3bLC59CiuJtlQaXLmSzhfOz1pVsQTfbZ151yordms+Q06les6pxvEMpZ hRpo5iwNVcelaQSQDObxGJfVN6e6tWGKj/ERf/B6l/PeZx3iU9Uvvghysp5pBMa3SfgS 5qMg== X-Gm-Message-State: ABuFfogz0WgpPPdCnThkd3fK47YJdddWZR+Wg9F35p2aLLo0L3XKJxtQ 3u0hkhK2iOzGsqL7skAcCqfXQg== X-Received: by 2002:a62:830e:: with SMTP id h14-v6mr5683608pfe.29.1539342025895; Fri, 12 Oct 2018 04:00:25 -0700 (PDT) Received: from kshutemo-mobl1.localdomain ([192.55.54.42]) by smtp.gmail.com with ESMTPSA id r73-v6sm1962024pfk.157.2018.10.12.04.00.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Oct 2018 04:00:24 -0700 (PDT) Received: by kshutemo-mobl1.localdomain (Postfix, from userid 1000) id 85BBE300030; Fri, 12 Oct 2018 14:00:20 +0300 (+03) Date: Fri, 12 Oct 2018 14:00:20 +0300 From: "Kirill A. Shutemov" To: Dan Williams Cc: Keith Busch , Linux MM , Linux Kernel Mailing List , "Kirill A. Shutemov" , Dave Hansen , Andrew Morton Subject: Re: [PATCHv2] mm/gup: Cache dev_pagemap while pinning pages Message-ID: <20181012110020.pu5oanl6tnz4mibr@kshutemo-mobl1> References: <20181011175542.13045-1-keith.busch@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 11, 2018 at 04:24:02PM -0700, Dan Williams wrote: > On Thu, Oct 11, 2018 at 11:00 AM Keith Busch wrote: > > > > Getting pages from ZONE_DEVICE memory needs to check the backing device's > > live-ness, which is tracked in the device's dev_pagemap metadata. This > > metadata is stored in a radix tree and looking it up adds measurable > > software overhead. > > > > This patch avoids repeating this relatively costly operation when > > dev_pagemap is used by caching the last dev_pagemap while getting user > > pages. The gup_benchmark kernel self test reports this reduces time to > > get user pages to as low as 1/3 of the previous time. > > > > Cc: Kirill Shutemov > > Cc: Dave Hansen > > Cc: Dan Williams > > Signed-off-by: Keith Busch > > Other than the 2 comments below, this looks good to me: > > Reviewed-by: Dan Williams Looks good to me too: Acked-by: Kirill A. Shutemov > > [..] > > diff --git a/mm/gup.c b/mm/gup.c > > index 1abc8b4afff6..d2700dff6f66 100644 > > --- a/mm/gup.c > > +++ b/mm/gup.c > [..] > > @@ -431,7 +430,22 @@ struct page *follow_page_mask(struct vm_area_struct *vma, > > return no_page_table(vma, flags); > > } > > > > - return follow_p4d_mask(vma, address, pgd, flags, page_mask); > > + return follow_p4d_mask(vma, address, pgd, flags, ctx); > > +} > > + > > +struct page *follow_page(struct vm_area_struct *vma, unsigned long address, > > + unsigned int foll_flags) > > +{ > > + struct page *page; > > + struct follow_page_context ctx = { > > + .pgmap = NULL, > > + .page_mask = 0, > > + }; > > You don't need to init all members. It is defined that if you init at > least one member then all non initialized members are set to zero, so > you should be able to do " = { 0 }". > > > + > > + page = follow_page_mask(vma, address, foll_flags, &ctx); > > + if (ctx.pgmap) > > + put_dev_pagemap(ctx.pgmap); > > + return page; > > } > > > > static int get_gate_page(struct mm_struct *mm, unsigned long address, > > @@ -659,9 +673,9 @@ static long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, > > unsigned int gup_flags, struct page **pages, > > struct vm_area_struct **vmas, int *nonblocking) > > { > > - long i = 0; > > - unsigned int page_mask; > > + long ret = 0, i = 0; > > struct vm_area_struct *vma = NULL; > > + struct follow_page_context ctx = {}; > > Does this have defined behavior? I would feel better with " = { 0 }" > to be explicit. Well, it's not allowed by the standart, but GCC allows this. You can see a warning with -pedantic. We use empty-list initializers a lot in the kernel: $ git grep 'struct .*= {};' | wc -l 997 It should be fine. -- Kirill A. Shutemov