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=-5.0 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 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 2E789CA9EBD for ; Fri, 25 Oct 2019 16:40:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CE8C3222CE for ; Fri, 25 Oct 2019 16:40:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="dBV0e+5i" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CE8C3222CE 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 388B76B0007; Fri, 25 Oct 2019 12:40:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 339036B0008; Fri, 25 Oct 2019 12:40:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 228116B000A; Fri, 25 Oct 2019 12:40:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0183.hostedemail.com [216.40.44.183]) by kanga.kvack.org (Postfix) with ESMTP id 019116B0007 for ; Fri, 25 Oct 2019 12:39:59 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 672C65DE2 for ; Fri, 25 Oct 2019 16:39:59 +0000 (UTC) X-FDA: 76082868918.15.aunt08_571ec5580901d X-HE-Tag: aunt08_571ec5580901d X-Filterd-Recvd-Size: 6373 Received: from mail-lf1-f67.google.com (mail-lf1-f67.google.com [209.85.167.67]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Fri, 25 Oct 2019 16:39:58 +0000 (UTC) Received: by mail-lf1-f67.google.com with SMTP id 195so2273432lfj.6 for ; Fri, 25 Oct 2019 09:39:58 -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:content-transfer-encoding:in-reply-to :user-agent; bh=jV9Dch1raHLsR25+85GoE5QfCe+OjbyMqmvOYwAWD34=; b=dBV0e+5igWnSIMH1I6cQAvvrajXF+IEkWbQyiwSisCvIeS7meFZ8+VlqXSz4lJjZTa /WjfBsFQoxbdX6t9CttZ0+GZZ59fszJtb9U50q8CLZDNgEHv7naw8Tz/GNqbVtRrkkt6 q8k4ZNWzh/Ri9QdNRp1aQcsWpKpcr+HAKl44epACJqNVMe9pYnXZ1licMv0rhotHOt1n SNz2FgOGVppp9Ac6Nn3tqLvJl1aQdPOjS3yUI46efVhb8p6yg0LwX9EMDHGdj/rVBBG2 YqMiort3N0Qnl/mzBaHWnJvK/ZN79Yvv9lFKA5fitUOAXasdEOZ3WZ1ixdvTsyv3KQBQ UbXA== 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:content-transfer-encoding :in-reply-to:user-agent; bh=jV9Dch1raHLsR25+85GoE5QfCe+OjbyMqmvOYwAWD34=; b=T1G7TqdWx/gQkRE6Kq9tlX9jP4rS3swG3ik+c/H/2zRAopOlGWEYfJIobgLxXtscDU +olZQ4RRV+dI+YgH++/9DTJYDj4+zHOphqhJLWbUPk9811ngc7RXm6Ql0i6oKExTVXzh WKEyxcxKHJCq8fjlij88MzPoQfsuvVSbWejZVK1Yn3E9+NRV86Avck8HHSWux1zeQ+YI XQKtCu2QUghopGMHAzmELw7utQYB3DE++Lmz4YFQ/GZjDGcvshxSCO/siKpKk8229itq vtdIdgve3k4h8sTus3OEZOxBUqvJjyMRbbwBLMlKqGwo8M/EDuPLpWv2PboMs3Q6nhcL URSQ== X-Gm-Message-State: APjAAAVO1diNblu2QZWXpm6wO6V7RoyA0hLjgg5Y+jh/5FNt5+oUpo+5 //4HBYO9wT+nxoAB814p1yMzNw== X-Google-Smtp-Source: APXvYqzhZ1oyOrj7QMbQz64HdHoSo1XvXp9txpsMpF1u8EkNVKOrigodpgTZKdocwM7HRO0vj/nqPA== X-Received: by 2002:a19:c219:: with SMTP id l25mr167994lfc.174.1572021596893; Fri, 25 Oct 2019 09:39:56 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id i17sm1064349ljd.2.2019.10.25.09.39.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2019 09:39:56 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id F172210267F; Fri, 25 Oct 2019 19:39:55 +0300 (+03) Date: Fri, 25 Oct 2019 19:39:55 +0300 From: "Kirill A. Shutemov" To: Yang Shi Cc: hughd@google.com, kirill.shutemov@linux.intel.com, aarcange@redhat.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: thp: clear PageDoubleMap flag when the last PMD map gone Message-ID: <20191025163955.qsvkqic2hrorvdzj@box> References: <1571938066-29031-1-git-send-email-yang.shi@linux.alibaba.com> <20191025153618.ajcecye3bjm5abax@box> <74becfc0-3c34-bdd2-02cd-25b763c92f3b@linux.alibaba.com> <20191025163233.myl7kcgz25qsbnwm@box> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <20191025163233.myl7kcgz25qsbnwm@box> User-Agent: NeoMutt/20180716 Content-Transfer-Encoding: quoted-printable 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 Fri, Oct 25, 2019 at 07:32:33PM +0300, Kirill A. Shutemov wrote: > On Fri, Oct 25, 2019 at 08:58:22AM -0700, Yang Shi wrote: > >=20 > >=20 > > On 10/25/19 8:36 AM, Kirill A. Shutemov wrote: > > > On Fri, Oct 25, 2019 at 01:27:46AM +0800, Yang Shi wrote: > > > > File THP sets PageDoubleMap flag when the first it gets PTE mappe= d, but > > > > the flag is never cleared until the THP is freed. This result in > > > > unbalanced state although it is not a big deal. > > > >=20 > > > > Clear the flag when the last compound_mapcount is gone. It shoul= d be > > > > cleared when all the PTE maps are gone (become PMD mapped only) a= s well, > > > > but this needs check all subpage's _mapcount every time any subpa= ge's > > > > rmap is removed, the overhead may be not worth. The anonymous TH= P also > > > > just clears PageDoubleMap flag when the last PMD map is gone. > > > NAK, sorry. > > >=20 > > > The key difference with anon THP that file THP can be mapped again = with > > > PMD after all PMD (or all) mappings are gone. > > >=20 > > > Your patch breaks the case when you map the page with PMD again whi= le the > > > page is still mapped with PTEs. Who would set PageDoubleMap() in th= is > > > case? > >=20 > > Aha, yes, you are right. I missed that point. However, I'm wondering = we > > might move this up a little bit like this: > >=20 > > diff --git a/mm/rmap.c b/mm/rmap.c > > index d17cbf3..ac046fd 100644 > > --- a/mm/rmap.c > > +++ b/mm/rmap.c > > @@ -1230,15 +1230,17 @@ static void page_remove_file_rmap(struct page= *page, > > bool compound) > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= if (atomic_add_negative(-1, &page[i]._mapcount)) > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 nr++; > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 } > > + > > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 /* No PTE map anymore */ > > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (nr =3D=3D HPAGE_PMD_N= R) > > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 C= learPageDoubleMap(compound_head(page)); > > + > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (!atomic_add_negativ= e(-1, compound_mapcount_ptr(page))) > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= goto out; > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (PageSwapBacked(page= )) > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= __dec_node_page_state(page, NR_SHMEM_PMDMAPPED); > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 else > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= __dec_node_page_state(page, NR_FILE_PMDMAPPED); > > - > > -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 /* The last PMD map is go= ne */ > > -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ClearPageDoubleMap(compou= nd_head(page)); > > =A0=A0=A0=A0=A0=A0=A0 } else { > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (!atomic_add_negativ= e(-1, &page->_mapcount)) > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= goto out; > >=20 > >=20 > > This should guarantee no PTE map anymore, it should be safe to clear = the > > flag. >=20 > At first glance looks safe, but let me think more about it. I didn't > expect it be that easy :P How do you protect from races? What prevents other thread/process to map the page as PTE after you've calculated 'nr'? I don't remember the code that well, but I believe we don't require PageLock for all cases... Or do we? --=20 Kirill A. Shutemov