From patchwork Wed Feb 3 21:08:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12065375 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 8FB81C433E0 for ; Wed, 3 Feb 2021 21:08:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0DE2561477 for ; Wed, 3 Feb 2021 21:08:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0DE2561477 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 99A336B006C; Wed, 3 Feb 2021 16:08:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 94C5E6B006E; Wed, 3 Feb 2021 16:08:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EB9A6B0070; Wed, 3 Feb 2021 16:08:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0022.hostedemail.com [216.40.44.22]) by kanga.kvack.org (Postfix) with ESMTP id 57C446B006C for ; Wed, 3 Feb 2021 16:08:42 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 051EE180AD81D for ; Wed, 3 Feb 2021 21:08:42 +0000 (UTC) X-FDA: 77778195684.18.floor48_190c7a8275d6 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id D5BAD100ED0D0 for ; Wed, 3 Feb 2021 21:08:41 +0000 (UTC) X-HE-Tag: floor48_190c7a8275d6 X-Filterd-Recvd-Size: 5769 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Wed, 3 Feb 2021 21:08:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612386520; 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=hpcxxdvarEEuWMY+Jy4oS6GiLBF6Y7YnCSl5hl8C5ro=; b=XeW32LN2VwiTrSWLpU76RhooZWRHY3/ihptdygKZATHAbQrCVGJMWP7hNbo3N9O8DO5Exw Qmqivs+ox/+iCvglim79UaRPnhvtBBJwSKIQB3a6f5xeT59YV92uiS6glxABGdRO4cegy+ UaCsg3KNHPaGTu7f2TiCtQONNqMKzZQ= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-477-gl5Z-FeUOliYuggnqLEFKA-1; Wed, 03 Feb 2021 16:08:36 -0500 X-MC-Unique: gl5Z-FeUOliYuggnqLEFKA-1 Received: by mail-qk1-f197.google.com with SMTP id g80so666212qke.17 for ; Wed, 03 Feb 2021 13:08:36 -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=TNWACLsdv3x1bUbvJdGKEfoXIQ+IjxeD0ZZzcQWojo0=; b=JoLkLPzkeZKZW1ZQdIuiZqut/c0+nHeSq7LgZ6K8/k4tpnYiex2V2tAaVv87skiVuF HLuIRf8Tr+J/ChhPYL3uo8tQJeVrMcsBvOQzdALYDi0HXSQOcisZqhCW0upaX7oAagHG FggJpXsLaPyFxupkxbgpaeVl5mIKjCW5PBlrfyqSN17nC9CKdzmjrq029MCA+9FlCJKY 885XLH655OJi/ZzNZw3FcQIEcXbl3WyCyAiCpj9rG46X7o0A2tQEou6Ov09GNCC9Itcs ah0zWUSXKTLcyX89MMH6XpO61oKPa8H0EYjoqLhXGyst8mLWS1S8Xus63hEqwJzHKBVP SdMQ== X-Gm-Message-State: AOAM533vB0W5E8fsLW+g1Mua/u552Evy9wU7B9jeQsLURx2zN7k7uRL6 fSxsYB6Q83nBSxNfBXQmi34cnLPy9a+/wVYaN7omSwctdS/gXhXhe0u7ku02TkgCEUHcp8CZU2p bfpfHmZk8xkg= X-Received: by 2002:a37:8dc7:: with SMTP id p190mr4405764qkd.308.1612386515708; Wed, 03 Feb 2021 13:08:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJwWJrU+fowec9PCAB1r46ozvnVAjrHd4MVk+0npIFwtKWt4j/MtEJeFldA6yj6yzHAmK8jpQA== X-Received: by 2002:a37:8dc7:: with SMTP id p190mr4405737qkd.308.1612386515452; Wed, 03 Feb 2021 13:08:35 -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 t6sm2507659qti.2.2021.02.03.13.08.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 13:08:34 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Wei Zhang , Matthew Wilcox , Linus Torvalds , Jason Gunthorpe , Gal Pressman , peterx@redhat.com, Christoph Hellwig , Andrea Arcangeli , Jan Kara , Kirill Shutemov , David Gibson , Mike Rapoport , Mike Kravetz , Kirill Tkhai , Jann Horn , Andrew Morton Subject: [PATCH 0/4] mm/hugetlb: Early cow on fork, and a few cleanups Date: Wed, 3 Feb 2021 16:08:28 -0500 Message-Id: <20210203210832.113685-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: 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 (4): 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 hugetlb: Do early cow when page pinned on src mm include/linux/mm.h | 21 ++++++++ mm/huge_memory.c | 8 +-- mm/hugetlb.c | 129 ++++++++++++++++++++++++++++++++++----------- mm/internal.h | 5 -- mm/memory.c | 7 +-- 5 files changed, 123 insertions(+), 47 deletions(-)