From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 372D6C4167B for ; Thu, 7 Dec 2023 11:25:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9D2C6B0087; Thu, 7 Dec 2023 06:25:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C25A96B0088; Thu, 7 Dec 2023 06:25:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A77FC6B0089; Thu, 7 Dec 2023 06:25:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 910716B0087 for ; Thu, 7 Dec 2023 06:25:17 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 61AAF16018E for ; Thu, 7 Dec 2023 11:25:17 +0000 (UTC) X-FDA: 81539791074.02.A3B419D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 1290118000C for ; Thu, 7 Dec 2023 11:25:14 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OVsPq3ZW; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701948315; h=from:from:sender: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:dkim-signature; bh=K0j7fBT8MBHy9QWJasxgiKZePtCf0WKdwcLYR8W8mIk=; b=3VmKJnMaCXLheyqahPB/9OIQ/1jb5Z+UedQy6iEmMGcrP7qMmRrD8fcSlesS9ymdu1M38+ WMtdBbNcCnxj2X+go6E7+a612Nwg845lwQaytVhM0SGXczAxwqvnspMB2sK53c22JFjTKr HNuFaMjBIPp8IRpp52Lo2VIoPffROKo= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OVsPq3ZW; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701948315; a=rsa-sha256; cv=none; b=MsRssWvhHY86AhACgP7RJHczhWNwFBOn2Urrk7z1ufDqZFKKNA+lgxrSdKLmed23l4z7vD 3NpQgWzrQ6Ljc5JNuzcBbUa1s27OQEO2zcww4ToHB3HtmJVdK5d5NX95VnZtU71mcu8dh8 s9tSRgP2rCI9wBX+fvD8aOp94OO/Wls= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701948314; 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=K0j7fBT8MBHy9QWJasxgiKZePtCf0WKdwcLYR8W8mIk=; b=OVsPq3ZWxqkfMXnsjWzjsM7pZ7OoAERAKlrXcK9AFAdiFuA67k5TvMto502OoFcSw3BwlQ FMazOSw1pueLbI+lg4hYHf8oUesr3dsSJMfuz5Hth8A6E7R01cqz3Jkff/+JR8DHNz9H6I Q0IYCNZc9VRoQ5/ZGVsUYgijUY4AOPY= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-399-OSE0bghFM5q4lSbdDTkifg-1; Thu, 07 Dec 2023 06:25:12 -0500 X-MC-Unique: OSE0bghFM5q4lSbdDTkifg-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-332ee20a3f0so755730f8f.0 for ; Thu, 07 Dec 2023 03:25:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701948312; x=1702553112; 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=K0j7fBT8MBHy9QWJasxgiKZePtCf0WKdwcLYR8W8mIk=; b=BXlgIUmugzb6QnQzB0YFsnuckMq8vIqROQpsotFewahRfzLbrcNwHXyLgYH86co50r 8k/NDxs5IQ0CeqVgt9ZtnMlzhH/ZwGXWsQ40CLNWRLtneWgD41a92gHbZK5yzywzHm5n OOdJP9WceIebo/CL5fESlRl3HjwZEJ+Ih1GNlBhgxS4Or5eagYy2mo2NDAazv8y6Pc8F k8BDiW7O3pvDoRf9f+tymm2pHTOWAsfRjuG6M7UJPLNiM++ckILCrat0HYDkhFyjHntt R+CVlaRpb3w0168GzgscFkF7gh0eW1Ex6r2yCkbyNsfGy0y1u63XeMaHQljr7rhtALmh CiFg== X-Gm-Message-State: AOJu0YzwqGqaZik5ri5ExmNf7fP0k5sJ3Smp1qX7dHMMXD12iOpUHY3d hiNTJvqoRWBv81pPlGSFQX5TR2gQYBUGdK5SsKj9FWro0wm3jDW8DcwleKFRAjVIOwhKLZY4IQa oijxhLIQy9a4= X-Received: by 2002:adf:e5c3:0:b0:333:3c4d:7ff5 with SMTP id a3-20020adfe5c3000000b003333c4d7ff5mr659420wrn.26.1701948311788; Thu, 07 Dec 2023 03:25:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFmWmk5Vyplt95qyM+itfs1NpTj4L+SVTdY4zz6yKXzsR9YO3s0D7m6mkG211G8K2hy+3azWg== X-Received: by 2002:adf:e5c3:0:b0:333:3c4d:7ff5 with SMTP id a3-20020adfe5c3000000b003333c4d7ff5mr659409wrn.26.1701948311206; Thu, 07 Dec 2023 03:25:11 -0800 (PST) Received: from ?IPV6:2003:cb:c71b:5d00:18d7:1475:24bc:2417? (p200300cbc71b5d0018d7147524bc2417.dip0.t-ipconnect.de. [2003:cb:c71b:5d00:18d7:1475:24bc:2417]) by smtp.gmail.com with ESMTPSA id q12-20020a5d658c000000b003333298eb4bsm1186219wru.61.2023.12.07.03.25.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Dec 2023 03:25:10 -0800 (PST) Message-ID: <44fdd46b-ad46-4ae2-a20f-20374acdf464@redhat.com> Date: Thu, 7 Dec 2023 12:25:08 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v8 03/10] mm: thp: Introduce multi-size THP sysfs interface 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 References: <20231204102027.57185-1-ryan.roberts@arm.com> <20231204102027.57185-4-ryan.roberts@arm.com> <004ed23d-5571-4474-b7fe-7bc08817c165@redhat.com> <378afc6b-f93a-48ad-8aa6-ab171f3b9613@redhat.com> <4aa520f0-7c84-4e93-88bf-aee6d8d3ea70@arm.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5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sstw2TAkFnMEbo9Zu9w7Kv AxBQXWeXhJI9XQssfrf4Gusdqx8nPEpfOqCtbbwJMATbHyqLt7/oz/5deGuwxgb65pWIzufa N7eop7uh+6bezi+rugUI+w6DABEBAAHCwXwEGAEIACYCGwwWIQQb2cqtc1xMOkYN/MpN3hD3 AP+DWgUCXw7HsgUJEqkpoQAKCRBN3hD3AP+DWrrpD/4qS3dyVRxDcDHIlmguXjC1Q5tZTwNB boaBTPHSy/Nksu0eY7x6HfQJ3xajVH32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/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: <4aa520f0-7c84-4e93-88bf-aee6d8d3ea70@arm.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 1290118000C X-Stat-Signature: x5omwim7jotkqpby5ixp93czfmua5sa6 X-Rspam-User: X-HE-Tag: 1701948314-112112 X-HE-Meta: U2FsdGVkX1+IrmxYAdzYas4kqpvE4KJbdmWK9geDYPsj77ajqXsQApUq8PPEcvcisWSSGkURmTikN7OyEAVg3aQf/AvWKhpGaS0POMpg9/bFPwc5b2N6plSHeP9Blt6tIOC1daXrzBz7vqo4QDb7xAza8ZyWoQ9NPh9MlpBGif5Qnl7qDmyBQMsXJAxD6T7ecxByyUQ0il7X02os5661Rs4E4waWuXmHPXTcPazbCkdxN9fQzboStLMm6XL3F93OOlKX26/QkxHq19nYvSiad/CPsNzpESTQCBRu3zb4ZqzwOBS1m2bG7+auDNfr7EJ7tP/m3vdtbzBP1QGMfi/OC4pU/hKhbYtfQSa+NaR+p7XY41SlvKKh+aoo65eGOlHPbyJqF/pG5cGiolQDaBfLnHD/MB4aTKJHrx1c61m0qERhc3nC10IQi6vDPwa+ReMso0dxIb1XuWyik/geUIIPN3zS6v5RupeHwpP3ETbRwhycxMpvoEoB+mH67aU4M0OhoxfSxllZsF1DIeO9bhOI2SMEACOdC/UAUCDVx9yhi3w75wDuKddc2np4D3UhH3ZYO4cxsoa3Ihu2zkGshRHJaMCWBq7GI0Oc6BfwNAI8q1WhOVtGmijY5SOvA+f0JLYlJ0AubmOlpEsPdZiEAWauIFkuhJufl8otqyb4xrzU9jvA1loTkfyaIKgE7/Sh63DI3tWUc3j+3veE4h2hCstkfykdjVbfRdiiJcaOGqIq3BXsRS6WcupWRwRiUGtNSI+OOh3FRsYLAAci1izUI0ttMTrnCrv+uKa74E5O8B/WylAYY0E3EZZyUVVHE/xf/cAd62sRLE8WdRWnhT1sLEf1e6GQty6qwnvagaLORBSllA45OYSKypjgvwOYrr+k4EfhAfssDPHgzQTjP08PSNiAgJHUFEhspDVMkLxqpKoMf+//bKAWQ4RPrMV23N7fV6MWvIVHnO5pF0/71MvXl9z gr+Muy5E OYSwMUn+FDkLWN3v2uJmElN6ENdhsyO8NJxyqLal+LNfEvneCotMkLcnDtAqKjPzQtGapxEYinY5z7P5SOPIT2I8jCzwa1w3z4oI7CZpB/pqGRzfzuhz/qEEVs5pKYQnH6k+a2jeSXKRFNHKekAZkKvDxB9gRW/geRfIXAYvqVuBdFqugkHAjlTkJGdOADilrfi6751keeIElC2dpBF3qQ0xJP/oetHTaHhOnMZPqMWnhl1Y14UEkIlGNLovX0BFUGFQILopoAvx3AfuDHJTfOMON/QUwOat2D5ZLOeJ6ceKqn74mWbHaZnM1XXdRaeYza6+58BVmXePUYpU1wkUEytAGX7UnqDptpSrP2vuGGs3UM3bUM2+ezcmfihNt08ZjhwqI+0ePACD9br3Pm1nLy+2SUqzgHU+r1vDEyFXKsfcWRu9YUScwwO7ZnzM9BlpMqS4P6t6GplqtOjX0yXQONTaLBG1HxN+CLVnqNNt9DvITcXj4D9+FtecoHA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 07.12.23 12:22, Ryan Roberts wrote: > On 07/12/2023 11:13, David Hildenbrand wrote: >>>> >>>>> + >>>>>        if (!vma->vm_mm)        /* vdso */ >>>>> -        return false; >>>>> +        return 0; >>>>>          /* >>>>>         * Explicitly disabled through madvise or prctl, or some >>>>> @@ -88,16 +141,16 @@ bool hugepage_vma_check(struct vm_area_struct *vma, >>>>> unsigned long vm_flags, >>>>>         * */ >>>>>        if ((vm_flags & VM_NOHUGEPAGE) || >>>>>            test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) >>>>> -        return false; >>>>> +        return 0; >>>>>        /* >>>>>         * If the hardware/firmware marked hugepage support disabled. >>>>>         */ >>>>>        if (transparent_hugepage_flags & (1 << >>>>> TRANSPARENT_HUGEPAGE_UNSUPPORTED)) >>>>> -        return false; >>>>> +        return 0; >>>>>          /* khugepaged doesn't collapse DAX vma, but page fault is fine. */ >>>>>        if (vma_is_dax(vma)) >>>>> -        return in_pf; >>>>> +        return in_pf ? orders : 0; >>>>>          /* >>>>>         * khugepaged special VMA and hugetlb VMA. >>>>> @@ -105,17 +158,29 @@ bool hugepage_vma_check(struct vm_area_struct *vma, >>>>> unsigned long vm_flags, >>>>>         * VM_MIXEDMAP set. >>>>>         */ >>>>>        if (!in_pf && !smaps && (vm_flags & VM_NO_KHUGEPAGED)) >>>>> -        return false; >>>>> +        return 0; >>>>>          /* >>>>> -     * Check alignment for file vma and size for both file and anon vma. >>>>> +     * Check alignment for file vma and size for both file and anon vma by >>>>> +     * filtering out the unsuitable orders. >>>>>         * >>>>>         * Skip the check for page fault. Huge fault does the check in fault >>>>> -     * handlers. And this check is not suitable for huge PUD fault. >>>>> +     * handlers. >>>>>         */ >>>>> -    if (!in_pf && >>>>> -        !transhuge_vma_suitable(vma, (vma->vm_end - HPAGE_PMD_SIZE))) >>>>> -        return false; >>>>> +    if (!in_pf) { >>>>> +        int order = first_order(orders); >>>>> +        unsigned long addr; >>>>> + >>>>> +        while (orders) { >>>>> +            addr = vma->vm_end - (PAGE_SIZE << order); >>>>> +            if (thp_vma_suitable_orders(vma, addr, BIT(order))) >>>>> +                break; >>>> >>>> Comment: you'd want a "thp_vma_suitable_order" helper here. But maybe the >>>> compiler is smart enough to optimize the loop and everyything else out. >>> >>> I'm happy to refactor so that thp_vma_suitable_order() is the basic primitive, >>> then make thp_vma_suitable_orders() a loop that calls thp_vma_suitable_order() >>> (that's basically how it is laid out already, just all in one function). Is that >>> what you are requesting? >> >> You got the spirit, yes. >> >>>> >>>> [...] >>>> >>>>> + >>>>> +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")) { >>>>> +        set_bit(order, &huge_anon_orders_always); >>>>> +        clear_bit(order, &huge_anon_orders_inherit); >>>>> +        clear_bit(order, &huge_anon_orders_madvise); >>>>> +    } else if (sysfs_streq(buf, "inherit")) { >>>>> +        set_bit(order, &huge_anon_orders_inherit); >>>>> +        clear_bit(order, &huge_anon_orders_always); >>>>> +        clear_bit(order, &huge_anon_orders_madvise); >>>>> +    } else if (sysfs_streq(buf, "madvise")) { >>>>> +        set_bit(order, &huge_anon_orders_madvise); >>>>> +        clear_bit(order, &huge_anon_orders_always); >>>>> +        clear_bit(order, &huge_anon_orders_inherit); >>>>> +    } else if (sysfs_streq(buf, "never")) { >>>>> +        clear_bit(order, &huge_anon_orders_always); >>>>> +        clear_bit(order, &huge_anon_orders_inherit); >>>>> +        clear_bit(order, &huge_anon_orders_madvise); >>>> >>>> Note: I was wondering for a second if some concurrent cames could lead to an >>>> inconsistent state. I think in the worst case we'll simply end up with "never" >>>> on races. >>> >>> You mean if different threads try to write different values to this file >>> concurrently? Or if there is a concurrent fault that tries to read the flags >>> while they are being modified? >> >> I thought about what you said first, but what you said last might also apply. As >> long as "nothing breaks", all good. >> >>> >>> I thought about this for a long time too and wasn't sure what was best. The >>> existing global enabled store impl clears the bits first then sets the bit. With >>> this approach you can end up with multiple bits set if there is a race to set >>> diffierent values, and you can end up with a faulting thread seeing never if it >>> reads the bits after they have been cleared but before setting them. >> >> Right, but user space is playing stupid games and can win stupid prices. As long >> as nothing breaks, we're good. >> >>> >>> I decided to set the new bit before clearing the old bits, which is different; A >>> racing fault will never see "never" but as you say, a race to set the file could >>> result in "never" being set. >>> >>> On reflection, it's probably best to set the bit *last* like the global control >>> does? >> >> Probably might just slap a simple spinlock in there, so at least the writer side >> is completely serialized. Then you can just set the bit last. It's unlikely that >> readers will actually run into issues, and if they ever would, we could use some >> rcu magic to let them read a consistent state. > > I'd prefer to leave it as it is now; clear first, set last without any explicit > serialization. I've convinced myself that nothing breaks and its the same > pattern used by the global control so its consistent. Unless you're insisting on > the spin lock? No, not at all. But it would certainly remove any possible concerns :) -- Cheers, David / dhildenb