From patchwork Mon Aug 14 18:44:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13353178 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 325E2C04A94 for ; Mon, 14 Aug 2023 18:44:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B1668E0001; Mon, 14 Aug 2023 14:44:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 939A9900003; Mon, 14 Aug 2023 14:44:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 78CFD8E0005; Mon, 14 Aug 2023 14:44:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 6A1648E0001 for ; Mon, 14 Aug 2023 14:44:22 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B672F140C37 for ; Mon, 14 Aug 2023 18:44:21 +0000 (UTC) X-FDA: 81123585522.27.2EDFE1C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 91F5C140027 for ; Mon, 14 Aug 2023 18:44:19 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LWIZN6aa; spf=pass (imf09.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692038659; 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=K80vu1sJx9DsGDhSbLEtYPGEOnTcZDHaiO/EYxwWGMs=; b=G+wBGno/vemfjqSRGzHuO60FN9yKhdpiebeYz1scu9zU2fQxSQH6Fmw3t9dDvyAPz6Siij qiGZ8QYpGxA9QWtFdggINJBRe8sXOTXBvFmku7lJeL3Fa+tocN+lVKBzaxofaZBLrgsioi epdFwTlPRP9alaouhZozVuVrR6gl2/k= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LWIZN6aa; spf=pass (imf09.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692038659; a=rsa-sha256; cv=none; b=UKOPYZ33uqGN7KHtOxLXCKyKK01XqHy6b3Ry6T2qoO+SQ/6ldIuyAqs5SpUULsF3ZQZJcj zyRXaV2qiTjUMPbE0XD4tVqHoAiPyMtKBGwtCzidCqwkvOXR8qlpjdL3NWo6v9YyHYqbYL PydzE5qdXw0Brxq5zJR6J1tvP3Xw4ho= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692038659; h=from:from: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; bh=K80vu1sJx9DsGDhSbLEtYPGEOnTcZDHaiO/EYxwWGMs=; b=LWIZN6aa3JqGirFL6e89Esdfk9wcCSfbu2topzZX1b7bSTGXY0JKYJv7/7CKf4895hGYF9 bZhfjZsiUPxD5rfuPZFsFk3h934OBYXErHVT5MiSGXnDVQd10+xS/UyVMn1hOuZSufTTqA p9syRkjGkBz08QWZiKbtmd9JGWFwf/8= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-662-NmHe97SoP0ilgB1R_dmB_w-1; Mon, 14 Aug 2023 14:44:15 -0400 X-MC-Unique: NmHe97SoP0ilgB1R_dmB_w-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-645778904dfso8657126d6.1 for ; Mon, 14 Aug 2023 11:44:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692038655; x=1692643455; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K80vu1sJx9DsGDhSbLEtYPGEOnTcZDHaiO/EYxwWGMs=; b=hoz0W8qcv6lftaIarvfacqAo+9VPiYTEWTKFXvF6LeWGpngmKqFM8UIngCo0FlY+tS I5Cuk6DpMfs2y+6TXbEXLKTU4LPxk8nFwNAtvZZQEUGX8dOmQkgJiYtXk5mujP6Jj632 Alz3iD5TbHolkpCg7jIJRTeuneYOfUB1UopNPtqhZSUAUmdZKJ5fPwApaRwkyaF3a0pS Um8McX+OFZRkFNkT/gJjG4OPNoXew/rJg1ERlnh8B2vCYwA3/DWm2kgVmZ3H0xJ+b0HU BiLybKFTBCwGJ7WGvTzh6j5I0C/cl/P1G01pClpNFnYXDsGEgQaIXLHdfWXKHesyEvhq yYRw== X-Gm-Message-State: AOJu0YzXYLgrbmzdvfk+iF1Ez/N9cYpMLmlvyMfyEwkF8iVDn2WRIhNJ 9cCiImUmuA4uGkG0Qww1i16Pao4ibJqlnXFUmxp8Z2zY0u7iSJJ4FPUkrGRkg+6D0Esnn6P7El2 m4MLfi5oZEbugcCu/LPKPGrxgJDUUqA9A8nF1C0zK3aia74mbhhl2dIkb869d7e96WzSm X-Received: by 2002:a05:6214:226b:b0:626:2305:6073 with SMTP id gs11-20020a056214226b00b0062623056073mr14561436qvb.4.1692038655250; Mon, 14 Aug 2023 11:44:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGWDv/pTkCgGz4dnpVLXX0rV2wACMdw+Qcy+eJSwM3xg9sOHmswZi98yBi7GjAnG22hvSrGEA== X-Received: by 2002:a05:6214:226b:b0:626:2305:6073 with SMTP id gs11-20020a056214226b00b0062623056073mr14561409qvb.4.1692038654848; Mon, 14 Aug 2023 11:44:14 -0700 (PDT) Received: from x1n.redhat.com (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id a7-20020a0cb347000000b00630c0ed6339sm3566561qvf.64.2023.08.14.11.44.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 11:44:14 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Mike Kravetz , David Hildenbrand , Matthew Wilcox , Andrew Morton , peterx@redhat.com, Yu Zhao , Ryan Roberts , Yang Shi , Hugh Dickins , "Kirill A . Shutemov" Subject: [PATCH RFC v2 1/3] mm: Add TAIL_MAPPING_REUSED_MAX Date: Mon, 14 Aug 2023 14:44:09 -0400 Message-ID: <20230814184411.330496-2-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230814184411.330496-1-peterx@redhat.com> References: <20230814184411.330496-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 91F5C140027 X-Rspam-User: X-Stat-Signature: 7ogo1pi5dm7xsxprxfc4d5emcur7dpcy X-Rspamd-Server: rspam01 X-HE-Tag: 1692038659-315777 X-HE-Meta: U2FsdGVkX181KgtHhKH3CoCH8uuwLt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0KOQ7zRfO3h3UoqFj4j9FjbuGB8JlTQ4kSbW7tjTw8tpPyncZf8QXywgc0NrruMOxc0wtFKqEu8a8cNWGGII6DPdxIv1c+WRgI6s2tpySIfHTtPJmQrW+65U6fl7XitMqW0Oso6jLBN8BbH+K6dqs3ToMPzGREo7q0LXJoCsX5bcWJ75xlmZx41fCjvTfBWfyCjKpetX2nMrZhtj4TIypv6yELAHD9Y6p9DBCwc13PEi94tQQlbdrzVoMMZlW7TsD/m5UefCJtI+PZt8x+FBh2UiHO5MBDRLZBN87XGfJEBA3ycP5K486YvuAcjp9vHK5sGATJTDNxjg== 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: Tail pages have a sanity check on ->mapping fields, not all of them but only upon index>2. It's because we reused ->mapping fields of the tail pages index=0,1 for other things. Define a macro for "max index of tail pages that got ->mapping field reused" on top of folio definition, because when we grow folio tail pages we'd want to boost this too together. Signed-off-by: Peter Xu --- include/linux/mm_types.h | 9 +++++++++ mm/huge_memory.c | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 291c05cacd48..3f2b0d46f5d6 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -248,6 +248,15 @@ static inline struct page *encoded_page_ptr(struct encoded_page *page) return (struct page *)(~ENCODE_PAGE_BITS & (unsigned long)page); } +/* + * This macro defines the maximum tail pages (of a folio) that can have the + * page->mapping field reused (offset 12 for 32bits, or 24 for 64bits). + * + * When the tail page's mapping field reused, it'll be exempted from + * ->mapping poisoning and checks. Also see the macro TAIL_MAPPING. + */ +#define TAIL_MAPPING_REUSED_MAX (2) + /** * struct folio - Represents a contiguous set of bytes. * @flags: Identical to the page flags. diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 0b709d2c46c6..72f244e16dcb 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2444,9 +2444,9 @@ static void __split_huge_page_tail(struct page *head, int tail, (1L << PG_dirty) | LRU_GEN_MASK | LRU_REFS_MASK)); - /* ->mapping in first and second tail page is replaced by other uses */ - VM_BUG_ON_PAGE(tail > 2 && page_tail->mapping != TAIL_MAPPING, - page_tail); + /* ->mapping in <=TAIL_MAPPING_REUSED_MAX tail pages are reused */ + VM_BUG_ON_PAGE(tail > TAIL_MAPPING_REUSED_MAX && + page_tail->mapping != TAIL_MAPPING, page_tail); page_tail->mapping = head->mapping; page_tail->index = head->index + tail;