Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp4200202rwi; Mon, 17 Oct 2022 03:01:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7EL0EdD27orbyK7VZjGdEecSsen/lbHuTG7zlEFZ8WKFaMXWFFYKc8bqcVtWLOe5H4b7No X-Received: by 2002:a05:6a00:218d:b0:565:b5ac:4810 with SMTP id h13-20020a056a00218d00b00565b5ac4810mr11799433pfi.83.1666000917291; Mon, 17 Oct 2022 03:01:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666000917; cv=none; d=google.com; s=arc-20160816; b=Gw07aKdrU7+jt4GT7YfjOkT0l1qsfEIAiNb3QGT/vWPUwG5SbzuLLCkQivC7FlNOLQ dHFGK+z/bZlL4UncKmWPnMbKZhD0sQCRNzV+xP5joNSJZs8Eip3WAg7dvdfor5uDf+mC WRaeXdvq8zaFr+Mny1/aXBuctLCqCYXjnNCMf4C0M1WqmT0JYiQe7Q5iYK6l4VhcA8Qm 3F5I3RL3Uin1IhT0cPNCpGmaCQCkAB6yTGHAB0+TXHZfzlZgzZjWPSbyXeyadeQuOd1n Fw9iKjHG5uAjV5FoqMPg7uxu7MEd323whUfBvIoustF6LW1P4+FQUXycnV9tnwsrH2jH TLgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=S13sFuTHswn9t8UWriob3QGuAvRLSQnyQGcFlgz2RJ4=; b=tBm6WC21eAzSAcbdi0dESlZbJVYkt3iBNou+T8kABjTuHUAa7WFsKkdum5vAN+UtFV Q9hTcXkOsuHGHtSpmwqveWX3s0F3mdpEXcBLHPXcWqv2UzLv4XO8+AAfpfsS5/A1Wp3t BWN5D65CgQrh5dXYSVEXTKI+eR2sCRVqqUwWiojyR9LTLlZgMau0B/ZGZtoOQgytjUau INm7EZvVzHE19O+cx0c4Tq/9BhGLAh/6uLfoqDu+8MzSFFFOTTQ52Z0aBIn5AjYf2D7K dst1XPUtN6kLKgZPDjUIa61T5kw9pZvw34uXNtkM7oMGv4dVBpiyIAouIYgqlRiYyWdC STog== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a656944000000b004370503d42dsi11554205pgq.554.2022.10.17.03.01.44; Mon, 17 Oct 2022 03:01:57 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230136AbiJQJli (ORCPT + 99 others); Mon, 17 Oct 2022 05:41:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230006AbiJQJlh (ORCPT ); Mon, 17 Oct 2022 05:41:37 -0400 Received: from outbound-smtp07.blacknight.com (outbound-smtp07.blacknight.com [46.22.139.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 061EB6425 for ; Mon, 17 Oct 2022 02:41:35 -0700 (PDT) Received: from mail.blacknight.com (pemlinmail01.blacknight.ie [81.17.254.10]) by outbound-smtp07.blacknight.com (Postfix) with ESMTPS id 61C421C41A7 for ; Mon, 17 Oct 2022 10:41:34 +0100 (IST) Received: (qmail 4063 invoked from network); 17 Oct 2022 09:41:34 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.198.246]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 17 Oct 2022 09:41:34 -0000 Date: Mon, 17 Oct 2022 10:41:32 +0100 From: Mel Gorman To: Yang Shi Cc: agk@redhat.com, snitzer@kernel.org, dm-devel@redhat.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/4] mm: mempool: introduce page bulk allocator Message-ID: <20221017094132.vnanndrwa2yn7qcw@techsingularity.net> References: <20221005180341.1738796-1-shy828301@gmail.com> <20221005180341.1738796-3-shy828301@gmail.com> <20221013123830.opbulq4qad56kuev@techsingularity.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS 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, Oct 13, 2022 at 01:16:31PM -0700, Yang Shi wrote: > On Thu, Oct 13, 2022 at 5:38 AM Mel Gorman wrote: > > > > On Wed, Oct 05, 2022 at 11:03:39AM -0700, Yang Shi wrote: > > > Since v5.13 the page bulk allocator was introduced to allocate order-0 > > > pages in bulk. There are a few mempool allocator callers which does > > > order-0 page allocation in a loop, for example, dm-crypt, f2fs compress, > > > etc. A mempool page bulk allocator seems useful. So introduce the > > > mempool page bulk allocator. > > > > > > It introduces the below APIs: > > > - mempool_init_pages_bulk() > > > - mempool_create_pages_bulk() > > > They initialize the mempool for page bulk allocator. The pool is filled > > > by alloc_page() in a loop. > > > > > > - mempool_alloc_pages_bulk_list() > > > - mempool_alloc_pages_bulk_array() > > > They do bulk allocation from mempool. > > > They do the below conceptually: > > > 1. Call bulk page allocator > > > 2. If the allocation is fulfilled then return otherwise try to > > > allocate the remaining pages from the mempool > > > 3. If it is fulfilled then return otherwise retry from #1 with sleepable > > > gfp > > > 4. If it is still failed, sleep for a while to wait for the mempool is > > > refilled, then retry from #1 > > > The populated pages will stay on the list or array until the callers > > > consume them or free them. > > > Since mempool allocator is guaranteed to success in the sleepable context, > > > so the two APIs return true for success or false for fail. It is the > > > caller's responsibility to handle failure case (partial allocation), just > > > like the page bulk allocator. > > > > > > The mempool typically is an object agnostic allocator, but bulk allocation > > > is only supported by pages, so the mempool bulk allocator is for page > > > allocation only as well. > > > > > > Signed-off-by: Yang Shi > > > > Overall, I think it's an ok approach and certainly a good use case for > > the bulk allocator. > > > > The main concern that I have is that the dm-crypt use case doesn't really > > want to use lists as such and it's just a means for collecting pages to pass > > to bio_add_page(). bio_add_page() is working with arrays but you cannot > > use that array directly as any change to how that array is populated will > > then explode. Unfortunately, what you have is adding pages to a list to > > take them off the list and put them in an array and that is inefficient. > > Yeah, I didn't think of a better way to pass the pages to dm-crypt. > > > > > How about this > > > > 1. Add a callback to __alloc_pages_bulk() that takes a page as a > > parameter like bulk_add_page() or whatever. > > > > 2. For page_list == NULL && page_array == NULL, the callback is used > > > > 3. Add alloc_pages_bulk_cb() that passes in the name of a callback > > function > > > > 4. In the dm-crypt case, use the callback to pass the page to bio_add_page > > for the new page allocated. > > Thank you so much for the suggestion. But I have a hard time > understanding how these work together. Do you mean call bio_add_page() > in the callback? But bio_add_page() needs other parameters. Or I > misunderstood you? > I expected dm-crypt to define the callback. Using bio_add_page directly would not work as the bulk allocator has no idea what to pass bio_add_page. dm-crypt would likely need to create both a callback and an opaque data structure passed as (void *) to track "clone" and "len" -- Mel Gorman SUSE Labs