From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD44F1E7C20 for ; Tue, 4 Mar 2025 09:17:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741079873; cv=none; b=WjH/jm3uksQcFiVL8P/RJR8bGF4sk/aD8NgasXSGVK7t3QGiwoy0T1zDGiV5xnT9PnAWJHC34HMefg9/qTVVnsp7A1XibJENkZnv6zlPTUeOhPorfJDx3UtYsuQ0zB6uH6ib1+vb8uCmpU9JnSo55P4/ws3B0WznaJBkSHlDyV0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741079873; c=relaxed/simple; bh=EYwd2Jf8ZA0KU9xC36aNCIR5lDQhcFK0j7Q6bTeAt5o=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=aGkIqEw9ctL6xmAEn59Yp0h+PebzhmTLr5DvHXOmhQ9GMVxPVZJ8Pe63/oEPN7hv4W//smq/RGaBU6+FeIIZYrkmkpatlvQTCXdPani5omrsi8Hr6NJg7Bzli0NUD3Vv+iP2yLHqV/BA4CimqDuecp8uK87II4x1zEAPdsJMMcA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=fuxu++ZY; arc=none smtp.client-ip=209.85.208.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="fuxu++ZY" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-5e5491eb37dso3459041a12.0 for ; Tue, 04 Mar 2025 01:17:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1741079869; x=1741684669; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=U7nVbwpLU0+lp6Hc0ee6jvbH0Pu/dJ0Otg1V1qw972I=; b=fuxu++ZYVsqoY3xjWsoTqcXMgLBOCtHww6PZHUOFjz5ZCu+QqJYXzitd9nUrbOXdjP vlId1tD1GAFFDUCt4mtRLBehfFm2IgtoWyfO8hYTXTsnU1JseV1C8hw5Zamf3QEi8Pl6 +DMmdH4u8snN/q8RavL3eaoQBoqjPBE2cz4VWdIrhOaXchpJgr6lSoBlL7nkBCv5wouJ unrymmFLGE0qhL/SferbZsj0JrR51NjppLcZExBfAWFN9AzRFpF4I31CILKK8ufUUOIs fnDizfeEvpw7uJNhqMuJSL8Lucj8/ma28e/HsVdlu4Gq2Z/5XQ2dljW3BkNmPVPbf9pa EZXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741079869; x=1741684669; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=U7nVbwpLU0+lp6Hc0ee6jvbH0Pu/dJ0Otg1V1qw972I=; b=SXvGcQjWI44/M2ZR+lr9gRDSIesSGb5Awg4yhuzohWowqQNpInsOrHV0sxigMP15xu c7rzp/8dKKqJpCWm1GUku4/uWWvnvzGNpfnLUsqEl9mD/9/PTIxybWf+ga1gLxq7tBDc 52Fyxe1HaqliVyANFFCLr6MC0jugD4GjJNqvatPKgxy63Mak6z7cRtE98FwIU+3JCxCY eHlJfD2cdOlLmuwJBjguumeGETI1iJpsAaBHbRuCiQ8MVp/SOxf4Vs7IF/Ei6oS05iqa E/MrPdW07mwNjm6VTzD+8qsYzy2bYRlFsLmAl9mUSXnhsOrlRt9exb5GLxHB+vaFeF71 PJaQ== X-Forwarded-Encrypted: i=1; AJvYcCWrB0XwCQZvNmZhwRM7COJjyFBdGKoQF0l0DW3MWiQ5vvpRrj/V7pEXXg0597b1/m+F+YKpMKat+NJ8m7Y=@vger.kernel.org X-Gm-Message-State: AOJu0Yz5OMSGObjf0s2LLWTYekzI33b3itldVji1n7O3gv/JCwJviG7r su5cXaNITDVS8hzFNylIIcspkSkZhZVSpDXzbt7+Q5iPdBArUdQEJt6x/AtCqko= X-Gm-Gg: ASbGncvPVUJ9ywK49IriDs9jqf0GWa4yBGSzZbSyDepIWHpvAh92CfVFoYsNUcd9YW7 yJmH84UPCZu3gHOGsL5pBf1X/K6m+z2G76esQ5WrRrfrmujyncsPmMm90ao++bCBP7YGWNBLMr9 VCZmHl3QO/mkMcxTnZRDPb1Mo1u8bUnA0ovwwgdcY+IcTUUXvbXHIea732NGMF9ck1HjlFkwCgd onR8BL6QtKBTTzmIGLh65PUprplxnHmiJf7oPJNVzmhEB5xXLheT3yBTFIKZ9I92qUQ8JP9+ilr hoDZgkSROTM4q/kARum/frRqFsM4etpTQWB06oj8znH0FSBe+q3inir5THovY7bh/p1n5CP3 X-Google-Smtp-Source: AGHT+IFEBbxQyaP0/2DWYOKB8ElC0B8gdpp7QbNW8c37nqwtwNfKPMEljUeKpMeGoOykV8PZYEcmVQ== X-Received: by 2002:a05:6402:2789:b0:5e0:52df:d569 with SMTP id 4fb4d7f45d1cf-5e4d6b852d0mr16127811a12.28.1741079868692; Tue, 04 Mar 2025 01:17:48 -0800 (PST) Received: from ?IPV6:2403:580d:fda1::299? (2403-580d-fda1--299.ip6.aussiebb.net. [2403:580d:fda1::299]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-223501f9dd8sm90968655ad.57.2025.03.04.01.17.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Mar 2025 01:17:48 -0800 (PST) Message-ID: <6f4017dc-2b3d-4b1a-b819-423acb42d999@suse.com> Date: Tue, 4 Mar 2025 19:47:34 +1030 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] mm: alloc_pages_bulk: remove assumption of populating only NULL elements To: Yunsheng Lin , 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 , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: 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 References: <20250228094424.757465-1-linyunsheng@huawei.com> Content-Language: en-US From: Qu Wenruo Autocrypt: addr=wqu@suse.com; keydata= xsBNBFnVga8BCACyhFP3ExcTIuB73jDIBA/vSoYcTyysFQzPvez64TUSCv1SgXEByR7fju3o 8RfaWuHCnkkea5luuTZMqfgTXrun2dqNVYDNOV6RIVrc4YuG20yhC1epnV55fJCThqij0MRL 1NxPKXIlEdHvN0Kov3CtWA+R1iNN0RCeVun7rmOrrjBK573aWC5sgP7YsBO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/lrSAAoJEMI9kfOhJf6o cakH+QHwDszsoYvmrNq36MFGgvAHRjdlrHRBa4A1V1kzd4kOUokongcrOOgHY9yfglcvZqlJ qfa4l+1oxs1BvCi29psteQTtw+memmcGruKi+YHD7793zNCMtAtYidDmQ2pWaLfqSaryjlzR /3tBWMyvIeWZKURnZbBzWRREB7iWxEbZ014B3gICqZPDRwwitHpH8Om3eZr7ygZck6bBa4MU o1XgbZcspyCGqu1xF/bMAY2iCDcq6ULKQceuKkbeQ8qxvt9hVxJC2W3lHq8dlK1pkHPDg9wO JoAXek8MF37R8gpLoGWl41FIUb3hFiu3zhDDvslYM4BmzI18QgQTQnotJH8= In-Reply-To: <20250228094424.757465-1-linyunsheng@huawei.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 在 2025/2/28 20:14, Yunsheng Lin 写道: > As mentioned in [1], it seems odd to check NULL elements in > the middle of page bulk allocating, and it seems caller can > do a better job of bulk allocating pages into a whole array > sequentially without checking NULL elements first before > doing the page bulk allocation for most of existing users. > > Through analyzing of bulk allocation API used in fs, it > seems that the callers are depending on the assumption of > populating only NULL elements in fs/btrfs/extent_io.c and > net/sunrpc/svc_xprt.c while erofs and btrfs don't, see: > commit 91d6ac1d62c3 ("btrfs: allocate page arrays using bulk page allocator") If you want to change the btrfs part, please run full fstests with SCRATCH_DEV_POOL populated at least. [...] > diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c > index f0a1da40d641..ef52cedd9873 100644 > --- a/fs/btrfs/extent_io.c > +++ b/fs/btrfs/extent_io.c > @@ -623,13 +623,26 @@ int btrfs_alloc_page_array(unsigned int nr_pages, struct page **page_array, > bool nofail) > { > const gfp_t gfp = nofail ? (GFP_NOFS | __GFP_NOFAIL) : GFP_NOFS; > - unsigned int allocated; > + unsigned int allocated, ret; > > - for (allocated = 0; allocated < nr_pages;) { > - unsigned int last = allocated; > + /* Defragment page_array so pages can be bulk allocated into remaining > + * NULL elements sequentially. > + */ > + for (allocated = 0, ret = 0; ret < nr_pages; ret++) { > + if (page_array[ret]) { You just prove how bad the design is. All the callers have their page array members to initialized to NULL, or do not care and just want alloc_pages_bulk() to overwrite the uninitialized values. The best example here is btrfs_encoded_read_regular(). Now your code will just crash encoded read. Read the context before doing stupid things. I find it unacceptable that you just change the code, without any testing, nor even just check all the involved callers. > + page_array[allocated] = page_array[ret]; > + if (ret != allocated) > + page_array[ret] = NULL; > + > + allocated++; > + } > + } > > - allocated = alloc_pages_bulk(gfp, nr_pages, page_array); > - if (unlikely(allocated == last)) { > + while (allocated < nr_pages) { > + ret = alloc_pages_bulk(gfp, nr_pages - allocated, > + page_array + allocated); I see the new interface way worse than the existing one. All btrfs usage only wants a simple retry-until-all-fulfilled behavior. NACK for btrfs part, and I find you very unresponsible not even bother running any testsuit and just submit such a mess. Just stop this, no one will ever take you serious anymore. Thanks, Qu