Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5937227rdb; Thu, 14 Dec 2023 04:13:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IG7sHUcFQ8V+4yO5lLXyiRYh2ssykwepMxofV4oQYFvYelqhT9Anah3HZwQQ0qfV0zeU88C X-Received: by 2002:a05:6358:591f:b0:170:ca20:6fd with SMTP id g31-20020a056358591f00b00170ca2006fdmr10687267rwf.62.1702555980047; Thu, 14 Dec 2023 04:13:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702555980; cv=none; d=google.com; s=arc-20160816; b=swsi9OvtpzfIsqX1Ezk3ypRebDRuvOnlAQJaiEn55U1Gut6IKGg8SHn2XYrk0VuAha O13NpSDE4d9NwTLM91uJwvSjjHPjvS1gTT88Hd6VKB4tHaw23w0xxMWL9k4i/AB+aX7w uwpF8hWr3eBsKzqkaszttPbChgkFyGEbCy9ak3kJxLwSmA0D08p3iZ13JnhlsJxC+hxC VdTgmObo6sFEhEL/R6z9HjWgTaRg0NlW6TjUoSEkyqko3WOw+tk/ar1/0+rnuM1ttUXq GOiK02QQD7mpxMxF6uRRs8cWWXpjqiwP/d3GxJlsfCSCjGfdtqUtqKvlbAMBKh/NlHIV NjnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=1+2BYN93oNw71Pv3xnDMzciK22t1Y0YilMByovpno0Y=; fh=lzHrxretJGeP3y1AT9FPuFWl5yHXsQjESAKJ8JXcPBo=; b=EPP2II/9vdGCjT04hiEc3Z4jNMoG8AlFiVTIXaedR9SMpRMyHU43iXSMO3iib8drUB BtJjEwfT/XVunEJ/RPt30KlcplEguMJKNDdbGTjykOch6/UzCXYVlWmaYfZ+THWUEokL gFgpO9oJoKqGZ1vpUL/CXq1SCR+XXSzNYXM6SLJMlYdlYvmt52sQQRVSpZ+EA8nc6jqu tkBroAng/x0wGAM40Xo+QEpUx3SEbSKCcIFwYyYlC9vHTRPyBRNXSUMwNtLwi+XYM8PS gyTI95OveUsqu9MSfJe47mygioBrARpV5IxUNdm2pZ3yt7D/QcyMW02w9h13wnwz3cG6 NvBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id m22-20020aa78a16000000b006ce63dbd7f4si11093821pfa.142.2023.12.14.04.12.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 04:13:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id D0E9A8023719; Thu, 14 Dec 2023 04:12:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1572930AbjLNMMI (ORCPT + 99 others); Thu, 14 Dec 2023 07:12:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1572948AbjLNMME (ORCPT ); Thu, 14 Dec 2023 07:12:04 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D7548121 for ; Thu, 14 Dec 2023 04:12:09 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1D1F0C15; Thu, 14 Dec 2023 04:12:55 -0800 (PST) Received: from [10.1.38.142] (XHFQ2J9959.cambridge.arm.com [10.1.38.142]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A8D4B3F738; Thu, 14 Dec 2023 04:12:06 -0800 (PST) Message-ID: <8e2a5b4c-ba3a-4dcd-8aae-e5d3170d048a@arm.com> Date: Thu, 14 Dec 2023 12:12:05 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v9 04/10] mm: thp: Support allocation of anonymous multi-size THP Content-Language: en-GB To: Dan Carpenter Cc: Andrew Morton , Matthew Wilcox , Yin Fengwei , David Hildenbrand , Yu Zhao , Catalin Marinas , Anshuman Khandual , Yang Shi , "Huang, Ying" , Zi Yan , Luis Chamberlain , Itaru Kitayama , "Kirill A. Shutemov" , John Hubbard , David Rientjes , Vlastimil Babka , Hugh Dickins , Kefeng Wang , Barry Song <21cnbao@gmail.com>, Alistair Popple , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20231207161211.2374093-1-ryan.roberts@arm.com> <20231207161211.2374093-5-ryan.roberts@arm.com> <43a8bfff-f939-4f2d-a8cd-97306d5e44c9@arm.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=0.9 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLACK autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 14 Dec 2023 04:12:26 -0800 (PST) On 14/12/2023 11:30, Dan Carpenter wrote: > On Thu, Dec 14, 2023 at 10:54:19AM +0000, Ryan Roberts wrote: >> On 13/12/2023 07:21, Dan Carpenter wrote: >>> On Thu, Dec 07, 2023 at 04:12:05PM +0000, Ryan Roberts wrote: >>>> @@ -4176,10 +4260,15 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) >>>> /* Allocate our own private page. */ >>>> if (unlikely(anon_vma_prepare(vma))) >>>> goto oom; >>>> - folio = vma_alloc_zeroed_movable_folio(vma, vmf->address); >>>> + folio = alloc_anon_folio(vmf); >>>> + if (IS_ERR(folio)) >>>> + return 0; >>>> if (!folio) >>>> goto oom; >>> >>> Returning zero is weird. I think it should be a vm_fault_t code. >> >> It's the same pattern that the existing code a little further down this function >> already implements: >> >> vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, addr, &vmf->ptl); >> if (!vmf->pte) >> goto release; >> >> If we fail to map/lock the pte (due to a race), then we return 0 to allow user >> space to rerun the faulting instruction and cause the fault to happen again. The >> above code ends up calling "return ret;" and ret is 0. >> > > Ah, okay. Thanks! > >>> >>> This mixing of error pointers and NULL is going to cause problems. >>> Normally when we have a mix of error pointers and NULL then the NULL is >>> not an error but instead means that the feature has been deliberately >>> turned off. I'm unable to figure out what the meaning is here. >> >> There are 3 conditions that the function can return: >> >> - folio successfully allocated >> - folio failed to be allocated due to OOM >> - fault needs to be tried again due to losing race >> >> Previously only the first 2 conditions were possible and they were indicated by >> NULL/not-NULL. The new 3rd condition is only possible when THP is compile-time >> enabled. So it keeps the logic simpler to keep the NULL/not-NULL distinction for >> the first 2, and use the error code for the final one. >> >> There are IS_ERR() and IS_ERR_OR_NULL() variants so I assume a pattern where you >> can have pointer, error or NULL is somewhat common already? > > People are confused by this a lot so I have written a blog about it: > > https://staticthinking.wordpress.com/2022/08/01/mixing-error-pointers-and-null/ Nice; thanks for the pointer :) > > The IS_ERR_OR_NULL() function should be used like this: > > int blink_leds() > { > led = get_leds(); > if (IS_ERR_OR_NULL(led)) > return PTR_ERR(led); <-- NULL means zero/success > return led->blink(); > } > > In the case of alloc_anon_folio(), I would be tempted to create a > wrapper around it where NULL becomes ERR_PTR(-ENOMEM). But this is > obviously fast path code and I haven't benchmarked it. > > Adding a comment is the other option. I'll add a comment; as you say this is a fast path, and I'm actively being burned in similar places (on another series I'm working on) where an additional check is regressing performance significantly so not keen on risking it here. Andrew, I'll fold in the David's suggested ifdef improvement at the same time. Would you prefer an additional patch to squash in, or a whole new version of the series to swap out with the existing patches in mm-unstable? > > regards, > dan carpenter >