Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5897542rdb; Thu, 14 Dec 2023 02:55:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IE8pf32P8RCX/YskZTqS3UvOWeaFwaYwQOn700gxN25Et1GWGXs20xxM4FQ8d/FAPlMC+Yl X-Received: by 2002:a05:6a00:1ac7:b0:6cb:bb92:1ce6 with SMTP id f7-20020a056a001ac700b006cbbb921ce6mr10629578pfv.18.1702551353028; Thu, 14 Dec 2023 02:55:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702551353; cv=none; d=google.com; s=arc-20160816; b=HzGMwaeUO0tUnUKrAIrycKSsX97HTGRoiL3zd7PRYQIXEVesMqzAS93mTAyElxPJy7 ZuQc8tkS5+CDgP7vZdnIerQGmgcHX6vymatW6YmyMyGBb/rKz/Dj3sceIsY5gIWC9D1Z wPt+/03xa9RMwHlDcqQT1nFgc+S1iWdXVPykoxkIHUW3fAzpQxuifz/z5HH4vpQNGuGi qJBcQMzc6Ig3K0XlYTRLbki/n7kWlFB8pvlU93KfXl1cvps1tZ+OXkp8UQJB31wA3Lg4 F6pJ8J4+4ZEEAfT+e7w45y1oNkdPCe32UinWW9P+xfWCUNiCabw/K8aMVdpZm9D9eb4r wRMg== 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=gUHYKXMLbX/Tw09mlO97SmPsrEM8o9cYRrVEtix3fLs=; fh=lzHrxretJGeP3y1AT9FPuFWl5yHXsQjESAKJ8JXcPBo=; b=ibHulHWEcEPXN/46joakMiIJDk/S3zKWgRXf0lsnKn3yFw3SDSQip+mesq8RsOVGNb iKIlgoVXnk19PtujBqDseYwSnbk0nvBJwQDViw9XWjOYl2kzwgXgNrAG4azxRnk9rhXg 47bmoERHLirFglaSjfHzvY7qJ2++/GEVhtM6eTUNhMydBNwynD1ormozZgyaQLcCpYqI 1PFfZbI7p9GgFPYsZ8ijVg53v0RY6p4sh1BZAZaETVT5phC6N5eB7tg+pdeKKoqmt7VK bDFkG97vaMlcro+/RojCX6asDOktFLCIJJJeoO+Q1oyubnGxXaqwWQPiOyFjj77mfMGd cgng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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. [23.128.96.36]) by mx.google.com with ESMTPS id r4-20020a6560c4000000b005acf0458523si10742506pgv.612.2023.12.14.02.55.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 02:55:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 2925C81FEC50; Thu, 14 Dec 2023 02:55:50 -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 S1443811AbjLNKzN (ORCPT + 99 others); Thu, 14 Dec 2023 05:55:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443880AbjLNKyz (ORCPT ); Thu, 14 Dec 2023 05:54:55 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EE2FD10E6 for ; Thu, 14 Dec 2023 02:54:23 -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 32EE8C15; Thu, 14 Dec 2023 02:55:09 -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 C091F3F738; Thu, 14 Dec 2023 02:54:20 -0800 (PST) Message-ID: <43a8bfff-f939-4f2d-a8cd-97306d5e44c9@arm.com> Date: Thu, 14 Dec 2023 10:54:19 +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> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 02:55:50 -0800 (PST) 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. > > 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? Thanks, Ryan > > It should return one or the other, or if it's a mix then add a giant > comment explaining what they mean. > > regards, > dan carpenter > >> >> + nr_pages = folio_nr_pages(folio); >> + addr = ALIGN_DOWN(vmf->address, nr_pages * PAGE_SIZE); >> + >> if (mem_cgroup_charge(folio, vma->vm_mm, GFP_KERNEL)) >> goto oom_free_page; >> folio_throttle_swaprate(folio, GFP_KERNEL); >