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 64A93C4332F for ; Wed, 4 Jan 2023 09:21:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC27A8E0002; Wed, 4 Jan 2023 04:21:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A72908E0001; Wed, 4 Jan 2023 04:21:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 960808E0002; Wed, 4 Jan 2023 04:21:14 -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 87F708E0001 for ; Wed, 4 Jan 2023 04:21:14 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 326641605D3 for ; Wed, 4 Jan 2023 09:21:14 +0000 (UTC) X-FDA: 80316572868.03.B50EC6F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 37C738000A for ; Wed, 4 Jan 2023 09:21:11 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=i9do6Il9; spf=pass (imf30.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672824072; a=rsa-sha256; cv=none; b=D7ycye0l025qhRYpO4iCkZF/iOek1wlDtWzUxJ/MyCRrMVftQNhEJv/Aagpjk0rlUXI6mv sIA5Gny1oXzHBMyN4LvsvBwRiGZPo3d9zACdhph/JT0BsQXV1rIzZIcuew6lRqn4AmDUSE CTm5xs/ZeMtCS48+aDXA5XW/YNpI+wg= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=i9do6Il9; spf=pass (imf30.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672824072; 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=QImjhOOloK+pXhrUnbGTzQOZj09SqLqo9+7GOgPxUls=; b=yVR3UaD3LFOV+8wVqtuuGWqw08/QYSXNi6oUmVvlKVBT7kO0o3+5sOAZWlzCsP8tNEsF60 bZedGpXARCt8HDpKcc6iMZcE+RRjEGsWZBr+hJbXcqe6K9E1ZZi1aD/glgOU4l+IOxwd75 2b/INR9gzslq92XPoGmspEAg+ghgTsc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1672824071; 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; bh=QImjhOOloK+pXhrUnbGTzQOZj09SqLqo9+7GOgPxUls=; b=i9do6Il93dC5vdTw11AXx/XG9Iq6Gq/KAzS5c5xiKpHeY7TV72XxDvGQfoaNHqXW+agS39 yLhxTuVz4te/8qIBH/LCffFykgm+8WNWawkw6QqoYXRErFvIxDTyN1qb34CXmlJJY8+ezl kbgPwdZk7k1ShnrX+gR/5la/9+0ZQ10= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-393-d5VcSDpEPEuAvX_EFbkY6A-1; Wed, 04 Jan 2023 04:20:54 -0500 X-MC-Unique: d5VcSDpEPEuAvX_EFbkY6A-1 Received: by mail-wr1-f72.google.com with SMTP id r21-20020adfb1d5000000b0026e4c198a43so4149686wra.20 for ; Wed, 04 Jan 2023 01:20:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QImjhOOloK+pXhrUnbGTzQOZj09SqLqo9+7GOgPxUls=; b=qAoPqdvGggE/Oun7aqB6ffd2pKpGzd6IvTPIAn4eXT6IOooaiL8k/shgC7EWroXHLS RgKz8peWdB1OUO4Znp+2ZlBl/KMbhBEhgpMXrCqaLQueNqhiJ34hhYj4WB2LwWH7qDSp f5AFmAJ17fk41BDHX6KuuRpUZ48R3WO07submRhLo6GPJuFwfuumm0SegEMeAM1BTIM4 RBMEth23V0Jk6gSfYg0LWiQpH2ZBjlwWBjo6VM/qn/XpOHWutWsTzNlJNUb6rnAq3LkD 9N8hzULHls6ylPnU8hOb7P2Hh9L1L8IwUmV8a5PPc7DKSVJ2/Y/dwMsd5HaOh/G8yDk0 UcSA== X-Gm-Message-State: AFqh2kr7x/OhRmP6Ba2EGQVBqMlVU8bIckYWTZVCTIxGzv0pBDuHfoXt AUFfUQqZK8ZJvx+yKTxWEE4jQUkHe6JWavXLtcNwg5ZdAnXhicWCypfJQSmrIC7rO/obrT2n86f kSE3myzg2eMQ= X-Received: by 2002:a7b:c4c8:0:b0:3d3:5a4a:9101 with SMTP id g8-20020a7bc4c8000000b003d35a4a9101mr36678245wmk.23.1672824053247; Wed, 04 Jan 2023 01:20:53 -0800 (PST) X-Google-Smtp-Source: AMrXdXuQGb/xlc8uVJfpF+0B9Kv9Yf6rBAZA/sTj1jXoQbUI6TjsIqRmKP5YuBzh4FDJj7hqyhEs1A== X-Received: by 2002:a7b:c4c8:0:b0:3d3:5a4a:9101 with SMTP id g8-20020a7bc4c8000000b003d35a4a9101mr36678230wmk.23.1672824052962; Wed, 04 Jan 2023 01:20:52 -0800 (PST) Received: from ?IPV6:2003:cb:c703:f100:8100:5a6c:eb:fd3b? (p200300cbc703f10081005a6c00ebfd3b.dip0.t-ipconnect.de. [2003:cb:c703:f100:8100:5a6c:eb:fd3b]) by smtp.gmail.com with ESMTPSA id w12-20020a05600c474c00b003d04e4ed873sm34465384wmo.22.2023.01.04.01.20.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Jan 2023 01:20:52 -0800 (PST) Message-ID: <7ff97950-b524-db06-9ad6-e98b80dcfefa@redhat.com> Date: Wed, 4 Jan 2023 10:20:51 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 To: Hugh Dickins Cc: Andrew Morton , Jann Horn , Yang Shi , Zach O'Keefe , Song Liu , linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <32be06f-f64-6632-4c36-bed7c0695a3b@google.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH] mm/khugepaged: fix collapse_pte_mapped_thp() to allow anon_vma In-Reply-To: <32be06f-f64-6632-4c36-bed7c0695a3b@google.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: 7bit X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 37C738000A X-Stat-Signature: btyx85or9tycku8y5r4xgx75pbmggy8r X-HE-Tag: 1672824071-88285 X-HE-Meta: U2FsdGVkX18t/fc3dmiR86yNKv+LBYxApbCzIZIArTldY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fUC1fLhdDu8emQfMR4wdtONJf339otLlCOW/bRXfEOlfr 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: >> Or am I wrong? >> >>> Is anon_vma lock required? Almost not: if any page other than expected >>> subpage of the non-anon huge page is found in the page table, collapse is >>> aborted without making any change. However, it is possible that an anon >>> page was CoWed from this extent in another mm or vma, in which case a >>> concurrent lookup might look here: so keep it away while clearing pmd >>> (but perhaps we shall go back to using pmd_lock() there in future). >>> >>> Note that collapse_pte_mapped_thp() is exceptional in freeing a page table >>> without having cleared its ptes: I'm uneasy about that, and had thought >>> pte_clear()ing appropriate; but exclusive i_mmap lock does fix the problem, >>> and we would have to move the mmu_notification if clearing those ptes. >>> >>> Fixes: 8d3c106e19e8 ("mm/khugepaged: take the right locks for page table >>> retraction") >>> Signed-off-by: Hugh Dickins >>> Cc: Jann Horn >>> Cc: Yang Shi >>> Cc: David Hildenbrand >>> Cc: Zach O'Keefe >>> Cc: Song Liu >>> Cc: [5.4+] >>> --- >>> What this fixes is not a dangerous instability! But I suggest Cc stable >>> because uprobes "healing" has regressed in that way, so this should follow >>> 8d3c106e19e8 into those stable releases where it was backported (and may >>> want adjustment there - I'll supply backports as needed). >> >> If it's really something that doesn't matter in practice (e.g., -1% >> performance while debugging :) ), I guess no CC is needed. If there are real >> production workloads that suffer, I guess ccing stable is fine. > > It's about recovering performance *after* debugging. It is not something > that is of any value to me personally, nor (so far as I know) to anyone > whom I work with. But it is something which Song Liu went to the trouble > to make possible in his "THP aware uprobe" series three years ago, and it > is something which Jann unintentionally regressed in his recent commit: > so I thought it proper to reinstate where regressed. Right, although I wonder if that original series fixed a real performance issue or was more a "this makes sense, let's just optimize this corner case by some serious complexity". I hope it's not the latter :) > > (What I do have more of an investment in, is for MADV_COLLAPSE to be able > to collapse some extents in a large vma where some other extent got CoWed, > so giving the whole vma an anon_vma. But that's not an issue for -stable, > and I cannot tell you offhand whether undoing this anon_vma exclusion is > enough to enable that or not - I suspect not, I suspect a result code or > switch statement needs to be adjusted too.) Yeah, having a single COWed page in a large MAP_PRIVATE file/shmem mapping would disable collapse, so it's the right thing to do. Thinking about it some more, and the effective code change, stable doesn't sound wrong. >> >> >> Side note: set_huge_pmd() wins the award of "ugliest mm function of early >> 2023". I was briefly concerned how do_set_pmd() decides whether the PMD can be >> writable or not. Turns out it's communicated via vm_fault->flags. Just >> horrible. > > I firmly disagree - it's from 2022! and much too small to be ugliest; > but I haven't thought about the aspect that is bothering you there. The ugliest I stumbled over in early 2023 -- until January 2nd :D > > What's bothered me most about it, is the way its name, and the naming of > the do_set_pmd() it interfaces with, give no hint that they are entirely > about file (or shmem) vmas, and would not work right on anon vmas > (I forget whether it's just a matter of which stats updated, or more). Yes. I dug very deep into in-place collapse yesterday because I was briefly concerned about anon THP, and it took me longer to understand that whole machinery than it should (and that anon THP never ever collapse in-place). Some of that khugepaged stuff needs some *serious* cleanups and refactoring. do_set_pmd() is not an exception. Some more examples: if (IS_ENABLED(CONFIG_SHMEM) && vma->vm_file) { ... hpage_collapse_scan_file() } else { hpage_collapse_scan_pmd() ... } 1) hpage_collapse_scan_pmd() is only for anon memory. Totally obvious from the name. But why are we potentially calling it for VMAs that are not applicable? For maximum David confusion? 2) "IS_ENABLED(CONFIG_SHMEM) && vma->vm_file" is also supposed to cover ordinary file-thp. Totally obvious from the IS_ENABLED(CONFIG_SHMEM) ... I probably spent 30minutes understanding what's happening here. Just misleading and wrong without CONFIG_SHMEM. ... and what's easier to get than this magic set of boolean flags: hugepage_vma_check(vma, vma->vm_flags, false, false, true) ... and obviously hugepage_vma_revalidate() is supposed to be a follow up to a previous hugepage_vma_check() and totally different from transhuge_vma_suitable() Hard to make it even less consistent. Also, it's very clear from the code that SCAN_PTE_MAPPED_HUGEPAGE only applies to file-thp, right? No. -- Thanks, David / dhildenb