From mboxrd@z Thu Jan 1 00:00:00 1970 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.3 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 C3A49C433DB for ; Tue, 9 Feb 2021 03:02:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 583BB64E9D for ; Tue, 9 Feb 2021 03:02:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 583BB64E9D 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 C43968D0001; Mon, 8 Feb 2021 22:02:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BF00C6B006E; Mon, 8 Feb 2021 22:02:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A6BC48D0001; Mon, 8 Feb 2021 22:02:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0030.hostedemail.com [216.40.44.30]) by kanga.kvack.org (Postfix) with ESMTP id 8B1FE6B006C for ; Mon, 8 Feb 2021 22:02:36 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 54F64824805A for ; Tue, 9 Feb 2021 03:02:36 +0000 (UTC) X-FDA: 77797231512.17.cough60_14006ed27603 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 2F9261820828F for ; Tue, 9 Feb 2021 03:02:36 +0000 (UTC) X-HE-Tag: cough60_14006ed27603 X-Filterd-Recvd-Size: 7008 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Feb 2021 03:02:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612839755; 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=s7EoKTCH5PoNhEysYwjvfHw2K5d7DEfeciRImKtwHgc=; b=i5nDds2wX0OVuPCfs+yu/uAC+RdV+FkETxLMmJkkpor39V0hmek28Pt0dn5+i2SwOkTcpu xh3N/EhphFrrmw8dYjqX28aH7XEtoT57IQwYPF27OiWAN3UnjAJup/nG/JbfmkRx8Icxbe kBKduCAJpg/ythUqb7YhAJ/3FTNDRoA= 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-98-Hr3NLYVDNHGoLuEhKZuvtg-1; Mon, 08 Feb 2021 22:02:33 -0500 X-MC-Unique: Hr3NLYVDNHGoLuEhKZuvtg-1 Received: by mail-qk1-f200.google.com with SMTP id b20so13086361qkg.0 for ; Mon, 08 Feb 2021 19:02:33 -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=RBKJHJerYt2KSF+eTc+DgeeMY1UBm0hZ6pOYGuVUj1Q=; b=L3wlwC8qBtm6TCkbYZ9czsCBEhoaWdIxLdPKQNQdqgyl5sURnc1syy8K/fENgaZwM6 nbYynxKcF8l2OfIsPNLXTUOk7XlSaglYEXsK/gyxKq1rkErXmhfXARKxX/n2NPSjRF5d gswSGxcupeMfBFrjIGL63yn7ghMmgx4qNmsshP8bmfmTIaqDJ19XQLLWprhdGNb8UYg0 vhQmPSrDzz5SopNJc+QL35UrXPlYetLvvskryBAuCiOYZxJZtfhquadvnsZlNcdx6Bo3 3ZSqLHsqdmRZ/OZbRWP9d4eLXIF2h482ThyiJt/40OEgG7JQ7Qo8hh5EcGPObwt2kvus ygtw== X-Gm-Message-State: AOAM533+cnB9u/ZDPtPHdZd8nkb6Yd9k2E548Mlpzx0yffHd0Kz84dVa NwTcqG8Bojd24rbo476iwanRcVmNXMrisS7fWByAMUwKNsQHlqnpE77xJU3qqUSn5DhAFJ0KJO6 6AdsJLSGfSzn3tQXzSQtD2FLo47mrwUR6aIoYSkGIk0XPzWc2ehTvDld3ZMzp X-Received: by 2002:ad4:4ba6:: with SMTP id i6mr3232344qvw.50.1612839752374; Mon, 08 Feb 2021 19:02:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJybLayjCqSqkV2EMC3QrWtF/NVm3sRdRjSiXft71EPzkOdMUwlhKoqtbSci9ONCrNK5bQEoPA== X-Received: by 2002:ad4:4ba6:: with SMTP id i6mr3232315qvw.50.1612839752119; Mon, 08 Feb 2021 19:02:32 -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 z20sm17078830qki.93.2021.02.08.19.02.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 19:02:31 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox , Linus Torvalds , Kirill Tkhai , Mike Rapoport , David Gibson , Kirill Shutemov , Christoph Hellwig , Miaohe Lin , Gal Pressman , Jason Gunthorpe , Jann Horn , peterx@redhat.com, Jan Kara , Wei Zhang , Mike Kravetz , Andrea Arcangeli , Andrew Morton Subject: [PATCH v4 0/5] mm/hugetlb: Early cow on fork, and a few cleanups Date: Mon, 8 Feb 2021 22:02:24 -0500 Message-Id: <20210209030229.84991-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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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: v4:=0D - add r-b for Mike on the last patch, add some more commit message explains= =0D that why we don't need wr-protect trick=0D - fix one warning of unused var in copy_present_page() [Gal]=0D =0D v3:=0D - rebase to linux-next/akpm, switch to the new HPAGE helpers [MikeK]=0D - correct error check for alloc_huge_page(); test it this time to make sure= =0D fork() fails gracefully when overcommit [MikeK]=0D - move page copy out of pgtable lock: this changed quite a bit of the logic= in=0D the last patch, prealloc is dropped since I found it easier to understand= =0D without looping at all [MikeK]=0D =0D v2:=0D - pass in 1 to alloc_huge_page() last param [Mike]=0D - reduce comment, unify the comment in one place [Linus]=0D - add r-bs for Mike and Miaohe=0D =0D ---- original cover letter ----=0D =0D As reported by Gal [1], we still miss the code clip to handle early cow for= =0D hugetlb case, which is true. Again, it still feels odd to fork() after usi= ng a=0D few huge pages, especially if they're privately mapped to me.. However I d= o=0D agree with Gal and Jason in that we should still have that since that'll=0D complete the early cow on fork effort at least, and it'll still fix issues= =0D where buffers are not well under control and not easy to apply MADV_DONTFOR= K.=0D =0D The first two patches (1-2) are some cleanups I noticed when reading into t= he=0D hugetlb reserve map code. I think it's good to have but they're not necess= ary=0D for fixing the fork issue.=0D =0D The last two patches (3-4) is the real fix.=0D =0D I tested this with a fork() after some vfio-pci assignment, so I'm pretty s= ure=0D the page copy path could trigger well (page will be accounted right after t= he=0D fork()), but I didn't do data check since the card I assigned is some rando= m=0D nic. Gal, please feel free to try this if you have better way to verify th= e=0D series.=0D =0D https://github.com/xzpeter/linux/tree/fork-cow-pin-huge=0D =0D Please review, thanks!=0D =0D [1] https://lore.kernel.org/lkml/27564187-4a08-f187-5a84-3df50009f6ca@amazo= n.com/=0D =0D Peter Xu (5):=0D hugetlb: Dedup the code to add a new file_region=0D hugetlg: Break earlier in add_reservation_in_range() when we can=0D mm: Introduce page_needs_cow_for_dma() for deciding whether cow=0D mm: Use is_cow_mapping() across tree where proper=0D hugetlb: Do early cow when page pinned on src mm=0D =0D drivers/gpu/drm/vmwgfx/vmwgfx_page_dirty.c | 4 +-=0D drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 2 +-=0D fs/proc/task_mmu.c | 2 -=0D include/linux/mm.h | 21 ++++=0D mm/huge_memory.c | 8 +-=0D mm/hugetlb.c | 123 +++++++++++++++------=0D mm/internal.h | 5 -=0D mm/memory.c | 8 +-=0D 8 files changed, 117 insertions(+), 56 deletions(-)=0D =0D --=20=0D 2.26.2=0D =0D