From patchwork Thu Feb 4 14:50:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12067473 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 6E209C433DB for ; Thu, 4 Feb 2021 14:50:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DC2F864F58 for ; Thu, 4 Feb 2021 14:50:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DC2F864F58 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 9B55B6B006C; Thu, 4 Feb 2021 09:50:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 87F2E6B0073; Thu, 4 Feb 2021 09:50:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 548D46B0071; Thu, 4 Feb 2021 09:50:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0113.hostedemail.com [216.40.44.113]) by kanga.kvack.org (Postfix) with ESMTP id 2FF186B0070 for ; Thu, 4 Feb 2021 09:50:43 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E6D62180AD817 for ; Thu, 4 Feb 2021 14:50:42 +0000 (UTC) X-FDA: 77780871924.19.bee35_4b0e799275dd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id D4CFD1AD1B3 for ; Thu, 4 Feb 2021 14:50:42 +0000 (UTC) X-HE-Tag: bee35_4b0e799275dd X-Filterd-Recvd-Size: 6018 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Thu, 4 Feb 2021 14:50:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612450241; 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=yM1yw6acStXI7UDlGCzJiFKj+FIN/hUwR5/Meq5woew=; b=XlUhL6KUcQRxwpx6lLcyuQA9Td4qd17/x9GFwdVGjcCvi+RQyBN60LwVZFag9E11xJgwge OkqvobFxHzNQ0PUD9ndB01lR37Mr9IL5e1qYMzUdD3hsyp2QxcBUHIEnedKwSwNq/0Ov2m e/dGEgA0VDfwF7xsWYbO9eyXNzFBYFM= 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-195-5WJIM5nUP8eggZZjAkgOwg-1; Thu, 04 Feb 2021 09:50:36 -0500 X-MC-Unique: 5WJIM5nUP8eggZZjAkgOwg-1 Received: by mail-qk1-f197.google.com with SMTP id e5so2843117qkn.2 for ; Thu, 04 Feb 2021 06:50: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=ZuE5C480kPs7RukduSN3hJlKKW4l1ob8mkB2FAPdH0s=; b=mIEeNtI23eeknaDqvv0JuUmwcQwS+1tDp1VpkDyEE6id9+9SZ/rYou/3Ud08VsDP7n etXMYpTrUCc4+9j7jpXOLH5+tUZ5TFmIbY9r26xSmHnqm0SWqYTcj1W94U7+vkNHe1gX e596r/0Li+CuvwoSXEak87RZdiexni3If7+3BMJjdGwChSxj7EA21ZDcqEs4Zd3ax0c9 DcCHo6qEjVdH3HVW4G69It9Wl49UWrlak7dAfoys+f+Yvv0lEUaBe3I3kfWx2FQ30D6h vUNtklphDRhZl5mFY51Nt2PYjRJHN4W32QUjdhENbgJ1wEI5sKyh2UxUv0pGEsShbCYB G+Ew== X-Gm-Message-State: AOAM531Gj2uEfnyB9/sZivdkzfjakuVOG6Bxw8cvj66L88dJbyZcznpm TQpruChtrKO2jAUOoD5AUMy8PDCRGRWO3ONqUgj4BStprp32q6C4+QpJwAaDzwZu9MTarb6pvlX MT04k5xIbzAqxuAhK3NaEAka/tVmu8/Zypne3KaNA78S0ySGlqKqwZIb3Ji8b X-Received: by 2002:ac8:5707:: with SMTP id 7mr7409537qtw.365.1612450236029; Thu, 04 Feb 2021 06:50:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJyWT2mtcic850Ww5E2xfzUAOlINS7TedhA/LzchazLXr02rlTqNLnn2cmt9+GtU9HzHoQRmng== X-Received: by 2002:ac8:5707:: with SMTP id 7mr7409494qtw.365.1612450235720; Thu, 04 Feb 2021 06:50: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 e14sm4697589qte.18.2021.02.04.06.50.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 06:50:35 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Kirill Shutemov , Wei Zhang , Mike Rapoport , Matthew Wilcox , Miaohe Lin , Andrea Arcangeli , peterx@redhat.com, Gal Pressman , Jan Kara , Jann Horn , Andrew Morton , Kirill Tkhai , Linus Torvalds , Mike Kravetz , Jason Gunthorpe , David Gibson , Christoph Hellwig Subject: [PATCH v2 0/4] mm/hugetlb: Early cow on fork, and a few cleanups Date: Thu, 4 Feb 2021 09:50:29 -0500 Message-Id: <20210204145033.136755-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: 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 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 | 114 +++++++++++++++++++++++++++++++++------------ mm/internal.h | 5 -- mm/memory.c | 7 +-- 5 files changed, 108 insertions(+), 47 deletions(-)