Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17452898rwd; Tue, 27 Jun 2023 03:17:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4k7ADJ2eY4/Fb6Tbfa39KirotjZyFJliwWCGuOSA43Sc8MHee1S3zOfPGexbHJrz+7Yb/6 X-Received: by 2002:a05:6e02:105:b0:340:ba08:3c34 with SMTP id t5-20020a056e02010500b00340ba083c34mr21930477ilm.11.1687861047045; Tue, 27 Jun 2023 03:17:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687861047; cv=none; d=google.com; s=arc-20160816; b=TX3WIME6HX0RifxlxklM5WswuDq0sTZtmVD4hNvtt64DAv7xBsII++98iOiQb50Cgj PDxp+lWKC3pi/PTi++UKDujkIp5k2yElqyqDh1jzlNGJ0v7HiY4W3kbmcN1TrKr2XC3Q 5eaZ3KGY4+u1eZkLIggQmAVuTXZ7QcGm1cAZiVIa6DiNimhABJNC7gwpDJsbucNVPx7T 3xl7eJLorrYXovxHyFaswXAYIBHNPVF4015jgJNUqRvbDM2Y/AVOxFnb5E6CvmBbCdVd YwNszLbuqXUf+4A3iYjMJNs30rZ6B3VZWpjAuFQ8SzzPVVAT/cX1Wa8+aaRx7fu5i9vr svaQ== 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:subject:user-agent:mime-version:date:message-id; bh=BVG+eXhnumlStBMFiTtXqE0aHsN1KbFoVO3Hrh5XUn4=; fh=LqvJMcFFyFVvpNq2QvzlJ3CnsFAYS/pnAlYmQGhubew=; b=R9ak0OAvdWC84dVqE4bIaKycr3JP1wvCbWv/dBDJlBT3FNXyCA+A+3fUzt+2WCMunR /Jo7/G3lcIf8GjpRBul4eAQcWhFk4qATCoV/u2v+s9oVgxh0z6yhoJ+aLZP9XryUzef3 INGmroahpHX4sQMvKoAsVgwfjQIK6Z7iDixO8GmbWb1AX06ViupgglmXZ9S1evIs3lWC HmSSDbobuQfHpnk+B0lsJrfKZr5fuxbA6loYWhXXC+UdrECBapIJ70HduHWS7kG0BER2 KjsBDL/YzPxRCbp7N8lsOoMJxu10dMMV1mk/lfS5FBw/4tfPqeXUZG9hM+9PgA1MmSWZ WYWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e190-20020a6369c7000000b00553800fe4dcsi6819619pgc.583.2023.06.27.03.17.14; Tue, 27 Jun 2023 03:17:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231974AbjF0KAn (ORCPT + 99 others); Tue, 27 Jun 2023 06:00:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232137AbjF0KAC (ORCPT ); Tue, 27 Jun 2023 06:00:02 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1F05330E4; Tue, 27 Jun 2023 02:57:51 -0700 (PDT) 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 E20E92F4; Tue, 27 Jun 2023 02:58:34 -0700 (PDT) Received: from [10.1.30.74] (C02Z41KALVDN.cambridge.arm.com [10.1.30.74]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 202713F64C; Tue, 27 Jun 2023 02:57:48 -0700 (PDT) Message-ID: <0c98f854-b4e4-9a71-8e0c-1556bc79468c@arm.com> Date: Tue, 27 Jun 2023 10:57:46 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH v1 10/10] mm: Allocate large folios for anonymous memory To: Yu Zhao Cc: Andrew Morton , "Matthew Wilcox (Oracle)" , "Kirill A. Shutemov" , Yin Fengwei , David Hildenbrand , Catalin Marinas , Will Deacon , Geert Uytterhoeven , Christian Borntraeger , Sven Schnelle , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-s390@vger.kernel.org References: <20230626171430.3167004-1-ryan.roberts@arm.com> <20230626171430.3167004-11-ryan.roberts@arm.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 27/06/2023 04:01, Yu Zhao wrote: > On Mon, Jun 26, 2023 at 11:15 AM Ryan Roberts wrote: >> >> With all of the enabler patches in place, modify the anonymous memory >> write allocation path so that it opportunistically attempts to allocate >> a large folio up to `max_anon_folio_order()` size (This value is >> ultimately configured by the architecture). This reduces the number of >> page faults, reduces the size of (e.g. LRU) lists, and generally >> improves performance by batching what were per-page operations into >> per-(large)-folio operations. >> >> If CONFIG_LARGE_ANON_FOLIO is not enabled (the default) then >> `max_anon_folio_order()` always returns 0, meaning we get the existing >> allocation behaviour. >> >> Signed-off-by: Ryan Roberts >> --- >> mm/memory.c | 159 +++++++++++++++++++++++++++++++++++++++++++++++----- >> 1 file changed, 144 insertions(+), 15 deletions(-) >> >> diff --git a/mm/memory.c b/mm/memory.c >> index a8f7e2b28d7a..d23c44cc5092 100644 >> --- a/mm/memory.c >> +++ b/mm/memory.c >> @@ -3161,6 +3161,90 @@ static inline int max_anon_folio_order(struct vm_area_struct *vma) >> return CONFIG_LARGE_ANON_FOLIO_NOTHP_ORDER_MAX; >> } >> >> +/* >> + * Returns index of first pte that is not none, or nr if all are none. >> + */ >> +static inline int check_ptes_none(pte_t *pte, int nr) >> +{ >> + int i; >> + >> + for (i = 0; i < nr; i++) { >> + if (!pte_none(ptep_get(pte++))) >> + return i; >> + } >> + >> + return nr; >> +} >> + >> +static int calc_anon_folio_order_alloc(struct vm_fault *vmf, int order) > > As suggested previously in 03/10, we can leave this for later. I disagree. This is the logic that prevents us from accidentally replacing already set PTEs, or wandering out of the VMA bounds etc. How would you catch all those corener cases without this?