Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4142461rwl; Tue, 28 Mar 2023 03:18:29 -0700 (PDT) X-Google-Smtp-Source: AKy350YJ+xjn3Uibn4H+HnyXa8ir0GJmB704FY3yOmi0Ro1O5vsIo1QaCl5Tfo48IOZBMwF8Gpae X-Received: by 2002:a17:90a:1917:b0:240:70dc:cf46 with SMTP id 23-20020a17090a191700b0024070dccf46mr11051106pjg.11.1679998709518; Tue, 28 Mar 2023 03:18:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679998709; cv=none; d=google.com; s=arc-20160816; b=Q/NSBRNRp4giTs8pVEmhu3ZTjFu6TPyDiMWbhRUV2bj2hrWhZXIJ5Sm1jDZGCUiEkB IKmVV4RpesVm1Rnqm3BVO5gEzPuYyC/KSDAH0RJC+l4NXTMw/8COYaDkqjMCU5bwrh/8 Ff6tCH89JqYbmXMLpzppb91k22sb3OuS1fV9BtJN44hcHN9QKnVLsWNDdu1f93MEZyTC V9VWUXuRa83SiWcAZFYiWFZAankg5kXwb+CdMANlTUNRG87taD0TIXrGY62RC0nYxV78 qrcPVb3ctFiZHY09/TTMe3pyRKyA9PZTH7vAkOBmvb+IrJ7s4T6CWKXqiYSJDaGFLf22 zMuQ== 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=YuWHlrgnjqi+E08CMvx3BkDBRZM025VHrWInVawRPxA=; b=PHhaJBZSdxsiNcUsH3ICmKOG2O8iZEqH95niTyTRgjBvJKDsTINfKS4vSGTTuAO/Ha hdRLw5YZ9tAY2Lkx1Y50AsMVRyAJqYoxnHD2vX+brlx2PgZ8/71KZoXfdLo3jAl3EvDs UMBBjox4oestPABS1eZdWCUgqJhBqJqTp79LalQP9ndjDLesidjKZKFs9YTPQHV3spFW A45dSqod4YhbLyEogQHwm76NLLxqiy3ATEiC1iYH73mi/cVH+gVTSTIo9tc7k2uJiIBw VvId11CZj9wuTZhvkBuNaD5WxITq31WCMOBLbTQCqIQH783+TCWVqzxZRH+WWUuBeLNJ ErhQ== 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 n9-20020a170902e54900b001994712728csi30279887plf.607.2023.03.28.03.18.18; Tue, 28 Mar 2023 03:18:29 -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 S232563AbjC1KNX (ORCPT + 99 others); Tue, 28 Mar 2023 06:13:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229608AbjC1KNR (ORCPT ); Tue, 28 Mar 2023 06:13:17 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0B13C1FEC for ; Tue, 28 Mar 2023 03:12:56 -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 75ACEC14; Tue, 28 Mar 2023 03:13:40 -0700 (PDT) Received: from [10.1.33.143] (C02CF1NRLVDN.cambridge.arm.com [10.1.33.143]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8A6813F663; Tue, 28 Mar 2023 03:12:55 -0700 (PDT) Message-ID: <7981dd12-4e56-a449-980b-52f27279df81@arm.com> Date: Tue, 28 Mar 2023 11:12:54 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: What size anonymous folios should we allocate? Content-Language: en-US To: Vlastimil Babka , Matthew Wilcox , Yang Shi Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <022e1c15-7988-9975-acbc-e661e989ca4a@suse.cz> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.3 required=5.0 tests=NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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/03/2023 16:48, Vlastimil Babka wrote: > On 3/27/23 17:30, Ryan Roberts wrote: >> On 27/03/2023 13:41, Vlastimil Babka wrote: >>> On 2/22/23 04:52, Matthew Wilcox wrote: >>>> On Tue, Feb 21, 2023 at 03:05:33PM -0800, Yang Shi wrote: >>>> >>>>>> C. We add a new wrinkle to the LRU handling code. When our scan of the >>>>>> active list examines a folio, we look to see how many of the PTEs >>>>>> mapping the folio have been accessed. If it is fewer than half, and >>>>>> those half are all in either the first or last half of the folio, we >>>>>> split it. The active half stays on the active list and the inactive >>>>>> half is moved to the inactive list. >>>>> >>>>> With contiguous PTE, every PTE still maintains its own access bit (but >>>>> it is implementation defined, some implementations may just set access >>>>> bit once for one PTE in the contiguous region per arm arm IIUC). But >>>>> anyway this is definitely feasible. >>>> >>>> If a CPU doesn't have separate access bits for PTEs, then we should just >>>> not use the contiguous bits. Knowing which parts of the folio are >>>> unused is more important than using the larger TLB entries. >>> >>> Hm but AFAIK the AMD aggregation is transparent, there are no bits. And IIUC >>> the "Hardware Page Aggregation (HPA)" Ryan was talking about elsewhere in >>> the thread, that sounds similar. So I IIUC there will be a larger TLB entry >>> transparently, and then I don't expect the CPU to update individual bits as >>> that would defeat the purpose. So I'd expect it will either set them all to >>> active when forming the larger TLB entry, or set them on a single subpage >>> and leave the rest at whatever state they were. Hm I wonder if the exact >>> behavior is defined anywhere. >> >> For arm64, at least, there are 2 separate mechanisms: >> >> "The Contiguous Bit" (D8.6.1 in the Arm ARM) is a bit in the translation table >> descriptor that SW can set to indicate that a set of adjacent entries are >> contiguous and have same attributes and permissions etc. It is architectural. >> The order of the contiguous range is fixed and depends on the base page size >> that is in use. When in use, HW access and dirty reporting is only done at the >> granularity of the contiguous block. >> >> "HPA" is a micro-architectural feature on some Arm CPUs, which aims to do a >> similar thing, but is transparent to SW. In this case, the dirty and access bits >> remain per-page. But when they differ, this affects the performance of the feature. >> >> Typically HPA can coalesce up to 4 adjacent entries, whereas for a 4KB base page >> at least, the contiguous bit applies to 16 adjacent entries. > > Hm if it's 4 entries on arm64 and presumably 8 on AMD, maybe we can only > care about how actively accessed are the individual "subpages" above that > size, to avoid dealing with this uncertainty whether HW tracks them. At such > smallish sizes we shouldn't induce massive overhead? I'm not sure I've fully understood this point. For arm64's HPA, there is no "uncertainty [about] whether HW tracks them"; HW will always track access/dirty individually for each base page. The problem is the inverse; if SW (or HW) sets those bits differently in each page, then TLB coalescing performance may decrease. Or are you actually suggesting that SW should always set the bits the same for a 4 or 8 page run, and forgo the extra granularity? > >> I'm hearing that there are workloads where being able to use the contiguous bit >> really does make a difference, so I would like to explore solutions that can >> work when we only have access/dirty at the folio level. > > And on the higher orders where we have explicit control via bits, we could > split the explicitly contiguous mappings once in a while to determine if the > sub-folios are still accessed? Although maybe with 16x4kB pages limit it may > still be not worth the trouble? I have a bigger-picture question; why is it useful to split these large folios? I think there are 2 potential reasons (but would like to be educated): 1. If a set of sub-pages that were pre-faulted as part of a large folio have _never_ been accessed and we are under memory pressure, I guess we would like to split the folio and free those pages? 2. If a set of subpages within a folio are cold (but were written in the past) and a separate set of subpages within the same folio are hot and we are under memory pressure, we would like to swap out the cold pages? If the first reason is important, I guess we would want to initially map non-contig, then only remap as contig once every subpage has been touched at least once. For the second reason, my intuition says that a conceptual single access and dirty bit per folio should be sufficient, and folios could be split from time-to-time to see if one half is cold? Thanks, Ryan > >> Thanks, >> Ryan >