From patchwork Wed Apr 28 22:50:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12230195 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F347C433B4 for ; Wed, 28 Apr 2021 22:51:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2DFA66143C for ; Wed, 28 Apr 2021 22:51:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2DFA66143C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C32406B0070; Wed, 28 Apr 2021 18:51:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C09A36B0071; Wed, 28 Apr 2021 18:51:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A81956B0072; Wed, 28 Apr 2021 18:51:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0140.hostedemail.com [216.40.44.140]) by kanga.kvack.org (Postfix) with ESMTP id 8DD256B0070 for ; Wed, 28 Apr 2021 18:51:20 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 403ED180AD820 for ; Wed, 28 Apr 2021 22:51:20 +0000 (UTC) X-FDA: 78083273520.09.295B344 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf14.hostedemail.com (Postfix) with ESMTP id BF0A2C0001FA for ; Wed, 28 Apr 2021 22:51:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619650279; 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: in-reply-to:in-reply-to:references:references; bh=ikZqRIOJ+24TbcCJgwh1xPSL1L/jSOOAtcHmb6Z6UD4=; b=G7YjTuoyfI5GQOMquCgnhJ+VUuwB4gEJiCf5AgNnMRedcYi757GsrBGkaZiHyeMHD42JQy BKRvYyT2YywMEOk7sohuD2YL+SboW1vLJD3KM+Q8Fmrg6X7naWQ1DUxhrWW676LgXuaCgk JvjPh/pnE4GjBXpB7tIcY8Mj2PawRRU= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-410-RAFlfduUPr6X-P4QeAn8nA-1; Wed, 28 Apr 2021 18:51:16 -0400 X-MC-Unique: RAFlfduUPr6X-P4QeAn8nA-1 Received: by mail-qk1-f200.google.com with SMTP id h22-20020a05620a13f6b02902e3e9aad4bdso22326944qkl.14 for ; Wed, 28 Apr 2021 15:51:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ikZqRIOJ+24TbcCJgwh1xPSL1L/jSOOAtcHmb6Z6UD4=; b=f4JtYSb6AhcioxEXbpP6Hwex/AJ12ZP6AFg/rIFcl7AUbVfarCLMl+9j6vh7JFItDG zVJWDcQQZG7Mha7HsBLlcJLMudo5t7SkTqSEumqSv+JNhi91O7cyiiF10HNdmvz0Shyz zdLxUB9MuKpM3cNT2sncqalpCf68dyDMoKe9OH4u28N5JFATwGEXOQffczpOcrdMgIah JWc+FKdGUWIp72X45KSaRwiSOWvaqKLO/ccxgve1wtGJDUbo/mpTu3Lxoy5GsDz2zKDz qMVzLVwXSF0p2GYCm7fyzqUubN6gEY0LasrlhukssDkUy2MAUHzHuGwxh/Ldygwb04lW OmUw== X-Gm-Message-State: AOAM532BFyf4JyhALPltkIFEt1j6yqmeS+ak4y2zia2Q6iTBCxtjxj5Q 9XV3K67nCMwKfNkLQ6+7N+eq9zPE0ex6pwCy6XDi3pqQX1n5Tm9J11V0W8qkPGwJOqvbdAle5vS K/9SXZEkxtWwSncblAxnPQW9ff4fgqG4FpRWGIozehjlQDVLU2o2IUtpqZ48B X-Received: by 2002:a05:622a:589:: with SMTP id c9mr28868887qtb.363.1619650275096; Wed, 28 Apr 2021 15:51:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrX3v3lU9B1pVnyP5Nb9hlKNKEN2NRRr8EhEd2xq4l8HH5y/69IZS/YQAW1T0WiwuZgL+rNg== X-Received: by 2002:a05:622a:589:: with SMTP id c9mr28868855qtb.363.1619650274762; Wed, 28 Apr 2021 15:51:14 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-77-184-145-104-227.dsl.bell.ca. [184.145.104.227]) by smtp.gmail.com with ESMTPSA id 191sm897459qkk.31.2021.04.28.15.51.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 15:51:14 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Mike Kravetz , peterx@redhat.com, Mike Rapoport , Axel Rasmussen , Andrea Arcangeli , Hugh Dickins , "Kirill A . Shutemov" , Andrew Morton , Jerome Glisse Subject: [PATCH 1/6] mm/thp: Simplify copying of huge zero page pmd when fork Date: Wed, 28 Apr 2021 18:50:25 -0400 Message-Id: <20210428225030.9708-2-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210428225030.9708-1-peterx@redhat.com> References: <20210428225030.9708-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Stat-Signature: ng6ro3krk1mg7hsmyc77emyoco5ou6jk X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: BF0A2C0001FA Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf14; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=170.10.133.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1619650263-826352 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: Huge zero page is handled in a special path in copy_huge_pmd(), however it should share most codes with a normal thp page. Trying to share more code with it by removing the special path. The only leftover so far is the huge zero page refcounting (mm_get_huge_zero_page()), because that's separately done with a global counter. This prepares for a future patch to modify the huge pmd to be installed, so that we don't need to duplicate it explicitly into huge zero page case too. Cc: Kirill A. Shutemov Signed-off-by: Peter Xu --- mm/huge_memory.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 98456017744d6..22bf2d0fff79b 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1076,17 +1076,13 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm, * a page table. */ if (is_huge_zero_pmd(pmd)) { - struct page *zero_page; /* * get_huge_zero_page() will never allocate a new page here, * since we already have a zero page to copy. It just takes a * reference. */ - zero_page = mm_get_huge_zero_page(dst_mm); - set_huge_zero_page(pgtable, dst_mm, vma, addr, dst_pmd, - zero_page); - ret = 0; - goto out_unlock; + mm_get_huge_zero_page(dst_mm); + goto out_zero_page; } src_page = pmd_page(pmd); @@ -1110,6 +1106,7 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm, get_page(src_page); page_dup_rmap(src_page, true); add_mm_counter(dst_mm, MM_ANONPAGES, HPAGE_PMD_NR); +out_zero_page: mm_inc_nr_ptes(dst_mm); pgtable_trans_huge_deposit(dst_mm, dst_pmd, pgtable);