Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4015358pxk; Tue, 22 Sep 2020 08:19:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhqoHThH9t5KSvDhGWmlU6IbfmF3zhvwuyeiqjWGiZD84JYkSTjzg2upDTEfzIfZbB0Vyj X-Received: by 2002:a17:906:c830:: with SMTP id dd16mr5622178ejb.196.1600787978643; Tue, 22 Sep 2020 08:19:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600787978; cv=none; d=google.com; s=arc-20160816; b=NzKylcHJCwvaKytRFfAHq/QB2eeyEJTcUkJoKXWnub/pMZNc06788skoa3WETPJUfm HptP49VYNXArA2DoKEHkxChZdxfbZqldq/z7gsLo4PbiMKUJRkcOrBb0aBkJaRoBF0Cs SST+GPdXe7d89pCmEeEhklbFKN8Klw0Ylmnh8rQop2ncZyyT1GofGUs7zq0adH+k/fte RC7/Du80l4kPvkjofd4VK1Tgio5iGcTjP64QfWbKWyM34f+jBfKqaibxh0BQ4KULZcOt jQsZPNwtGWknyskDbyW+ytlUxhUw7zSU2cHja+wzu4P4csGPVcTElc81Tk6tkTvS9OJ9 YdRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=stngSWzZPetsvj++1tiyUoEccJXuMfV3PLP1Yk0w4TE=; b=ZL2rf0co8q3+Cw1M8uZnT5eg+rcLWmTJ9tvmopCQsLJKQ1aXKeHslBnl0erckZwoq1 1zztouLqdBIJFkRiZgD5JT2NJRg37tLr0pwUJeHrDUKBriAtBz7WphPTxgnd+B9b7q9W 9skjohg+EoE50Kz/KfNsP0t9gNS+ceEVl2uD7MdIQxQxRE+LkhlRVf5APC9dmGCybmWV P4E40cwkh+3ox4TghPdTvz+50JU6fby0AZ5Fani4/TOAbm5noNRjfzDkcLr7yjgUFmCB cNV0URkLO/SNVuW8/OuEmAy/X6bVYDpSQJjEnaJ8APAwcPCMA/seJ6sk4ZVpXQtbhLbH kYYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BijKpcdN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ay11si10333179edb.517.2020.09.22.08.19.12; Tue, 22 Sep 2020 08:19:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BijKpcdN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726711AbgIVPRp (ORCPT + 99 others); Tue, 22 Sep 2020 11:17:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:54310 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726566AbgIVPRo (ORCPT ); Tue, 22 Sep 2020 11:17:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600787863; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=stngSWzZPetsvj++1tiyUoEccJXuMfV3PLP1Yk0w4TE=; b=BijKpcdNnp1TElmDJDvTziWXJk5Q9zVxSx8U6CMwMePgGNGYleCpF0Uk25naC+AWOmXfvV 5y5bbsa0ihRm3S5orbPh+vEfH1zToXr9BsgheXRNI/85PnFxXkCDYXpzQDgpP9oc8Pd5bN G8zyJY+JEOkO1Y3uVRT40NXIMqyyjF8= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-506-li7MeSfMOfGEOdHre-FCug-1; Tue, 22 Sep 2020 11:17:40 -0400 X-MC-Unique: li7MeSfMOfGEOdHre-FCug-1 Received: by mail-qv1-f72.google.com with SMTP id l1so11739125qvr.0 for ; Tue, 22 Sep 2020 08:17:39 -0700 (PDT) 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; bh=stngSWzZPetsvj++1tiyUoEccJXuMfV3PLP1Yk0w4TE=; b=TW9L2qbswqEdS5J2sei8SHQW4umQL8qwg/MshaVZu7b8XasaXeE5JPssuPYk50WJgh Q1g/+wezKISnufJIJzxo0okBgSFglfHZqZM57iA7iSdwiwSCU5iFDcIBrt4neNV5M0qB jrm1Kn/J2uMVToaLRTahua/9jDkJM0617Qe8roQfNBPBLZiNNVO7bFeDAsI2m8gvta2a axnjhVfAJlQAEJfDU4MsaDpuRUJVhR3yXG2XwtIoSaqkD3ew6vlmqGclHQ0OJ8GQMK2G j3Y4K7zXfIjQ+JG1kKcxtube3zhTDQDYRxXT3fJhI5EoftOB5yoe7Q0AQOyBwwqj920J xSwA== X-Gm-Message-State: AOAM531bMSLR7bqbjWYqGCdIHTLkr6mwiX4FW1waTdMvPaUxz4QmZIRV RoRbG00db9TlpE/FaK7uGmkgMLCzeo4Wyrq036kUP+Lbyet6+8H0sETXqEx+hU24iIw31HZrtmm hInFqlYEwdH38JHSVXh/Nm/Z4 X-Received: by 2002:a37:8484:: with SMTP id g126mr4829941qkd.119.1600787859240; Tue, 22 Sep 2020 08:17:39 -0700 (PDT) X-Received: by 2002:a37:8484:: with SMTP id g126mr4829914qkd.119.1600787858869; Tue, 22 Sep 2020 08:17:38 -0700 (PDT) Received: from xz-x1 (bras-vprn-toroon474qw-lp130-11-70-53-122-15.dsl.bell.ca. [70.53.122.15]) by smtp.gmail.com with ESMTPSA id x197sm11883363qkb.17.2020.09.22.08.17.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 08:17:38 -0700 (PDT) Date: Tue, 22 Sep 2020 11:17:36 -0400 From: Peter Xu To: John Hubbard Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jason Gunthorpe , Andrew Morton , Jan Kara , Michal Hocko , Kirill Tkhai , Kirill Shutemov , Hugh Dickins , Christoph Hellwig , Andrea Arcangeli , Oleg Nesterov , Leon Romanovsky , Linus Torvalds , Jann Horn Subject: Re: [PATCH 1/5] mm: Introduce mm_struct.has_pinned Message-ID: <20200922151736.GD19098@xz-x1> References: <20200921211744.24758-1-peterx@redhat.com> <20200921211744.24758-2-peterx@redhat.com> <224908c1-5d0f-8e01-baa9-94ec2374971f@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <224908c1-5d0f-8e01-baa9-94ec2374971f@nvidia.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 21, 2020 at 04:53:38PM -0700, John Hubbard wrote: > On 9/21/20 2:17 PM, Peter Xu wrote: > > (Commit message collected from Jason Gunthorpe) > > > > Reduce the chance of false positive from page_maybe_dma_pinned() by keeping > > Not yet, it doesn't. :) More: > > > track if the mm_struct has ever been used with pin_user_pages(). mm_structs > > that have never been passed to pin_user_pages() cannot have a positive > > page_maybe_dma_pinned() by definition. This allows cases that might drive up > > the page ref_count to avoid any penalty from handling dma_pinned pages. > > > > Due to complexities with unpining this trivial version is a permanent sticky > > bit, future work will be needed to make this a counter. > > How about this instead: > > Subsequent patches intend to reduce the chance of false positives from > page_maybe_dma_pinned(), by also considering whether or not a page has > even been part of an mm struct that has ever had pin_user_pages*() > applied to any of its pages. > > In order to allow that, provide a boolean value (even though it's not > implemented exactly as a boolean type) within the mm struct, that is > simply set once and never cleared. This will suffice for an early, rough > implementation that fixes a few problems. > > Future work is planned, to provide a more sophisticated solution, likely > involving a counter, and *not* involving something that is set and never > cleared. This looks good, thanks. Though I think Jason's version is good too (as long as we remove the confusing sentence, that's the one starting with "mm_structs that have never been passed... "). Before I drop Jason's version, I think I'd better figure out what's the major thing we missed so that maybe we can add another paragraph. E.g., "future work will be needed to make this a counter" already means "involving a counter, and *not* involving something that is set and never cleared" to me... Because otherwise it won't be called a counter.. > > > > > Suggested-by: Jason Gunthorpe > > Signed-off-by: Peter Xu > > --- > > include/linux/mm_types.h | 10 ++++++++++ > > kernel/fork.c | 1 + > > mm/gup.c | 6 ++++++ > > 3 files changed, 17 insertions(+) > > > > diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h > > index 496c3ff97cce..6f291f8b74c6 100644 > > --- a/include/linux/mm_types.h > > +++ b/include/linux/mm_types.h > > @@ -441,6 +441,16 @@ struct mm_struct { > > #endif > > int map_count; /* number of VMAs */ > > + /** > > + * @has_pinned: Whether this mm has pinned any pages. This can > > + * be either replaced in the future by @pinned_vm when it > > + * becomes stable, or grow into a counter on its own. We're > > + * aggresive on this bit now - even if the pinned pages were > > + * unpinned later on, we'll still keep this bit set for the > > + * lifecycle of this mm just for simplicity. > > + */ > > + int has_pinned; > > I think this would be elegant as an atomic_t, and using atomic_set() and > atomic_read(), which seem even more self-documenting that what you have here. > > But it's admittedly a cosmetic point, combined with my perennial fear that > I'm missing something when I look at a READ_ONCE()/WRITE_ONCE() pair. :) Yeah but I hope I'm using it right.. :) I used READ_ONCE/WRITE_ONCE explicitly because I think they're cheaper than atomic operations, (which will, iiuc, lock the bus). > > It's completely OK to just ignore this comment, but I didn't want to completely > miss the opportunity to make it a tiny bit cleaner to the reader. This can always become an atomic in the future, or am I wrong? Actually if we're going to the counter way I feel like it's a must. Thanks, -- Peter Xu