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.129.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 8242B802 for ; Sat, 13 Jul 2024 01:08:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720832938; cv=none; b=fDj8U3JO7XPpOxMRXZfB1DTyEG9BdtDQfHtxlEz/dabTw9zZBdiE7UXETVoZ9yWeDi3GPRmBagEKe9v1WENUzAjHBGr5YJ8Qkh/KDtAwTC3NywuFHC7OWfYLZk3CvgkQ5qc0UQZoJZo3I6EIO27yss8WcLBTiVrmGKI791JbwrQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720832938; c=relaxed/simple; bh=vymcOzfkp+e8M4vMHjDtx9NJryu+f5ZRgMjb3ffSU/w=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=dXMde3XzpHYCak1Ja4H3DZejMpC2yFTHndQtYcV1N6v7sv3KCcVyOl5z3QGD2H+n/4Fnj2P6IV+6Rvm3NaZC45IDhUV9p2z5ay3ZK3LPG8QctG4Zm2gjnE4VQs4xhyYd0auJ/Pl5HQj0kOy+CP5eeskp9XgLaMzw/tp097I64bw= 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=Lu0AMrg5; arc=none smtp.client-ip=170.10.129.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="Lu0AMrg5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720832935; 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=8hgY2LXUckGLUahLQvB6QT3LwtMnlKKwQsSz2J7Za6U=; b=Lu0AMrg55CxWQNBnIeFBYPNaqx61Fey6fZPzoosRttw9t2UuqfvI2BZVRtU7eEx9qtNIel 1SO1wdQ+RAcOjk9717/p3S4NfIRP3mn+NNPIHIU/7gL5YcTDn324GA/kb4j/aFLk9CcS7K eCWG9xbBA9tAZRMOq0DkxZjJRSbuXik= Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-117-ApbkrlM5MMKaPetMVnTRLg-1; Fri, 12 Jul 2024 21:08:53 -0400 X-MC-Unique: ApbkrlM5MMKaPetMVnTRLg-1 Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-70af7dc9780so2028139b3a.1 for ; Fri, 12 Jul 2024 18:08:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720832933; x=1721437733; 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=8hgY2LXUckGLUahLQvB6QT3LwtMnlKKwQsSz2J7Za6U=; b=c94cOPONcSs+djdZymDAVPQZLqzHbxwsBCVOodMXGZMltVOAE/a1MFwEW+3hCQal3e sciGe9lU1GPRRZRrjdZO/4nbIN09e4vWzf9E+BEr1RPIm/2uZ4lEgpVjbZvEzDE38dGG 6fnTxD+qg9Ht0qHp1TXKkyA1VQEMZnnzMoiYnX9SPWOWyn77O1UyFN07QAnYZUiPvw6l 40U2/plnTtvJATndzVQZe50WNcDWHy/dSBhex5EeSdC9+D3153RI5Ax2gwCxwU53E/st bWJou5K10P0iREz4QVpv/ttZUL4v3v6cqg/heQ3cL5i1Kf/PWh87H/6IqxS0SF7uIZe9 6Viw== X-Forwarded-Encrypted: i=1; AJvYcCUioTKJX6neU+5UUEtsGeDWwDLD8rfDr3LlxcGJo9GS04CHwjUMKImU+xq/w64ibwMo/BcX0CRynszsj7zU6HjGNI67OGEgHF7e8OiK X-Gm-Message-State: AOJu0Yy9VkmH+llxaQW6gHizPme9wfI21XsLuBkpv9iSoYqDF9r6TT3T MDihf81ckjKV3BaElJ6F3CeHfIdhNJ3IIofJ2WlScUclilcnD2NqYhd6XdcKqVreTusexBpw6oG JFFZxL5j/uFycz4azhWqDIj44xbXVRcfmhUHDNSmg/013jDtu5C2sImDECzTi5g== X-Received: by 2002:a05:6a00:4b51:b0:706:3d61:4b21 with SMTP id d2e1a72fcca58-70b6cae4c6amr6293790b3a.3.1720832932798; Fri, 12 Jul 2024 18:08:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHa2cumK9ibyG97YOlpEN8kL079eVttDRnz0SscxZBj5CpAVCC9P68ouCFgnidIdRQ8q2ieVQ== X-Received: by 2002:a05:6a00:4b51:b0:706:3d61:4b21 with SMTP id d2e1a72fcca58-70b6cae4c6amr6293763b3a.3.1720832932353; Fri, 12 Jul 2024 18:08:52 -0700 (PDT) Received: from [172.20.2.228] ([4.28.11.157]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70b7ecc9965sm157529b3a.199.2024.07.12.18.08.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 18:08:52 -0700 (PDT) Message-ID: <756c359e-bb8f-481e-a33f-163c729afa31@redhat.com> Date: Sat, 13 Jul 2024 03:08:50 +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: Lance Yang , Baolin Wang Cc: Ryan Roberts , 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> 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 UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrH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qY0VVqSUwImzTDLX9S4g/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 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. 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). Hmmmmm -- Cheers, David / dhildenb