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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B4FBC433FE for ; Sat, 19 Nov 2022 00:13:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17EDF6B007D; Fri, 18 Nov 2022 19:13:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1083B8E0001; Fri, 18 Nov 2022 19:13:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC40C6B0080; Fri, 18 Nov 2022 19:13:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DA1A06B007D for ; Fri, 18 Nov 2022 19:13:31 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id AE77D160924 for ; Sat, 19 Nov 2022 00:13:31 +0000 (UTC) X-FDA: 80148267822.19.411421E Received: from mail-vs1-f49.google.com (mail-vs1-f49.google.com [209.85.217.49]) by imf09.hostedemail.com (Postfix) with ESMTP id 59E5A140009 for ; Sat, 19 Nov 2022 00:13:31 +0000 (UTC) Received: by mail-vs1-f49.google.com with SMTP id 128so6253450vsz.12 for ; Fri, 18 Nov 2022 16:13:31 -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=UEgq8Qv2cTHaYtHk7/XX6dIK5bTNKyMxnbN+XNgJwDAjHxF1U1ZZ2L9hzYLFgWHi94 KDWBjp4PiP8pd+Ym0OE77+jhuaRpKpWeAaIRslmAZ5jyXlKbAlhGWH44d4H2ZBIynXy9 LAocfcX14QC7XuTAIV12uLsl+AQI1qSXr8SJ1MY5ze5uTy76OrKb11ivWzK6pEvV4C8M RYHkXDTQQtvFSoczVT5uf8+ATrA4vBAtt46VFYavNXLC5qL3Cx/lnUnozY/gBUjsXLuI 9kIVt2xnik2ms/YWhy2cxh5CHlyLCgNr5GIzR19udwqqxWCPdC1ofTNpXKZALgNPe95r moyQ== X-Gm-Message-State: ANoB5pllVTcTa4qbT6c8oRcRriumF30irupX5ITdR/cdpzbm6rSmuvsx n1/dsvvPrgLXqOKlR1CocCRNnLMcsFZBhnW1cDIVaA== X-Google-Smtp-Source: AA0mqf4ucx80ljcZJYuBW4hshwBqDPXbTimQMrLOxY/XuGAYAN+112jE9PPXrLCq6Sf4jJgrDiNgMTRfRiZHNPTCNKw= 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" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668816811; a=rsa-sha256; cv=none; b=rP3K9HdBBmAESISALUy4cdmyvLtb+h366IR4IME552M8m6aTA1If4716nuPIiAo2UGkbyu mWBF+t3vbFcX7sc6FJixnCSLf/3Ph223eqA/660YU9JyDlDHxXbYV6h8sI5PODTc4/Hu/x EKci0hgF7W333VrhCK40ANIgxKdz6RI= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="cenM/AUe"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of yuzhao@google.com designates 209.85.217.49 as permitted sender) smtp.mailfrom=yuzhao@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668816811; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=JdmpmzFhPorrlLui7TzB6H1/XRLaC1WwAIIUyyVa8yA=; b=Z88CkjeB3qnctplI6CfWGa7PIplF0MoCPgv7B7ovniJ1su3B3BXYUL4PRuSfCAeEGqsVzW La/O2svhFRMsJ4dJ/GTqlEAtrSFRBDkgUVs3rEDYx4TTX8Q2e2rF3u5FJ7fmH8nU7AQDBA krUE/jmcsXje5abm62iOyU3L3cLlOpk= X-Stat-Signature: 4smp86rxbff1gwjeru6qbt5q1b1ymqau X-Rspamd-Queue-Id: 59E5A140009 X-Rspam-User: Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="cenM/AUe"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of yuzhao@google.com designates 209.85.217.49 as permitted sender) smtp.mailfrom=yuzhao@google.com X-Rspamd-Server: rspam09 X-HE-Tag: 1668816811-266929 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, 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); ^~~~~