Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp24633lqr; Tue, 4 Jun 2024 19:22:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXKWNy2mUaG8RkhPtygGBhAUahR7zMOGgyl1X+ZGuAMRVQi0+wiiyqIlZFriLkZiR0SkA+Evqwac8T04ATr+ADFmBl3e+4yy+DTAHYGWg== X-Google-Smtp-Source: AGHT+IFEUQdvWXo4AMkGBnp3pt9fYC/Grx3zTl6VC1y4nkm8wk64QG5a+aVuIuoZ2yVh+D57bu1d X-Received: by 2002:a50:9b1b:0:b0:57a:588:747c with SMTP id 4fb4d7f45d1cf-57a8bca0fb8mr733400a12.32.1717554166757; Tue, 04 Jun 2024 19:22:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717554166; cv=pass; d=google.com; s=arc-20160816; b=L2ga1cqbIzA6yaHusmxdtauHUpz7ZIzBrjuUyASBtJqy2joQQl0PwMtbj8AdXogNZe Y6feUtwMurJ2GC91mTjg52Ouk3WeuhzirCwUwcjhGerMx8kJNbrRr3oy0Z3MGi0c/yi0 BWms/4o8c1C79kk84DQT4jHnwwQO65ncEXDDQIqgzXLw/c4WzDfNzfDbseBuBca0JIMF I2VUlM4FYRCuzeiG/FSmL94JC6/iAckKxz9MHmAa2lmDBFvEm6ub/06gW62GTcHFhdax BGyrKHE5cnQ5hwTet9ZwsDCXpgwY25g4Twl+fEPTCe2S7qm9ImpOCGPEtlHoSAm1q8Gz +nhg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=99UK3SS0coifAlgek0C0Ovd66JCCH+0Fhwar14jUuug=; fh=OYQpwPoclz22RP7/p8M8aCub1i3OpGl4bZFrlAM8xAA=; b=wpGrVo/lDvYOUl0iCL+8wK9+sYhuv4HD16roSuP3DAKN122K+NOUVAs3D3D0b2eB+t LTtXksSu3COyyfIull7lzRfGLL4Xo9/TGmHxT+GISKUklcRUXqUKG7rOZQ8wwqjwPOVh us0qkXmp2CsZaDnnjvIS3/2l4dcHEOhMFSLn7clFDVDEKl9D+GOJLM7RKYOr8Lu5Hf/t l/+UUzdKlvVcesW8kf7TLYidrt3Ui5GSNNhCyeCj6tUgPwntDbv8Hfm2A+tTzLrCp3Rh 2MICjJ774pRINNHmvto/UejtfuefO0fThsWruYSeXLfHKJOdpcH9A8IZBNrZ7dzlyO5q 2tDQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=JOz8422U; arc=pass (i=1 spf=pass spfdomain=163.com dkim=pass dkdomain=163.com dmarc=pass fromdomain=163.com); spf=pass (google.com: domain of linux-kernel+bounces-201684-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201684-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57a31cca1b8si5462137a12.665.2024.06.04.19.22.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 19:22:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-201684-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=JOz8422U; arc=pass (i=1 spf=pass spfdomain=163.com dkim=pass dkdomain=163.com dmarc=pass fromdomain=163.com); spf=pass (google.com: domain of linux-kernel+bounces-201684-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201684-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 7E3941F24CD6 for ; Wed, 5 Jun 2024 02:22:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9FC7561FF2; Wed, 5 Jun 2024 02:21:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="JOz8422U" Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.2]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E14C124B34 for ; Wed, 5 Jun 2024 02:21:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.2 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717554110; cv=none; b=Nca8F3J2dy/iVtpp41QonUweMoN+8i0SfyLI/O/IT4j5MoN3FZyN8hCG7/vIWy0g9o3nuCXpE403xheCM4EG8+7ilbCLOGG/Z3bmArw7iOaYcZ1sQoUU6oJAJlapdA2dU4IfeA2wplB6G3dOJr3cOs+BSJBgA0fOStwgAQ3x72w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717554110; c=relaxed/simple; bh=JTnSNyXJb9/n4zWhEsZEgrjDjA6qKcjZ618TEtxWRng=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hrjIZOjJPBqMn0LUmL/UWDip765JwMD8a6p+Pc7sTY0KKf63vn1yGwQrHAIlknGa/wOl0hbzJbpH21J4xl3rylQM4b1msctypLA3ES9Wh2QwShIGiEXGBkF1X+TAPOSaCO0AlVdATTyUKVU95SIYp6hAYCRzL2ZZ5hMv6QsRydo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=JOz8422U; arc=none smtp.client-ip=220.197.31.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=99UK3 SS0coifAlgek0C0Ovd66JCCH+0Fhwar14jUuug=; b=JOz8422UqF4y12MhdI7Et lvvWapEK9ZQJU2hQfpblOuw+sH+e3/67SrafWczT5optIR+7BvaVIb26Asy9u0Xa PXq4z4nF3zy7gb+Ir5osyFz0KQQGRHuzisRvq75yrO/uwCmXPSuINVvKr5FZFokE e+bqCVP03/fHLMG+GZva+k= Received: from localhost.localdomain (unknown [193.203.214.57]) by gzga-smtp-mta-g1-1 (Coremail) with SMTP id _____wDXr06Dy19m1Y57HA--.24429S4; Wed, 05 Jun 2024 10:20:53 +0800 (CST) From: ran xiaokai To: david@redhat.com Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhocko@kernel.org, v-songbaohua@oppo.com, ran.xiaokai@zte.com.cn, xu.xin16@zte.com.cn, yang.yang29@zte.com.cn, ziy@nvidia.com Subject: Re: [PATCH linux-next] mm: huge_memory: fix misused mapping_large_folio_support() for anon folios Date: Wed, 5 Jun 2024 02:20:51 +0000 Message-Id: <20240605022051.888955-1-ranxiaokai627@163.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:_____wDXr06Dy19m1Y57HA--.24429S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxGr45tryUCr1UZr4rWr4kZwb_yoWrWw47pF W2grn3tFWkXrZI9r12qF4jkrn5ZrW8Xa4kAay3XwnxA3ZxGF429FW7J3Wruay7uryfJr4x Xa1UXFy3W3Z8tFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRrb15UUUUU= X-CM-SenderInfo: xudq5x5drntxqwsxqiywtou0bp/xtbB0gn0TGWXyKdRAQAAsu > On 04.06.24 07:47, xu.xin16@zte.com.cn wrote: > > From: Ran Xiaokai > > > > When I did a large folios split test, a WARNING > > "[ 5059.122759][ T166] Cannot split file folio to non-0 order" > > was triggered. But my test cases are only for anonmous folios. > > while mapping_large_folio_support() is only reasonable for page > > cache folios. > > Agreed. > > I wonder if mapping_large_folio_support() should either > > a) Complain if used for anon folios, so we can detect the wrong use more > easily. (VM_WARN_ON_ONCE()) > b) Return "true" for anonymous mappings, although that's more debatable. > Hi, David, Thanks for the review. I think a) is better. But we have to add a new parameter "folio" to mapping_large_folio_support(), right ? something like mapping_large_folio_support(struct address_space *mapping, struct folio *folio) ? But in the __filemap_get_folio() path, __filemap_get_folio() no_page: .... if (!mapping_large_folio_support(mapping)) the folio is not allocated yet, yes ? Or do you mean there is some other way to do this ? > > > > In split_huge_page_to_list_to_order(), the folio passed to > > mapping_large_folio_support() maybe anonmous folio. The > > folio_test_anon() check is missing. So the split of the anonmous THP > > is failed. This is also the same for shmem_mapping(). We'd better add > > a check for both. But the shmem_mapping() in __split_huge_page() is > > not involved, as for anonmous folios, the end parameter is set to -1, so > > (head[i].index >= end) is always false. shmem_mapping() is not called. > > > > Using /sys/kernel/debug/split_huge_pages to verify this, with this > > patch, large anon THP is successfully split and the warning is ceased. > > > > Signed-off-by: Ran Xiaokai > > Cc: xu xin > > Cc: Yang Yang > > --- > > mm/huge_memory.c | 38 ++++++++++++++++++++------------------ > > 1 file changed, 20 insertions(+), 18 deletions(-) > > > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > > index 317de2afd371..4c9c7e5ea20c 100644 > > --- a/mm/huge_memory.c > > +++ b/mm/huge_memory.c > > @@ -3009,31 +3009,33 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, > > if (new_order >= folio_order(folio)) > > return -EINVAL; > > > > - /* Cannot split anonymous THP to order-1 */ > > - if (new_order == 1 && folio_test_anon(folio)) { > > - VM_WARN_ONCE(1, "Cannot split to order-1 folio"); > > - return -EINVAL; > > - } > > - > > if (new_order) { > > /* Only swapping a whole PMD-mapped folio is supported */ > > if (folio_test_swapcache(folio)) > > return -EINVAL; > > - /* Split shmem folio to non-zero order not supported */ > > - if (shmem_mapping(folio->mapping)) { > > - VM_WARN_ONCE(1, > > - "Cannot split shmem folio to non-0 order"); > > - return -EINVAL; > > - } > > - /* No split if the file system does not support large folio */ > > - if (!mapping_large_folio_support(folio->mapping)) { > > - VM_WARN_ONCE(1, > > - "Cannot split file folio to non-0 order"); > > - return -EINVAL; > > + > > + if (folio_test_anon(folio)) { > > + /* Cannot split anonymous THP to order-1 */ > > + if (new_order == 1) { > > + VM_WARN_ONCE(1, "Cannot split to order-1 folio"); > > + return -EINVAL; > > + } > > + } else { > > + /* Split shmem folio to non-zero order not supported */ > > + if (shmem_mapping(folio->mapping)) { > > + VM_WARN_ONCE(1, > > + "Cannot split shmem folio to non-0 order"); > > + return -EINVAL; > > + } > > + /* No split if the file system does not support large folio */ > > + if (!mapping_large_folio_support(folio->mapping)) { > > + VM_WARN_ONCE(1, > > + "Cannot split file folio to non-0 order"); > > + return -EINVAL; > > + } > > } > > } > > What about the following sequence: > > if (folio_test_anon(folio)) { > if (new_order == 1) > ... > } else if (new_order) { > if (shmem_mapping(...)) > ... > ... > } > > if (folio_test_swapcache(folio) && new_order) > return -EINVAL; > > Should result in less churn and reduce indentation level. > Thanks. The code is cleaner in this way. > -- > Cheers, > > David / dhildenb