From patchwork Fri Feb 5 16:54:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12070459 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,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 39C77C433E0 for ; Fri, 5 Feb 2021 16:53:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 761FB64EE0 for ; Fri, 5 Feb 2021 16:53:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 761FB64EE0 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 B84486B0071; Fri, 5 Feb 2021 11:53:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B336F6B0073; Fri, 5 Feb 2021 11:53:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FBEB6B0074; Fri, 5 Feb 2021 11:53:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0249.hostedemail.com [216.40.44.249]) by kanga.kvack.org (Postfix) with ESMTP id 8B4946B0071 for ; Fri, 5 Feb 2021 11:53:35 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 52F022478 for ; Fri, 5 Feb 2021 16:53:35 +0000 (UTC) X-FDA: 77784810390.11.drink92_0018596275e6 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id 2FAC3180F8B82 for ; Fri, 5 Feb 2021 16:53:35 +0000 (UTC) X-HE-Tag: drink92_0018596275e6 X-Filterd-Recvd-Size: 6798 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Fri, 5 Feb 2021 16:53:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612544014; 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=9fw0uYqDHavPgnkv1z2A8kDbROmTc5ODo87/ntsQhsU=; b=aV6imtzKgHVH7u80aD7Kg0iS+R1vaEFRNsoe/VcBwJ3XzhROycw9j/Qga8BG33MvzlZTDi veuBarI0wU3AHlRv+SDOmWAFbgsbI33qjXXypbyvtyPnmAP9lv5GmdHYcJjzqniKMf0+sk YKdquyaNRjGmT5q38vZur8wEF6tqZyM= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-70-o3HNXeQ4MdGDeSr2JJ-tcw-1; Fri, 05 Feb 2021 11:53:32 -0500 X-MC-Unique: o3HNXeQ4MdGDeSr2JJ-tcw-1 Received: by mail-qv1-f70.google.com with SMTP id h13so5435363qvs.13 for ; Fri, 05 Feb 2021 08:53:32 -0800 (PST) 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:mime-version :content-transfer-encoding; bh=SoQrqQPF9+borL+qHQ4hNWJYo4oscRnbkbb9Q51ktbk=; b=j633e7CQv80B8ypWS7zdSy65bR6CBfgjHEVen1LrTvXYOSGilssVuCDBGJ3wQEGFnp R9rEnIEVqN7s8l3505EITm7WPrNC1D3tRD7RXIUDtFei0/DHR5o6T5GeXjI/jloYJ1/z bj//emNSjCs1LejsFGWyPOT1PDzJqqIUlNodFoAxfv3YrQU9ZhmWMQ6fbZrhzZgQa+bW tKuHkPTqRXasU/rm6IS5IDiW9Kv9XCdAhAbIEicHXEcf0RuXPFAre9JS4VDThuhjyM/H YXYM2NRoZVG/AcsGnbNl2pOAUbEUi/qdjj5KfqdkOcQayZypmhu4jC2BhhRLzSKhgh/2 D7yQ== X-Gm-Message-State: AOAM532y4y6psFaHqffPFXK08AyYPalj2jq7+lkjzw1Xh/QiPFXUTnzd jkKuGy0NQnHUmiuWP4xJvncM+Fay+YqzGAi0DDAr4W/ojH+7/Q+MXLKau0fFEC/zQWqiZo1FLhH AU53X3gK9MqEagcod2dCMAz8HKEKr9P8G0Zamu0Pbey/iDdig6n4PaYJopvZP X-Received: by 2002:ac8:5a0d:: with SMTP id n13mr4868985qta.172.1612544011061; Fri, 05 Feb 2021 08:53:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwhGJdXJrGmwrXmKNbOfGZisxwRZvH9uZmN6zAs71jWNsD2lLWwz1jxezZDDIeb0pNDGx93TQ== X-Received: by 2002:ac8:5a0d:: with SMTP id n13mr4868948qta.172.1612544010663; Fri, 05 Feb 2021 08:53:30 -0800 (PST) Received: from xz-x1.redhat.com (bras-vprn-toroon474qw-lp130-20-174-93-89-182.dsl.bell.ca. [174.93.89.182]) by smtp.gmail.com with ESMTPSA id 12sm9618893qkg.39.2021.02.05.08.53.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 08:53:29 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Gal Pressman , Andrea Arcangeli , Christoph Hellwig , Miaohe Lin , Kirill Shutemov , Jann Horn , Matthew Wilcox , Jan Kara , Jason Gunthorpe , Linus Torvalds , Mike Rapoport , David Gibson , Mike Kravetz , peterx@redhat.com, Kirill Tkhai , Wei Zhang , Andrew Morton Subject: [PATCH v3 0/5] mm/hugetlb: Early cow on fork, and a few cleanups Date: Fri, 5 Feb 2021 11:54:01 -0500 Message-Id: <20210205165406.4655-1-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 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-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: v3: - rebase to linux-next/akpm, switch to the new HPAGE helpers [MikeK] - correct error check for alloc_huge_page(); test it this time to make sure fork() fails gracefully when overcommit [MikeK] - move page copy out of pgtable lock: this changed quite a bit of the logic in the last patch, prealloc is dropped since I found it easier to understand without looping at all [MikeK] v2: - pass in 1 to alloc_huge_page() last param [Mike] - reduce comment, unify the comment in one place [Linus] - add r-bs for Mike and Miaohe ---- original cover letter ---- As reported by Gal [1], we still miss the code clip to handle early cow for hugetlb case, which is true. Again, it still feels odd to fork() after using a few huge pages, especially if they're privately mapped to me.. However I do agree with Gal and Jason in that we should still have that since that'll complete the early cow on fork effort at least, and it'll still fix issues where buffers are not well under control and not easy to apply MADV_DONTFORK. The first two patches (1-2) are some cleanups I noticed when reading into the hugetlb reserve map code. I think it's good to have but they're not necessary for fixing the fork issue. The last two patches (3-4) is the real fix. I tested this with a fork() after some vfio-pci assignment, so I'm pretty sure the page copy path could trigger well (page will be accounted right after the fork()), but I didn't do data check since the card I assigned is some random nic. Gal, please feel free to try this if you have better way to verify the series. https://github.com/xzpeter/linux/tree/fork-cow-pin-huge Please review, thanks! [1] https://lore.kernel.org/lkml/27564187-4a08-f187-5a84-3df50009f6ca@amazon.com/ Peter Xu (5): hugetlb: Dedup the code to add a new file_region hugetlg: Break earlier in add_reservation_in_range() when we can mm: Introduce page_needs_cow_for_dma() for deciding whether cow mm: Use is_cow_mapping() across tree where proper hugetlb: Do early cow when page pinned on src mm drivers/gpu/drm/vmwgfx/vmwgfx_page_dirty.c | 4 +- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 2 +- fs/proc/task_mmu.c | 2 - include/linux/mm.h | 21 ++++ mm/huge_memory.c | 8 +- mm/hugetlb.c | 123 +++++++++++++++------ mm/internal.h | 5 - mm/memory.c | 7 +- 8 files changed, 117 insertions(+), 55 deletions(-)