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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D2E5C4332F for ; Thu, 14 Dec 2023 10:54:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD47B8D00A9; Thu, 14 Dec 2023 05:54:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D5C2A8D00A2; Thu, 14 Dec 2023 05:54:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C23E18D00A9; Thu, 14 Dec 2023 05:54:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B34AF8D00A2 for ; Thu, 14 Dec 2023 05:54:26 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 679E31401CD for ; Thu, 14 Dec 2023 10:54:26 +0000 (UTC) X-FDA: 81565114932.10.B1FCF96 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf16.hostedemail.com (Postfix) with ESMTP id 6A4A3180008 for ; Thu, 14 Dec 2023 10:54:24 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf16.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702551264; h=from:from:sender: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=gUHYKXMLbX/Tw09mlO97SmPsrEM8o9cYRrVEtix3fLs=; b=eYrQzcyb1Nj9pZoJpueeGQrWOhRxzQIQFFmssWy8VZ/v7Xjm/4PG55HeEc81mye6nTA9ac SCcgR++DQKM2mfAb9ygsNRptc9u8nXsZtVf4tUK+lFlxlQcu1ogk7h+swnBpp3p70+oqSE mWaXDtj/x93Pbca/LhxWKtcu7g4laIo= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf16.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702551264; a=rsa-sha256; cv=none; b=y7PKzhFN8ux0AUlpu2qqyjOK0m9wSzeVEizz/6jcKD/7qaMHnsOx4xtux3Ihj25eNb1Mrc zDc+XPy5sTqRU1n16Ai88g5MQum392D7HQID1pb5FIhQbSU5cp8cBs6+TamF5nnjHZR3jy wVXdNm9BIrMPs2HtFj4Uidv3Qc8u8G8= 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-Rspamd-Queue-Id: 6A4A3180008 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 8zib89a3pcb4bzf3cir59tha8di9559e X-HE-Tag: 1702551264-982982 X-HE-Meta: U2FsdGVkX19FQZGzfOJFBMd033vM0HwwY8fLojDDRjgHzSgvzLt7ZN5Qv3BoeuR7AjywssVQIkR0WLY/HlZKLA05DLnauKoUpkNGVQH3eFRVLeStNrR3LF5ObqdRE1t9724zHII91pBhCPZC1NHKO6RZ27Qbx90DgH6+jEmy+2EIwvxIB4RgdNzqmIJFuG4fhyx04nLJkHCdwwufSq6r5gn6I+j8WAycTuIN9KpjO6Mokb6uaJxxo7lSJAcEYnJ4cEWWFOg/H6TLIMgHxqYVz8os86cO5mtw8T7sIeBzlZjakIUv6wJG9sGUqYB5S+qdeTmZ6JE78XuhmGZE3C4QZxTuI9yKG4syH0DVtgwVjqi6gvkzGviXF+ae8R9YMdNix29sMDKDUFUK7KZPcauB/IcpkSn6nRx6EPMq4Ee+d2FaVcrPGcJ0hVhvtLwBJOiXKqlV+fKnxgZfaOfIoCRq0kgnJwCuEOm1FAh5DcKaHcPqaydg3LtqgfxL4GT4zvovTykibCXg58nzmIp/GrNWq5DicUGXW/ejAmXG7SF4Ix8E9s9eZObpifGIVbBDAYH7BXEulMgQDI30QSzPu4LawsMw9qcia7xP9tRhNL84fhqCToAlDcZgpn9WuKdpDCPHdG3hGcbEzmvy5CXODmkIsLcLqbknW7b5LQaWdBcAESiUoTOdAXr4iygojV3n4A/ATFeDZdDxifKO2cxVC9KMwIRuqlgSWyZtcbDFn2ZH4oKiV1fJo9Z3hSY+MZVpjRP3dKpXa3pe4cCHq1qQD5RzBM3WxF1NpG64CssE83VuIfEudoQCjzFVxOXaiqf+s6pIO7bUDGYZaDbCUaM391SZUBvkXBoW3/ekrh15UGcJRnerojZNTnQHxJAN/30IAFiVsUlhiJtbHKRaJ7vjnVTt7UTHKcQ8vSyJNQwLNAQ1EFiK14terwiSJbuOlz6+5/Dw6iXY0BPJZ57NRwMkiMn eIl+HqNr /1vVSKI0EB6ntWip3oECghQRlL59tQGbihNqTH3/zKtnpPQWLBfjN4ygoZ1JPWQu0Gq3QTSJihwcRf0LbIIlo0kUbuzszBtHxaxD5hfZjiVLCFG0VpdYTp4lJ59dOIrSozuDwfK++GuKs4ZlJ35/O56X/nayDCG6ckWfV4zXqwAwxFY971YwnomyCR8son90cQC5dDUBxIiGS/TPHLiRgauOgyRqzcxlIZRfV X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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); >