Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3958786rdh; Tue, 28 Nov 2023 08:08:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGXYR79Sgv0jWCb3wQnv5pBzGhA69krId/p9nznPmjD5AN0Q+JkgG/RkOyUnUGMLottsW2g X-Received: by 2002:a17:902:db02:b0:1cf:ca67:4346 with SMTP id m2-20020a170902db0200b001cfca674346mr8640224plx.46.1701187734039; Tue, 28 Nov 2023 08:08:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701187734; cv=none; d=google.com; s=arc-20160816; b=SLD7ss3c/cYzewx3UawT5bAxTGkpBYCH997ORiLDJ9x0fDLsVXJmdunOYAtbmTf3DM XOMviTrrWxJJrH1J7aEmZ3rdk1cFmdaUEAfqlonCpj6HZGBz9T/7pcfCVc9ETJWXC19q e2GdAxDlrYXC/dCrNsJnZQSFyEeFxV178kkf0q0OT6T/xE0mcUJeIx3HrZoSECnnWbB0 GXRRoJxGratDwTIKAQzekWBF/sRaO6qa0YcvSusbAnCorVH4gKtX8TsPh2g6NB1RQQxo AzlfLYfbr20tukbf1fspfOPVsCKJYG1ZkqRTNKcjAaEcH+rGxalWgj0CzHx7v+fyq7ge 0ILQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=soyiTtP+gPlQ7bbuHvFbNVbbE3R/GLF0+Udhto1bAz0=; fh=NkH3HZVMVAUJ9u9/jI0HsUpBysM73vtwnakiBn4cHcs=; b=rGGjslDcLX8ScAKXy+GDqo3zMpmagICh81Gb5VsbK7LB79Kx2ZtMuQA9huoX2Xd7S7 0eHAGlaAQy7qW8Vjhg8AQT9CWyTa2b23TOjVN1gamCtPlPsyZbMqhvkHnVzuQruTDIQY yOArCKtWx+NMmqN2c22nUpt3BAjhKRQTKNw8RXFa0cYih+zupLRi+RhHsHE2h4SnmfrB CyGWRhZT61GrqDTKaYB73K3OBnEiyH+VdgR8nXWc1DWbA84efYUMMh/gqWLfKTBICLuE /bC2rxl7gLTGhmbkX2L5vqeUzBYnBZQk/MfiN4KQo8Y6ZN6MVzApgoKeeHcXR2pTg8Y8 Vu/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Y62MCe3y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id k4-20020a170902c40400b001c430af53b8si13729628plk.574.2023.11.28.08.08.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 08:08:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Y62MCe3y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 81700807D549; Tue, 28 Nov 2023 08:08:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344263AbjK1QI2 (ORCPT + 99 others); Tue, 28 Nov 2023 11:08:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232688AbjK1QI1 (ORCPT ); Tue, 28 Nov 2023 11:08:27 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74A91DA for ; Tue, 28 Nov 2023 08:08:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701187711; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=soyiTtP+gPlQ7bbuHvFbNVbbE3R/GLF0+Udhto1bAz0=; b=Y62MCe3y9WP0dj6AkU/wMsJagJyTc2oTPTZaudFr9ZqHY/GKoPTgMufpjUL3UKCnmWUMin fq1kkai27S3FlD5zirLOOFLVayUOp8YB0wCmRS34DB+MI2MNc3t7ME+urmV83oIvZcHJT0 uDjVs0n5zOF9FTbh5ZpaiVyRylXnokw= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-637-TizjiYd8NdWGOIo7wLGfzA-1; Tue, 28 Nov 2023 11:08:29 -0500 X-MC-Unique: TizjiYd8NdWGOIo7wLGfzA-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-67a24e9712aso9562046d6.1 for ; Tue, 28 Nov 2023 08:08:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701187708; x=1701792508; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=soyiTtP+gPlQ7bbuHvFbNVbbE3R/GLF0+Udhto1bAz0=; b=KztrQgZ7g47UKsfeDeYmNDi/EGL7IBSMC9faKAkL4IyVh0aho5BJwGXfn2CxSfwv0p AhQoUBxkYXSP/4/P/54F6U6ufclbj8mBc1PqVNQ4cgO40p+92h0mPBTwtTAP14YiAKJP DK1Kv5KnOFuh37KvMqAeSbXmeM8QavDwXhc2iDgnzmSLjueAT7mb9Nn2YaWIDthvLNwk 8K5QyyoSFkLIx5IC+MS2rkCnqBumKEOM+7j5kddSU5IEbayEegNHgIU0okEW9+ljcsjv 8rlSrm+MUi2Zm6K8iABurEnon+m/kUQdcq0BpsyLYKjCSEaj3bJFplntYjKfqXpUZWQ4 xOHg== X-Gm-Message-State: AOJu0Yy/3p5uWtGEHWtmNjx6/PV49hIR5LMnv9KKItkQwS4BAYzcF35L L9UQ9RAOCWLfK6wSnz2j9dcREYnFs+3T3QIkND8CTdzj8ONh76TJxxl4mG4mgegYgxIwJQgBinM PcLH9RwRc6gQJuJhBS2GDqcY1hWZDSJST X-Received: by 2002:a05:6214:3018:b0:67a:8e0:bf28 with SMTP id ke24-20020a056214301800b0067a08e0bf28mr16757303qvb.3.1701187708084; Tue, 28 Nov 2023 08:08:28 -0800 (PST) X-Received: by 2002:a05:6214:3018:b0:67a:8e0:bf28 with SMTP id ke24-20020a056214301800b0067a08e0bf28mr16757283qvb.3.1701187707742; Tue, 28 Nov 2023 08:08:27 -0800 (PST) Received: from x1n (cpe688f2e2cb7c3-cm688f2e2cb7c0.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id a24-20020a0ca998000000b00677a12f11bcsm5234822qvb.24.2023.11.28.08.08.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 08:08:27 -0800 (PST) Date: Tue, 28 Nov 2023 11:08:25 -0500 From: Peter Xu To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Mike Kravetz , Muchun Song Subject: Re: [PATCH v1 2/5] mm/rmap: introduce and use hugetlb_remove_rmap() Message-ID: References: <20231128145205.215026-1-david@redhat.com> <20231128145205.215026-3-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20231128145205.215026-3-david@redhat.com> X-Spam-Status: No, score=0.6 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SORBS_WEB,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 28 Nov 2023 08:08:42 -0800 (PST) On Tue, Nov 28, 2023 at 03:52:02PM +0100, David Hildenbrand wrote: > hugetlb rmap handling differs quite a lot from "ordinary" rmap code. We > don't want this hugetlb special-casing in the rmap functions, as > we're special casing the callers already. Let's simply use a separate > function for hugetlb. We were special casing some, not all.. And IIUC the suggestion from the community is we reduce that "special casing", instead of adding more? To be explicit below.. > > Let's introduce and use hugetlb_remove_rmap() and remove the hugetlb > code from page_remove_rmap(). This effectively removes one check on the > small-folio path as well. > > While this is a cleanup, this will also make it easier to change rmap > handling for partially-mappable folios. > > Note: all possible candidates that need care are page_remove_rmap() that > pass compound=true. > > Signed-off-by: David Hildenbrand > --- > include/linux/rmap.h | 5 +++++ > mm/hugetlb.c | 4 ++-- > mm/rmap.c | 17 ++++++++--------- > 3 files changed, 15 insertions(+), 11 deletions(-) > > diff --git a/include/linux/rmap.h b/include/linux/rmap.h > index 4c5bfeb05463..e8d1dc1d5361 100644 > --- a/include/linux/rmap.h > +++ b/include/linux/rmap.h > @@ -208,6 +208,11 @@ void hugetlb_add_anon_rmap(struct folio *, struct vm_area_struct *, > void hugetlb_add_new_anon_rmap(struct folio *, struct vm_area_struct *, > unsigned long address); > > +static inline void hugetlb_remove_rmap(struct folio *folio) > +{ > + atomic_dec(&folio->_entire_mapcount); > +} > + > static inline void __page_dup_rmap(struct page *page, bool compound) > { > if (compound) { > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 4cfa0679661e..d17bb53b19ff 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -5669,7 +5669,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma, > make_pte_marker(PTE_MARKER_UFFD_WP), > sz); > hugetlb_count_sub(pages_per_huge_page(h), mm); > - page_remove_rmap(page, vma, true); > + hugetlb_remove_rmap(page_folio(page)); > > spin_unlock(ptl); > tlb_remove_page_size(tlb, page, huge_page_size(h)); > @@ -5980,7 +5980,7 @@ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma, > > /* Break COW or unshare */ > huge_ptep_clear_flush(vma, haddr, ptep); > - page_remove_rmap(&old_folio->page, vma, true); > + hugetlb_remove_rmap(old_folio); > hugetlb_add_new_anon_rmap(new_folio, vma, haddr); > if (huge_pte_uffd_wp(pte)) > newpte = huge_pte_mkuffd_wp(newpte); > diff --git a/mm/rmap.c b/mm/rmap.c > index 112467c30b2c..5037581b79ec 100644 > --- a/mm/rmap.c > +++ b/mm/rmap.c > @@ -1440,13 +1440,6 @@ void page_remove_rmap(struct page *page, struct vm_area_struct *vma, > > VM_BUG_ON_PAGE(compound && !PageHead(page), page); > > - /* Hugetlb pages are not counted in NR_*MAPPED */ > - if (unlikely(folio_test_hugetlb(folio))) { > - /* hugetlb pages are always mapped with pmds */ > - atomic_dec(&folio->_entire_mapcount); > - return; > - } Fundamentally in the ideal world when hugetlb can be merged into generic mm, I'd imagine that as dropping here, meanwhile... > - > /* Is page being unmapped by PTE? Is this its last map to be removed? */ > if (likely(!compound)) { > last = atomic_add_negative(-1, &page->_mapcount); > @@ -1804,7 +1797,10 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, > dec_mm_counter(mm, mm_counter_file(&folio->page)); > } > discard: > - page_remove_rmap(subpage, vma, folio_test_hugetlb(folio)); > + if (unlikely(folio_test_hugetlb(folio))) > + hugetlb_remove_rmap(folio); > + else > + page_remove_rmap(subpage, vma, false); ... rather than moving hugetlb_* handlings even upper the stack, we should hopefully be able to keep this one as a generic api. I worry this patch is adding more hugetlb-specific paths even onto higher call stacks so it's harder to generalize, going the other way round to what we wanted per previous discussions. Said that, indeed I read mostly nothing yet with the recent rmap patches, so I may miss some important goal here. > if (vma->vm_flags & VM_LOCKED) > mlock_drain_local(); > folio_put(folio); > @@ -2157,7 +2153,10 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, > */ > } > > - page_remove_rmap(subpage, vma, folio_test_hugetlb(folio)); > + if (unlikely(folio_test_hugetlb(folio))) > + hugetlb_remove_rmap(folio); > + else > + page_remove_rmap(subpage, vma, false); > if (vma->vm_flags & VM_LOCKED) > mlock_drain_local(); > folio_put(folio); > -- > 2.41.0 > > Thanks, -- Peter Xu