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 0566FC433FE for ; Wed, 2 Nov 2022 20:44:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C1048E0002; Wed, 2 Nov 2022 16:44:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 66EEF8E0001; Wed, 2 Nov 2022 16:44:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 536DD8E0002; Wed, 2 Nov 2022 16:44:24 -0400 (EDT) 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 4493F8E0001 for ; Wed, 2 Nov 2022 16:44:24 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 111E84094C for ; Wed, 2 Nov 2022 20:44:24 +0000 (UTC) X-FDA: 80089680048.23.6D0D6F2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 9049F180002 for ; Wed, 2 Nov 2022 20:44:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667421863; 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=W/vNqEe9kdMiUGr3xRIJxtzc4rwHsL9U2+4y8NsyPqk=; b=i0Udu18c8G0MYlV4wUfX6xDGAdLyuMtReytEncKcBmxavlEbeqpEZ6QkWfJLTOmc65AruM KRkBa67XkXV6ncV5aGtveEsWSYSkz+Fb55qlKRgbpP7N6H1aSKDua/eH3Agpnjj4/UyWyF 88mwy+5iVQab7jb92abTSd+XZFPcND8= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-630-qtVoAGErMSGHgq298X20iw-1; Wed, 02 Nov 2022 16:44:21 -0400 X-MC-Unique: qtVoAGErMSGHgq298X20iw-1 Received: by mail-qt1-f197.google.com with SMTP id s14-20020a05622a1a8e00b00397eacd9c1aso73001qtc.21 for ; Wed, 02 Nov 2022 13:44:21 -0700 (PDT) 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=W/vNqEe9kdMiUGr3xRIJxtzc4rwHsL9U2+4y8NsyPqk=; b=lT0IpttjIuet7NXjKTj9Kd9wOqlCz3K0VhTCZzmroBP0n/Eb8kpBBb1QgmnZoNGxOQ TpZyh8EMHmlxhTeTrd9pyOr5s6KjxqtFK1VkR40u8TUwFe/6TcXA/Sb0UyBoQD50HZwv 2DOVZJacTQGQVJAE9VYtrwLAVtTrYtOXw2UZhOYBJZJjx9J0pw7uNPdkQTckR9woHQ7e 7fcGF/EIGmlVg89MM8BnR4h1aweIRGztqc9AKNWLZrBQYUQTrXo9fh5ooD9Yqhpkws+X 2vomO1peRh+tYZUVSZv+5Ca/b7lxUyqlEo9f7uHr19HgF3rsi6Gmih/+nqRPOsnsqSbw 8yWQ== X-Gm-Message-State: ACrzQf1BJoMIMtV8g+ZkADEq5TJCVvmYq1UrLIFM35rPgtzB3Usq2zNQ XSp6jWjfgfHkibsDaX/ZssQHe2Rylezlvymmo9RJ5tpZuFd1qBsXLgJcJgOzJZiI5oulSKu+gXh 9p7yuYKqNnYQ= X-Received: by 2002:a37:c4d:0:b0:6fa:b44:1610 with SMTP id 74-20020a370c4d000000b006fa0b441610mr18938084qkm.153.1667421860290; Wed, 02 Nov 2022 13:44:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM45PiqOchTm473K6yukASrI7J3XtwxvJ2ubdKVdWdx5zZccQ1R7pEO4ceI62cTHD1N+1bBGJA== X-Received: by 2002:a37:c4d:0:b0:6fa:b44:1610 with SMTP id 74-20020a370c4d000000b006fa0b441610mr18938066qkm.153.1667421860080; Wed, 02 Nov 2022 13:44:20 -0700 (PDT) Received: from x1n (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id w20-20020a05620a445400b006cbe3be300esm1873284qkp.12.2022.11.02.13.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 13:44:19 -0700 (PDT) Date: Wed, 2 Nov 2022 16:44:18 -0400 From: Peter Xu To: Matthew Wilcox Cc: "Vishal Moola (Oracle)" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, akpm@linux-foundation.org, Hugh Dickins , Axel Rasmussen Subject: Re: [PATCH 3/5] userfualtfd: Replace lru_cache functions with folio_add functions Message-ID: References: <20221101175326.13265-1-vishal.moola@gmail.com> <20221101175326.13265-4-vishal.moola@gmail.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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667421863; 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=W/vNqEe9kdMiUGr3xRIJxtzc4rwHsL9U2+4y8NsyPqk=; b=lyYfOANJV9eZRaF1JJAQNyFFVE31qBeBWUgWz6noHjLmGc7IkfkwgwN0ISSaUoaBBClHV0 xqfaRN5KC91i2aVHhhCSGYTcv8cTPKNgxSApXXLnr2kFtHBJakRw5CYlLN+RIWK4wqfJLR bQpcH8cJ2jRCj858/B+CL84Du80wTc0= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=i0Udu18c; spf=pass (imf06.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667421863; a=rsa-sha256; cv=none; b=M/JjRFRmqoF/Q4FPPYUiWXMkY0s5tDT5aN5j4lL4afAEx/GjdFLNbbj4fpC+hKsIA+51c9 DBKD5CtZw8Dex4SGrJLKuXrWTL+RLd0e2VlV4qO2SmjpGjLgdhdwnZlCX4E6PMC5qAS04V ClgreEZGUZ4gkYSSxbnPX6f158S/lt8= X-Stat-Signature: 4g6gt3kxrtynuqxpfuzhcx1ene181fxz X-Rspamd-Queue-Id: 9049F180002 X-Rspamd-Server: rspam06 X-Rspam-User: Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=i0Udu18c; spf=pass (imf06.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1667421863-880251 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: On Wed, Nov 02, 2022 at 07:21:19PM +0000, Matthew Wilcox wrote: > On Wed, Nov 02, 2022 at 03:02:35PM -0400, Peter Xu wrote: > > Does the patch attached look reasonable to you? > > Mmm, no. If the page is in the swap cache, this will be "true". It will not happen in practise, right? I mean, shmem_get_folio() should have done the swap-in, and we should have the page lock held at the meantime. For anon, mcopy_atomic_pte() is the only user and it's passing in a newly allocated page here. > > > diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c > > index 3d0fef3980b3..650ab6cfd5f4 100644 > > --- a/mm/userfaultfd.c > > +++ b/mm/userfaultfd.c > > @@ -64,7 +64,7 @@ int mfill_atomic_install_pte(struct mm_struct *dst_mm, pmd_t *dst_pmd, > > pte_t _dst_pte, *dst_pte; > > bool writable = dst_vma->vm_flags & VM_WRITE; > > bool vm_shared = dst_vma->vm_flags & VM_SHARED; > > - bool page_in_cache = page->mapping; > > + bool page_in_cache = page_mapping(page); > > We could do: > > struct page *head = compound_head(page); > bool page_in_cache = head->mapping && !PageMappingFlags(head); Sounds good to me, but it just gets a bit complicated. If page_mapping() doesn't sound good, how about we just pass that over from callers? We only have three, so quite doable too. -- Peter Xu