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 11924C4332F for ; Thu, 3 Nov 2022 17:35:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4ECAF6B0072; Thu, 3 Nov 2022 13:35:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 49D246B0073; Thu, 3 Nov 2022 13:35:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 364A96B0074; Thu, 3 Nov 2022 13:35:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 248206B0072 for ; Thu, 3 Nov 2022 13:35:20 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D7D68C0D58 for ; Thu, 3 Nov 2022 17:35:19 +0000 (UTC) X-FDA: 80092832358.02.121D957 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) by imf20.hostedemail.com (Postfix) with ESMTP id 4D6111C0006 for ; Thu, 3 Nov 2022 17:35:19 +0000 (UTC) Received: by mail-lf1-f44.google.com with SMTP id be13so4049472lfb.4 for ; Thu, 03 Nov 2022 10:35:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=nbc5sLo4GtFM3+CrjPxJa3FUz65TVuj3idceDshPhx4=; b=Gn5IZG7BOHVOBTuMOBcjNXxPjeolIRNHRVpauV2nqG9N5UUKknJaArW6gDsufzjd0L gVL0m43iclxR+zBnj9MMlyKToMT+/mimOdJyztrBuRcSy7sxCwBS9lS0wATTWIORIjGW XvaDl8tm8xEdFZca6VSXMudYB/kz0siWXxNy/UEuwYTCqEPaDk/wKBFVr3oNcQPoSIqh 0rmI0KUq0E4QXyAhmYIde2LLM4evQ2C2oAnx/26L4RNDXvrSZ/8WJ6gTAPXrZbe1ay9T Bmt5oEvcukzbI4Rezy4U5PTu3bubW4clu2rHJRwG8oCYCNzwn5SBHTyFCzchnMHyaCdU Q73g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nbc5sLo4GtFM3+CrjPxJa3FUz65TVuj3idceDshPhx4=; b=CDvRgxH/wHhCPZfJJf277bmZd4GLbIsu2CmiTx08lNQNVGMBEdsjaU10PzLY5RVfiV VJJCaIDqf/myRJ/7E0MbVbsYtqLpJ64/cL3fobps2OTq9Fbc27WfUa07UWFsvFbSmqpp F0H6ZfOB2yk4NOSATnSb5J+CNt4kSiU30uz1eqPTK04bi/Fbbes3n+njhYnamTxnVPQb /aYyh6Ugp73BMuXvy35wE0cbKTNeKgYNM2zLlqPaLD+VPLPuESiP6AJRSQTzBLwKkiue p0nGQhCiEFRXWndqThP9j0lpt0NqURRn7wmMfw9O9e3Po/6/sGQ65s0Kfz4nMjRMunRh gnng== X-Gm-Message-State: ACrzQf2ODUy87F53Eeo8wmaqiPbFwbW7iL1Kp0a/uJrvy92tTY/V5wFz vSVAmkrsn8NOo+7JklVAxrtxLWaoZOLhCuS3HJos9A== X-Google-Smtp-Source: AMsMyM7EJNOVEGyOCeEHgo74cDzxE4T1yFulU/v18cx9x7m6GcDlFRNGIcw4cn8WGmS4u1u9Xxkff71gyckQBcqL+L4= X-Received: by 2002:a05:6512:110f:b0:4a2:697f:c39a with SMTP id l15-20020a056512110f00b004a2697fc39amr11456204lfg.685.1667496916076; Thu, 03 Nov 2022 10:35:16 -0700 (PDT) MIME-Version: 1.0 References: <20221101175326.13265-1-vishal.moola@gmail.com> <20221101175326.13265-4-vishal.moola@gmail.com> In-Reply-To: From: Axel Rasmussen Date: Thu, 3 Nov 2022 10:34:38 -0700 Message-ID: Subject: Re: [PATCH 3/5] userfualtfd: Replace lru_cache functions with folio_add functions To: Peter Xu Cc: Matthew Wilcox , "Vishal Moola (Oracle)" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, akpm@linux-foundation.org, Hugh Dickins Content-Type: text/plain; charset="UTF-8" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667496919; 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=nbc5sLo4GtFM3+CrjPxJa3FUz65TVuj3idceDshPhx4=; b=QIGKq5AHb9vG8/6OqY8ERYsT3Qu9BLln1DM9kG7jdTWVR4nHOXp1+KB/XZQEhSQhNUfw7V PaxesoeZvK/lt/JFo+F6XlV8wagbO+PE1fTpAo14qIbh7aJ7pDoYhdNYaNzp95tOR8zZbw vaqwWPZjSL7MTh2ZA0+7SODxXgQEBVY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Gn5IZG7B; spf=pass (imf20.hostedemail.com: domain of axelrasmussen@google.com designates 209.85.167.44 as permitted sender) smtp.mailfrom=axelrasmussen@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667496919; a=rsa-sha256; cv=none; b=INyaHnjn0UrHzIgfVK+W1et4R9JvUHgZaJOYhv6fpAcQqaMAomjt5uc4q3++pi0j17Q/d5 jv73h6eCD2tLhjSsk8LDHPjG+EAuMNdHPdEHi9g8SYb94dtWb/2Yl7WCdZzgeqKIiKRt3s Y+vrJAOp/qjNG/OxPnVsd7IKc90HrW0= X-Stat-Signature: 3m98ksyj6th96bw4k1ce6w6i8th55ie1 X-Rspamd-Queue-Id: 4D6111C0006 X-Rspamd-Server: rspam06 X-Rspam-User: Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Gn5IZG7B; spf=pass (imf20.hostedemail.com: domain of axelrasmussen@google.com designates 209.85.167.44 as permitted sender) smtp.mailfrom=axelrasmussen@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1667496919-211376 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 2, 2022 at 1:44 PM Peter Xu wrote: > > 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. For what it's worth, I think I like Matthew's version better than the original patch. This is because, although page_mapping() looks simpler here, looking into the definition of page_mapping() I feel it's handling several cases, not all of which are relevant here (or, as Matthew points out, would actually be wrong if it were possible to reach those cases here). It's not clear to me what is meant by "pass that over from callers"? Do you mean, have callers pass in true/false for page_in_cache directly? That could work, but I still think I prefer Matthew's version slightly better, if only because this function already takes a lot of arguments. > > -- > Peter Xu >