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 91074C282D1 for ; Thu, 6 Mar 2025 21:14:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B60BE280004; Thu, 6 Mar 2025 16:14:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B10BE280003; Thu, 6 Mar 2025 16:14:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98AA8280004; Thu, 6 Mar 2025 16:14:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 7B0D1280003 for ; Thu, 6 Mar 2025 16:14:39 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3B65512036E for ; Thu, 6 Mar 2025 21:14:40 +0000 (UTC) X-FDA: 83192380320.12.C5F8745 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf17.hostedemail.com (Postfix) with ESMTP id DD2AB40002 for ; Thu, 6 Mar 2025 21:14:37 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=tKlJ2CN0; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=cuwYJRYL; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=tKlJ2CN0; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=cuwYJRYL; spf=pass (imf17.hostedemail.com: domain of neilb@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=neilb@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741295678; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=W8wPE8KKZYE0b2eeWO1d4HM7Dis42luxW+pjVxoJ1rs=; b=qfnvUHf6esFMXdbgySU+zFySkm+5vXfkCYZm+kzJkuMiEH69nkdingwQ9vdvILFSheyDu5 jSh6ujYvKmrEUxMb0NUgNlkB3HRcRE1uDGapxh3xrnzEHw8zDlcOoXw5xqCcxUw0DtrsWh IUs7P65nh5icdUCUCrzxrbzf/wtii/U= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=tKlJ2CN0; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=cuwYJRYL; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=tKlJ2CN0; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=cuwYJRYL; spf=pass (imf17.hostedemail.com: domain of neilb@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=neilb@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741295678; a=rsa-sha256; cv=none; b=nCnNE7rdtusXPmvRNgKTs/2huaxDToNVPc1Icpc/r+bB+VkrNHxNfa4FSqIBMWjFfANWF9 IrCw1HNMcO4pSwpo5zgazxV54KrHFOZiie6+GM7n5pb3aY8PPFjriM4tWM8SB3EjgsgwwE mHxc/KXrzb5LzELdXxHdndmd3R0DArg= Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D3BE321172; Thu, 6 Mar 2025 21:14:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1741295675; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W8wPE8KKZYE0b2eeWO1d4HM7Dis42luxW+pjVxoJ1rs=; b=tKlJ2CN0wPg7rRWhJblyU+m6/5JlLhvjqJs9DUQdv95bf35qpGhbrKpwR4L1ubUl6HHzMC ojHovccIPbw0DHajEIngncj4h9SzsPp7jcDSVykyVxYvu+K6xi485lt2OJtDUqbxaO8V2q 1Vt+eGq4eU93co2ldGDFw3X1pdN63uY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1741295675; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W8wPE8KKZYE0b2eeWO1d4HM7Dis42luxW+pjVxoJ1rs=; b=cuwYJRYLTPadg9cLaIfWHdAJDR33+mWHNeymeUhWYbcZ+XGJ68tR+aeh5VXxvpzyhsQA8a TbH2enWt9B0YdnCg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1741295675; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W8wPE8KKZYE0b2eeWO1d4HM7Dis42luxW+pjVxoJ1rs=; b=tKlJ2CN0wPg7rRWhJblyU+m6/5JlLhvjqJs9DUQdv95bf35qpGhbrKpwR4L1ubUl6HHzMC ojHovccIPbw0DHajEIngncj4h9SzsPp7jcDSVykyVxYvu+K6xi485lt2OJtDUqbxaO8V2q 1Vt+eGq4eU93co2ldGDFw3X1pdN63uY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1741295675; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W8wPE8KKZYE0b2eeWO1d4HM7Dis42luxW+pjVxoJ1rs=; b=cuwYJRYLTPadg9cLaIfWHdAJDR33+mWHNeymeUhWYbcZ+XGJ68tR+aeh5VXxvpzyhsQA8a TbH2enWt9B0YdnCg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 1D40E13A61; Thu, 6 Mar 2025 21:14:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id MBkAMC0QymdSewAAD6G6ig (envelope-from ); Thu, 06 Mar 2025 21:14:21 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: "NeilBrown" To: "Yunsheng Lin" Cc: "Qu Wenruo" , "Yishai Hadas" , "Jason Gunthorpe" , "Shameer Kolothum" , "Kevin Tian" , "Alex Williamson" , "Chris Mason" , "Josef Bacik" , "David Sterba" , "Gao Xiang" , "Chao Yu" , "Yue Hu" , "Jeffle Xu" , "Sandeep Dhavale" , "Carlos Maiolino" , "Darrick J. Wong" , "Andrew Morton" , "Jesper Dangaard Brouer" , "Ilias Apalodimas" , "David S. Miller" , "Eric Dumazet" , "Jakub Kicinski" , "Paolo Abeni" , "Simon Horman" , "Trond Myklebust" , "Anna Schumaker" , "Chuck Lever" , "Jeff Layton" , "Olga Kornievskaia" , "Dai Ngo" , "Tom Talpey" , "Luiz Capitulino" , "Mel Gorman" , "Dave Chinner" , kvm@vger.kernel.org, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-erofs@lists.ozlabs.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-nfs@vger.kernel.org Subject: Re: [PATCH v2] mm: alloc_pages_bulk: remove assumption of populating only NULL elements In-reply-to: References: <>, Date: Fri, 07 Mar 2025 08:14:14 +1100 Message-id: <174129565467.33508.7106343513316364028@noble.neil.brown.name> X-Stat-Signature: 6jwummwrt73zqgy55phjrdj5jppq6t9w X-Rspamd-Queue-Id: DD2AB40002 X-Rspamd-Server: rspam06 X-Rspam-User: X-HE-Tag: 1741295677-872971 X-HE-Meta: U2FsdGVkX19uNzJc93j7HdQQY61HTCDVEOStD4yX85ZhojY8d+d/YgrLOYuCq32zxfG6WBMpgnWUf2GkWl9aIKTZTARTw1FSOvFb+gcEi4fvT5nh4ZBMdLEBBeG6qKdkszzTWzr+bbLoKkrSd6dIDorMvXIAxHk0KdfOW6e11CbLu4V6idn+EGDbZUWDcDgTXH08pAOLN71jWqZg1af69+TNr0regJkMF143n/u8ZGmbgeJ4zM+xUGYpYiXZLFQuxUhSXNEapyPe3l8IIVJDNnIGs5gIgaB7YetReRDJ8pIRk/4ysRRPR8PFNJfFn8/toKgI0lb4Nr6E/qem+1EIBQa4zcl7RbW1PJ1b2JUeedFovie4ALs6aUOSQWe2Ip2M3Z4UelNhnXCtRnPMEWK5Ujz9d8GiFrFAA/DwKJpFWuYC27hELjU91LWQDwTe4IufjuwIDMCM2rdcsym40T7l8bRr9pRJhuBAERr27AgMB6zb1SRshwzRD1Hq5Mh+3VnZXVpeoiT4jq77H5qDMuxlBV+JSIZXnenFcy+GHC2ga/a0RosYuqwkNYIOrXCwjluiIu2YIhI6s6ODq3rTFYFoLBUwyI6YZWjRwlwxy06uXsGiSx6Hyd3VpZA66WXZqciiyL1KTbe9sluXJT5E1OyWWbr1qdOllf+vw5Z4+GuPNmyUnoJIn04IrQRbqOZCWwGv3cCMUxdy8TtaDh4illTcMr+v0H1ylVhQoyrPU6EyVppcmZHsM3uadJuHFxfuxhgJIGWjaxpO6kJyOswrROlW+1I6Q1Lh2DBXngDEBGYo/IwDAIbmDQkJlMAkDPg5dnZE/+RySwrHJTC8Xol7j7YwkZqpSr8VsbEwXuNjpl6O9jvP3v/japcUoIM6u454od3isXD8oNqjAVW9u9wtpwaG23UQov5Dx27J6vGCvb7v2yytvkBtn0rVyT2lwtvzaQm3KlmDxZahWsDLxj60Ueg 0AjMu/8h fRUWWu6n7ACyWL2RDddVIkHtIu1LzR4FtO4ruCOBDIhLeUTEedpn7ejk0DeHfJ6LPZYMBwkmQWtsEh4/pLKFQZY9sXlASozUajp7kaKUfEW6vQzAelUdSaNLPDgi0vvjVpPuPP8NTE+O0w7reDCBdi+kEUQTt1h+aThm+uaxwVs+wlTzLU9lwr/LkZQZvR2UAoY4oknOcldmJs846ltoMmuPD8XxRHEGjj7/JdIMwveBUJdITgzZ0g3vU6nCbQmGpn6HjtE0V85Nl4BU+/YhXQ95hxHP7SUTCGW54EybowQRBUbWL6/DnnvFKm09hFkPscez5nLgrNE42zQKga00pTVFdoWaW9+iYptLyq7QH+qGx1jY= 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: List-Subscribe: List-Unsubscribe: On Thu, 06 Mar 2025, Yunsheng Lin wrote: > On 2025/3/6 7:41, NeilBrown wrote: > > On Wed, 05 Mar 2025, Yunsheng Lin wrote: > >> > >> For the existing btrfs and sunrpc case, I am agreed that there > >> might be valid use cases too, we just need to discuss how to > >> meet the requirements of different use cases using simpler, more > >> unified and effective APIs. > > > > We don't need "more unified". > > What I meant about 'more unified' is how to avoid duplicated code as > much as possible for two different interfaces with similar‌ functionality. > > The best way I tried to avoid duplicated code as much as possible is > to defragment the page_array before calling the alloc_pages_bulk() > for the use case of btrfs and sunrpc so that alloc_pages_bulk() can > be removed of the assumption populating only NULL elements, so that > the API is simpler and more efficient. > > > > > If there are genuinely two different use cases with clearly different > > needs - even if only slightly different - then it is acceptable to have > > two different interfaces. Be sure to choose names which emphasise the > > differences. > > The best name I can come up with for the use case of btrfs and sunrpc > is something like alloc_pages_bulk_refill(), any better suggestion about > the naming? I think alloc_pages_bulk_refill() is a good name. So: - alloc_pages_bulk() would be given an uninitialised array of page pointers and a required count and would return the number of pages that were allocated - alloc_pages_bulk_refill() would be given an initialised array of page pointers some of which might be NULL. It would attempt to allocate pages for the non-NULL pointers and return the total number of allocated pages in the array - just like the current alloc_pages_bulk(). sunrpc could usefully use both of these interfaces. alloc_pages_bulk() could be implemented by initialising the array and then calling alloc_pages_bulk_refill(). Or alloc_pages_bulk_refill() could be implemented by compacting the pages and then calling alloc_pages_bulk(). If we could duplicate the code and have two similar but different functions. The documentation for _refill() should make it clear that the pages might get re-ordered. Having looked at some of the callers I agree that the current interface is not ideal for many of them, and that providing a simpler interface would help. Thanks, NeilBrown