From patchwork Thu Oct 20 19:38:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13013954 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 5A4BAC433FE for ; Thu, 20 Oct 2022 19:38:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0F2A8E0002; Thu, 20 Oct 2022 15:38:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9994E8E0001; Thu, 20 Oct 2022 15:38:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8393A8E0002; Thu, 20 Oct 2022 15:38:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6FAD38E0001 for ; Thu, 20 Oct 2022 15:38:49 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 25B861A12B6 for ; Thu, 20 Oct 2022 19:38:49 +0000 (UTC) X-FDA: 80042340378.26.E85E959 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 4FD2E40036 for ; Thu, 20 Oct 2022 19:38:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666294727; 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: content-transfer-encoding:content-transfer-encoding; bh=85S5u2Kj0kLXjbV1eC6tH45ETLd1PtrOIvBagjXXKHg=; b=S5HLCpSBNiaaaxrQJTygDSkRq86ZdlTGSULHsqZJOzHhwWlwyJBxTcGbT8PrSJlFlY6C+M dsA+RCXHSmthCTCIG4CfyJ4tNsYtDJsgDiS3iHq7ljutUBSBO5CBJ0eBzHRBeSxPCtihbU Zd4yvoxnKmCVHFivQSNkTbjGOnuyjeI= 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_128_GCM_SHA256) id us-mta-472-FNQWiOybP3W0GATuhd39bA-1; Thu, 20 Oct 2022 15:38:46 -0400 X-MC-Unique: FNQWiOybP3W0GATuhd39bA-1 Received: by mail-qv1-f71.google.com with SMTP id ny15-20020a056214398f00b004b9152f4b53so408224qvb.17 for ; Thu, 20 Oct 2022 12:38:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=85S5u2Kj0kLXjbV1eC6tH45ETLd1PtrOIvBagjXXKHg=; b=CqKBqaFXfnQ5bCoA5Mr8o85rPqMUISEbAa75W/oohDBROD6N8untV4dn0a3hf5bkdz SPq2i0Ooej3qtzi9/0QoTbyTWr8W32xbzPlRks6Y/e0Jk1MHQ0iButXL2TirDDKZxcIr fKCKW77AmJo3VI7Hv2N6K4Fv1d/CciJlxWx76d8FZ213YelwQaowcRFw9YKBy1HsCXxi q+LEcKYjrhoUkWyyagzXLTkxRtNrPkvghxqG5RrLBdfaksf5bQ3QjjpK1GIgSZ1rY0IS HShvMzkH27esGYxv8cnvyr5mMycv7AWfyYKU01dMJn762tY9bIDSs9I6WmylmayruxZv fQkQ== X-Gm-Message-State: ACrzQf2kf68AaZg7q2w7dgDZfzFlWuY6tWZhCSLv8FOXTbB6CFsneeEy tyq34VHdichLkuETk6H8O0O9Vhm13QEzZZwY+DRfnpVqGDmFzcYTaPammpzrGajJioymd6IgDWD 2QVyjGOtLa+w= X-Received: by 2002:ac8:57c2:0:b0:39c:dbec:9488 with SMTP id w2-20020ac857c2000000b0039cdbec9488mr12849923qta.580.1666294725710; Thu, 20 Oct 2022 12:38:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5+lZIN+opAk1J1sWYCJQufRZwqLE9h0Kf49Du8fY7l1ltie0di6XohikrUIV3lzIMrn1ey0A== X-Received: by 2002:a05:622a:1312:b0:39c:fbd3:6dbf with SMTP id v18-20020a05622a131200b0039cfbd36dbfmr9453063qtk.335.1666294714733; Thu, 20 Oct 2022 12:38:34 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id y13-20020a05620a25cd00b006bbf85cad0fsm8074982qko.20.2022.10.20.12.38.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 12:38:34 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Muchun Song , peterx@redhat.com, Mike Kravetz Subject: [PATCH] mm/hugetlb: Unify clearing of RestoreReserve for private pages Date: Thu, 20 Oct 2022 15:38:32 -0400 Message-Id: <20221020193832.776173-1-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666294728; a=rsa-sha256; cv=none; b=nIhJFbBTpzFeKnGRxHhCwHrQzR7IcLxGCmgmKSDjXukgQ9Vi98/zFmHLg6NtzeBsBSSsl7 X8B7dR8cvyOaNYfcNRaUv7rxDI094XnNy6pLxWnNXTQt4UeMd4TwM6UeaoQ5Yqb2RRH63p vu1dQAEd2BsizRJhn/vv+JcOXbhjJ9c= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=S5HLCpSB; spf=pass (imf07.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666294728; 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:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=85S5u2Kj0kLXjbV1eC6tH45ETLd1PtrOIvBagjXXKHg=; b=Qz6ZXHm7zrjXq52Naibh7olR6mGszep42pWpcTc4kUXN35WCHeUdz/t+BD+IpUk0XSGFEm MaDKqXsE7JtbQTOQWoXSqdE93ElRqkj9ZcmZrcVOD5K0kUeNMM3nyuSfx2J4K2+kUXm2ct TtpmBr+eB15lquDztcBjTM+1rF4OJBY= X-Stat-Signature: bfepepk7uc1p4dk9o86ppb77xoqso7c4 X-Rspamd-Queue-Id: 4FD2E40036 Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=S5HLCpSB; spf=pass (imf07.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1666294728-666127 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: A trivial cleanup to move clearing of RestoreReserve into adding anon rmap of private hugetlb mappings. It matches with the shared mappings where we only clear the bit when adding into page cache, rather than spreading it around the code paths. Cc: Mike Kravetz Signed-off-by: Peter Xu Reviewed-by: Mike Kravetz --- mm/hugetlb.c | 14 ++++---------- mm/rmap.c | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 1a7dc7b2e16c..931789a8f734 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4784,7 +4784,6 @@ hugetlb_install_page(struct vm_area_struct *vma, pte_t *ptep, unsigned long addr hugepage_add_new_anon_rmap(new_page, vma, addr); set_huge_pte_at(vma->vm_mm, addr, ptep, make_huge_pte(vma, new_page, 1)); hugetlb_count_add(pages_per_huge_page(hstate_vma(vma)), vma->vm_mm); - ClearHPageRestoreReserve(new_page); SetHPageMigratable(new_page); } @@ -5447,8 +5446,6 @@ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma, spin_lock(ptl); ptep = huge_pte_offset(mm, haddr, huge_page_size(h)); if (likely(ptep && pte_same(huge_ptep_get(ptep), pte))) { - ClearHPageRestoreReserve(new_page); - /* Break COW or unshare */ huge_ptep_clear_flush(vma, haddr, ptep); mmu_notifier_invalidate_range(mm, range.start, range.end); @@ -5743,10 +5740,9 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm, if (!pte_same(huge_ptep_get(ptep), old_pte)) goto backout; - if (anon_rmap) { - ClearHPageRestoreReserve(page); + if (anon_rmap) hugepage_add_new_anon_rmap(page, vma, haddr); - } else + else page_dup_file_rmap(page, true); new_pte = make_huge_pte(vma, page, ((vma->vm_flags & VM_WRITE) && (vma->vm_flags & VM_SHARED))); @@ -6133,12 +6129,10 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, if (!huge_pte_none_mostly(huge_ptep_get(dst_pte))) goto out_release_unlock; - if (page_in_pagecache) { + if (page_in_pagecache) page_dup_file_rmap(page, true); - } else { - ClearHPageRestoreReserve(page); + else hugepage_add_new_anon_rmap(page, dst_vma, dst_addr); - } /* * For either: (1) CONTINUE on a non-shared VMA, or (2) UFFDIO_COPY diff --git a/mm/rmap.c b/mm/rmap.c index 9bba65b30e4d..3b2d18bbdc44 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -2571,7 +2571,7 @@ void hugepage_add_new_anon_rmap(struct page *page, BUG_ON(address < vma->vm_start || address >= vma->vm_end); atomic_set(compound_mapcount_ptr(page), 0); atomic_set(compound_pincount_ptr(page), 0); - + ClearHPageRestoreReserve(page); __page_set_anon_rmap(page, vma, address, 1); } #endif /* CONFIG_HUGETLB_PAGE */