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 DFD04C433F5 for ; Fri, 15 Apr 2022 20:04:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 327296B0073; Fri, 15 Apr 2022 16:04:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AE7D6B0074; Fri, 15 Apr 2022 16:04:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 103256B0075; Fri, 15 Apr 2022 16:04:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id F00916B0073 for ; Fri, 15 Apr 2022 16:04:44 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BE9E760D6B for ; Fri, 15 Apr 2022 20:04:44 +0000 (UTC) X-FDA: 79360191288.19.7E7DDE3 Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) by imf04.hostedemail.com (Postfix) with ESMTP id 42EE040008 for ; Fri, 15 Apr 2022 20:04:44 +0000 (UTC) Received: by mail-lj1-f179.google.com with SMTP id v13so4385580ljg.10 for ; Fri, 15 Apr 2022 13:04:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=d6P7bmQOL4UgotCsfBfpuQrcjld7F7Kse/JT8F6RGWk=; b=QPDVDrHHFGu2y2JmFL977iiuSfwSCn4dh2Wp9HCSTNOQCBoZqWWq8jEC5VT+6gJiTD BlPNGl5elYSHGO8xQ+paG6k7HRWQiYhjZyJjNfUu+UxqhS5mfmCKnMGvEPAhlzXv8bJ7 udaIMklcuCCFzRkfe43fgY7m7uhE4KscIzmGkBi3iAgzI/DehvfnS1bcYaYbuRbh1xwD P7KFZ2ami6sMxJ0uYDHLLyZ6ZmoN5oXCtdzZ25SRrUb+JK84d5Rbd16rKUVgotUWTBZ0 SSWJeiZxXWvhpwCZ3uWZUnvBg9A1zqigY4bmWlokpvEUetx8OFCiS52/rg45OMi6CAzO iZSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=d6P7bmQOL4UgotCsfBfpuQrcjld7F7Kse/JT8F6RGWk=; b=L8FGw8LhTV12B8RVOH7WIxuLZOMe/j+Y46GC/f+AlpnPVr10BGz+7V6JOCY5aq1Kwx NNyiJKBgauZEtF2G0eN4CyLbTC/ZOqBV+qWLyrgi3d8AkKB4kOIphY2LXfgKkIXTJlYw rwgiEy6SJ81Emdid/qUKM/Eaog4HBR2jFrefCgpiWc78fKItF6Ospid71GS8yWPTdVIx t7YD/xGeykNz0W7S09+OX9+dJbLm2yjTJmzsC+8/K5B5SjfHISOjP2A5p6YRDKvrtsQI JbBViPiEgqAutSfZE/yZiW5GPSqEGqvT8g541G72KeHRAhj2S2FH4nAd29m+ZFvaQ0Sb YGqw== X-Gm-Message-State: AOAM531rB0f6lijS96Q64upg3+PpwCFWAJt8PcJdpPCeAU4jtD6oq0Y1 Q2I6cggk0TqKFbswkoe40laNjJviYiIxQaWr7pZrvg== X-Google-Smtp-Source: ABdhPJwdHDtog+84girdLi6k7gYaQRJoaHuXPuGYvOFM8G/OwCszPpsQpdmjkk+XHhLSJyHM+icBvg8D0zAwAUZwg4Y= X-Received: by 2002:a05:651c:992:b0:249:9dc2:9ede with SMTP id b18-20020a05651c099200b002499dc29edemr391979ljq.187.1650053081132; Fri, 15 Apr 2022 13:04:41 -0700 (PDT) MIME-Version: 1.0 References: <20220414180612.3844426-1-zokeefe@google.com> In-Reply-To: From: "Zach O'Keefe" Date: Fri, 15 Apr 2022 13:04:04 -0700 Message-ID: Subject: Re: [PATCH v2 00/12] mm: userspace hugepage collapse To: Peter Xu Cc: Alex Shi , David Hildenbrand , David Rientjes , Matthew Wilcox , Michal Hocko , Pasha Tatashin , SeongJae Park , Song Liu , Vlastimil Babka , Yang Shi , Zi Yan , linux-mm@kvack.org, Andrea Arcangeli , Andrew Morton , Arnd Bergmann , Axel Rasmussen , Chris Kennelly , Chris Zankel , Helge Deller , Hugh Dickins , Ivan Kokshaysky , "James E.J. Bottomley" , Jens Axboe , "Kirill A. Shutemov" , Matt Turner , Max Filippov , Miaohe Lin , Minchan Kim , Patrick Xia , Pavel Begunkov , Thomas Bogendoerfer Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: 3qai8kh9w895tetnnp8efkmo4a3uq6zg X-Rspam-User: Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=QPDVDrHH; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of zokeefe@google.com designates 209.85.208.179 as permitted sender) smtp.mailfrom=zokeefe@google.com X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 42EE040008 X-HE-Tag: 1650053084-991503 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000278, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Apr 15, 2022 at 6:39 AM Peter Xu wrote: > > On Thu, Apr 14, 2022 at 05:52:43PM -0700, Zach O'Keefe wrote: > > Hey Peter, > > > > Thanks for taking the time to review! > > > > On Thu, Apr 14, 2022 at 5:04 PM Peter Xu wrote: > > > > > > Hi, Zach, > > > > > > On Thu, Apr 14, 2022 at 11:06:00AM -0700, Zach O'Keefe wrote: > > > > process_madvise(2) > > > > > > > > Performs a synchronous collapse of the native pages > > > > mapped by the list of iovecs into transparent hugepages. > > > > > > > > Allocation semantics are the same as khugepaged, and depend on > > > > (1) the active sysfs settings > > > > /sys/kernel/mm/transparent_hugepage/enabled and > > > > /sys/kernel/mm/transparent_hugepage/khugepaged/defrag, and (2) > > > > the VMA flags of the memory range being collapsed. > > > > > > > > Collapse eligibility criteria differs from khugepaged in that > > > > the sysfs files > > > > /sys/kernel/mm/transparent_hugepage/khugepaged/max_ptes_[none|swap|shared] > > > > are ignored. > > > > > > The userspace khugepaged idea definitely makes sense to me, though I'm > > > curious how the line is drown on the different behaviors here by explicitly > > > ignoring the max_ptes_* entries. > > > > > > Let's assume the initiative is to duplicate a more data-aware khugepaged in > > > the userspace, then IMHO it makes more sense to start with all the policies > > > that applies to khugepaged already, including max_pte_*. > > > > > > I can understand the willingness to provide even stronger semantics here > > > than khugepaged since the userspace could have very clear knowledge of how > > > to provision the memories (better than a kernel scanner). It's just that > > > IMHO it could be slightly confusing if the new interface only partially > > > apply the khugepaged rules. > > > > > > No strong opinion here. It could already been a trade-off after the > > > discussion from the RFC with Michal which I read.. Just curious about how > > > you made that design decision so feel free to read it as a pure question. > > > > > > > Understand your point here. The allocation and max_pte_* semantics are > > split between khugepaged-like and fault-like, respectively - which > > could be confusing. Originally, I proposed a MADV_F_COLLAPSE_LIMITS > > flag to control the former's behavior, but agreed to keep things > > simple to start, and expand the interface if/when necessary. I opted > > to ignore max_ptes_* as the default since I envisioned that early > > adopters would "just want it to work". One such example would be > > backing executable text by hugepages on program load when many pages > > haven't been demand-paged in yet. > > > > What do you think? > > I'm just slightly worried that'll make the default MADV_COLLAPSE semantics > blurred. > > To me, a clean default definition for MADV_COLLAPSE would be nice, as "do > khugepaged on this range, and with current thread context". IMHO any > feature bits then can be supplementing special needs, and I'll take the thp > backing executable example to be one of the (good?) reason we'd need an > extra flag for ignoring the max_ptes_* knobs. > > So personally if I were you maybe I'll start with the simple scheme of that > (even if it won't immediately service a thing) but then add either the > defrag or ignore_max_ptes_* as feature bits later on, with clear use case > descriptions about why we need each of the feature flags. IMHO numbers > would be even more helpful when there's specific use cases on the show. > > Or, perhaps you think all potential MADV_COLLAPSE users should literally > skip max_ptes_* limitations always? > Thanks for your time and valuable feedback here, Peter. I had a response typed up, but after a few iterations became increasingly unsatisfied with my own response. I think this feature should be able to stand on its own without consideration of a userspace khugepaged, as we have existing concrete examples where it would be useful. In these cases, and I assume almost all other use-cases outside userspace khugepaged, max_ptes_* should be ignored as the fundamental assumption of MADV_COLLAPSE is that the user knows better, and IMHO, khugepaged heuristics shouldn't tell users they are wrong. But this, as you mention, unsatisfactorily blurs the semantics of MADV_COLLAPSE: "act like khugepaged here, but not here". As such, WDYT about the reverse-side of the coin of what you proposed: to not couple the default behavior of MADV_COLLAPSE with khugepaged at all? I.e. Not tie the allocation semantics to /sys/kernel/mm/transparent_hugepage/khugepaged/defrag. We can add flags as necessary when/if a reimplementation of khugepaged in userspace proves fruitful. Thanks for your time and input, Zach > Anyway, I won't pretend I am an expert in this area. :) So please take that > with a grain of salt. > > Thanks, > > -- > Peter Xu >