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 530ACC433F5 for ; Sat, 16 Apr 2022 19:26:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3166B6B0072; Sat, 16 Apr 2022 15:26:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2C5A96B0073; Sat, 16 Apr 2022 15:26:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 140486B0074; Sat, 16 Apr 2022 15:26:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 008DE6B0072 for ; Sat, 16 Apr 2022 15:26:46 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id BBC391204ED for ; Sat, 16 Apr 2022 19:26:46 +0000 (UTC) X-FDA: 79363724412.09.9B840D5 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 2311C180003 for ; Sat, 16 Apr 2022 19:26:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650137205; 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: in-reply-to:in-reply-to:references:references; bh=aHsSSPFnojZsUNIsLijzTeQnA/+ajAs0v/TliJbEKKw=; b=U9e5/o+Rmsm3HfvNNY/1n5VrMgx2/88mv4214xsj5UQvggLhd1MbKR0VPabJ0iInYTPEZB rtRJ6kDk0ugUxb3W+UoUaII3D50UWYyqenxt/QHQzN+3uW3LgyV/IrovRYhyt7MgeE9bxb 062xai/vKZZN/XsIhvejHmjCi72SkAQ= Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-153-JKG7aUMYMgS0H2VF8BhtWA-1; Sat, 16 Apr 2022 15:26:44 -0400 X-MC-Unique: JKG7aUMYMgS0H2VF8BhtWA-1 Received: by mail-io1-f70.google.com with SMTP id f5-20020a6be805000000b00649b9faf257so6981869ioh.9 for ; Sat, 16 Apr 2022 12:26:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=aHsSSPFnojZsUNIsLijzTeQnA/+ajAs0v/TliJbEKKw=; b=4/F6SUwpmifksq/cLwNBJgGtpm5SwLv43UZiRxqSd5hKik5VeXCDjpWLaPpjT1sH3L JMGhDhKTb5w4zhnyMdyXc+TYaEkVZ4BgWNeSM+/71zVqiyo2sC0luZLxznAB6ixvwlth vw3AsZPoJaE+g51wkWkgxSKYZQLKjq+5GDEkW/ItqtHFZZgFjtkNEwZ02P3X3WGGoTQA UQhg2z8bmKnw9TMOjWfeL+etRQthyUdcTMpMUyBvD9DxRzi6woQ3bM9Fo9M8a5GZ3fha yI5F58lDw6QrEbPF5VgmbCOOYos/uSl5ywlv5bRPCSt3txWAFuQNbxEUpj0lpJQYJTJK DZXw== X-Gm-Message-State: AOAM531lG0o0jK5tVV30DpslIqSd1Bq4j6u3kFolPzc7kjPGShx5xvu/ mru14OHl707d8LVGyfxiEBN/LE2n3q8kFVeYM5rz8qVGGIyF/4nsLTbTxajO8Sn4GS0IvNH7qoM NgG0B4RDipYg= X-Received: by 2002:a6b:580d:0:b0:64d:2495:b598 with SMTP id m13-20020a6b580d000000b0064d2495b598mr1682215iob.89.1650137203783; Sat, 16 Apr 2022 12:26:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTCfFNuqjOPvXomdZfcBwoSpQ9Eo7l3UxXsVhLqnTWjadXJ5yTZmJ/oCCdIjq7+v1QtYGoRg== X-Received: by 2002:a6b:580d:0:b0:64d:2495:b598 with SMTP id m13-20020a6b580d000000b0064d2495b598mr1682185iob.89.1650137203397; Sat, 16 Apr 2022 12:26:43 -0700 (PDT) Received: from xz-m1.local (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id e17-20020a056602045100b006538224d4ccsm2164110iov.25.2022.04.16.12.26.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Apr 2022 12:26:43 -0700 (PDT) Date: Sat, 16 Apr 2022 15:26:40 -0400 From: Peter Xu To: Zach O'Keefe 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 Subject: Re: [PATCH v2 00/12] mm: userspace hugepage collapse Message-ID: References: <20220414180612.3844426-1-zokeefe@google.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="U9e5/o+R"; spf=none (imf16.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: w94cf5myoast8hck57n8traw77ss1mk4 X-Rspamd-Queue-Id: 2311C180003 X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1650137205-294682 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: Hi, Zach, On Fri, Apr 15, 2022 at 01:04:04PM -0700, Zach O'Keefe wrote: > 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. Valid point. And actually right after I replied I thought similarly on whether we need to connect the two interfaces at all.. It's just that it's very easy to go think like that after reading the cover letter since that's exactly what it is comparing to. :) There's definitely a difference view on user/kernel level of things, then it sounds reasonable to me if we add a new interface it by default has a stronger semantics otherwise we may not bother if with MADV_HUGEPAGE's existance. So maybe max_ptes_* won't even make sense for MADV_COLLAPSE in most cases as you said. And that's a real pure question I asked above, and I feel like your answer is actually "yes" we should always ignore the max_ptes_* fields until there's a proof that it'll be helpful. > > 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. Let's see whether others have thoughts, but what you proposed here makes sense to me. Thanks, -- Peter Xu