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=-11.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham 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 11A91C4363D for ; Tue, 22 Sep 2020 15:17:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8695623A1E for ; Tue, 22 Sep 2020 15:17:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="O+14cyJA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8695623A1E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 250A390006A; Tue, 22 Sep 2020 11:17:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 227FF90000F; Tue, 22 Sep 2020 11:17:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 116D590006A; Tue, 22 Sep 2020 11:17:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0066.hostedemail.com [216.40.44.66]) by kanga.kvack.org (Postfix) with ESMTP id ED75990000F for ; Tue, 22 Sep 2020 11:17:43 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B5E8D181AC9C6 for ; Tue, 22 Sep 2020 15:17:43 +0000 (UTC) X-FDA: 77291052006.13.sack93_450d2e32714e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id DFCDA18140B75 for ; Tue, 22 Sep 2020 15:17:42 +0000 (UTC) X-HE-Tag: sack93_450d2e32714e X-Filterd-Recvd-Size: 7805 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Sep 2020 15:17:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600787861; 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=O+14cyJAIueN9bhvmKe1FmqirjDm7UhgSAydvwctXwhC3iPWAaSERFzFiLZaIRTGaFcUcp zgEgWwhnk8AzI9dRNaiSu6aknDR7c9Zu0Dkx1OorJ0045jF6A16x/5uVvdkBJZQgT5to22 Fgc2+qhdqAt/40e8NzaeGKmQG19ZDvI= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-2-4hM1KZRYMWaZpQ-VpKyshw-1; Tue, 22 Sep 2020 11:17:40 -0400 X-MC-Unique: 4hM1KZRYMWaZpQ-VpKyshw-1 Received: by mail-qv1-f71.google.com with SMTP id a20so11568563qvk.17 for ; Tue, 22 Sep 2020 08:17:40 -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=Mj/M41n6hIxwqoAHw7pbe8XmEROgUpaQap3VGQG4QGuanfCYzAzp0Cv3ry5/F1PUYL c5HaCF5cNmSohu4ZaOVDW9jM3N2SHsFkkyD7u0pbWbsUQ6Dzm9LRtgq6q7ZvdLltdUsa QYVsWv+IScnOG/tonunqn+v0ZMrlQw+Do/96eiHnyjORoholeQ1eqzRG9LDdNOYECxaV vJUOhrrGHH2xRrg4UUrRzIt1JTJnlZNsCaoGpH3HV+ksjIkave2JXKiKW45B7znFYFa+ h6XewG/N39FP5Ee/yujNTliomnAqXCHtCy74ogpgbUZLxhuxwex9wlOMBKSv7z1GqrZU eYQg== X-Gm-Message-State: AOAM530S3HX/B8+jHK74M+nb95UvgOKjz71pTbwO5CBBq9cC5npBEx3N QPCBVHnhY6yEbb919fZZ4nAg5N/vz8UPaNHQvjnvoLSmrM2WvlpYEeZXNjpcUxmPiF/0vhcAyLM F2IrIjN3u2Aw= X-Received: by 2002:a37:8484:: with SMTP id g126mr4829952qkd.119.1600787859241; Tue, 22 Sep 2020 08:17:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNj2fsPXKI9avxY2ntwJeZST+nN/BfCLVpgNX+5WSlsWAV7mZfn+bK9EKVHF1t74PJCuFT0Q== 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 In-Reply-To: <224908c1-5d0f-8e01-baa9-94ec2374971f@nvidia.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline 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 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