Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1083703pxb; Thu, 23 Sep 2021 17:59:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7xx2WhhDfxJOzt0pU+lOzUWxRcGoJKxG5SltV5OG7cCTmk3ks/pKwh5KDNtzvL/tBHGWa X-Received: by 2002:a17:906:318f:: with SMTP id 15mr8421474ejy.206.1632445178742; Thu, 23 Sep 2021 17:59:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632445178; cv=none; d=google.com; s=arc-20160816; b=zPhq0CrfQKQGgiGjXvwYFTmoKbcTpULmPpa4YXhmTFOwe95rrp4RFPizRGv+sfc91c 6KOlF9REQukxaV/xOe6cbHUsSdaMFNxv6nxwQnZX/G1EHJFaJCTkP7uo6NAM7wd+3TTY GGzrhMFbdXo+wxY6CN1qec3bqDGQDPvI12Iic64PanaeV2slSX/+iFsMTNRFuy7n5dyF TTA6Oj/U6cJVIbEkC/ZkrOcR+KKsjYKl70tv+hyy5Bsp7pYoIkDQp+O3ZsyRMG1RnSkO 0dzsNoYg00wRFGgnbzQXPP95gH1hGyKHsMZLAX6vl9Zxxxg+w7nhCyxj1D2A1EVfjgvk dOsQ== 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=yOg+nzwKS/Xe9boE1XYCVEvuo4RAHMroRl1PMQiLGaE=; b=aIYEB6bYdVuUoVoLtZjXhrusr8EB2YB1tMV0ghsxa9dcq97cVs/11e48mOF2ISBban Lz1YCTXSZZCo/IbAOHhYABsfqjCPNg5gwHQwhD9SbCCfflhXJvDOyehN6vxfQpOaeERK ZrWpS7NgeCqh+ubwAILUltkkduB2bYuy773ERzh+uuJkzyAyLgxvYSrvN0i+7ciGWTdf HYhWCdHR0kollkeGGypG3R+ULtt6NwdZSRxwZ0ZvvxS9Ubm255ONMGQ7R1ov4PeQmUVA FVhstOoTpCSH/nm8zXq+d+fIIeZoqiVEC9Rh1/RAuxt7+bj0Cu1w8Fo41Ql08M/AKvFd QQvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=UdSi8cTq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y21si7457922eds.53.2021.09.23.17.59.14; Thu, 23 Sep 2021 17:59:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=UdSi8cTq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S243699AbhIXA67 (ORCPT + 99 others); Thu, 23 Sep 2021 20:58:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243693AbhIXA66 (ORCPT ); Thu, 23 Sep 2021 20:58:58 -0400 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A58DC061756 for ; Thu, 23 Sep 2021 17:57:26 -0700 (PDT) Received: by mail-qt1-x82b.google.com with SMTP id j13so8032356qtq.6 for ; Thu, 23 Sep 2021 17:57:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=yOg+nzwKS/Xe9boE1XYCVEvuo4RAHMroRl1PMQiLGaE=; b=UdSi8cTqG77oru82hEmJklps5D805r9qSr9pTi5SYcSwhasEbm9rWVspjcCQSnRf8Q oX8CtlqZO7VNdTkw/JeNVrL4ZAJDGwNEL54yb43mYHbxLf94ZzRljWHYkVJj6/LZUIw4 6ZAG6NTAVbHoPcQCdj2m5GcMHAt1TNFWi3i7J0CDS9W39XJDpK3YH7T2NXD7OvWggs8T ofMDlCmiLCJT7MWrlO0+jgNkRRgpFqZC5t5cbYoiHrx38fpoY25TgBNELp+8xoLOUpYU DzRGKPLbppIUwv3bQZGzMtW+dY4LJxp/H4wNNf7gQFX4cHFxnEH4RP/74F4affCg0oyy rEUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=yOg+nzwKS/Xe9boE1XYCVEvuo4RAHMroRl1PMQiLGaE=; b=LeMkbf1Yjk3i1MdzmNeDfazC6QmOkC+BJR5Fo0SsB3vSnrfMXdKdHzF98TInGG2nIN msm89uOUggyRm+VYd3oMynCCUWmHkbWJ7K+NWC1+G+z5i389kqBQOvpHXC25M/Fx9qTR dPj4QsbKPTxrIu5Evm1zleKiGClwCUIAG7jghifvzoipus1SshhyHzHySmW1jW9X1Q0N 24ooK+qESL7I6k8m2b76KilSsuXuw1BiFMx6ziAiLgAzsMrNpRfqMpORwLXUjmLeulyn tcFKXEai8hoFMlXKt6ZF0uyU7LnOhdEKoN4Mg459+fC0NIZ+y3sRan4wg6XrE56ja5zq KL/w== X-Gm-Message-State: AOAM532YMJUR9w1AUijZ1D7xjC54iEC0IS6pwxjbDTrAfq+/OGTBUxll qzT1456yjJfVarrH0oFKZJefSw== X-Received: by 2002:ac8:4755:: with SMTP id k21mr1730713qtp.150.1632445045392; Thu, 23 Sep 2021 17:57:25 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id g22sm5530005qkk.87.2021.09.23.17.57.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Sep 2021 17:57:24 -0700 (PDT) Date: Thu, 23 Sep 2021 17:57:11 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Zi Yan cc: Hugh Dickins , Yang Shi , "Kirill A. Shutemov" , Matthew Wilcox , Kent Overstreet , Linux FS-devel Mailing List , Linux Kernel Mailing List , Linux MM , Johannes Weiner , Linus Torvalds , Andrew Morton , "Darrick J. Wong" , Christoph Hellwig , David Howells , Mike Kravetz Subject: Re: Mapcount of subpages In-Reply-To: <24B432CB-5CBB-4309-A9D0-6E1C4395A013@nvidia.com> Message-ID: <63e1cfcc-b7dd-ca55-39b2-7a9d2f6ff7eb@google.com> References: <20210923124502.nxfdaoiov4sysed4@box.shutemov.name> <72cc2691-5ebe-8b56-1fe8-eeb4eb4a4c74@google.com> <2A311B26-8B33-458E-B2C1-8BA2CF3484AA@nvidia.com> <77b59314-5593-1a2e-293c-b66e8235ad@google.com> <24B432CB-5CBB-4309-A9D0-6E1C4395A013@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 23 Sep 2021, Zi Yan wrote: > On 23 Sep 2021, at 19:48, Hugh Dickins wrote: > > On Thu, 23 Sep 2021, Zi Yan wrote: > >> On 23 Sep 2021, at 17:54, Yang Shi wrote: > >>> On Thu, Sep 23, 2021 at 2:10 PM Hugh Dickins wrote: > >>>> > >>>> NR_FILE_MAPPED being used for /proc/meminfo's "Mapped:" and a couple > >>>> of other such stats files, and for a reclaim heuristic in mm/vmscan.c. > >>>> > >>>> Allow ourselves more slack in NR_FILE_MAPPED accounting (either count > >>>> each pte as if it mapped the whole THP, or don't count a THP's ptes > >>>> at all - you opted for the latter in the "Mlocked:" accounting), > >>>> and I suspect subpage _mapcount could be abandoned. > >>> > >>> AFAIK, partial THP unmap may need the _mapcount information of every > >>> subpage otherwise the deferred split can't know what subpages could be > >>> freed. > > > > I believe Yang Shi is right insofar as the decision on whether it's worth > > queuing for deferred split is being done based on those subpage _mapcounts. > > That is a use I had not considered, and I've given no thought to how > > important or not it is. > > > >> > >> Could we just scan page tables of a THP during deferred split process > >> instead? Deferred split is a slow path already, so maybe it can afford > >> the extra work. > > > > But unless I misunderstand, actually carrying out the deferred split > > already unmaps, uses migration entries, and remaps the remaining ptes: > > needing no help from subpage _mapcounts to do those, and free the rest. > > You are right. unmap_page() during THP split is scanning the page tables > already. > > For deciding whether to queue a THP for deferred split, we probably can > keep PageDoubleMap bit to indicate if any subpage is PTE mapped. Maybe, maybe not. > > But without subpage _mapcount, detecting extra pins to a THP before split > might be not as easy as with it. This means every THP split will need to > perform unmap_page(), then check the remaining page_count to see if > THP split is possible. That would also introduce extra system-wide overheads > from unmapping pages. Am I missing anything? I did not explain clearly enough: a subpage's ptes must still be counted in total_mapcount(); but I'm suggesting that perhaps they can be counted all together (either in the head page's _mapcount, or in a separate field if that works better), instead of being distributed amongst the separate subpages' _mapcounts. And this would lower the system-wide overheads inside total_mapcount() and page_mapped() (and maybe others). Hugh