Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp759763lqt; Thu, 6 Jun 2024 19:02:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUFA+SPJONc9fFplrJ8XrIIpAMLZA5q4Sh4oLbFpgABvNXHS0eUs8gOdAHP1u7kZfHVeEU5XeyC+D9NtW6MnP7opFthZjBdqSpEG0nQTg== X-Google-Smtp-Source: AGHT+IFfKRjfsN4UqAD7n9IdqbMfSWHxP+hq4psdgp3YzGy8bcHrOfYp2YzsLBNhe+w2VOf3iuYN X-Received: by 2002:a05:6602:3fc3:b0:7e1:7fd2:676 with SMTP id ca18e2360f4ac-7eb57225cb5mr156769139f.12.1717725758351; Thu, 06 Jun 2024 19:02:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717725758; cv=pass; d=google.com; s=arc-20160816; b=NIjDNYHe94EPqkZM9kwEecSEwnA2Tzag7c/sk77BvNnfgMcBdFGuRaGKKYh1lHPzna 6mSbTdKYe0axrLYEPIDWfHGTWKSCxpcxMwAxONe/bPdJ5vhireWTyFeigWYXm0MZ9i+O FXYzuwxMPhojUCgjM+qUmhGz9MtzsI7nZ2glA3RTMmMlKD5Fa6IkpjbOxd9Cz23lsOC+ Vg637MTWcq5fCTjVqo2pkXU4UEbUCeYvqLF7KQFWP3oGlOV4ij1OkqDcnrhbtJM1pBMU 07jQv05FGJa+evLgd0BElQYN0GP3xHnodNkPEGCvomdA3DDdHHzfi5UT2Nk9zhTbB0ML GSxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=Peut3ZHW0CaxiZSEBfz/De33tzBSHWA6rV+eq1ptdg4=; fh=MkUbkuaPcssjzYe7RgGEhC8BLxnWjAfd/QUprs6+BA8=; b=giSRxswxWPxvNJPVRpLMOl+RkcK9NJp7i/SBlfM1riqtAF8UjX9B/My24bi6g2NL/+ lN0UxM2y1xLc67LeFWyytF8jQqaRPpVIXWh5QlqAztBkQbqJkoP4jtCJAeddTB7juL4l NCPFCm1sLPtD5Dzzv/SpeFxNNaMZkLeXRJF4xXSd9xKimddtEUtb66cRwzAsLC3VN9YG VTfnykil+Mg5EZE1uuj/ojco5s0esil7KzwAZyBblh9CQStcMDL7qTRc8T1/zGP+RgaT OUH6vz6qUcpZdoBfQCStQuhCFj2cU4qpNW6urCUKr4n+F5BdYUEoLo8SVyK0y5spt25q muRA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dJL37RP4; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-205238-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205238-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-6de20831cc0si2087329a12.1.2024.06.06.19.02.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 19:02:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205238-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dJL37RP4; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-205238-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205238-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 8B7F1B21A21 for ; Fri, 7 Jun 2024 02:01:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2A6D114006; Fri, 7 Jun 2024 02:01:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dJL37RP4" Received: from mail-vk1-f177.google.com (mail-vk1-f177.google.com [209.85.221.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A031C4C70 for ; Fri, 7 Jun 2024 02:01:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717725662; cv=none; b=BzLjlvCjOyBusGR1j1PcVaoUYdzKZ9KgEYPbbieDkOD74nEUL9HZ/egWcwBoJuCw5i3/dG+RrEE/48yUzkABUE/6DbzF+DzphgraJ7DF0tyuvo+H1EWMwpuIn5mzjA9cpTRjUY442O8ZSQp+zlBBn7FXWrEZptcAqTr/s85uHZ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717725662; c=relaxed/simple; bh=/xcGYKkMrmyvxXdQr0zjgzN8XMOZABCsWQiVdP7zNCw=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Te43iEuldU/U+aZYKFKguFdqPpnrEZTSbFHHhNx3Jm7rYRmYyIna+VB//kCcdER635Ttpaf4DgvXiDU72sSAr1su2zzFDOihz72jJ+uTjNJGTvpzhasXuIREVdPPUjwLt6xSQ69OiKxFVGIJwY/fbSyX16K1oal3paw5hnXFYpc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dJL37RP4; arc=none smtp.client-ip=209.85.221.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-vk1-f177.google.com with SMTP id 71dfb90a1353d-4e1c721c040so598829e0c.3 for ; Thu, 06 Jun 2024 19:01:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717725659; x=1718330459; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Peut3ZHW0CaxiZSEBfz/De33tzBSHWA6rV+eq1ptdg4=; b=dJL37RP4K/UuAFCrznfqqWJP4+30dWaIT+HP3qxWSIlWK+Y8ANBdZmb1RnsjNLW8+R hWGSAZS2W8Dl+A0ERCkTQQbzk3f/dhb264wwpOspwlefVkF4+H+CppwWrRaQQpJP5dCh bgdlRxCtYgGcUT9DZ/Q+78rMAe5wfFJDHC0yKHDaXoojl7fZqIp8QJC6JOVcrqghGCQB vjLdzRbb9epsPbJ6zeZYJe3c+GU2CBSlsb0hMfHjW1YNcyWRlZpl28RsN9Z6fB/fgO+l Yg3mi3jC8QadO0HZZ+xTPrbX+WHnAsVNdxxJ6L5glCwUcYyIR8COgdgZuFvSOXU6bGZe fOTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717725659; x=1718330459; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Peut3ZHW0CaxiZSEBfz/De33tzBSHWA6rV+eq1ptdg4=; b=ZzyJqTWWPQrZGJew18AtoOWq7nmVKO8pHpnzAt+XHSmbsL/6GrfWD4VZFadlZhViVg hJgqjSVMxh6+v8x6Zuq8G5YELCqJE+f7fO76yO/YApefXQJEWI4DVPjw/d9HUPDWAW4u 8APMlGossNMkxMe+FNCbxOhKyCz2HoGoFNJftiQdOJLImZnCZbPIHN7TvwRb/q6Bsnf3 fkba83o9pa5aXKKVGylc7igzuoeghzk0+TSRQxegNgWJ19fTTo21Z3ja6fJXcjARBxaK dGkJ4AXEWyh0dSQNLW9R4o5DmyWP3LkQa3soYQHygyBy7h1xjpb2cPAyTuTSzROtasd9 78Xg== X-Forwarded-Encrypted: i=1; AJvYcCVDrQDAGcBDRKh5VGXfsl2aSL5JJ1ak8pGwVjeXNN2eFGIA7TpqhYziJa9OxuouPrEJN/d7i8OrLJUqPiaHlpAxXXRYMBJXZv7WQ+kz X-Gm-Message-State: AOJu0Yy3XfFG5IPkFvnquTp0vomEBISf9An4lB88Cy9/HZOGc8X8IYNS NhAyu0HJNdzGSZFORSNXmjY2z42+uth3RMvHbSHnlBHnB1alpQ2INpVRvOZJtoA1+aWbFEujeP9 9paJaV7LbYqIMi0DZUJKY4sUu4ko= X-Received: by 2002:a1f:7d4e:0:b0:4ea:ede1:ab15 with SMTP id 71dfb90a1353d-4eb562cd389mr1343760e0c.15.1717725659274; Thu, 06 Jun 2024 19:00:59 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240607013617.913054-1-ranxiaokai627@163.com> In-Reply-To: <20240607013617.913054-1-ranxiaokai627@163.com> From: Barry Song <21cnbao@gmail.com> Date: Fri, 7 Jun 2024 14:00:47 +1200 Message-ID: Subject: Re: [PATCH linux-next v2] mm: huge_memory: fix misused mapping_large_folio_support() for anon folios To: ran xiaokai Cc: akpm@linux-foundation.org, david@redhat.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhocko@kernel.org, ran.xiaokai@zte.com.cn, v-songbaohua@oppo.com, si.hao@zte.com.cn, xu.xin16@zte.com.cn, yang.yang29@zte.com.cn, ziy@nvidia.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jun 7, 2024 at 1:37=E2=80=AFPM ran xiaokai = 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 the test cases are only for anonmous folios. > > > while mapping_large_folio_support() is only reasonable for page > > > cache folios. > > > > > > 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 >=3D end) is always false. shmem_mapping() is not call= ed. > > > > > > Also add a VM_WARN_ON_ONCE() in mapping_large_folio_support() > > > for anon mapping, So we can detect the wrong use more easily. > > > > > > THP folios maybe exist in the pagecache even the file system doesn't > > > support large folio, it is because when CONFIG_TRANSPARENT_HUGEPAGE > > > is enabled, khugepaged will try to collapse read-only file-backed pag= es > > > to THP. But the mapping does not actually support multi order > > > large folios properly. > > > > > > 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 > > > --- > > > include/linux/pagemap.h | 4 ++++ > > > mm/huge_memory.c | 27 ++++++++++++++++----------- > > > 2 files changed, 20 insertions(+), 11 deletions(-) > > > > > > diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h > > > index ee633712bba0..59f1df0cde5a 100644 > > > --- a/include/linux/pagemap.h > > > +++ b/include/linux/pagemap.h > > > @@ -381,6 +381,10 @@ static inline void mapping_set_large_folios(stru= ct address_space *mapping) > > > */ > > > static inline bool mapping_large_folio_support(struct address_space = *mapping) > > > { > > > + /* AS_LARGE_FOLIO_SUPPORT is only reasonable for pagecache fo= lios */ > > > + VM_WARN_ONCE((unsigned long)mapping & PAGE_MAPPING_ANON, > > > + "Anonymous mapping always supports large foli= o"); > > > + > > > return IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && > > > test_bit(AS_LARGE_FOLIO_SUPPORT, &mapping->flags); > > > } > > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > > > index 317de2afd371..62d57270b08e 100644 > > > --- a/mm/huge_memory.c > > > +++ b/mm/huge_memory.c > > > @@ -3009,30 +3009,35 @@ int split_huge_page_to_list_to_order(struct p= age *page, struct list_head *list, > > > if (new_order >=3D folio_order(folio)) > > > return -EINVAL; > > > > > > - /* Cannot split anonymous THP to order-1 */ > > > - if (new_order =3D=3D 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 supporte= d */ > > > - if (folio_test_swapcache(folio)) > > > + if (folio_test_anon(folio)) { > > > + /* Cannot split anonymous THP to order-1 */ > > > > This is simply what the code is indicating. Shouldn't we phrase > > it differently to explain "why" but not "how"? for example, anon > > order-1 mTHP is not supported? > > Hi, Barry, > Good comments, thanks. > Is "order-1 is not a anonymouns mTHP suitable order." better? could pick up some words from include/linux/huge_mm.h, particularly those words regarding "a limitation of the THP implementation". /* * Mask of all large folio orders supported for anonymous THP; all orders u= p to * and including PMD_ORDER, except order-0 (which is not "huge") and order-= 1 * (which is a limitation of the THP implementation). */ #define THP_ORDERS_ALL_ANON ((BIT(PMD_ORDER + 1) - 1) & ~(BIT(0) | BIT(= 1))) perhaps, you can even do if (order > 0 && !(bit(order) & THP_ORDERS_ALL_ANON)) return -EINVAL; This is self-commented. Either way is fine. > > > Otherwise, it looks good to me. > > > > Reviewed-by: Barry Song > Thanks Barry