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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 077FEC4332F for ; Thu, 14 Dec 2023 10:54:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=scHEF5pJGEygwYkscTXL5P0Rm4+OhQHceQhNIV6Vuuc=; b=wtTSwBeBNCfI5a ewWhSb7jABX1a9VlPOGGfAw+ULjLKl2DS+Jv1Ib/KmuBHIc4rhqOgnDEY+0C/6VooQqpvBOuw3K4H Z8MAAQWgbi9nFjU2x5GL+E+3Hg6la/ed6ygZZBeyCL2ttvZpVMiLAb9ZK+B1sZHw0YWOv5Nw8eV+a jhJlsodqkMFw+hG9ffd5XPJcbBADRzztDfl2iA0zNY+p0f8FKoYLrlL+3lH6oQ4vFwtRSVLn8ezkG sneYek4WYyW9AWGKBegOitlUYYuEKdC2c+oVIffk9yRX68976l7zIvTJD13szmxujKr7cyKEc0P8u C+dHRt/8TairrCUDDHIA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rDjMN-00HYeb-0G; Thu, 14 Dec 2023 10:54:31 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rDjMK-00HYbB-08 for linux-arm-kernel@lists.infradead.org; Thu, 14 Dec 2023 10:54:29 +0000 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: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231214_025428_189073_658DCE0E X-CRM114-Status: GOOD ( 21.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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); > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel