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 2E1A1C43457 for ; Thu, 15 Oct 2020 10:41:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 729082224A for ; Thu, 15 Oct 2020 10:41:38 +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="c/k395T4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 729082224A 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 9281C940017; Thu, 15 Oct 2020 06:41:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D6F094000C; Thu, 15 Oct 2020 06:41:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7ECE8940017; Thu, 15 Oct 2020 06:41:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0165.hostedemail.com [216.40.44.165]) by kanga.kvack.org (Postfix) with ESMTP id 527CA94000C for ; Thu, 15 Oct 2020 06:41:37 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C150A8249980 for ; Thu, 15 Oct 2020 10:41:36 +0000 (UTC) X-FDA: 77373818592.12.smash34_090eef727213 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 871A81814CBF6 for ; Thu, 15 Oct 2020 10:41:36 +0000 (UTC) X-HE-Tag: smash34_090eef727213 X-Filterd-Recvd-Size: 5259 Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Thu, 15 Oct 2020 10:41:35 +0000 (UTC) Received: by mail-lj1-f193.google.com with SMTP id m20so2634794ljj.5 for ; Thu, 15 Oct 2020 03:41:35 -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=oTyqt8lOISm2/Q6Ius7a9+u5P1zHGu4C4oeKYhyirko=; b=c/k395T4C7fxLgITZtwwUbXRSIjkHzaQJRP8TMgAR6Jj6qMtNxe+F97Tva02YJUxvv JJoMXODkyqZ9ebU3RARGNIrHtxoUMems2m6bKdnCiHSJC+XEIJH4Y3mqccgV+jLH76ix k8i66t6C/vEZxyOfWWNnEfhbqcYg193NvBwU7vSmxCtlgsErdIA/caX5vp4c9WfDZdrm nnTQzw099M7PgyA6ZFbHiKfECUrBFS6iINzId/DgGgBIQqxpNxHvI+eizTalEZxBOFU3 Fj4j8SivDRHeMtZpwVf9fS2ChjLzBFt/NNQnEoZdNl4EDKGUay4sVAMGfTRbP3fHOWQs cHBQ== 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=oTyqt8lOISm2/Q6Ius7a9+u5P1zHGu4C4oeKYhyirko=; b=k7DIqUatA4/3qgoiN/EItDacwWxLbFZ2tWWuh4jRS3NOkeUAf+FruscV9l4txo+p+b Vrs9TiZuy7S+U9Btyue5oP1WoxBBGb/qXgpyMg8ttZ/q7yd3xE9LZ71WpTjJgq6pY0rT gDj9eQYm7l1C56tBx3Q+ZLUriwQbhOAbLQvsPaQn+CscHk8WG0X0PKT5LzctUwK08UMs nQHXN65wZG/l6qfRSPKLOBu0TR1/c95+bftJsVRK1WkaYmPeeF2gTr0Yfg9ZXBMlouuA 6+nu4xsH77oL6d5i6clZJkWXj3TlnmSY14pG+rett7NlSzyvkkskq6IBDN4QaQYWU+9V bTQw== X-Gm-Message-State: AOAM531fZG212zk1cf13aEJ+ge1BAKGoknXVegBRwAafFV2D+JATAAIc segwZtABFILqJGIy4xLAFhviIg== X-Google-Smtp-Source: ABdhPJzkDT7ggGHj39T9CC/2vjzS+9Qpwj2Yfr28KG/1oncAExd7A3xrsgWyO4OCEjvA+YcGJVD5yA== X-Received: by 2002:a2e:8596:: with SMTP id b22mr941489lji.455.1602758494282; Thu, 15 Oct 2020 03:41:34 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id r15sm896215lfn.65.2020.10.15.03.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Oct 2020 03:41:33 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id A8B5F1023C1; Thu, 15 Oct 2020 13:41:39 +0300 (+03) Date: Thu, 15 Oct 2020 13:41:39 +0300 From: "Kirill A. Shutemov" To: Matthew Wilcox Cc: Linus Torvalds , Hugh Dickins , Linux-MM , Andrew Morton , linux-fsdevel , Amir Goldstein Subject: Re: [PATCH 0/4] Some more lock_page work.. Message-ID: <20201015104139.ryllzhzdxevrjrbg@box> References: <20201014130555.kdbxyavqoyfnpos3@box> <20201014181509.GU20115@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201014181509.GU20115@casper.infradead.org> 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 07:15:09PM +0100, Matthew Wilcox wrote: > 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* > [...] > > And they aren't necessarily a _lot_ more involved. In fact, I think we > > may already hold the page table lock due to doing that > > "pte_alloc_one_map()" thing over all of filemap_map_pages(). So I > > think the only _real_ problem is that I think we increment the > > page_mapcount() too late in alloc_set_pte(). > > I'm not entirely sure why we require the page lock to be held in > page_add_file_rmap(): > > } else { > if (PageTransCompound(page) && page_mapping(page)) { > VM_WARN_ON_ONCE(!PageLocked(page)); > > SetPageDoubleMap(compound_head(page)); > if (PageMlocked(page)) > clear_page_mlock(compound_head(page)); > } > > We have a reference to the page, so compound_head() isn't going > to change. SetPageDoubleMap() is atomic. PageMlocked() is atomic. > clear_page_mlock() does TestClearPageMlocked() as its first thing, > so that's atomic too. What am I missing? (Kirill added it, so I > assume he remembers ;-) In general (with current scheme), we need page lock here to serialize against try_to_unmap() and other rmap walkers. For file THP, we also serialize against follow_trans_huge_pmd(FOLL_MLOCK). -- Kirill A. Shutemov