Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1352409rwb; Fri, 18 Nov 2022 17:19:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf6r5hDn3hSaW9ACHOdjlPO7XWTHDl0ECq9I6CBjNJbLP1TzqPEkY7non5oa79E8yjLdNkp4 X-Received: by 2002:a17:907:78d8:b0:78d:b712:fe99 with SMTP id kv24-20020a17090778d800b0078db712fe99mr8078986ejc.462.1668820776817; Fri, 18 Nov 2022 17:19:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668820776; cv=none; d=google.com; s=arc-20160816; b=id4HwLj8sjeRAOH3jTZwV2IOCWBddQfG4O48JCRSC+M3AKtuff+PIT2lHz9qv7JNzs sEalcFT5rFxqUCTStvjj+bxxCy2qGWNzxWeJFF2dF4QwmZ9s3gmioo/2bogYpoAzqrNw O7WnySsfjTRJXpuh/kb58GRXIamMjLhKupRyYe1tMC0FttdFlppUJj7YnTprptoP5k0F U9dvOsBMcxofYKzScTrte7p25tvb4LSSp/ix6Q3hERvv0nmA/EEQYImvUQr4hoFYzY9w gdr2CuFTpfQGieX0rYeEV7OGa/+BTvQpDgymxSqzxjnxvGXBsQXGRk6In8eu8VYnV/TS Gdww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=JdmpmzFhPorrlLui7TzB6H1/XRLaC1WwAIIUyyVa8yA=; b=pBGHkNlapc16OGSBILFrq3FTaujGFCxD5bB81JjnqkR+zqQLnIICw/Y/vrESQvyqEI lx0bBM4sFwat1SSfbQYx3LoBi0Aixj5HAKeaTnBev2iuxad3NTu9Pb/6VEJR30ZI/hRL XACfIzOPYKyeu8Q/KtYX/sN3hwkXMZNr89pKcxaZ26FvmX7bXzScO36VrmITDfpo5NsA Lu449e/iwO2bWwhvC4gGC9sTvEBYooqmdpjXwPipbZb+MYReEeY2lLBpN9ps5shH3yMx rMQkEDDdQA4MYUXPZ1MSn+AYzh8vYFNPpChygFKVPNhNIJr1ccWyCvGTE4mVwFm/T4yc bnBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="cenM/AUe"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs30-20020a1709072d1e00b00780def41dc4si4556116ejc.527.2022.11.18.17.19.14; Fri, 18 Nov 2022 17:19:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="cenM/AUe"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231740AbiKSBQb (ORCPT + 92 others); Fri, 18 Nov 2022 20:16:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229862AbiKSBQL (ORCPT ); Fri, 18 Nov 2022 20:16:11 -0500 Received: from mail-vs1-xe36.google.com (mail-vs1-xe36.google.com [IPv6:2607:f8b0:4864:20::e36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8898620BE6 for ; Fri, 18 Nov 2022 16:13:39 -0800 (PST) Received: by mail-vs1-xe36.google.com with SMTP id p4so6265348vsa.11 for ; Fri, 18 Nov 2022 16:13:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=JdmpmzFhPorrlLui7TzB6H1/XRLaC1WwAIIUyyVa8yA=; b=cenM/AUehb33kVe/wriotJSNfoT0pUpiqq5JYeBo/QoKxqRT9/7jfQy4dU+5d0rhao GRpOjb7oudyp5YxrmNODpPLJv0GW7Y/50vGRlMp65Lwr/4tK6h9HY/mQXeiYz04T8w6w 6LEIh/TvtYykowDbbraSxPq81pSP9oxMcMgqaVGNmrGEvlMtWaLT+V/nFto5hLkp14N+ YBxr5HK6VwFM/E1Fb2KGoWBD0kIdEsVZfT1oRXWTHSfWapUOX2zXHcIEQZBSzZ74Cw7s w69hUA093t+SdJ/1O1lnzVbasdc0v9gniPiWkhKLTG2WgdhokXCB3HxHljaMos5Wog5P Fj0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JdmpmzFhPorrlLui7TzB6H1/XRLaC1WwAIIUyyVa8yA=; b=R54xHfqjQKVmbS+rtZNlVD8JyFr3G5Yo+Xz8FGeuxReexGiiVx1p2pMFKJUU+lLGab kkDXuKxKO9fSctoRduoYoxj7VY0B/uz8RyJJrQbnIg9ki4d/dUtNMo815/8lN3Wmk8/p 0wKSn5jPuNtsKnMU4x36Tt2V6RWOGlLsUqmLA96zIGFsVAbseC5FKtaVJdjIxXnpAV8a wfHsoYrygtzNks15U8BgDngdTIVwAyomAmzd0itV9fY3FxIGA/yf2UiGSYmQ1cLcnt3T 9gpl65N8+GECOC8fLUP+imjtq2x/kaPlsIa3PZXQQXI0/gYmKI3JBvx2bRrSyvLk44MV 5C4w== X-Gm-Message-State: ANoB5pk6JYf6veCUP6fyEE17b8OVaM77EDXSsBuWXqPis6AEmfkgzMgA H5Vbc29j4kzLXwbr8rhhKEWQn3Pxd3oKu4Rj9II9HQ== X-Received: by 2002:a67:f8d4:0:b0:3aa:1a3a:6447 with SMTP id c20-20020a67f8d4000000b003aa1a3a6447mr5755961vsp.50.1668816810456; Fri, 18 Nov 2022 16:13:30 -0800 (PST) MIME-Version: 1.0 References: <5f52de70-975-e94f-f141-543765736181@google.com> <78fa518-85b5-32c0-ee92-537fa46131f6@google.com> In-Reply-To: <78fa518-85b5-32c0-ee92-537fa46131f6@google.com> From: Yu Zhao Date: Fri, 18 Nov 2022 17:12:54 -0700 Message-ID: Subject: Re: [PATCH 1/3] mm,thp,rmap: subpages_mapcount of PTE-mapped subpages To: Hugh Dickins Cc: Andrew Morton , Linus Torvalds , Johannes Weiner , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Vlastimil Babka , Peter Xu , Yang Shi , John Hubbard , Mike Kravetz , Sidhartha Kumar , Muchun Song , Miaohe Lin , Naoya Horiguchi , Mina Almasry , James Houghton , "Zach O'Keefe" , linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 18, 2022 at 2:12 AM Hugh Dickins wrote: ... > @@ -1308,31 +1285,29 @@ void page_add_anon_rmap(struct page *page, > > if (unlikely(PageKsm(page))) > lock_page_memcg(page); > - else > - VM_BUG_ON_PAGE(!PageLocked(page), page); > > - if (likely(!PageCompound(page))) { > + if (likely(!compound /* page is mapped by PTE */)) { > first = atomic_inc_and_test(&page->_mapcount); > nr = first; > + if (first && PageCompound(page)) { > + struct page *head = compound_head(page); > + > + lock_compound_mapcounts(head, &mapcounts); > + mapcounts.subpages_mapcount++; > + nr = !mapcounts.compound_mapcount; > + unlock_compound_mapcounts(head, &mapcounts); > + } > + } else if (PageTransHuge(page)) { > + /* That test is redundant: it's for safety or to optimize out */ > > - } else if (compound && PageTransHuge(page)) { > lock_compound_mapcounts(page, &mapcounts); > first = !mapcounts.compound_mapcount; > mapcounts.compound_mapcount++; > if (first) { > - nr = nr_pmdmapped = thp_nr_pages(page); > - if (mapcounts.subpages_mapcount) > - nr = nr_subpages_unmapped(page, nr_pmdmapped); > + nr_pmdmapped = thp_nr_pages(page); > + nr = nr_pmdmapped - mapcounts.subpages_mapcount; > } > unlock_compound_mapcounts(page, &mapcounts); > - } else { > - struct page *head = compound_head(page); > - > - lock_compound_mapcounts(head, &mapcounts); > - mapcounts.subpages_mapcount++; > - first = subpage_mapcount_inc(page); > - nr = first && !mapcounts.compound_mapcount; > - unlock_compound_mapcounts(head, &mapcounts); > } > > VM_BUG_ON_PAGE(!first && (flags & RMAP_EXCLUSIVE), page); Hi Hugh, I got the following warning from the removed "else" branch. Is it legit? Thanks. mm/rmap.c:1236:13: warning: variable 'first' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] } else if (PageTransHuge(page)) { ^~~~~~~~~~~~~~~~~~~ mm/rmap.c:1248:18: note: uninitialized use occurs here VM_BUG_ON_PAGE(!first && (flags & RMAP_EXCLUSIVE), page); ^~~~~