Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1436003rwd; Thu, 18 May 2023 11:57:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ZFtv94rRLp3alO3f8U9Op+WjPWAQqfNRZHiGfrxZ/Y0Cyj+UJ5f7cgU4NoXUvCriN0cqI X-Received: by 2002:a17:90a:d710:b0:24e:9e6:7067 with SMTP id y16-20020a17090ad71000b0024e09e67067mr3508783pju.7.1684436253669; Thu, 18 May 2023 11:57:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684436253; cv=none; d=google.com; s=arc-20160816; b=HEP0yzbxTJRPVjFSOB2yL0IOQxl4o56Zl4aQQnuVTtp6VvYLKMCnoepOImhCkk0Lo1 HblLVR4sY40LkUytaleixghh+4SZklyEpY0Tw/1L9w7u7hxAybqn0TRc5NLe394GcgZ2 ml4huJO4uWWLBIr/SJroiAviN0AVPVeTzjpqHuLPF4BHOC1wFa4Uez92oj8WCZm/vV7y TxWqmvy/cJKYkH4BPer2x51Cki0ZoguDA5yHiEY0DYrlvYO/C34xnkfgctoyU2AVLJbt 4QmijuHahKtvNqL77EncJGG/C1A93qEmRUAhAna+qBewsPMTl92gTVXhHQY8vO37Fkkw cecg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=PwjszGGbFiAKWyCBInDp/gi7XkhqivYocgollkpnG/c=; b=CMRyjZOwI47LGWWVwn6cgFHjYRhhtjwgTjghwOGfGWcBpYMTins1cI/QbTK200Y3qy qeSRHz9l+b34aRUPE5UQbSn5m6Y4vATFA4Ii1mygaLRZyCAV0sD8voCLjxyNCW5wFllC +eu2OFfrJgBL4nOzFbECJWhVBXB6khcdxqGzU/7efcxPWANAzVUzVPpjI5qq5OJ+BOqZ EtimRIeSIBmuXn6JZCsAe7JtpP+UxvWcvJPqXua0goUfvI0rK4BEpDHIezctbf2wVKrj smz8xsFbKnm9KQjbL6AvBb0IfViTHNW5H/efYttdb9Ze8OHXcpWqaGc4u2Hm49XEntdz FN4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iqbg7GPc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 19-20020a631553000000b005307598826csi2085537pgv.87.2023.05.18.11.57.18; Thu, 18 May 2023 11:57:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iqbg7GPc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230031AbjERSsF (ORCPT + 99 others); Thu, 18 May 2023 14:48:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbjERSsE (ORCPT ); Thu, 18 May 2023 14:48:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0FD0E5E for ; Thu, 18 May 2023 11:48:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 467976518E for ; Thu, 18 May 2023 18:48:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADC9FC433D2 for ; Thu, 18 May 2023 18:48:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684435681; bh=keVuOeJQn7MUYbsAN7orx57MdKZnoEd10BmBQ0B0DpY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=iqbg7GPcXvGJ8jHsEUSRhh+HbeOxVbSs284ElEG5RrCjw3gvZEfzlvvLQ5M0faBBL RprpbhSg/5nSGt7U8qHCSApNn0qCzolxZFAxgsBAK5qipCS28lR5mqSjM/vjfaZG/A UY8fj2ZTRwbpPctIoAaSFtfsoHj0TNeFQEWNsoUd9uLj5W4QLkqnofE0wFGZGuBVcN 1yPWtO2EenfvhPSKYdnxQoPXhGypSTiISqYPkekbWPRJ/DXvN7f7MsZ6Lpe/a/n+se uPxAgaxEiDruKqyL6dfTBwc1A8GntsYAl/TXwdVsdzsK6lU9AipV+TKGvEIYOiRsl/ WBUr/PhKtmMQg== Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2ac79d4858dso25531891fa.2 for ; Thu, 18 May 2023 11:48:00 -0700 (PDT) X-Gm-Message-State: AC+VfDz5ZnmL5wBbSRcEGskD43nogPW0NLw1o5RoXn9DRNlbcJQmksaA m4rSGU/Qvc0Hd/6794DEyWBvApqmZaPEqoHlNF4= X-Received: by 2002:a2e:9053:0:b0:2ac:7ab1:a441 with SMTP id n19-20020a2e9053000000b002ac7ab1a441mr11685597ljg.30.1684435678735; Thu, 18 May 2023 11:47:58 -0700 (PDT) MIME-Version: 1.0 References: <20230308094106.227365-1-rppt@kernel.org> <20230308094106.227365-2-rppt@kernel.org> <20230518152354.GD4967@kernel.org> In-Reply-To: From: Song Liu Date: Thu, 18 May 2023 11:47:46 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 1/5] mm: intorduce __GFP_UNMAPPED and unmapped_alloc() To: Kent Overstreet Cc: Mike Rapoport , linux-mm@kvack.org, Andrew Morton , Dave Hansen , Peter Zijlstra , Rick Edgecombe , Thomas Gleixner , Vlastimil Babka , linux-kernel@vger.kernel.org, x86@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 18, 2023 at 10:24=E2=80=AFAM Kent Overstreet wrote: > > On Thu, May 18, 2023 at 10:00:39AM -0700, Song Liu wrote: > > On Thu, May 18, 2023 at 9:48=E2=80=AFAM Kent Overstreet > > wrote: > > > > > > On Thu, May 18, 2023 at 09:33:20AM -0700, Song Liu wrote: > > > > I am working on patches based on the discussion in [1]. I am planni= ng to > > > > send v1 for review in a week or so. > > > > > > Hey Song, I was reviewing that thread too, > > > > > > Are you taking a different approach based on Thomas's feedback? I thi= nk > > > he had some fair points in that thread. > > > > Yes, the API is based on Thomas's suggestion, like 90% from the discuss= ions. > > > > > > > > My own feeling is that the buddy allocator is our tool for allocating > > > larger variable sized physically contiguous allocations, so I'd like = to > > > see something based on that - I think we could do a hybrid buddy/slab > > > allocator approach, like we have for regular memory allocations. > > > > I am planning to implement the allocator based on this (reuse > > vmap_area logic): > > Ah, you're still doing vmap_area approach. > > Mike's approach looks like it'll be _much_ lighter weight and higher > performance, to me. vmalloc is known to be slow compared to the buddy > allocator, and with Mike's approach we're only modifying mappings once > per 2 MB chunk. > > I don't see anything in your code for sub-page sized allocations too, so > perhaps I should keep going with my slab allocator. The vmap_area approach handles sub-page allocations. In 5/5 of set [2], we showed that multiple BPF programs share the same page with some kernel text (_etext). > Could you share your thoughts on your approach vs. Mike's? I'm newer to > this area of the code than you two so maybe there's an angle I've missed > :) AFAICT, tree based solution (vmap_area) is more efficient than bitmap based solution. First, for 2MiB page with 64B chunk size, we need a bitmap of 2MiB / 64B =3D 32k bit =3D 4k bytes While the tree based solution can adapt to the number of allocations within This 2MiB page. Also, searching a free range within 4kB of bitmap may actually be slower than searching in the tree. Second, bitmap based solution cannot handle > 2MiB allocation cleanly, while tree based solution can. For example, if a big driver uses 3MiB, the tree based allocator can allocate 4MiB for it, and use the rest 1MiB for smaller allocations. Thanks, Song [2] https://lore.kernel.org/linux-mm/20221107223921.3451913-6-song@kernel.o= rg/