Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1503563rwd; Thu, 18 May 2023 12:55:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6lFTeSQw4Qc0TjVu9fTVInRQ9Z0vSeBUEz5XP7Paqxf5hPBa/3asbHB/tXkG2hzbuVuzNn X-Received: by 2002:a17:90a:ccf:b0:24e:37c6:9681 with SMTP id 15-20020a17090a0ccf00b0024e37c69681mr4057934pjt.38.1684439756830; Thu, 18 May 2023 12:55:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684439756; cv=none; d=google.com; s=arc-20160816; b=lNhGGfB5x2+m3KnIbq9K81bIzd51Ns7pEV+XDUg2oZNkyoSUMZQK8UJt5V9xmgB68d 76/xMAr/To/ovqJRgtgSqDQqrfDbEMa8SlmAs25FoDYWYRt3M0mRbbkmeDHGlOWeYVuh bmxx7XYHHtgooUQmy0jWpqXMhsonDq8KvHuWdn0uE6ABk3Cg7MDg+sYOXnmIx+yk1LHq fUQQQbEbgPqPlrl678x1LrvBH5kxD3OzDvYhm3KOhZ8OiIFPY5WPMdgyhkH1BXdEpJZF k/vkFyrwtFlHrWWLLv5cbm3a2ZnbQJwUDJAy4c+GFIffSTwny9vJEeccTNmvlDUw7JVt YKGQ== 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=0Y0RqGagcYjlQAFm/IWSrNSzj7W+UdS1UVZleO5FMag=; b=t2rz2vRldA/iD4dvI+zuBe5EbQSXnmGzVuTrOZ10IHedKd1AyHV6oyCbQtbMwD7Qh7 3Cowg7kRYW1LU7XQr2d2w1Z5FKVqQGk+8b6XHGH9R2TMI8hOW01zR3Qz55hVQ2muaP1H GnvyfiOA6SgtmeR8M8iEksDK5OiQXWif4hi3zGmvRtiiw3RPO/3+7uSt1NrArR+wbAph LwFpLwNQgNqdXmLYWwOQHZthA02vchX2SOxC/+zCKns5QJwpIm799f8uh70ziHR7pu2K j0g6/DfFNVft8JEq93MxynLTBwS6xVKqfkvZlsIDtJERiQJNqHxzuf6fvybM5RVTRG1X ljdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Q9o775Rj; 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 62-20020a17090a0fc400b0024e22853a90si127845pjz.170.2023.05.18.12.55.45; Thu, 18 May 2023 12:55:56 -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=Q9o775Rj; 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 S230144AbjERTDW (ORCPT + 99 others); Thu, 18 May 2023 15:03:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229553AbjERTDU (ORCPT ); Thu, 18 May 2023 15:03:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27E10ED for ; Thu, 18 May 2023 12:03:19 -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 B8BF660B7C for ; Thu, 18 May 2023 19:03:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2585AC433A4 for ; Thu, 18 May 2023 19:03:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684436598; bh=34OAiZIPKDw+WhaknFtzgMGGRM/uM4kd2z9SISgsEqo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Q9o775RjZoJw0WQin4BFUO3ZA5OnWpQgL1Qn8JGF4VaTWwMo4/agvV3GzFmNmdCED kGoBngLWXC0fRFbJGbZllNRgvY3oilqV3BHnUH+9zRXMdAbH2S/ZXRoQRm7JcTaWBh PX4BtGKTg8J3a0NEMfbS23q3bKcu4NaOMDQ6QlyfOms0NMjgAPr0KWa3ivz4pExqCu 50eyJ9xXLD9v6V2322Cx3gtCQN3jajySQ9JQDJ2AeGo64Syg/FZa0kzwq39VkNVMT2 qkdaZ0TFry0ar8aOTSYbxatuW92n2rtkeSwOqVudIkN+5j7nfE9hDYiF9+XjbxjvyE aqVW1nzg9FPUQ== Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-4f00c33c3d6so2913312e87.2 for ; Thu, 18 May 2023 12:03:18 -0700 (PDT) X-Gm-Message-State: AC+VfDyoBJOBUn3s0NobfeznuoTCGo3vNMOmE60HQjW/bn3U+/LuKMlM F2C61n7ilmi3OaMkoQ4W4hcd4qzMUALFxq/CKrc= X-Received: by 2002:a2e:9dca:0:b0:2a9:ee54:289f with SMTP id x10-20020a2e9dca000000b002a9ee54289fmr12043370ljj.13.1684436596130; Thu, 18 May 2023 12:03:16 -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 12:03:03 -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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 11:47=E2=80=AFAM Song Liu wrote: > > 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 plan= ning 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 t= hink > > > > he had some fair points in that thread. > > > > > > Yes, the API is based on Thomas's suggestion, like 90% from the discu= ssions. > > > > > > > > > > > My own feeling is that the buddy allocator is our tool for allocati= ng > > > > larger variable sized physically contiguous allocations, so I'd lik= e to > > > > see something based on that - I think we could do a hybrid buddy/sl= ab > > > > 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, s= o > > 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 misse= d > > :) > > 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 with= in > 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, th= e > tree based allocator can allocate 4MiB for it, and use the rest 1MiB for > smaller allocations. Missed one: Third, bitmap based solution requires a "size" parameter in free(). It is a= n overhead for the user. Tree based solution doesn't have this issue. Thanks, Song > > [2] https://lore.kernel.org/linux-mm/20221107223921.3451913-6-song@kernel= .org/