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=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 7B464C43457 for ; Thu, 15 Oct 2020 09:43:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BC3942224A for ; Thu, 15 Oct 2020 09:43:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="M0zz6chP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC3942224A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 04A0794000F; Thu, 15 Oct 2020 05:43:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0212494000C; Thu, 15 Oct 2020 05:43:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E798A94000F; Thu, 15 Oct 2020 05:43:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0133.hostedemail.com [216.40.44.133]) by kanga.kvack.org (Postfix) with ESMTP id BC10194000C for ; Thu, 15 Oct 2020 05:43:41 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 587C8181AC9BF for ; Thu, 15 Oct 2020 09:43:41 +0000 (UTC) X-FDA: 77373672642.07.rings95_3217e9927213 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id 3816A1803F9A3 for ; Thu, 15 Oct 2020 09:43:41 +0000 (UTC) X-HE-Tag: rings95_3217e9927213 X-Filterd-Recvd-Size: 4812 Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Thu, 15 Oct 2020 09:43:40 +0000 (UTC) Received: by mail-lj1-f193.google.com with SMTP id x16so2490955ljh.2 for ; Thu, 15 Oct 2020 02:43:40 -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; bh=y5gLMYh6tiv5jrOp8DDHnBYYv5xjV9PK4XVv2LHi9HE=; b=M0zz6chPROoVSVOCZC0aLZ1gj+BhaQ6Ov/AvatoQ8JrkYfLr7MRn3CRZr7L7jCjGDa D9O2uYXHGdoUZ7kuPGnWxvcjpopWkDVwdzvdyYgsKIWZ9IZf7uc9Yk9sHq++vsnqYxg1 ZBOdKMBU1QWUS3C3TR4JihECrrELTBnV6+410JYbWQcc4d6S1mL91OZHJObaTYvNAEPz c9fRxv+/tGJB92OH8BYZsbxTRJ+SECrPMAFyPASNxYE5ZPHPjBQ3/Ir+jCgyjta62fWn g5cVAoIaQBBVN1pO+i8D6B7U7VPMF6Rv3lzl1cu89UUG9aok3BCL4vBDR3fpyD3Sd/aJ vVmg== 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=y5gLMYh6tiv5jrOp8DDHnBYYv5xjV9PK4XVv2LHi9HE=; b=Psi8fZ6wgy2dpEQHXjLZdh/60TfjBQ2btOmSVReansdkIEbslWEBo0138NPac+/ICC qvpGZu69qZ7s0rTqSGqEMESgRFAf05JJ3E6b8yMRuKAxZsjH8yjbKEj4UCHy0nsnbMJx +Uq5z29lYFEsWBN8j/aRhooWLHkj5qcmgh6sTdAPu765fQDWsHsQEQiSItMnUrvGQo8T gk4XluISVaLYMn+XEYI8Hh/nJ3aj/uAaFuxnVpjDJ1n/XfY+J4oSSUxkqQDfQUA3kRca HHpRS6R6/LCnVqTrP/w7NT6s4y6fUsmDrPn4jNc+hadOPLOrahQIWbTL9SgnAP3TpTWH 31WA== X-Gm-Message-State: AOAM533c9wvqsPh5wDecDReyV7l0IRbGXR8P8WnxtPvfM98ssZl19gjf EhA0uZ7DxDwNAljthiLgMNYyzw== X-Google-Smtp-Source: ABdhPJz4F33dFkInG4mtppG2zYRso/KoI52LxAW4cL/ghmUDvzUcQIRmZrmsVFfkmGSsPJnj+N0chw== X-Received: by 2002:a2e:9148:: with SMTP id q8mr990058ljg.182.1602755019168; Thu, 15 Oct 2020 02:43:39 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id p14sm857738lfc.40.2020.10.15.02.43.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Oct 2020 02:43:38 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id 12A851023C1; Thu, 15 Oct 2020 12:43:44 +0300 (+03) Date: Thu, 15 Oct 2020 12:43:44 +0300 From: "Kirill A. Shutemov" To: Linus Torvalds Cc: Hugh Dickins , Matthew Wilcox , Linux-MM , Andrew Morton , linux-fsdevel , Amir Goldstein Subject: Re: [PATCH 0/4] Some more lock_page work.. Message-ID: <20201015094344.pmvg2jxrb2bsoanr@box> References: <20201014130555.kdbxyavqoyfnpos3@box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Wed, Oct 14, 2020 at 09:53:35AM -0700, Linus Torvalds wrote: > In particular, what I _think_ we could do is: > > - lock the page tables > > - check that the page isn't locked > > - increment the page mapcount (atomic and ordered) > > - check that the page still isn't locked > > - insert pte > > without taking the page lock. And the reason that's safe is that *if* > we're racing with something that is about the remove the page mapping, > then *that* code will > > (a) hold the page lock > > (b) before it removes the mapping, it has to remove it from any > existing mappings, which involves checking the mapcount and going off > and getting the page table locks to remove any ptes. > > but my patch did *not* do that, because you have to re-organize things a bit. Okay, I see what you propose. But I don't think it addresses race with try_to_unmap(): CPU0 CPU1 filemap_map_pages() take ptl PageLocked() == false lock_page() try_to_unmap() rwc->done() page_mapcount_is_zero() == true rwc->done() == true, skip full rmap walk never take ptl taken by CPU0 try_to_unmap() == true ... unlock_page() increment mapcount PageLocked() == false insert PTE Are we willing to give up rwc->done() optimization? Or do I miss some other serialization point? -- Kirill A. Shutemov