From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0B7955896 for ; Tue, 16 Jul 2024 10:19:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721125178; cv=none; b=sIgEOszT9/RBmLQeAKlmO/B42oNP7/O/omIWh8/mg9EJJTZvWK35+PBdnOd2ZlWMZoiVo63FrlbU7OrhbYdDE0ljYDw7eBZJ7hg4WIbF/4XanDDwXUwSJ7t2z11zAmbLIeruDEVckCfMsk4TQpiRb3XbA4XvQuPVYb+tQzpepzY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721125178; c=relaxed/simple; bh=RSxyNj04AfZi3vXzSOv3ZWY4vZlJmzD52/tOPSJBZVI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=hfyCiDLOFxQIPUES+7YfDsTgY4zjSYNW/VthiQdUwZNFrn6QuoYMmopgfImqqHjpTBH6wB6Dg8GzpmO5bQhpEIVNns4/Fphm18VaAmllaTR/Bofv3g5f/2HPIBAl16ns6UGpiGIsVixy7pnC9ml4gGxGLSGsH2zYui3joRdVAzw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=GQgFlV/a; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GQgFlV/a" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721125175; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=CFikzQ9FR6uq6Qkl11RGCdjEuVlFhdkxIDCeTFIs1Mk=; b=GQgFlV/aSVWNBDnbLnu/mnjdNFF72wlnriGrOVs/o0d6Utkf7WDsesqdq/xfttrx+Dxq2r gVHJSl45OWcMBUoA/hItneIy5KxU6iWEeDB4aRU/U1BMv6EAJ+RImxO/Vw756UHXAruBiO nEBMA08O/sN9j0MoXe9j6ZJeF+LP/ac= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-542-zOP5WjQiNditrkXnhwZapQ-1; Tue, 16 Jul 2024 06:19:34 -0400 X-MC-Unique: zOP5WjQiNditrkXnhwZapQ-1 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-52ea4178bafso5452103e87.2 for ; Tue, 16 Jul 2024 03:19:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721125172; x=1721729972; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=CFikzQ9FR6uq6Qkl11RGCdjEuVlFhdkxIDCeTFIs1Mk=; b=ZApt1im69hN7797jyYuz3EDoq9isFpzA0EIatB3M+7NcRdKTUkUfVRS6pviWabOdto 7pbTGg1VMZU896O9SS4cdAcflS9dd4/7TGVhL/lSD/sSuvm2ex2CfKao1Pdg0uXbx87V +u+I40eUxwNvF9Aax3ZxBWmRHHXWLW3dV353kChpL1X4oZ4iIyVvspxo2zkU/NKlrwHF 48o/oMD5lg0o5zSQIT0IrqUS8q1sl6lu+LqmMpPRaiBQPVE1rcaBfjXu4BekqqrvXZa9 Ya8KgWCU+HfPkjNKu8YN+HmLalYRHurhjnpDXbXKW3G1EtSo30NP9xJ6Ivtz+Gam/IOT 0ONQ== X-Forwarded-Encrypted: i=1; AJvYcCW/X17q06A9cn2DFT8swRWu0gvgjgErtkZUOd6l7n51hUm6ZFKGH+26hlok66aSKiNl/G4ip3agqCCUeye2zeBM1JPYSOlJXjpDXk6J X-Gm-Message-State: AOJu0Yz0E4SceqzUY7CbvbDMVVpSY4uUACMMvaB608cA8r1NjIW3++5+ m6Sb38YLD53+NCtk6xW414t+/Bdc/rzlLMBktUQQvOjDAsw5Ffm+528/zwPFR1CgLHXP0YKKv0V NnnT2Z9ll6lf/9XhnFoHUN5MW1C7cR8KZj0BaLNR3W88/P91j7F9tE3jooj/SqQ== X-Received: by 2002:a05:6512:1091:b0:52e:9c0a:3514 with SMTP id 2adb3069b0e04-52edf030c05mr989908e87.44.1721125172561; Tue, 16 Jul 2024 03:19:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEIW/1pxgkTNM1wTgFJhZVq+2eKZEG0JtpvIoXxgJyFvHvcVymyCR1jszuYP8kB03uFUMIH+g== X-Received: by 2002:a05:6512:1091:b0:52e:9c0a:3514 with SMTP id 2adb3069b0e04-52edf030c05mr989893e87.44.1721125171989; Tue, 16 Jul 2024 03:19:31 -0700 (PDT) Received: from ?IPV6:2003:d8:2f02:7c00:e95e:dbc6:7ea8:d075? (p200300d82f027c00e95edbc67ea8d075.dip0.t-ipconnect.de. [2003:d8:2f02:7c00:e95e:dbc6:7ea8:d075]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427b8609d54sm30775205e9.42.2024.07.16.03.19.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 Jul 2024 03:19:31 -0700 (PDT) Message-ID: <5c58d9ea-8490-4ae6-b7bf-be816dab3356@redhat.com> Date: Tue, 16 Jul 2024 12:19:30 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 2/2] mm: mTHP stats for pagecache folio allocations To: Ryan Roberts , Lance Yang , Baolin Wang Cc: Andrew Morton , Hugh Dickins , Jonathan Corbet , "Matthew Wilcox (Oracle)" , Barry Song , linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20240711072929.3590000-1-ryan.roberts@arm.com> <20240711072929.3590000-3-ryan.roberts@arm.com> <9e0d84e5-2319-4425-9760-2c6bb23fc390@linux.alibaba.com> <756c359e-bb8f-481e-a33f-163c729afa31@redhat.com> <8c32a2fc-252d-406b-9fec-ce5bab0829df@arm.com> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc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9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 16.07.24 10:31, Ryan Roberts wrote: > On 13/07/2024 11:45, Ryan Roberts wrote: >> On 13/07/2024 02:08, David Hildenbrand wrote: >>> On 12.07.24 14:22, Lance Yang wrote: >>>> On Fri, Jul 12, 2024 at 11:00 AM Baolin Wang >>>> wrote: >>>>> >>>>> >>>>> >>>>> On 2024/7/11 15:29, Ryan Roberts wrote: >>>>>> Expose 3 new mTHP stats for file (pagecache) folio allocations: >>>>>> >>>>>>     /sys/kernel/mm/transparent_hugepage/hugepages-*kB/stats/file_alloc >>>>>>     /sys/kernel/mm/transparent_hugepage/hugepages-*kB/stats/file_fallback >>>>>> >>>>>> /sys/kernel/mm/transparent_hugepage/hugepages-*kB/stats/file_fallback_charge >>>>>> >>>>>> This will provide some insight on the sizes of large folios being >>>>>> allocated for file-backed memory, and how often allocation is failing. >>>>>> >>>>>> All non-order-0 (and most order-0) folio allocations are currently done >>>>>> through filemap_alloc_folio(), and folios are charged in a subsequent >>>>>> call to filemap_add_folio(). So count file_fallback when allocation >>>>>> fails in filemap_alloc_folio() and count file_alloc or >>>>>> file_fallback_charge in filemap_add_folio(), based on whether charging >>>>>> succeeded or not. There are some users of filemap_add_folio() that >>>>>> allocate their own order-0 folio by other means, so we would not count >>>>>> an allocation failure in this case, but we also don't care about order-0 >>>>>> allocations. This approach feels like it should be good enough and >>>>>> doesn't require any (impractically large) refactoring. >>>>>> >>>>>> The existing mTHP stats interface is reused to provide consistency to >>>>>> users. And because we are reusing the same interface, we can reuse the >>>>>> same infrastructure on the kernel side. The one small wrinkle is that >>>>>> the set of folio sizes supported by the pagecache are not identical to >>>>>> those supported by anon and shmem; pagecache supports order-1, unlike >>>>>> anon and shmem, and the max pagecache order may be less than PMD-size >>>>>> (see arm64 with 64K base pages), again unlike anon and shmem. So we now >>>>>> create a hugepages-*kB directory for the union of the sizes supported by >>>>>> all 3 memory types and populate it with the relevant stats and controls. >>>>> >>>>> Personally, I like the idea that can help analyze the allocation of >>>>> large folios for the page cache. >>>>> >>>>> However, I have a slight concern about the consistency of the interface. >>>>> >>>>> For 64K, the fields layout: >>>>> ├── hugepages-64kB >>>>> │   ├── enabled >>>>> │   ├── shmem_enabled >>>>> │   └── stats >>>>> │       ├── anon_fault_alloc >>>>> │       ├── anon_fault_fallback >>>>> │       ├── anon_fault_fallback_charge >>>>> │       ├── file_alloc >>>>> │       ├── file_fallback >>>>> │       ├── file_fallback_charge >>>>> │       ├── shmem_alloc >>>>> │       ├── shmem_fallback >>>>> │       ├── shmem_fallback_charge >>>>> │       ├── split >>>>> │       ├── split_deferred >>>>> │       ├── split_failed >>>>> │       ├── swpout >>>>> │       └── swpout_fallback >>>>> >>>>> But for 8K (for pagecache), you removed some fields (of course, I >>>>> understand why they are not supported). >>>>> >>>>> ├── hugepages-8kB >>>>> │   └── stats >>>>> │       ├── file_alloc >>>>> │       ├── file_fallback >>>>> │       └── file_fallback_charge >>>>> >>>>> This might not be user-friendly for some user-space parsing tools, as >>>>> they lack certain fields for the same pattern interfaces. Of course, >>>>> this might not be an issue if we have clear documentation describing the >>>>> differences here:) >>>>> >>>>> Another possible approach is to maintain the same field layout to keep >>>>> consistent, but prohibit writing to the fields that are not supported by >>>>> the pagecache, and any stats read from them would be 0. >>>> >>>> I agree that maintaining a uniform field layout, especially at the stats >>>> level, might be necessary ;) >>>> >>>> Keeping a consistent interface could future-proof the design. It allows >>>> for the possibility that features not currently supported for 8kB pages >>>> might be enabled in the future. >>> >>> I'll just note that, with shmem/file effectively being disabled for order > 11, >>> we'll also have entries there that are effectively unused. >> >> Indeed, I mentioned that in the commit log :) Well, I think it's more extreme than what you mentioned. For example, shmem_enable on arm64 with 64k is now effectively non-functional. Just like it will be for other orders in the anon-shmem case when the order exceeds MAX_PAGECACHE_ORDER. >> >>> >>> Good question how we want to deal with that (stats are easy, but what about when >>> we enable something? Maybe we should document that "enabled" is only effective >>> when supported). >> >> The documentation already says "If enabling multiple hugepage sizes, the kernel >> will select the most appropriate enabled size for a given allocation." for anon >> THP (and I've added similar wording for my as-yet-unposted patch to add controls >> for page cache folio sizes). So I think we could easily add dummy *enabled >> controls for all sizes, that can be written to and read back consistently, but >> the kernel just ignores them when deciding what size to use. It would also >> simplify the code that populates the controls. >> >> Personally though, I'm not convinced of the value of trying to make the controls >> for every size look identical. What's the real value to the user to pretend that >> they can select a size that they cannot? What happens when we inevitably want to >> add some new control in future which only applies to select sizes and there is >> no good way to fake it for the other sizes? Why can't user space just be >> expected to rely on the existance of the files rather than on the existance of >> the directories? >> >> As always, I'll go with the majority, but just wanted to register my opinion. > > Should I assume from the lack of reply on this that everyone else is in favour > of adding dummy controls so that all sizes have the same set of controls? If I > don't hear anything further, I'll post v2 with dummry controls today or tomorrow. Sorry, busy with other stuff. Indicating only what really exists sounds cleaner. But I wonder how we would want to handle in general orders that are effectively non-existant? -- Cheers, David / dhildenb