Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5585556rwb; Tue, 22 Nov 2022 01:59:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf54LsQy9hiGVz3k+RdrjOGxMXk9qxNf0M+wcBlD/IiOtPiZRVIiK+KcjecMxBL/34HkDMBF X-Received: by 2002:a17:906:ecfa:b0:78d:9723:d9c3 with SMTP id qt26-20020a170906ecfa00b0078d9723d9c3mr18938732ejb.316.1669111177756; Tue, 22 Nov 2022 01:59:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669111177; cv=none; d=google.com; s=arc-20160816; b=obe268f2QMQzgfgki5KvNYMl3uWTjTxQbO6BPNPISgkKL5GCfQm1+tMXmrc32ukfI1 F1N7mQDwGcuL59OftxZJZ2kawFrnjjKgBTNF5JB6x3AJd9HPf6xmKwMm9zPQhh1O+JZh vy9Lgdrm5qdDxvD/Dvku9lgYsyElo31pnYXKoszZ4LcU6plSCYu5DJXekl2iba//8MSG TB5QtCxbR7SjgfVO/b1aErBWgv8e5Eu7CGvNywZxm3IZaogJ6LKvA6CdL9/HrTxE2QGl KBT0R8FZVCMt9ZvtZ25cVIn89E7nVE9uPdmLbHKV6tbIVPIeVVAO6uAHcyhh5nAu7ppk CM2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=m0GDJhfeb/mlDuXgY9TptD7saYe6PZinj6F8K2HKaeU=; b=FbPkM6vVsVpHmjbTgDund0Cd2IQqdycgwHOHZReS+1wtGepwX7u0CXGnOYAQYZFs7T PC+sJdhYm++yfKBkZC1I9fbXJlClxaIyN8n94UB/ztQSdm9gTc6+7m58eTUpW44/rBnU mv8YtyFcsZEC3rSvzX50SQW+unbASkMXC5ylKwfinkkp7kSjobPLh4FkwKyI3iWZ5MRj SS5Pxtit+lUcGYSPL02VBBVIjMNwSEEupT5tyrJ4KbfcDfWezxRzV/7/h0utox2VeJXW 7qy7tehFkIhQ6xSiomplCxNFL0afC6KQg1CU35TNhbLCGDhU+fXz6huvDqhyXQ/ihMuE inTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Yh5afxIF; 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 d7-20020a056402400700b004676b9092e0si11385781eda.408.2022.11.22.01.59.15; Tue, 22 Nov 2022 01:59:37 -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=Yh5afxIF; 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 S232783AbiKVJdf (ORCPT + 91 others); Tue, 22 Nov 2022 04:33:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232402AbiKVJdd (ORCPT ); Tue, 22 Nov 2022 04:33:33 -0500 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5404C644C for ; Tue, 22 Nov 2022 01:33:32 -0800 (PST) Received: by mail-qt1-x829.google.com with SMTP id c15so8901670qtw.8 for ; Tue, 22 Nov 2022 01:33:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=m0GDJhfeb/mlDuXgY9TptD7saYe6PZinj6F8K2HKaeU=; b=Yh5afxIF4nlJ5tGvdSmhfMKs2zILGlBSVIL6Dq8svTLaZHbiVmfrTeSTd8e+VFVvst 3erxOjcuLZe1zhu4vW5V2FMYdoqnAyzGkmSS116EBggRl4QM2sJmFknFJXbXyQe/QgUI jartFLar8+ghwZmgy2UPOsDpCVGvHLnrwgpr8lTj2kDN/LztPZP9s4j5rs6eA62W3XCS XomsQLw4VX5GCBbdWgFTc2M88EcFeyEBemXHdHoGfHWJmV3whtY014IHkiRYExZSASq6 RSCpprBqiuPj8HU71hKDjHKiFHtYJZuydkXMf1qj4o//thj4EMkxAiA4/tBWhPv01ekX Unuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=m0GDJhfeb/mlDuXgY9TptD7saYe6PZinj6F8K2HKaeU=; b=mgW0ApnpZiz+MUR+IUAoTKJYvkDaNwlzqrt1VYcAHB35ABbvgPFX2s0sA8Rq76dYAd 7vhPw+gHatJX7ZI8SRdvtxxSeITbsx+2vm77xK/+A0g3ELYwJApSgec4igvvOGoKaCYl XHBiNZ02V/AbtGvIjMslvTW2zFG4LdBelajiSyfgFFFzxm64HOhDpKDC2+JLD7o/FK1s YCYSfdnuUJXnkl9WF3iy4pWXxEjoomSvbQ3m5TcJXEdUsDAedIM+GEU/2Jq0ic578w8m yyMHeTKyStTc2EympKMyLOFlNFQCFQhuDHEuHLiywafsQ+7Dvsyv6avzVgcvHqDeBmQq LE0g== X-Gm-Message-State: ANoB5plEJtepIf/Kk4vnmRYVQlpgBJlX4oFSEXcdbm+Ukyv87rQNvHZW OZQAKZb0TftpqbWt4qshCmT4xkIBoFtM5A== X-Received: by 2002:a05:622a:4d94:b0:3a5:fb6c:d96a with SMTP id ff20-20020a05622a4d9400b003a5fb6cd96amr21306888qtb.185.1669109611343; Tue, 22 Nov 2022 01:33:31 -0800 (PST) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id t20-20020a05620a451400b006ceb933a9fesm10089200qkp.81.2022.11.22.01.33.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 01:33:30 -0800 (PST) Date: Tue, 22 Nov 2022 01:33:27 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: "Kirill A. Shutemov" cc: Hugh Dickins , Andrew Morton , Linus Torvalds , Johannes Weiner , 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 Subject: Re: [PATCH 2/3] mm,thp,rmap: subpages_mapcount COMPOUND_MAPPED if PMD-mapped In-Reply-To: <20221121130900.xb224cesbzfptldo@box.shutemov.name> Message-ID: References: <5f52de70-975-e94f-f141-543765736181@google.com> <25a09a7a-81a9-e9c2-7567-c94ce18ac2@google.com> <20221121130900.xb224cesbzfptldo@box.shutemov.name> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII 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 Mon, 21 Nov 2022, Kirill A. Shutemov wrote: > On Fri, Nov 18, 2022 at 01:14:17AM -0800, Hugh Dickins wrote: > > Can the lock_compound_mapcount() bit_spin_lock apparatus be removed now? > > Yes. Not by atomic64_t or cmpxchg games, those get difficult on 32-bit; > > but if we slightly abuse subpages_mapcount by additionally demanding that > > one bit be set there when the compound page is PMD-mapped, then a cascade > > of two atomic ops is able to maintain the stats without bit_spin_lock. > > Yay! New home for PageDoubleMap()! :P :) You only asked for one bit for PageDoubleMap, I've been greedier; so it's not surprising if it has worked out better now. ... > Jokes aside, looks neat. > > Acked-by: Kirill A. Shutemov Thanks; but I'm very glad that Linus expressed his dissatisfaction with the first implementation, this one does feel much better. > > As always few minor nits below. ... > > @@ -893,8 +902,12 @@ static inline int total_mapcount(struct page *page) > > > > static inline bool folio_large_is_mapped(struct folio *folio) > > { > > - return atomic_read(folio_mapcount_ptr(folio)) + > > - atomic_read(folio_subpages_mapcount_ptr(folio)) >= 0; > > + /* > > + * Reading folio_mapcount_ptr() below could be omitted if hugetlb > > + * participated in incrementing subpages_mapcount when compound mapped. > > + */ > > + return atomic_read(folio_mapcount_ptr(folio)) >= 0 || > > + atomic_read(folio_subpages_mapcount_ptr(folio)) > 0; > > Maybe check folio_subpages_mapcount_ptr() first? It would avoid > folio_mapcount_ptr() read for everything, but hugetlb. Okay: I'm not convinced, but don't mind switching those around: done. > > --- a/mm/debug.c > > +++ b/mm/debug.c > > @@ -97,7 +97,7 @@ static void __dump_page(struct page *page) > > pr_warn("head:%p order:%u compound_mapcount:%d subpages_mapcount:%d compound_pincount:%d\n", > > head, compound_order(head), > > head_compound_mapcount(head), > > - head_subpages_mapcount(head), > > + head_subpages_mapcount(head) & SUBPAGES_MAPPED, > > Looks like applying the SUBPAGES_MAPPED mask belong to the > head_subpages_mapcount() helper, not to the caller. Yes, that would be more consistent, helper function doing the massage. Done. __dump_page() then remains unchanged, but free_tail_pages_check() uses subpages_mapcount_ptr(head_page) to check the whole field is zero. v2 coming up - thanks. Hugh