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 7A715C27C52 for ; Thu, 6 Jun 2024 21:00:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 061676B00A4; Thu, 6 Jun 2024 17:00:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F2CAA6B00AC; Thu, 6 Jun 2024 17:00:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DCC9D6B00AD; Thu, 6 Jun 2024 17:00:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BD2566B00A4 for ; Thu, 6 Jun 2024 17:00:47 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5FF5EA348F for ; Thu, 6 Jun 2024 21:00:47 +0000 (UTC) X-FDA: 82201682934.10.F363D7B Received: from mail-vs1-f44.google.com (mail-vs1-f44.google.com [209.85.217.44]) by imf06.hostedemail.com (Postfix) with ESMTP id 9080B18002B for ; Thu, 6 Jun 2024 21:00:45 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=l+GzAri0; spf=pass (imf06.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.217.44 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717707645; a=rsa-sha256; cv=none; b=qhvwgrAX1D10HEPuNCTOyfFO2DLW9+F9EqmIyTnxYG8E9RGI8dwS8tPGPKIO0rY6X3TTvA 1Az3RrFKoy26NJOEh5oRcGJA4yYSne9z1Le/9H/EeRM2BJYtXUZz6IKaKNRlNTLo58EsHL NnqgKukHvWZRGoiL0aXkOaIvTWToQ+Q= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=l+GzAri0; spf=pass (imf06.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.217.44 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717707645; 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:dkim-signature; bh=lbT4Y3Y/h7wbsMDxOnKoTQqMWb5YcFDUKO9fnBN+XwE=; b=jnDXDYN83h3FWfJWmk5UjJeOFquRgq1ET+5QhCzVUHVm8OdcetwdJ+TADbyslumzHOxcQf yjdXd83aG5VRmtQWoWMkE3UI+fzMGLzAGW9Es5B/CK2yiG05tCg0V1rFs1if+gFCFrua6M xISnD3ktm67JmH/2NK89tu3Ji+V4Uoc= Received: by mail-vs1-f44.google.com with SMTP id ada2fe7eead31-48bd2a9fc5fso485411137.1 for ; Thu, 06 Jun 2024 14:00:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717707644; x=1718312444; darn=kvack.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=lbT4Y3Y/h7wbsMDxOnKoTQqMWb5YcFDUKO9fnBN+XwE=; b=l+GzAri02q6sOytYUEKSJahUFeIWEYmVSvhH7KwVjivRBiFS+ABX6S+p6ADVkdWIUR vDDZiAopw1en1fDQfaYJ2DZEM3hNz7/SyRpIz/PTXlq9RNA2WHwNzlhYeQ1OYg7mapgL BZun1/omAdCgY+xf3zE5QXEkV49GgDAKWOZqAXdsTGAv0wvyo1YW5Pkz7z5VF4jFJoc1 ZF8H0TJOtEloJEbdbyZ9TDwSJ9pcLqA61Gjx0lAFFPP97lC7tGRUNpTqR45TkKrn21l5 yTPj0FzJHHaLaMBIGvyxijfrTezMejAH6MkqsnzI9CoCH+UzKcFMNB5nJOmWrrBziVtE plow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717707644; x=1718312444; 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=lbT4Y3Y/h7wbsMDxOnKoTQqMWb5YcFDUKO9fnBN+XwE=; b=W/2bxevN8W7WlPHi7F+8QeKsvXiH1fpcZVkqUNN62dGgCf0eh9PKM9ZATFaVREWjV8 7NVGho83oBgiIoQRn2uUIWWefMmsqyoSB04HXkJLzjLyKz3g7UYX/dVvcmGAz78PVyy1 QNYrcfA6mILYHK83ugZVSyR6kpy0QaX+8xHFvQa4KUNoYFE0yBmW5h7LHBlvHq39gX7/ 7HgOUHbaOXMFpRgLJRsrY0aVPrMm90fi6mDm2HHdwYhbXG0DWezALyQQOv2U3pOZFE/5 Khihzzik42L71t+uWG5Ni81U+NfFpveKzIr6Ftda9UImBx9j59q/Y3YJ5Ee/lNS/j3Je wGCg== X-Forwarded-Encrypted: i=1; AJvYcCXvKgcgPod97DuXFVs8OJGZ7Ke0ZaC1pjXz3/2TocNlwUtBPrWh0xSbciJbzc+P9geWiYf/uq6SAWuGqQA1jNhZSSQ= X-Gm-Message-State: AOJu0Yzc2wtcbTKbev8CqtzU/z+I4hIAqTTPQlZViGmI2cKwJQOdu4Pl c4zQ44U+b8USI950cH2cVrs9nOXqeeUFIgq6tXwgs7DujmISaRgXIQrybx8KB+3mCfh4CKEO5P3 Bo+yL73DqCkbh72lFICx0PB3+ILk= X-Google-Smtp-Source: AGHT+IF/5u5Baa4VRSA+h9ecC9KG95vBFCUol6RE+wcGpEiVT3tgGrNT8/lIIXLfb1GhipEd6Z7hDApzS1cjsbkxgkk= X-Received: by 2002:a05:6102:3092:b0:48c:1157:2f58 with SMTP id ada2fe7eead31-48c275dd6edmr434522137.17.1717707644169; Thu, 06 Jun 2024 14:00:44 -0700 (PDT) MIME-Version: 1.0 References: <20240606174203124_OW-VQZ_ZLm4lGEimA-K9@zte.com.cn> <51DED95F-832A-4836-AA81-556968F6B645@nvidia.com> In-Reply-To: <51DED95F-832A-4836-AA81-556968F6B645@nvidia.com> From: Barry Song <21cnbao@gmail.com> Date: Fri, 7 Jun 2024 09:00:33 +1200 Message-ID: Subject: Re: [PATCH linux-next v2] mm: huge_memory: fix misused mapping_large_folio_support() for anon folios To: Zi Yan Cc: xu.xin16@zte.com.cn, david@redhat.com, v-songbaohua@oppo.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhocko@kernel.org, yang.yang29@zte.com.cn, ran.xiaokai@zte.com.cn, Matthew Wilcox Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 9080B18002B X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: 18xasuqko1b47n58j6td7ct8jigztije X-HE-Tag: 1717707645-772973 X-HE-Meta: U2FsdGVkX190TwIzmuO/DUrX1kl1UZN31AWAAAa/fl6qGbqpoTgqPK6dmmQnQ8PEWAgKOb1uvmbdGTsnFyC40SaO9lZbTPAvcV3tFVieEH6Y0c9jqXcSQppqdfRaSlHMcqIbytmktAzEgOyy2m2iHtKzI/9g6Ym6HSIwTdBzhm2EYIjxWiT9iLul3FtI+nk6XLLiFasFxykpafAWuHeceNhjDkCaR1zMCuMnkXA2ImhPn6Dua42+6/LH0bVVEzeNYbO1K15ElHahwzE1Sj122B6fBAjOHZCelJP8XNwG5N/3Bx+BXPRD93iws4u8J0ZZ6ML5n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UbV5sdPPhOL5QGia7IrA7Bc6GYRM1bpHxJP3+izy2RN4F9zDP6xqwf0tafcVN6fkY/jBtqZmD9lvufjKxxL6dybi3Q= 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 Fri, Jun 7, 2024 at 2:35=E2=80=AFAM Zi Yan wrote: > > +Matthew > > For mapping_large_folio_support() changes. > > On 6 Jun 2024, at 2:42, 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 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, s= o > > (head[i].index >=3D end) is always false. shmem_mapping() is not called= . > > > > 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 pages > > 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(struct= address_space *mapping) > > */ > > static inline bool mapping_large_folio_support(struct address_space *m= apping) > > { > > + /* AS_LARGE_FOLIO_SUPPORT is only reasonable for pagecache folios= */ > > + VM_WARN_ONCE((unsigned long)mapping & PAGE_MAPPING_ANON, > > + "Anonymous mapping always supports large folio"); > > + > > 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 pag= e *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 supported */ > > - if (folio_test_swapcache(folio)) > > + if (folio_test_anon(folio)) { > > + /* Cannot split anonymous THP to order-1 */ > > + if (new_order =3D=3D 1) { > > + VM_WARN_ONCE(1, "Cannot split to order-1 folio"); > > return -EINVAL; > > + } > > + } else if (new_order) { > > /* 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 fol= io */ > > - if (!mapping_large_folio_support(folio->mapping)) { > > + /* No split if the file system does not support large fol= io. > > + * Note that we might still have THPs in such mappings du= e to > > + * CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the map= ping > > + * does not actually support large folios properly. > > + */ > > + if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && > > + !mapping_large_folio_support(folio->mapping)) { > > Shouldn=E2=80=99t this be > > if (!IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && > !mapping_large_folio_support(folio->mapping)) { > > ? > > When CONFIG_READ_ONLY_THP_FOR_FS is not set, we need to check > mapping_large_folio_support(), otherwise we do not. while CONFIG_READ_ONLY_THP_FOR_FS is not set, that is no way a large folio can be mapped to a filesystem which doesn't support large folio mapping. i think if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS)) is correct. The below means a BUG which has never a chance to happen if it is true. !IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && !mapping_large_folio_support(folio->mapping)); > > > VM_WARN_ONCE(1, > > "Cannot split file folio to non-0 order")= ; > > return -EINVAL; > > } > > } > > > > + /* Only swapping a whole PMD-mapped folio is supported */ > > + if (folio_test_swapcache(folio) && new_order) > > + return -EINVAL; > > > > is_hzp =3D is_huge_zero_folio(folio); > > if (is_hzp) { > > -- > > 2.15.2 > > > Best Regards, > Yan, Zi Thanks Barry