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 EF5BEEB64DC for ; Mon, 17 Jul 2023 23:37:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 680D66B0071; Mon, 17 Jul 2023 19:37:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6315C6B0074; Mon, 17 Jul 2023 19:37:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D2CE8D0001; Mon, 17 Jul 2023 19:37:44 -0400 (EDT) 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 3EF2F6B0071 for ; Mon, 17 Jul 2023 19:37:44 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 197AAC0452 for ; Mon, 17 Jul 2023 23:37:44 +0000 (UTC) X-FDA: 81022718448.02.04EFE3E Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) by imf13.hostedemail.com (Postfix) with ESMTP id 429A220008 for ; Mon, 17 Jul 2023 23:37:42 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=xgmV+C3G; spf=pass (imf13.hostedemail.com: domain of hughd@google.com designates 209.85.219.177 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689637062; 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=ZLu2xhwd4SAqbSYI2ps1VyFCry+LyNldvcwZWPQNIvo=; b=nbbL9DQh9Km1/JeAp2FeCQ7XzuaNiMU1fqDt2+TqYPBI72Myu7y3Fx9NMzkJqk3+cVk/+o DbGApCmF5K4bUbu8seVPyIOfsHNcTh8+7ssB3pMjjAsS1+DI2WTcDwhiKcE7nQ5HVMrQCz 2O3d6chS2kp6IsjfxDbQ5LldFuY8/H8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689637062; a=rsa-sha256; cv=none; b=cZItgOMmZBxf9YXlBGfP6boO9O5ajN1rK4RJLJNKCioaX11T2CAcI++k/sww67BCstUQzh JPHLOGR+dJht5ffkkKsourzcdKZSOvkhox+2ys6Tk5ir4HGNbUizst+jAsVzGf1K+uaWqq ewFiaXfJVmorSEmzET6mBW7sNRBGk6o= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=xgmV+C3G; spf=pass (imf13.hostedemail.com: domain of hughd@google.com designates 209.85.219.177 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-c01e1c0402cso3828338276.0 for ; Mon, 17 Jul 2023 16:37:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689637061; x=1692229061; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=ZLu2xhwd4SAqbSYI2ps1VyFCry+LyNldvcwZWPQNIvo=; b=xgmV+C3G4eKZrk06U+JRuxOEbOvrN8vsGVx7JH5ITC5xHrh8dYiRF7tBA0EJtNrDP2 wOqChQD4Jrv4EbshHiPvhsxYuat1xtKSTyUoK8bv/Mwf8W3j50zYsrqP0nm5bwbGZW8l bpUdpXg3sWLAOzI0goJtj1gpJ8tIDaKzOBSrYC4SXKq1naWk5HgzCuPjAm7yEXt2z7ct eLnrySKUHZmL3iguIw3nA5turmozcLLMv2kKOzdDFs2O+ZKzrWiZIcl4DCjlsVcdQ0/f lsZ4XFCgYcb3pH0LH+U+WL7ciZp6yBKJPcDKZZWrT1WkhCS960H684y8mePbsVJneIz9 +7RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689637061; x=1692229061; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZLu2xhwd4SAqbSYI2ps1VyFCry+LyNldvcwZWPQNIvo=; b=Sb7GQT5tWO6wd7GJXXs+UXCyRDElrkE4NHPywxmVz2m6OKNlVszcvKrfmN1GeRUhnX OD87C/nnyCxFIf8gSZbSBlN8CRJTOQL8BJ9ujEsANn6wrsFge5A5R/nAMvUfgLcwAA8E mOc94OuVSjmudhI0RNTIxWMZMDzQdex9j79BPzbQOgCTdYAfWnwS9GBDnVZIT4V1D2cF fiqJcZfn1V4IhXxRZ9tpONgc8mr/tVkhuX1IXRhBdIJs1MWJS3wpBZG8pnnK0Bo8yohk AGRwb81eCmVKgmmolUdr1crquzqiw5ikmuaZNvdWdPVpumMrQR9tr60+be5otIhu2rHa curg== X-Gm-Message-State: ABy/qLY+ZZuiF8kuUu8gcz3mxr27zAwFtMqF+R2Pi0T3LBgVX6MWFeFj nVE2PA8wGY6AjBxkicTvhF4SnA== X-Google-Smtp-Source: APBJJlHbG9lgcp914LKgXhja8Amg4xcjiZMX1if2yS+Nn7RkrbWXjIgJApIlAYuBISZHBJ/wewImPQ== X-Received: by 2002:a81:4f0c:0:b0:56d:2f9d:42cc with SMTP id d12-20020a814f0c000000b0056d2f9d42ccmr7057474ywb.51.1689637061083; Mon, 17 Jul 2023 16:37:41 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id d126-20020a0ddb84000000b00577139f85dfsm151563ywe.22.2023.07.17.16.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jul 2023 16:37:40 -0700 (PDT) Date: Mon, 17 Jul 2023 16:37:31 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Ryan Roberts cc: Yu Zhao , Hugh Dickins , Matthew Wilcox , Andrew Morton , "Kirill A. Shutemov" , Yin Fengwei , David Hildenbrand , Catalin Marinas , Will Deacon , Anshuman Khandual , Yang Shi , "Huang, Ying" , Zi Yan , Luis Chamberlain , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v3 3/4] mm: FLEXIBLE_THP for improved performance In-Reply-To: <5df787a0-8e69-2472-cdd6-f96a3f7dfaaf@arm.com> Message-ID: <8bdfd8d8-5662-4615-86dc-d60259bd16d@google.com> References: <20230714160407.4142030-1-ryan.roberts@arm.com> <20230714161733.4144503-3-ryan.roberts@arm.com> <432490d1-8d1e-1742-295a-d6e60a054ab6@arm.com> <5df787a0-8e69-2472-cdd6-f96a3f7dfaaf@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Rspamd-Queue-Id: 429A220008 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: a4dxqtu3ebj6exgyhcezi76mbf1k57yb X-HE-Tag: 1689637061-833171 X-HE-Meta: U2FsdGVkX18rYrKdcl5lS72Njt/4ETWM/6uMnWsdoLxLyLCo4zDJ2IfDUayaPH6umdDzrhsU1vkiGytBenuMAeKdShKtzmFjom1jqlGoQBGMZFU4M5WF5odYU5343Vrjr8BVA2AQcPgKanSnO+T64K6ttawrhDibdd6DLRLW6XDtbFKMkYikzBrWOkgvS7qwDs4vvU7KCz5lpf/clM8J6cxyUxjzGtEkCJtz8HjylbHHkdSkY+nJNPR3wVJaiAOImNJreP1JPVd50MEwQqMvxR+0RevyU/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J3Fgp+HTBUPgGoBHkpyiudWpKnYob3U+q0/v2VFjDNfYwWVaTM2E 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 Mon, 17 Jul 2023, Ryan Roberts wrote: > >>>> +static int alloc_anon_folio(struct vm_fault *vmf, struct folio **folio) > >>>> +{ > >>>> + int i; > >>>> + gfp_t gfp; > >>>> + pte_t *pte; > >>>> + unsigned long addr; > >>>> + struct vm_area_struct *vma = vmf->vma; > >>>> + int prefer = anon_folio_order(vma); > >>>> + int orders[] = { > >>>> + prefer, > >>>> + prefer > PAGE_ALLOC_COSTLY_ORDER ? PAGE_ALLOC_COSTLY_ORDER : 0, > >>>> + 0, > >>>> + }; > >>>> + > >>>> + *folio = NULL; > >>>> + > >>>> + if (vmf_orig_pte_uffd_wp(vmf)) > >>>> + goto fallback; > >>>> + > >>>> + for (i = 0; orders[i]; i++) { > >>>> + addr = ALIGN_DOWN(vmf->address, PAGE_SIZE << orders[i]); > >>>> + if (addr >= vma->vm_start && > >>>> + addr + (PAGE_SIZE << orders[i]) <= vma->vm_end) > >>>> + break; > >>>> + } > >>>> + > >>>> + if (!orders[i]) > >>>> + goto fallback; > >>>> + > >>>> + pte = pte_offset_map(vmf->pmd, vmf->address & PMD_MASK); > >>>> + if (!pte) > >>>> + return -EAGAIN; > >>> > >>> It would be a bug if this happens. So probably -EINVAL? > >> > >> Not sure what you mean? Hugh Dickins' series that went into v6.5-rc1 makes it > >> possible for pte_offset_map() to fail (if I understood correctly) and we have to > >> handle this. The intent is that we will return from the fault without making any > >> change, then we will refault and try again. > > > > Thanks for checking that -- it's very relevant. One detail is that > > that series doesn't affect anon. IOW, collapsing PTEs into a PMD can't > > happen while we are holding mmap_lock for read here, and therefore, > > the race that could cause pte_offset_map() on shmem/file PTEs to fail > > doesn't apply here. > > But Hugh's patches have changed do_anonymous_page() to handle failure from > pte_offset_map_lock(). So I was just following that pattern. If this really > can't happen, then I'd rather WARN/BUG on it, and simplify alloc_anon_folio()'s > prototype to just return a `struct folio *` (and if it's null that means ENOMEM). > > Hugh, perhaps you can comment? I agree with your use of -EAGAIN there: I find it better to allow for the possibility, than to go to great effort persuading that it's impossible; especially because what's possible tomorrow may differ from today. And notice that, before my changes, there used to be a pmd_trans_unstable() check above, implying that it is possible for it to fail (for more reasons than corruption causing pmd_bad()) - one scenario would be that the pte_alloc() above succeeded *because* someone else had managed to insert a huge pmd there already (maybe we have MMF_DISABLE_THP but they did not). But I see from later mail that Yu Zhao now agrees with your -EAGAIN too, so we are all on the same folio. Hugh p.s. while giving opinions, I'm one of those against using "THP" for large but not pmd-mappable folios; and was glad to see Matthew arguing the same way when considering THP_SWPOUT in another thread today.