Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp2959172rdh; Mon, 27 Nov 2023 03:29:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IF7SolYcbidfGcjB+Srb3jIOro/Og6w98+UEziB5/ST1Q2JRAw8tcnMKIboGqtpnKS0+Feg X-Received: by 2002:a05:6808:2381:b0:3b2:db24:6384 with SMTP id bp1-20020a056808238100b003b2db246384mr14780101oib.38.1701084547308; Mon, 27 Nov 2023 03:29:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701084547; cv=none; d=google.com; s=arc-20160816; b=SN/I2zdtn/TPs+o4iXgSuyOwcZzdtGh0zDSHp6PC0yFVFJYsG0v72B0sQbO8MsDe6O kV/EoM4I/IIxBaCEXJhqhEHbwpuZDxVR3QsHFyh9uY+cjM5mPlPz2I73SV+wgB/RNggT g8QqENAi/UBsZkpMnuPD74TwlaM7G3RUZDpZMSI0eDNQTOftkLUzjiLJUXuNnsjCi0sS 8h8jHSGhDXzfCFuEqiCogQK+1wXpKwhHSImHigu3JnvdPRT0sa21SHP4wIOn/Sso5zR+ oY/pO1ciMEsTvAza4d3OUlaL8s3CY+KyKaT0cibXnTSOxZaD4jueLd/RUJHNLUJieVUC cTNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=EB+S+jQIam85ubwvaV7N4Poa2E0R4HF5clPbLUTQZXk=; fh=T1vs46TCCoF4pbUyjBsdSzYx80GdyXOTIvnat0bBwqw=; b=ckedjZuEqRrKS8tv23jWtfAY2Ye5yKpLoigFEDwycQYWYR+uCVAtoWBup4ORG5eFev M9JV1EWnQs3RAyM/vBSz8QhbOpYdf7nwxdecXWDbYZj0+5s0l/1aWaUnN85+IFmms+bQ iwXSqfJqoj4h10Mu3wZHYv0FWZMTEqwVnN8Dre/Rrrb0Zs6kTY331PLHHn0H0nK67QL/ sPCtih2vJAplCkHivZpJvUWgAuul1P3r1TkquibwQxQMOpJyLsfZsbdx+nBpa4qLLIxq GURrVY689mCwnf/MTCiOL0+HieQiKbsex0Hl2Bedk5LBvECwSsdQbH0QDcFnO1/zJPSb qzfw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id r9-20020a63fc49000000b005be209ac7fesi9405105pgk.744.2023.11.27.03.29.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 03:29:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id DA993807F647; Mon, 27 Nov 2023 03:29:04 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233202AbjK0L2r (ORCPT + 99 others); Mon, 27 Nov 2023 06:28:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233158AbjK0L2q (ORCPT ); Mon, 27 Nov 2023 06:28:46 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9A5D1B8 for ; Mon, 27 Nov 2023 03:28:52 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DF9142F4; Mon, 27 Nov 2023 03:29:39 -0800 (PST) Received: from [10.57.73.191] (unknown [10.57.73.191]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F21143F73F; Mon, 27 Nov 2023 03:28:48 -0800 (PST) Message-ID: <4785ad95-7af7-4d41-9997-e97b2a8e9666@arm.com> Date: Mon, 27 Nov 2023 11:28:47 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RESEND PATCH v7 04/10] mm: thp: Support allocation of anonymous small-sized THP Content-Language: en-GB To: Barry Song <21cnbao@gmail.com> Cc: akpm@linux-foundation.org, anshuman.khandual@arm.com, catalin.marinas@arm.com, david@redhat.com, fengwei.yin@intel.com, hughd@google.com, itaru.kitayama@gmail.com, jhubbard@nvidia.com, kirill.shutemov@linux.intel.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mcgrof@kernel.org, rientjes@google.com, shy828301@gmail.com, vbabka@suse.cz, wangkefeng.wang@huawei.com, willy@infradead.org, ying.huang@intel.com, yuzhao@google.com, ziy@nvidia.com References: <20231122162950.3854897-5-ryan.roberts@arm.com> <20231127034135.6754-1-v-songbaohua@oppo.com> From: Ryan Roberts In-Reply-To: <20231127034135.6754-1-v-songbaohua@oppo.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=1.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SORTED_RECIPS,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 27 Nov 2023 03:29:05 -0800 (PST) X-Spam-Level: * On 27/11/2023 03:41, Barry Song wrote: >> + if ((nr_pages == 1 && vmf_pte_changed(vmf)) || >> + (nr_pages > 1 && !pte_range_none(vmf->pte, nr_pages))) { >> + for (i = 0; i < nr_pages; i++) >> + update_mmu_tlb(vma, addr + PAGE_SIZE * i, vmf->pte + i); >> goto release; >> } > > Hi Ryan, > what has stopped nr_pages == 1 from using !pte_range_none(vmf->pte, 1) > directly, then the code can become, > + if (!pte_range_none(vmf->pte, nr_pages)) { > + for (i = 0; i < nr_pages; i++) > + update_mmu_tlb(vma, addr + PAGE_SIZE * i, vmf->pte + i); > goto release; > } > > for both 1 and > 1 cases? We can get to do_anonymous_page() from 2 routes: - page fault on unallocated memory (pte_none()) - page fault on uffd_wp pte marker In the latter case, we guarrantee that we are only operating on nr_pages == 1 because when uffd is in the picture we need to preserve any uffd state per-pte. It also means we can't just check the pte is none because in this case it is not none, it has a pte marker so we need to check it hasn't changed. I was previously abstracting this in vmf_pte_range_changed() but there were complaints [1] about the semantic being different based on the number of pages, so this was my attempt to make it more understandable. [1] https://lore.kernel.org/linux-mm/a6fa0847-a950-4044-972c-e5dc8cbc7922@arm.com/ Thanks, Ryan > > Thanks > Barry >