Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4691006rdb; Tue, 12 Dec 2023 06:55:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZ8T0zEtnRHLAgSIPgHHqDcfKqcsjISduu5I4PNsC24MCLK4LqGqSN+d8U6yx1JqD554oC X-Received: by 2002:a05:6a20:12c9:b0:190:1d2b:cb67 with SMTP id v9-20020a056a2012c900b001901d2bcb67mr7232928pzg.32.1702392900023; Tue, 12 Dec 2023 06:55:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702392900; cv=none; d=google.com; s=arc-20160816; b=cZrGKm8YneOBdYi/Lfz9QqPjmGuHGzSgI5WveCjj0wImH4F9zXcZesun1z3bxZztQj pJSbv+zJFEf45BqCKwLgM/BdXe442ihIDFPoEMhNANCdegrMTyM32UHnmv5k0S5NNGzX +v9FP2nTPwDYBotTWDQ9ahzWw1uyBL6vBPQVZirGlitTJNznBqe+yf7ISHav/9+OYclZ ODkS7HhNH9EUeCo+rnKln83hwhp6Y6BUGgVZIZ23OkqMrd9Q/SbBp9+5mkOEdsg95i8O Qo6qgGnrBCILluixV+Z8oy0VZUz6aR6jz0OzwWmce6sWEK5DyHtNgeMIJ5vAr5ZAtsyI jmag== 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 :organization:autocrypt:from:references:cc:to:content-language :subject:user-agent:mime-version:date:message-id:dkim-signature; bh=nHow/OuTkq7ZGC7us2BB0pRida/FxOxA+wS3+9JxabI=; fh=TKr08NM8qZ2DiqYoir63SZj5x+J9IyFyGy5eABlLL40=; b=QHpPfOso9qoXu5n5s03TY65ZIkrka77VWf4aXFlg2Xv2tnQJQLIzr5pl65mJPOBK+W 0K6DErOehoKsuyOhL/JyCYc3sFsskbno8/9uAQI6H6y4/pooiDyeg2FgGK0XSGg25fW6 v/taXCoFpe3sJkt34gglfaoSt5dvwvJjNegTjubOk+s2O0l6/Pg8rwoEpWz3F/YXGd4Z h6V8wMV2H4MFPrVMNM89LR5Cg/E/f4w0gKCHEB1M8KyIGloazTBLOG1dn9cleWhr+sdC TD+VVlkjJAqBTdSaJ2rcoJHASUf1fs4C1Io4s7W5tLc5q9GPDDMxUnHS9JOs7a4CjjaF AA2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EpWPonnD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id f18-20020a056a00229200b006ce65a4a67bsi7918679pfe.325.2023.12.12.06.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 06:55:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EpWPonnD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 57C618026DAE; Tue, 12 Dec 2023 06:54:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376945AbjLLOyf (ORCPT + 99 others); Tue, 12 Dec 2023 09:54:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376919AbjLLOye (ORCPT ); Tue, 12 Dec 2023 09:54:34 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E01DD3 for ; Tue, 12 Dec 2023 06:54:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702392879; 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=nHow/OuTkq7ZGC7us2BB0pRida/FxOxA+wS3+9JxabI=; b=EpWPonnDkYtIfTi23kKvPSOITPnfvWg3KKrO24x1iLIq1KeZWgTDyblwHPJ8/vWQ0KKa55 NH369uGEwCF/5/XYUc8vJGpx8KbtIf2/mnbN02oAUYSYVVLXTf+pBwCEPSSYpbATfjmf/8 e0HuZQOX+Bp4WndGisPLr1rnemN5+lg= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-490-4up4vSD8OUqKGXWxqsZbIw-1; Tue, 12 Dec 2023 09:54:38 -0500 X-MC-Unique: 4up4vSD8OUqKGXWxqsZbIw-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-40c3f0f88e3so20910885e9.0 for ; Tue, 12 Dec 2023 06:54:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702392877; x=1702997677; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=nHow/OuTkq7ZGC7us2BB0pRida/FxOxA+wS3+9JxabI=; b=WOWFVGV/4Ir9qJjvtzwFtbjvQ2NhPgNK8OjVdyKmygSWdyn5OIyo58+qP82izXbOeI DKsikh4xQPuxIGcUxBNqjQqNzTdlwWkeLMCnab7+oJMRQk/4m5GTzOJM4JQnu9ImpQAy ajOmqtjGtsI4UHsVchtoQmQlA3WJr56al/jS+RoFO4qvInkbHQPizbwqJzzc8Mn+4Gre WP0w2QZYdT1JU5V66nyzixCAsG0+NC+Xj26xM8d9N40Dfq0LaciDn6dM0RdKvbThR8IL sl3u72Ohl9hE6SYevBKQw8Qs633XR3DmGtF1Dx/pPw/1YRIoKgr+NTyv6KcIGdq8xbaA k8+A== X-Gm-Message-State: AOJu0YyUprQ3qfbHEY6M1Y0xwezJGIkspdQTjJdgUTBGmGAI5rHFNlg3 GrDDT0FhCZu+vJhPRb+dYbuP5uRcxDPMfYDkCTCWw5RnLcY5a1AwMw9pWfXovR+ih4ORSmBjowH O6WfkgyM4sGQg/zXx9bFyOhnk X-Received: by 2002:a05:600c:2946:b0:40c:296e:7bfe with SMTP id n6-20020a05600c294600b0040c296e7bfemr3180077wmd.140.1702392876801; Tue, 12 Dec 2023 06:54:36 -0800 (PST) X-Received: by 2002:a05:600c:2946:b0:40c:296e:7bfe with SMTP id n6-20020a05600c294600b0040c296e7bfemr3180058wmd.140.1702392876335; Tue, 12 Dec 2023 06:54:36 -0800 (PST) Received: from ?IPV6:2003:cb:c74b:ca00:4ca2:ff2c:9092:f070? (p200300cbc74bca004ca2ff2c9092f070.dip0.t-ipconnect.de. [2003:cb:c74b:ca00:4ca2:ff2c:9092:f070]) by smtp.gmail.com with ESMTPSA id fs27-20020a05600c3f9b00b0040b36050f1bsm16489167wmb.44.2023.12.12.06.54.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Dec 2023 06:54:35 -0800 (PST) Message-ID: Date: Tue, 12 Dec 2023 15:54:34 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v9 03/10] mm: thp: Introduce multi-size THP sysfs interface Content-Language: en-US To: Ryan Roberts , Andrew Morton , Matthew Wilcox , Yin Fengwei , Yu Zhao , Catalin Marinas , Anshuman Khandual , Yang Shi , "Huang, Ying" , Zi Yan , Luis Chamberlain , Itaru Kitayama , "Kirill A. Shutemov" , John Hubbard , David Rientjes , Vlastimil Babka , Hugh Dickins , Kefeng Wang , Barry Song <21cnbao@gmail.com>, Alistair Popple Cc: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Barry Song References: <20231207161211.2374093-1-ryan.roberts@arm.com> <20231207161211.2374093-4-ryan.roberts@arm.com> From: David Hildenbrand 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 B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0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <20231207161211.2374093-4-ryan.roberts@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Tue, 12 Dec 2023 06:54:57 -0800 (PST) On 07.12.23 17:12, Ryan Roberts wrote: > In preparation for adding support for anonymous multi-size THP, > introduce new sysfs structure that will be used to control the new > behaviours. A new directory is added under transparent_hugepage for each > supported THP size, and contains an `enabled` file, which can be set to > "inherit" (to inherit the global setting), "always", "madvise" or > "never". For now, the kernel still only supports PMD-sized anonymous > THP, so only 1 directory is populated. > > The first half of the change converts transhuge_vma_suitable() and > hugepage_vma_check() so that they take a bitfield of orders for which > the user wants to determine support, and the functions filter out all > the orders that can't be supported, given the current sysfs > configuration and the VMA dimensions. The resulting functions are > renamed to thp_vma_suitable_orders() and thp_vma_allowable_orders() > respectively. Convenience functions that take a single, unencoded order > and return a boolean are also defined as thp_vma_suitable_order() and > thp_vma_allowable_order(). > > The second half of the change implements the new sysfs interface. It has > been done so that each supported THP size has a `struct thpsize`, which > describes the relevant metadata and is itself a kobject. This is pretty > minimal for now, but should make it easy to add new per-thpsize files to > the interface if needed in future (e.g. per-size defrag). Rather than > keep the `enabled` state directly in the struct thpsize, I've elected to > directly encode it into huge_anon_orders_[always|madvise|inherit] > bitfields since this reduces the amount of work required in > thp_vma_allowable_orders() which is called for every page fault. > > See Documentation/admin-guide/mm/transhuge.rst, as modified by this > commit, for details of how the new sysfs interface works. > > Reviewed-by: Barry Song > Tested-by: Kefeng Wang > Tested-by: John Hubbard > Signed-off-by: Ryan Roberts > --- [...] > + > +static ssize_t thpsize_enabled_store(struct kobject *kobj, > + struct kobj_attribute *attr, > + const char *buf, size_t count) > +{ > + int order = to_thpsize(kobj)->order; > + ssize_t ret = count; > + > + if (sysfs_streq(buf, "always")) { > + spin_lock(&huge_anon_orders_lock); > + clear_bit(order, &huge_anon_orders_inherit); > + clear_bit(order, &huge_anon_orders_madvise); > + set_bit(order, &huge_anon_orders_always); > + spin_unlock(&huge_anon_orders_lock); > + } else if (sysfs_streq(buf, "inherit")) { > + spin_lock(&huge_anon_orders_lock); > + clear_bit(order, &huge_anon_orders_always); > + clear_bit(order, &huge_anon_orders_madvise); > + set_bit(order, &huge_anon_orders_inherit); > + spin_unlock(&huge_anon_orders_lock); > + } else if (sysfs_streq(buf, "madvise")) { > + spin_lock(&huge_anon_orders_lock); > + clear_bit(order, &huge_anon_orders_always); > + clear_bit(order, &huge_anon_orders_inherit); > + set_bit(order, &huge_anon_orders_madvise); > + spin_unlock(&huge_anon_orders_lock); > + } else if (sysfs_streq(buf, "never")) { > + spin_lock(&huge_anon_orders_lock); > + clear_bit(order, &huge_anon_orders_always); > + clear_bit(order, &huge_anon_orders_inherit); > + clear_bit(order, &huge_anon_orders_madvise); > + spin_unlock(&huge_anon_orders_lock); Why not perform lock/unlock only once in surrounding code? :) Much better Acked-by: David Hildenbrand -- Cheers, David / dhildenb