Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp183320lqr; Wed, 5 Jun 2024 02:55:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWiw2gWM6VKdTbptojMFSM2BjwUaxOVJlwCPv+dQuC/KDZGmcDmKaub44snfI529fRFCFLX+13voEsNyWdwZRzwmBPUxrd5lxTB+KhFaA== X-Google-Smtp-Source: AGHT+IHG3WXt3+AktZN15QcN0GQ/y67BW/TkzpytMM2PxSmhKXZ2ufhaiMtafhArdOJ75zM9vpz+ X-Received: by 2002:a19:4358:0:b0:52b:8a71:2688 with SMTP id 2adb3069b0e04-52bab50b6c0mr1546637e87.61.1717581316241; Wed, 05 Jun 2024 02:55:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717581316; cv=pass; d=google.com; s=arc-20160816; b=gcigkwXjWoTJDpTQDkQUC0saRAnOu4wJGelpU9wC0O5b0jLMafv9jVSbOx9lGdSYmM HVSG29E0C8BnbSIkyfe3RUn/wRXlRGnWsGbguNqNruWSj0ryg+YLXV9IsFNkD7IofqIN XkSV1harPz5Z2/jLA976o5UBTU9Xm7iJ+h7ZCvO4LpLYyWwIQ4Ha9NOVH9qW0Mn+3C7F 16sTcaNN5fxSoKzyzVgKl00gdGU4H6HNu3uHnH9R9v4q046k1umTWSl7kB8Ig5U0woWO 7tH594UXJhwehxBT2yVaQMmsT1ijW1naygdb/b4OHtVerdOmGo0Yc1wtFGemvASKML1q RkbA== 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=/oakUifhniV84QMFd9hK/xRSzvvRjN1nHsDWsGL/yU8=; fh=dd70AGUT2pkWdOj48ptQ/gEqBeX3rjWeEpXY9TBiOh4=; b=mkno6KA7Gp2SjWyBi3rYWomzJywffQ35noSEBgHzfBlvnob0ICSoyaI6xKlRKCJ3D8 RfTPAtjOQU0bbdSOZWT177NWowoHP2TRmNLH4whqY6jLJ6n0dCFmBxYimvvMcfXY3nn/ QLkuM6mTasJeQ4KOaY1R8WEJDl/nJrMbe4+D6nmx7HhMiKHR2AemXBz7AVej/VfxLy/Y yr8ttw71+Xo5Ir/7Um0A5mC0snyM0J9b6BGpYxczBl5rCJ/Lf6vRm83+vcHp04mfFxs5 UJNxaO634rpiHo91uS/lQsYZsG14E0PQTfJ5wF4rKsW8M4npVgCqN8Gx8CJrC9yCbHdO FsQg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=DxZzDfW3; 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-202150-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202150-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 a640c23a62f3a-a691c32906esi260925066b.384.2024.06.05.02.55.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 02:55:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202150-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=DxZzDfW3; 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-202150-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202150-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 BBB311F2167F for ; Wed, 5 Jun 2024 09:55:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0F1D318FDB6; Wed, 5 Jun 2024 09:55:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="DxZzDfW3" Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.2]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E80E163 for ; Wed, 5 Jun 2024 09:55:06 +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=1717581309; cv=none; b=Y2843zFEco8HU6PZKiR50oMj4ii8Bbm3pavTwaw1J5yu+EnLk/2kiIL4z2qeBHovrJ6py/NxwdM+Z4qpaFGFH2WOgjZ1I9ymUkbmtdTRnvlsxAiHLHA/ZOCG+4ddi0O+r39ohH9TTWtIscRNs7DKrbcl7eXWw4g1dzvqDPVeb2I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717581309; c=relaxed/simple; bh=QXeiEtnyemZNpJWeY5akh3tqj/FK6IvnOXT8E5iE5ZE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Uct7Z41NVE1h/ibUQw6qSUmpjPqXfkDa4ITsOoeZjM9AAlAIz25RhQk3oWpIJVeboQPCOLnG4b2X9GLJTSBq4WEVfPIyo32NuDg5d2KjUiT5c+XMH/CbrUMndGCpBMMtblLloGy83DAXXkAFARg3DyqkW2FJ0a1vbp8R5wvOkQs= 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=DxZzDfW3; 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=/oakU ifhniV84QMFd9hK/xRSzvvRjN1nHsDWsGL/yU8=; b=DxZzDfW3K5loicecZdNMP pS8zyO7P3zNo7c1R02FRNTabdIi82Cqt9N62M3VdzY8fAhT/5SX2iBZ5XFmXIOn5 qyTbKLwb5OJRKIzr9Zo5loSd9NdKKHrv4Rt68j4YUlG2vPUFZ+2uX97wyDpOPuuv 3ncJQNb5WXq0U8JLDu11fs= Received: from localhost.localdomain (unknown [193.203.214.57]) by gzga-smtp-mta-g1-3 (Coremail) with SMTP id _____wDn932+NWBmjnx1HA--.48089S4; Wed, 05 Jun 2024 17:54:08 +0800 (CST) From: ran xiaokai To: 21cnbao@gmail.com Cc: akpm@linux-foundation.org, david@redhat.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhocko@kernel.org, v-songbaohua@oppo.com, 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 09:54:06 +0000 Message-Id: <20240605095406.891512-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:_____wDn932+NWBmjnx1HA--.48089S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxXr43KFy3XF15Jr15Cr4kJFb_yoW5uFWrpF W2grn3ta95XFZIkr12qr40kr15XrWkXa4kAay3ZwnxA3ZxJrnF9Fy7J3W8uay7uryfJrWI qa1UXFy3W3WDtFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRoKZZUUUUU= X-CM-SenderInfo: xudq5x5drntxqwsxqiywtou0bp/1tbiMwT0TGXAlpWHBAAAsq > On Tue, Jun 4, 2024 at 5:47?PM 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. > > > > 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; > > + } > > Am I missing something? if file system doesn't support large folio, > how could the large folio start to exist from the first place while its > mapping points to a file which doesn't support large folio? I think it is the CONFIG_READ_ONLY_THP_FOR_FS case. khugepaged will try to collapse read-only file-backed pages to 2M THP.