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 982D0C678D5 for ; Wed, 8 Mar 2023 15:08:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 15F3A6B0072; Wed, 8 Mar 2023 10:08:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E89A6B0074; Wed, 8 Mar 2023 10:08:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E7CA76B0075; Wed, 8 Mar 2023 10:08:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D1F966B0072 for ; Wed, 8 Mar 2023 10:08:22 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9AE561A0FCB for ; Wed, 8 Mar 2023 15:08:22 +0000 (UTC) X-FDA: 80546062044.30.A9532C5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf07.hostedemail.com (Postfix) with ESMTP id D791E4002C for ; Wed, 8 Mar 2023 15:08:19 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JxVAyuPU; spf=pass (imf07.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678288100; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2BnqD+81nCal2yLTQN92JWzrb8KpwRfcqu8eYT7DAKQ=; b=iwG0DKeymkNcEhyYsMFjY7Kcsfil0CEX9XVOC/FI0I25qCtNLXwFGjDJp/7cEkYSMYGiZ1 slpeWxOVhN/9uT3+CzqZQcNvHcfEnsGU8doVQbCiG5ui+uzBmnLqPRS67lF+FXNafTki7I YD/0zSvYXrtyMC+0G9Bcd7y6fhcOD24= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JxVAyuPU; spf=pass (imf07.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.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=1678288100; a=rsa-sha256; cv=none; b=tdmbaTYuiT/j27xpSeqht0Irwclx0ulW/oD4Fc43nKmFqI2UHYq54bXuU/cf4IPUbf0W+B pXz5MnQ2WwcY3WirmMzqt3XljfUm6MSDxdpuZ55LRKPRLOsG8Ir+N950pjwoI5LyUIfpkY uXhrRYNlNT2qrz/K8qc+zMqA4Dx6zZc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678288099; 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: in-reply-to:in-reply-to:references:references; bh=2BnqD+81nCal2yLTQN92JWzrb8KpwRfcqu8eYT7DAKQ=; b=JxVAyuPUn9YIYnNvvD/rK2gsc6YpLEnZrXzOMaWFNpaMqBC+BeNrPt5kaWT1hQAiTUL88C AXboRVST35kPtrbdJ1DGwgBVOet6hjMxClWHkzcolWFdqaDNmbxe82igYiuurFKj6pESvj xGuvq14Ipg3ixWdcYGVa+sbHtss1xP0= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-437-UPfMzyFhMdaOhdSOo3YENQ-1; Wed, 08 Mar 2023 10:08:17 -0500 X-MC-Unique: UPfMzyFhMdaOhdSOo3YENQ-1 Received: by mail-qk1-f200.google.com with SMTP id d4-20020a05620a166400b00742859d0d4fso9542287qko.15 for ; Wed, 08 Mar 2023 07:08:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678288097; h=in-reply-to:content-transfer-encoding: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=2BnqD+81nCal2yLTQN92JWzrb8KpwRfcqu8eYT7DAKQ=; b=LZSoBXyAN0dGxtp3OLCZJuEaopoW7UvJ94F7dEdHdSdcHaTC+Xkty/eWCMgmqorl/T hfnLjn7dUFxHjQKlv8ht2DPQKs/HtpvHBEjGQXEbeoZ42rViNMqAl2eY5jhg6p2Z8tYo 4n0o9FcLfzxcusXZqxUW8dhellNpNvCE0geytYyttHdhK9skeaklLum1rqP21iJaYr63 js8osyBuQWSGKB/NfLvyXxwxfxnu4NP5JERb3+jQR9XnQCbEcKaFSLh96RDLMo9K9vHT CSZtw58mamSif/XrEc1/J1aZuunRV8S+CLELtoI0JtSsKQORqMovFyg4MbtLcgMUn4D/ /zyQ== X-Gm-Message-State: AO0yUKUpHAkkA6+/80EbrpiYivcsuIokff2gq7CcpULGpQ1KQbvwp2tT j3qmoU76574GmJymB0i3VMOvsIua3xmQArUHthcE+0j/vvZVNmI6BwXSmx8MHbiwIjkm7nvXQUC ZOkaEchezO+k= X-Received: by 2002:ac8:5a96:0:b0:3bf:cc1b:9512 with SMTP id c22-20020ac85a96000000b003bfcc1b9512mr5698874qtc.1.1678288097349; Wed, 08 Mar 2023 07:08:17 -0800 (PST) X-Google-Smtp-Source: AK7set90507PYoUM+Jlyh4YHTT3wJEfvvW4+2hu/qzxxuItg/QPKpPxf3VHQA3LvpODkPX3Li/FGXQ== X-Received: by 2002:ac8:5a96:0:b0:3bf:cc1b:9512 with SMTP id c22-20020ac85a96000000b003bfcc1b9512mr5698828qtc.1.1678288097053; Wed, 08 Mar 2023 07:08:17 -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 b1-20020ac812c1000000b003bfa932525dsm11608784qtj.51.2023.03.08.07.08.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Mar 2023 07:08:16 -0800 (PST) Date: Wed, 8 Mar 2023 10:08:15 -0500 From: Peter Xu To: Nadav Amit Cc: Axel Rasmussen , Alexander Viro , Andrew Morton , Hugh Dickins , Jan Kara , "Liam R. Howlett" , Matthew Wilcox , Mike Kravetz , Mike Rapoport , Muchun Song , Shuah Khan , James Houghton , "linux-fsdevel@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "linux-kselftest@vger.kernel.org" Subject: Re: [PATCH v3 2/5] mm: userfaultfd: don't pass around both mm and vma Message-ID: References: <20230306225024.264858-1-axelrasmussen@google.com> <20230306225024.264858-3-axelrasmussen@google.com> <54D49E2C-F2EF-4C1E-AFE9-FD742CEA33EB@vmware.com> MIME-Version: 1.0 In-Reply-To: <54D49E2C-F2EF-4C1E-AFE9-FD742CEA33EB@vmware.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: dmhajr1qo9ttkayrd6jfequedtatphpw X-Rspamd-Queue-Id: D791E4002C X-HE-Tag: 1678288099-639859 X-HE-Meta: U2FsdGVkX19HT//AKf0F1Bw6CVZHm9jHwaH5jkAB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pMUCJFjtrtp8l+i0Ouc+9eVLtuVFXwRTBh+QcLhuMtF+d45rZzXjvOaEzy91JmUcTsigg4BRhPPdAdK8BNAVZ5Y/YBqJTK0d8WhZ+khk0cimeX7TJ3vUr0iG9TEGgLIGNmLv3ynzJlsI8NH1osMGkGnuwyqFsBYadz1G2xixxVZdat2NZ9Dh5iQiCHLfzs74M6xFz28NlhALCLztXLVIBhdoG9iGFf4dhUoTIFBY1WFNHFDsEwNcraxiHDustrHyvcYhoKh70DiBz8aT8mT0jAxSV8QS2gd/5G1RpqC/b9oxsbPcu60XeT81taxBY4K2Jvf7ZASFVktygSFCHC0F0gIJw== 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 Tue, Mar 07, 2023 at 01:44:05AM +0000, Nadav Amit wrote: > > > > On Mar 6, 2023, at 5:03 PM, Peter Xu wrote: > > > > !! External Email > > > > On Mon, Mar 06, 2023 at 02:50:21PM -0800, Axel Rasmussen wrote: > >> Quite a few userfaultfd functions took both mm and vma pointers as > >> arguments. Since the mm is trivially accessible via vma->vm_mm, there's > >> no reason to pass both; it just needlessly extends the already long > >> argument list. > >> > >> Get rid of the mm pointer, where possible, to shorten the argument list. > >> > >> Signed-off-by: Axel Rasmussen > > > > Acked-by: Peter Xu > > > > One nit below: > > > >> @@ -6277,7 +6276,7 @@ int hugetlb_mfill_atomic_pte(struct mm_struct *dst_mm, > >> folio_in_pagecache = true; > >> } > >> > >> - ptl = huge_pte_lock(h, dst_mm, dst_pte); > >> + ptl = huge_pte_lock(h, dst_vma->vm_mm, dst_pte); > >> > >> ret = -EIO; > >> if (folio_test_hwpoison(folio)) > >> @@ -6319,9 +6318,9 @@ int hugetlb_mfill_atomic_pte(struct mm_struct *dst_mm, > >> if (wp_copy) > >> _dst_pte = huge_pte_mkuffd_wp(_dst_pte); > >> > >> - set_huge_pte_at(dst_mm, dst_addr, dst_pte, _dst_pte); > >> + set_huge_pte_at(dst_vma->vm_mm, dst_addr, dst_pte, _dst_pte); > >> > >> - hugetlb_count_add(pages_per_huge_page(h), dst_mm); > >> + hugetlb_count_add(pages_per_huge_page(h), dst_vma->vm_mm); > > > > When vm_mm referenced multiple times (say, >=3?), let's still cache it in a > > temp var? > > > > I'm not sure whether compiler is smart enough to already do that with a > > reg, even if so it may slightly improve readability too, imho, by avoiding > > the multiple but same indirection for the reader. > > I am not sure if you referred to this code specifically or in general. In general. IIRC there're more than one such case in this patch. > I once looked into it, and the compiler is really stupid in this regard > and super conservative when it comes to aliasing. Even if you use > “restrict” keyword or “__pure” or “__const” function attributes, in > certain cases (function calls to other compilation units, or inline > assembly - I don’t remember) the compiler might ignore them. Worse, llvm > and gcc are inconsistent. > > From code-generated perspective, I did not see a clear cut that benefits > caching over not. From performance perspective the impact is negligible. I > mention all of that because I thought it matters too, but it mostly does > not. > > That’s all to say that in most cases, I think that whatever makes the code > more readable should be preferred. I think that you are correct in saying > that “caching” it will make the code more readable, but performance-wise > it is probably meaningless. Thanks for the knowledge. I would suspect no matter how the output layout of the compilers will be the difference will be small. I prefer it more for readability as you said but not strongly either way. -- Peter Xu