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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 504A5C001DC for ; Wed, 19 Jul 2023 08:21:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:Message-ID: In-Reply-To:Subject:cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7lcRyZfCQKr0SB/unzIajG4fcPzGg+Q1/r4+/DXsgtw=; b=qZi1Ui2oaAnDwj p6kqSRZfZRI/h0r3eJmf3S1y7tga6wAzkJ2p22LvdLzoUOFRvPmug5EzpO52hND/dvVKp19AxOunR 3zQO1y6pKQ/uYmK/cxH99/tNIJ+wXVx8KciaY8oXTf2I47TVTKx8ayMf+4xSh/T+VJHM0g5tsIz2P kVjDdWtfoxosQE3qLhK0KE7qCaOZe8sYVqiPmg6B12hCVnxD3IRNvjJ3wrVAwMR35e6BlWQIUt51p 43lFh4zL7SHD8QwGC76BP+oY3hDYlPJ9WILYHJ4Jq1/OTvPk4YHQ/8vsKHl4dSrx+rbDFHO59/06I NduQg7w+4eN5Yuoquucw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qM2QO-006Inp-2i; Wed, 19 Jul 2023 08:20:44 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qM2QI-006Ikb-0W for linux-arm-kernel@bombadil.infradead.org; Wed, 19 Jul 2023 08:20:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Message-ID:In-Reply-To:Subject:cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=ZLu2xhwd4SAqbSYI2ps1VyFCry+LyNldvcwZWPQNIvo=; b=kE1rj6hT4IpsuXlwWAbwyeMLg8 FO0QqImE1eY8D4hGjNj/SdH6UweyGHJ46hDJw/xf4aI/s20EBtsy4Mvbg3GyCcu0sUISNA3DWAlSH +wX2s6XhB6pz6/I8XBjMHciHP4o181UFcffPR8JVOsLwmdXQQB9+lccY3O5OKAEsO5W9WntjI25uK ndF1q3WQG1mfIchkkd6HpABC8uz0TOizf5/9O6hgKAnaMk/FGNaxl5iLM8zn+DerqZoGg2DwUdYYW Li+Gw5XfEVa6wdr9C9oJo3SS07ABtE+wzfvxE39jkHJ0Dms3CPJrAkuKMGre6Eocd6FFmSfQSEqAJ rkkj2lFA==; Received: from mail-yb1-xb30.google.com ([2607:f8b0:4864:20::b30]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLXnj-009Scx-35 for linux-arm-kernel@lists.infradead.org; Mon, 17 Jul 2023 23:38:50 +0000 Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-bff89873d34so3821998276.2 for ; Mon, 17 Jul 2023 16:38:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689637062; x=1692229062; 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=k9GbXOYqPe1POhby7opK5kclsobljuvSzYRz76LxTowmpjIJR51rHEsa/yMmfrNLqD Tx4kCMNCwjq5YXwP018228iomQaNPdM3GDlsazU1hVWtrnBNJ79PmOggaaMmyYtQSVFj /8hsbtkFxoXWDYPpBRhOoq1X2gAYexB2wShawSOOUGS5+lYJhd3LDyigzAMix5UgaKww CG7lL2pMXLSVSK1RTDS/lgzSXnvShQzpWdMiRaxfe9dQ5E+8Fbrrngyu27DzmzUSFTGO dXgfcxfYHfaAP3EZDPV7qeD1XhCeYDZANKuXxc+riOKnWQl9GUKFj4HBYfXczIocRlPN lH5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689637062; x=1692229062; 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=cGKYk7T/tWzXyAMBAd+Aa0tgRpdwXZZ2kln/lcGaVyLg7u/PWxrbU/13xKThn70mZF 9Wct1LoJPGJ0JjeJwmg+GZfNMnaxyHgTUVWfGTlDCKx9XBqE1QaFOydn8LXYdAr8nVMo m2izUHgRt/gkpfBRfNyJliCjSp33Tezhas5vCH/bRjJIaa6CwWsAVgikK8QPYJkmRz1s sY0/LwGFqEYTcOVRs1wbVY1CVHTIoHeH1a1u6upJ+x5Mbp2mN/o9AUkmKcr6kLXo1G5M K8ic6u0esz3V2d1TZjW3n5qtBlOwBwli4hvm/qGM5ET0pREtJh6DALneeDJOr7FjhoQl 6Y1Q== X-Gm-Message-State: ABy/qLbBCWvnLvzaZXrBvpTktq87ADdr1P8D56BYL2U42DTtBaQqN9Bb dTA77MOuULUQ/6NyyuQCS/9w/w== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230718_003848_268086_E1475698 X-CRM114-Status: GOOD ( 28.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel