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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 312FDC636D3 for ; Mon, 6 Feb 2023 20:52:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B1B136B0072; Mon, 6 Feb 2023 15:52:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ACB0F6B0073; Mon, 6 Feb 2023 15:52:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 993096B0074; Mon, 6 Feb 2023 15:52:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 896F46B0072 for ; Mon, 6 Feb 2023 15:52:28 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 586FF1A02E5 for ; Mon, 6 Feb 2023 20:52:28 +0000 (UTC) X-FDA: 80438065176.26.0DED959 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 28CC140002 for ; Mon, 6 Feb 2023 20:52:25 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bYaWop1H; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675716746; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rqLlmct7lX+JFmd+5pxF8+BD7yXad1T5vU6UwHJMxwY=; b=OXoIXpnS9HgaTKa8oS+ee2i/jqF6JKtUhp1xq0bjaF4eLlcDS1XceQk49ciHg7Nm50OsMe b2srf6cbAL3FqonP5jG0UBcGjm8ZPV51/2LRBzs1c2abo28Uk01XXBNlWmfXODtBJEwD5e OJn3TiplXSPKhS3Z21+FP71VNlVRbAA= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bYaWop1H; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675716746; a=rsa-sha256; cv=none; b=ricIPfpoIws0xVoXbTKRpihm3AxXqoEuxWbtxRR9daUUsEWBCigBKxHAbxhCKzCaylO3Oz KIsHjyzbYmdMLzTQGPUy115saJdZ5YUW3yMcTfrp36L3f3iSGKc238fyMi17X38rMnR6kx eKJZdSlF6miZZ6PskG4VHtDCC1dXmyg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675716745; 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: in-reply-to:in-reply-to:references:references; bh=rqLlmct7lX+JFmd+5pxF8+BD7yXad1T5vU6UwHJMxwY=; b=bYaWop1HxvFH0O104nmtNDS84v8oPxf5a0CdughAf8dHpVPfWgnHqzj7d7mZA2R9hn074Z zjIA+z8rpX48X0HA7ESnTC/M/fVQ/24j3ayYgaPPZ4TMulJ9DOU2J7m3836rnvR8C0NTPn 7p8R7XgdGJpBk868Qkng7hJyCZV2kAE= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-611-vMz-GX9UNJaro1reUi-ZIg-1; Mon, 06 Feb 2023 15:52:22 -0500 X-MC-Unique: vMz-GX9UNJaro1reUi-ZIg-1 Received: by mail-qk1-f199.google.com with SMTP id s7-20020ae9f707000000b007294677a6e8so8628381qkg.17 for ; Mon, 06 Feb 2023 12:52:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=rqLlmct7lX+JFmd+5pxF8+BD7yXad1T5vU6UwHJMxwY=; b=dXCJ0Uv4xXA9jioeqgjjBFxKyXeSIzdjrIJRgwEHporJYunPiVbNXQxHrVdak7/zNv vy5nEEPAq6hizh+NnkD1uGMhp52WMUrmBYKA7hFUSn4TKe5x9+dR01tOJkAk9WrMLUer cLcJWNlTFV3K/eMvdIll+gfjWwqpePBoNI3XbEe300acNKQJdMJQVqYAgvIVu1H0uVmB e46d/9pEQ7Kdk4nLyzZwbngLiiuYgDikJPjud1Xuh0giwWONiPgGRB0c5/Bca3+fLcq/ jk7gbjsu9jOfOQYGhNMwPlWDE6ytdkKtQDnTNDJtUNtW2F5DSoiQhgWBEFOLXwS7P9kM +/vQ== X-Gm-Message-State: AO0yUKVv7Z+8dX7Vs5Sd81Ce+GnP10QamQqu3iNHGu1YnzfjxSOVJ7DX ia/TwicMf3yLP0pA+YlBIpiQDrW1rDpcxyJatLxC5hfcGUTDpjJwr+MiYr43LTLO6h20lCjYqnM peH29J3IpsKI= X-Received: by 2002:a05:622a:4b:b0:3b8:6d44:ca7e with SMTP id y11-20020a05622a004b00b003b86d44ca7emr1435600qtw.4.1675716741778; Mon, 06 Feb 2023 12:52:21 -0800 (PST) X-Google-Smtp-Source: AK7set+xt3VpKVSjbng5Isjbb9ILCPJQRmOIPFhgB09Fc0XTzyXKXefEhRFVU+CjRKGOYRPbyw2L9Q== X-Received: by 2002:a05:622a:4b:b0:3b8:6d44:ca7e with SMTP id y11-20020a05622a004b00b003b86d44ca7emr1435563qtw.4.1675716741494; Mon, 06 Feb 2023 12:52:21 -0800 (PST) Received: from x1n (bras-base-aurron9127w-grc-56-70-30-145-63.dsl.bell.ca. [70.30.145.63]) by smtp.gmail.com with ESMTPSA id x10-20020a05620a12aa00b0071d57a0eb17sm7923473qki.136.2023.02.06.12.52.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Feb 2023 12:52:20 -0800 (PST) Date: Mon, 6 Feb 2023 15:52:19 -0500 From: Peter Xu To: Matthew Wilcox Cc: David Stevens , linux-mm@kvack.org, Andrew Morton , "Kirill A . Shutemov" , Yang Shi , David Hildenbrand , Hugh Dickins , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm/khugepaged: skip shmem with userfaultfd Message-ID: References: <20230206112856.1802547-1-stevensd@google.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspamd-Queue-Id: 28CC140002 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: n75chc3e6a9hgbgz95cg9w6uz5d1u7ab X-HE-Tag: 1675716745-204751 X-HE-Meta: U2FsdGVkX18cYwj2VyFtwcvLjxZ42TppadHsJE5II0JMgaypCpfDyZAcz2tSqhwv8Xa+ddZiEgX6MFco21/ZlYfY/S9H/qs5r7C0vmjFsh+bo/alhoIYEXF8ly+k9x7r+itI1m9YW1m2KKLaMqcKYcAQxQNXoPzJN602KZKkqVTjlL3bwocHyOnkP8EoluMHFMvw3QNmHmaXWLdY/CcfqOVYUwJjvfxg1xnIm8Ml1svnGA6ae7RkkgUvzpQQolm5ydF9BP1yBveR/MIRf/L/fAXwEI2lmFQxU7XTaPQKb3msD8MFJsiyO9VmO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ogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Feb 06, 2023 at 07:01:39PM +0000, Matthew Wilcox wrote: > On Mon, Feb 06, 2023 at 08:28:56PM +0900, David Stevens wrote: > > This change first makes sure that the intermediate page cache state > > during collapse is not visible by moving when gaps are filled to after > > the page cache lock is acquired for the final time. This is necessary > > because the synchronization provided by locking hpage is insufficient > > for functions which operate on the page cache without actually locking > > individual pages to examine their content (e.g. shmem_mfill_atomic_pte). > > I've been a little scared of touching khugepaged because, well, look at > that function. But if we are going to touch it, how about this patch > first? It does _part_ of what you need by not filling in the holes, > but obviously not the part that looks at uffd. > > It leaves the old pages in-place and frozen. I think this should be > safe, but I haven't booted it (not entirely sure what test I'd run > to prove that it's not broken) That logic existed since Kirill's original commit to add shmem thp support on khugepaged, so Kirill should be the best to tell.. but so far it seems reasonalbe to me to have that extra operation. The problem is khugepaged will release pgtable lock during collapsing, so AFAICT there can be a race where some other thread tries to insert pages into page cache in parallel with khugepaged right after khugepaged released the page cache lock. For example, it seems to me new page cache can be inserted when khugepaged is copying small page content to the new hpage. -- Peter Xu