From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 748E62D8390 for ; Tue, 25 Nov 2025 08:58:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764061090; cv=none; b=U10BkBoUXn9LPdxNYQ2qLHGmfI0MdhzhVwdwx+M0CG95w0rOhTrPwEYR5g+FjU3sXN0KIlk2Dcfggmt4ugcqFENeeWeaAAJn7zqGHjl4Dbf72wxiZy7XjjeLxUKYLqW9qkB1SlBOAbSHC2jqWC6PLAYiIAGsKQzgBJzT2NER0zI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764061090; c=relaxed/simple; bh=nAXWuJtSjBIcO6/FobEkrLN/I6WQQ5is6xaKK3EqJg8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=YiuKdGkf3fzj3d2MUJppA8avIAV24kbJpwjtLPD8NE4brdVOI01YJnuvo7grLb2zC2NEeRPlZwPSgypNoLMF3SCBynK+Yprle+qbjscXrHs7TSEDcYegx16G5ihd0VTrDZFwTt1jhe+A4BVZtphKbToDfwDnOfxhzLAOo4PPRwM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qd/lV+kX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qd/lV+kX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A55AC4CEF1; Tue, 25 Nov 2025 08:58:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764061090; bh=nAXWuJtSjBIcO6/FobEkrLN/I6WQQ5is6xaKK3EqJg8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=qd/lV+kXV823/dqZYQyjNpk9Nq6la3jMN44UkQVCD5maKDw8ebaQjIMyP4KTE+slP C+DBaHpVPOYWTSdoPVwWBaBj7gO3gwrYugftPBfUXdPeZaoq6e422zKRQvordVBZU1 7R4lZ6CqEBMC6srVnhIEI0Bgaw7D+wodXrO4lJfMS/9k+/M2VBlXhH5Dx+alEUTLNQ Io3PBIJbQ6WRAi5pA6LU9JYONzCCA52ttQBLuh+WdbqsAyfqc0XjjRlXw8iMvsn2kN aTkVvtvbw/0zrw6XPUbkTJHaOOvNec1BPomP7ZQ2H4Mhe3Tnod5jNsI0gFUpwAk/Zf 8MJnOFHWf5PrA== Message-ID: Date: Tue, 25 Nov 2025 09:58:03 +0100 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/4] mm/huge_memory: change folio_split_supported() to folio_check_splittable() To: Zi Yan , Lorenzo Stoakes Cc: Andrew Morton , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Miaohe Lin , Naoya Horiguchi , Wei Yang , Balbir Singh , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20251122025529.1562592-1-ziy@nvidia.com> <20251122025529.1562592-2-ziy@nvidia.com> From: "David Hildenbrand (Red Hat)" Content-Language: en-US In-Reply-To: <20251122025529.1562592-2-ziy@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 11/22/25 03:55, Zi Yan wrote: > folio_split_supported() used in try_folio_split_to_order() requires > folio->mapping to be non NULL, but current try_folio_split_to_order() does > not check it. There is no issue in the current code, since > try_folio_split_to_order() is only used in truncate_inode_partial_folio(), > where folio->mapping is not NULL. > > To prevent future misuse, move folio->mapping NULL check (i.e., folio is > truncated) into folio_split_supported(). Since folio->mapping NULL check > returns -EBUSY and folio_split_supported() == false means -EINVAL, change > folio_split_supported() return type from bool to int and return error > numbers accordingly. Rename folio_split_supported() to > folio_check_splittable() to match the return type change. > > While at it, move is_huge_zero_folio() check and folio_test_writeback() > check into folio_check_splittable() and add kernel-doc. > > Signed-off-by: Zi Yan > --- > include/linux/huge_mm.h | 10 ++++-- > mm/huge_memory.c | 74 +++++++++++++++++++++++++---------------- > 2 files changed, 53 insertions(+), 31 deletions(-) > > diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h > index 1d439de1ca2c..97686fb46e30 100644 > --- a/include/linux/huge_mm.h > +++ b/include/linux/huge_mm.h > @@ -375,8 +375,8 @@ int __split_huge_page_to_list_to_order(struct page *page, struct list_head *list > int folio_split_unmapped(struct folio *folio, unsigned int new_order); > int min_order_for_split(struct folio *folio); > int split_folio_to_list(struct folio *folio, struct list_head *list); > -bool folio_split_supported(struct folio *folio, unsigned int new_order, > - enum split_type split_type, bool warns); > +int folio_check_splittable(struct folio *folio, unsigned int new_order, > + enum split_type split_type, bool warns); > int folio_split(struct folio *folio, unsigned int new_order, struct page *page, > struct list_head *list); > > @@ -407,7 +407,11 @@ static inline int split_huge_page_to_order(struct page *page, unsigned int new_o > static inline int try_folio_split_to_order(struct folio *folio, > struct page *page, unsigned int new_order) > { > - if (!folio_split_supported(folio, new_order, SPLIT_TYPE_NON_UNIFORM, /* warns= */ false)) > + int ret; > + > + ret = folio_check_splittable(folio, new_order, SPLIT_TYPE_NON_UNIFORM, > + /* warns= */ false); > + if (ret) > return split_huge_page_to_order(&folio->page, new_order); > return folio_split(folio, new_order, page, NULL); > } > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 041b554c7115..c1f1055165dd 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -3688,15 +3688,43 @@ static int __split_unmapped_folio(struct folio *folio, int new_order, > return 0; > } > > -bool folio_split_supported(struct folio *folio, unsigned int new_order, > - enum split_type split_type, bool warns) > +/** > + * folio_check_splittable() - check if a folio can be split to a given order > + * @folio: folio to be split > + * @new_order: the smallest order of the after split folios (since buddy > + * allocator like split generates folios with orders from @folio's > + * order - 1 to new_order). > + * @split_type: uniform or non-uniform split > + * @warns: whether gives warnings or not for the checks in the function > + * > + * folio_check_splittable() checks if @folio can be split to @new_order using > + * @split_type method. The truncated folio check must come first. > + * > + * Context: folio must be locked. > + * > + * Return: 0 - @folio can be split to @new_order, otherwise an error number is > + * returned. > + */ > +int folio_check_splittable(struct folio *folio, unsigned int new_order, > + enum split_type split_type, bool warns) > { > + VM_WARN_ON_FOLIO(!folio_test_locked(folio), folio); > + /* > + * Folios that just got truncated cannot get split. Signal to the > + * caller that there was a race. > + * > + * TODO: this will also currently refuse shmem folios that are in the > + * swapcache. > + */ Per the other discussion, should this even be: "this will also currently refuse folios without a mapping in the swapcache (shmem or to-be-anon folios)" IOW, to spell out that anon folios that were read into the swapcache but not mapped yet into page tables (where we set folio->mapping). -- Cheers David