From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6776946B5 for ; Fri, 3 Jan 2025 14:47:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735915625; cv=none; b=safkC/nNZ0b/r9CTw3cuYq2gJq1MHyRh5U4XGhYT2Nv6CURvUwFUnXAkMY4H3nNr+cHCzLvFmP1v+j5tuldOtYh51TUE2aD+UbPbIE9oxTmR2bdl/USKt5XmdVLDc469lsrwUYNnD/M/onGndp9R9tKczDLzbasm1fqAAcWGOaU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735915625; c=relaxed/simple; bh=BqngFdnDtTFXEzEOIQgeZC+3yTvusas4lCH6QLAfIeQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=cTXCqJYQWLpxq6JGryze1tfOEEDGEX15XKA2vXIFuD+jZdy67xp+POzAFrcfw+vfdgpwkpl6T5drwziK6YuNlSlHiBdIX6sMQE0aaep0PB/I/C7kMUaqt6aa3c3MlfBtimvm5lUzzDKcO30Xa3WtvhgdKsiAye/SU71Izzsgu84= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=WFV6xwjR; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WFV6xwjR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1735915622; h=from:from: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; bh=7ugLikuePf+W66VlwF+hcqdH51iUEo4PuTVkmD6aZBk=; b=WFV6xwjRuN0YS5cA1iwjcXEtqTBSD7Pm1r7+psE8qLOxVPw4GSLZmJbhtEYSiht6eMTJjF vn1frbSBfLoADZFZrZcD/vUD8l/s3TpIq1rNPISMwCBGyGqZr+AaQMCtAffUcYE/2MP4tk T9Uj3kderP5tD3FxCQAw6t0DCpRRYnQ= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-146-hdtUy5MdMjekxyF0Y8sPfQ-1; Fri, 03 Jan 2025 09:47:00 -0500 X-MC-Unique: hdtUy5MdMjekxyF0Y8sPfQ-1 X-Mimecast-MFC-AGG-ID: hdtUy5MdMjekxyF0Y8sPfQ Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7b6f274f1f9so1994975285a.3 for ; Fri, 03 Jan 2025 06:47:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735915620; x=1736520420; h=content-transfer-encoding:in-reply-to: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=7ugLikuePf+W66VlwF+hcqdH51iUEo4PuTVkmD6aZBk=; b=a5DKiRly00+LHwnvHOf4Kipivm8Vg0j/XP/ez1V/dnTq8vyBTYCRom5AR97xL2eidD HXU/l2jvX0hvQzyrR3VbGLDnCGjdiPNebnK3Ls5XOuqou4MIewFcSM/jhlSmSAei5ZbD lpsQLaNAfDZoqO/ZECT402Io6EkJONvOx6xHG42FmaHb2DFv9Ye/hXILXrAlguqBYMmr BZgMY3ydCgwQ2kdufbO9bb9I0nDcf4GSjSp7hAnaREUZJ++dQuaabTAosyTq1+WivKCx BuvUA5sw6+bxE/32q1wQITSRj1C1gvBApXlrWAW3iV/YkPCL/0gwlKHryuqsRbz0k+UT Xf1g== X-Forwarded-Encrypted: i=1; AJvYcCXJowY++ISciXdD8TUunPKMOyvysgGUAJ69oUIwKWmmnqx6VQYDN/s6AXINtrL/SQdQXXXlk2yBDua4pSM=@vger.kernel.org X-Gm-Message-State: AOJu0Ywo8GDYIojK+Bi+MaitsXH4eXeUPSEAnrcawEObT7yV/Pdvs+qM 8veSzJ7rnIAYwmXlHBohJjcfiU0t0Y+BzxS0hG6FrD2JkyNfmMugkmIaf6KudP6qfAB6WQsX9jq gwsAaXn7P7QKLVwMaLiY8WjyCkL/z8ptRlWqMfTifD7zdMP5mW41DlHIcwstkKA== X-Gm-Gg: ASbGncs87qdQdjja+JJDMqMo7bBCyMgzjuWrh0Fq/Hon4v+Yyw4lTQV+nfr66qIX+b7 6x73qn3TDc7LTbV3QG5ZoXA/z8Yd0VDxiL5FVFbUrUCc/qTkI8bpk+urRRmPeOm/CUGTbBa93YH u+dLi6GDw9EbhB7oP6jCY2I2whdL2e/1MWrcsqTuVX4QFSnm9+93vn+SLrVvJNuJ/cgdYIxQrC8 fCSp3m00a3e0rmiulim23pjadQeXXczNTmysr1MyM4/gFXBvq/b80+gUuu9QwDvdG+z2O41jbM3 v+07JA6dASUmVkCF9fELcJthwCRtaViB5D6POI4zIw== X-Received: by 2002:a05:620a:4807:b0:7b6:d611:ce82 with SMTP id af79cd13be357-7b9ba83580dmr7444754185a.59.1735915619505; Fri, 03 Jan 2025 06:46:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IHBSq0s088Q5EscUvHxlxZ1a9kvCLX7Le1q6E7WC2oWr2U1JvGLdvRAuVcgUhhOwb3tZuXENw== X-Received: by 2002:a05:620a:4807:b0:7b6:d611:ce82 with SMTP id af79cd13be357-7b9ba83580dmr7444739685a.59.1735915617727; Fri, 03 Jan 2025 06:46:57 -0800 (PST) Received: from [192.168.2.110] (bras-base-aylmpq0104w-grc-14-70-52-22-87.dsl.bell.ca. [70.52.22.87]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b9ac480ea7sm1275469185a.94.2025.01.03.06.46.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Jan 2025 06:46:57 -0800 (PST) Message-ID: Date: Fri, 3 Jan 2025 09:46:56 -0500 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 1/2] mm: alloc_pages_bulk_noprof: drop page_list argument To: Mel Gorman , Yunsheng Lin Cc: linux-mm@kvack.org, willy@infradead.org, david@redhat.com, linux-kernel@vger.kernel.org, lcapitulino@gmail.com References: <6b56af9b-2670-4a15-84e8-314443ae590c@huawei.com> Content-Language: en-US, en-CA From: Luiz Capitulino In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2025-01-03 09:27, Mel Gorman wrote: > On Fri, Jan 03, 2025 at 07:29:30PM +0800, Yunsheng Lin wrote: >> On 2025/1/3 4:00, Mel Gorman wrote: >>> On Wed, Dec 25, 2024 at 08:36:04PM +0800, Yunsheng Lin wrote: >>>> On 2024/12/24 6:00, Luiz Capitulino wrote: >>>> >>>>> /* >>>>> - * __alloc_pages_bulk - Allocate a number of order-0 pages to a list or array >>>>> + * __alloc_pages_bulk - Allocate a number of order-0 pages to an array >>>>> * @gfp: GFP flags for the allocation >>>>> * @preferred_nid: The preferred NUMA node ID to allocate from >>>>> * @nodemask: Set of nodes to allocate from, may be NULL >>>>> - * @nr_pages: The number of pages desired on the list or array >>>>> - * @page_list: Optional list to store the allocated pages >>>>> - * @page_array: Optional array to store the pages >>>>> + * @nr_pages: The number of pages desired in the array >>>>> + * @page_array: Array to store the pages >>>>> * >>>>> * This is a batched version of the page allocator that attempts to >>>>> - * allocate nr_pages quickly. Pages are added to page_list if page_list >>>>> - * is not NULL, otherwise it is assumed that the page_array is valid. >>>>> + * allocate nr_pages quickly. Pages are added to the page_array. >>>>> * >>>>> - * For lists, nr_pages is the number of pages that should be allocated. >>>>> - * >>>>> - * For arrays, only NULL elements are populated with pages and nr_pages >>>>> + * Note that only NULL elements are populated with pages and nr_pages >>>> >>>> It is not really related to this patch, but while we are at this, the above >>>> seems like an odd behavior. By roughly looking at all the callers of that >>>> API, it seems like only the below callers rely on that? >>>> fs/erofs/zutil.c: z_erofs_gbuf_growsize() >>>> fs/xfs/xfs_buf.c: xfs_buf_alloc_pages() >>>> >>>> It seems it is quite straight forward to change the above callers to not >>>> rely on the above behavior, and we might be able to avoid more checking >>>> by removing the above behavior? >>>> >>> >>> It was implemented that way for an early user, net/sunrpc/svc_xprt.c. >>> The behaviour removes a burden from the caller to track the number of >>> populated elements and then pass the exact number of pages that must be >>> allocated. If the API does not handle that detail, each caller needs >>> similar state tracking implementations. As the overhead is going to be >>> the same whether the API implements it once or each caller implements >>> there own, it is simplier if there is just one implementation. >> >> It seems it is quite straight forward to change the above use case to >> not rely on that by something like below? >> >> diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c >> index 43c57124de52..52800bfddc86 100644 >> --- a/net/sunrpc/svc_xprt.c >> +++ b/net/sunrpc/svc_xprt.c >> @@ -670,19 +670,21 @@ static bool svc_alloc_arg(struct svc_rqst *rqstp) >> pages = RPCSVC_MAXPAGES; >> } >> >> - for (filled = 0; filled < pages; filled = ret) { >> - ret = alloc_pages_bulk_array(GFP_KERNEL, pages, >> - rqstp->rq_pages); >> - if (ret > filled) >> + for (filled = 0; filled < pages;) { >> + ret = alloc_pages_bulk_array(GFP_KERNEL, pages - filled, >> + rqstp->rq_pages + filled); >> + if (ret) { >> + filled += ret; >> /* Made progress, don't sleep yet */ >> continue; >> + } >> >> set_current_state(TASK_IDLE); >> if (svc_thread_should_stop(rqstp)) { >> set_current_state(TASK_RUNNING); >> return false; >> } >> - trace_svc_alloc_arg_err(pages, ret); >> + trace_svc_alloc_arg_err(pages, filled); >> memalloc_retry_wait(GFP_KERNEL); >> } >> rqstp->rq_page_end = &rqstp->rq_pages[pages]; >> > > The API implementation would also need to change to make this work as the > return value is a number of pages that are on the array, not the number of > new pages allocated. Even if fixed, it still moves cost and complexity to > the caller and the API is harder to use and easier to make mistakes. That > shift in responsibility and the maintenance burden would need to be > justified. While it is possible to use wrappers to allow callers to decide > whether to manage the tracking or let the API handle it, the requirement > then is to show that there is a performance gain for a common use case. I agree with all your points, but I think there's value in simplifying alloc_pages_bulk_noprof() if the wrappers turn out not be complex or difficult to use. If all users of this case always fill the array sequentially, then maybe we could just have a wrapper that scans the array first (this is the first loop in alloc_pages_bulk_noprof()) or maybe callers could keep track of 'filled' (via a pointer or macro usage). But this is just brainstorming, we'd need to see the resulting code to know if it works and makes sense. > This is outside the scope of a serise that removes the page_list > argument. Even if a series was proposed to shift responsibility to the > caller, I would not expect it to be submitted with a page_list removal. Yes, absolutely.