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 303BCC433EF for ; Fri, 26 Nov 2021 09:17:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4584F6B0072; Fri, 26 Nov 2021 04:17:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 408516B0078; Fri, 26 Nov 2021 04:17:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A8446B007B; Fri, 26 Nov 2021 04:17:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0244.hostedemail.com [216.40.44.244]) by kanga.kvack.org (Postfix) with ESMTP id 1860B6B0072 for ; Fri, 26 Nov 2021 04:17:16 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C412F184E5898 for ; Fri, 26 Nov 2021 09:17:05 +0000 (UTC) X-FDA: 78850527168.07.E0BEE97 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 48B3210000B9 for ; Fri, 26 Nov 2021 09:17:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637918224; 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=v3CdXWc1SZaICoTk9b5MrvXGDxRWiBZQIkDS68EgmRQ=; b=hfTaiwAuhfxceAgevLfzQShagbb6v6SSw7Ee1XHo5JisLfdbxuYYxZo2hTFMpq+bTqME+l M98isGHnF9950UuGmMCY/YucxVZNm/p2kq+MBXBXuJ3zqJmuYCajTFWVQC0m4IGdQXAqKQ 0hG6NKWlNygNngeRGyiR+JNnpuHZh4k= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-483-uOdZWSJXPxqBDFZ31uNMbg-1; Fri, 26 Nov 2021 04:17:01 -0500 X-MC-Unique: uOdZWSJXPxqBDFZ31uNMbg-1 Received: by mail-wm1-f69.google.com with SMTP id j25-20020a05600c1c1900b00332372c252dso5044721wms.1 for ; Fri, 26 Nov 2021 01:17:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=v3CdXWc1SZaICoTk9b5MrvXGDxRWiBZQIkDS68EgmRQ=; b=WNViCKfh24ZDmvVM3crNTFW2uJ5QtBFpfodaO0LEVWNfqV2MmTmKpAObMp8nJL7F3b 0+YHBk+ryflR/Ww/nuuPVsEmm9wKSBrrLCU/JShIO8L8YZwUOushkbk6uSvPb/mQ8pNu Zcmf4hNXbHmX7E45GZ23AqLAHEYevqmkXtOv2YmJh16+bBq6hfsaqnQEv/BRnTpkeszw I5GHCXhqTMaVdSnfqg8cU5ThVBxsgp66asHKQaQchaXGihZaWxhCRnndXga/R8vfj5F2 HkPq2f+YhX9yhabzF6alKdoPkNMMaWFpXSAFOZLgAgxz8B9GY/RmIEadnwp+d3yZ7FPV hxWg== X-Gm-Message-State: AOAM531sslteDIplXvocWcUcg5n3t+bghceq+hLeC6Hl/73Bxe0ARZVs rD/ft45GHoYBzZI56DGG3LgtmLguqC+HpzDTDznlbodxsn5kGr6hJS9H3a9P69ybGxwkUeEvYCw Fa73oMhzzRf0= X-Received: by 2002:a5d:6dab:: with SMTP id u11mr12716359wrs.46.1637918220335; Fri, 26 Nov 2021 01:17:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJw0Xs4/dvseMjQSCGAu8v5sW1hnGyhvEhMdCBtyjW6s4Rl5ZE978y0sOrNpmxY1pUPNudYfyw== X-Received: by 2002:a5d:6dab:: with SMTP id u11mr12716341wrs.46.1637918220137; Fri, 26 Nov 2021 01:17:00 -0800 (PST) Received: from [192.168.3.132] (p5b0c69e1.dip0.t-ipconnect.de. [91.12.105.225]) by smtp.gmail.com with ESMTPSA id w7sm4989545wru.51.2021.11.26.01.16.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Nov 2021 01:16:59 -0800 (PST) Message-ID: Date: Fri, 26 Nov 2021 10:16:58 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 To: Peter Xu , Shakeel Butt Cc: "Kirill A . Shutemov" , Yang Shi , Zi Yan , Matthew Wilcox , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, David Rientjes References: <20211120201230.920082-1-shakeelb@google.com> <25b36a5c-5bbd-5423-0c67-05cd6c1432a7@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH] mm: split thp synchronously on MADV_DONTNEED In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 48B3210000B9 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hfTaiwAu; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf12.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com X-Stat-Signature: tyw3iuc5ejzg8iydq8sie9wqu541d1ph X-HE-Tag: 1637918225-759288 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: >> >> Thanks for making me rerun this and yes indeed I had a very silly bug in the >> benchmark code (i.e. madvise the same page for the whole loop) and this is >> indeed several times slower than without the patch (sorry David for misleading >> you). No worries, BUGs happen :) >> >> To better understand what is happening, I profiled the benchmark: >> >> - 31.27% 0.01% dontneed [kernel.kallsyms] [k] zap_page_range_sync >> - 31.27% zap_page_range_sync >> - 30.25% split_local_deferred_list >> - 30.16% split_huge_page_to_list >> - 21.05% try_to_migrate >> + rmap_walk_anon >> - 7.47% remove_migration_ptes >> + 7.34% rmap_walk_locked >> + 1.02% zap_page_range_details > > Makes sense, thanks for verifying it, Shakeel. I forgot it'll also walk > itself. > > I believe this effect will be exaggerated when the mapping is shared, > e.g. shmem file thp between processes. What's worse is that when one process > DONTNEED one 4k page, all the rest mms will need to split the huge pmd without > even being noticed, so that's a direct suffer from perf degrade. Would this really apply to MADV_DONTNEED on shmem, and would deferred splitting apply on shmem? I'm constantly confused about shmem vs. anon, but I would have assumed that shmem is fd-based and we wouldn't end up in rmap_walk_anon. For shmem, the pagecache would contain the THP which would stick around and deferred splits don't even apply. But again, I'm constantly confused so I'd love to be enlighted. > >> >> The overhead is not due to copying page flags but rather due to two rmap walks. >> I don't think this much overhead is justified for current users of MADV_DONTNEED >> and munmap. I have to rethink the approach. Most probably not. > > Some side notes: I digged out the old MADV_COLLAPSE proposal right after I > thought about MADV_SPLIT (or any of its variance): > > https://lore.kernel.org/all/d098c392-273a-36a4-1a29-59731cdf5d3d@google.com/ > > My memory was that there's some issue to be solved so that was blocked, however > when I read the thread it sounds like the list was mostly reaching a consensus > on considering MADV_COLLAPSE being beneficial. Still copying DavidR in case I > missed something important. > > If we think MADV_COLLAPSE can help to implement an userspace (and more > importantly, data-aware) khugepaged, then MADV_SPLIT can be the other side of > kcompactd, perhaps. > > That's probably a bit off topic of this specific discussion on the specific use > case, but so far it seems all reasonable and discussable. User space can trigger a split manually using some MADV hackery. But it can only be used for the use case here, where we actually want to zap a page. 1. MADV_FREE a single 4k page in the range. This will split the PMD->PTE and the compound page. 2. MADV_DONTNEED either the complete range or the single 4k page. -- Thanks, David / dhildenb