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 X-Spam-Level: X-Spam-Status: No, score=-18.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9E36C4338F for ; Sun, 8 Aug 2021 17:28:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AAC4B60F25 for ; Sun, 8 Aug 2021 17:28:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232199AbhHHR3K (ORCPT ); Sun, 8 Aug 2021 13:29:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230448AbhHHR3J (ORCPT ); Sun, 8 Aug 2021 13:29:09 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39CD9C061760 for ; Sun, 8 Aug 2021 10:28:50 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id h14so18177534wrx.10 for ; Sun, 08 Aug 2021 10:28:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=iatl/yvHUEXssqGaxmM3VVGCUZ13Zupn9QAYDy9G4Ic=; b=L8s5/CXK1BrLFzBCHTucpUv+lXw1DZcBfy1WmBT0IH2EugIraGzHYc/cXSG/W2Nh/5 WD5/PfjLu5EHDGGDyEdnCqxnnnrVVYI+hJSS7kLtiJXz1gxT1dgZ3J1oRfrlR433D/GN IKR5L3D773alI6Z0HSdo6Dj4oVEdnv1eqjo3qaZvvowCkVGwc2SO6F7kqfq8mDoAoO4v LF+cvxllz5eVwq+kcFH9/9U6eNF1gec1Lp31i7X3HA6USrLTqQa4iqcfeO/2bCpWo4Nf IRWxgfj+4y/5JnVQCTlNRQ1PClYFP4nCkt86IqjTwSFHHw8j+zeI87QtYekF5ZhfO9V7 /HwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=iatl/yvHUEXssqGaxmM3VVGCUZ13Zupn9QAYDy9G4Ic=; b=UBXTz9wsnnoJRGgXfg7ZdUuqAs2CUCMNeW41yfzxe1tG3CWTFhxeFNZfB6kK0RLZVZ MiDPgMdbINb6DOfenZBLcz/9grYJkfyj0T4soBcHNQJLiD2uAqcre72+zDafwgM+REzJ zl7PbMQ4TWz9iP7EXRIUVsdhSyKqHhj4Hsy98C9f5EQukHdNtBwSREIUIWMS+/z+33s1 2C7wKmUWZre1g6KTWYpjLbvoN/rP+E3NH7oiX8MQDh1NxttII6PVq5coobRvSJx+dsGP c0ZuuBJeAMQhh/Ng51DNPE2oKg8hEQGK3Y/PPyXCISRaphCb/f6dSAO0J9ovnfRYwDmI JVJA== X-Gm-Message-State: AOAM5320hQHlt2klI/vDqGF7KMwsIe/l068vpKUy1jYzTKxv3cRs9TlO OWm6NiOf46ZhQ4rbx3zq3cM1V1s2MdQ20+dDRK2MmA== X-Google-Smtp-Source: ABdhPJwIX7nUgxNitNxYTgIOm5Ad/d+mcp90wIYMeBSyeiulv8eOHmZzPAw7bHQDAaA26DPAifYHopw9d/vgLIgW2Gs= X-Received: by 2002:adf:d087:: with SMTP id y7mr20381698wrh.323.1628443728684; Sun, 08 Aug 2021 10:28:48 -0700 (PDT) MIME-Version: 1.0 References: <20210731063938.1391602-1-yuzhao@google.com> <20210731063938.1391602-3-yuzhao@google.com> <20210804142257.tsgzpfc3zq7um7iu@box.shutemov.name> In-Reply-To: <20210804142257.tsgzpfc3zq7um7iu@box.shutemov.name> From: Yu Zhao Date: Sun, 8 Aug 2021 11:28:37 -0600 Message-ID: Subject: Re: [PATCH 2/3] mm: free zapped tail pages when splitting isolated thp To: "Kirill A. Shutemov" Cc: Linux-MM , Andrew Morton , Hugh Dickins , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Yang Shi , Zi Yan , linux-kernel , Shuang Zhai Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 4, 2021 at 8:22 AM Kirill A. Shutemov wrote: > > On Sat, Jul 31, 2021 at 12:39:37AM -0600, Yu Zhao wrote: > > @@ -2506,6 +2508,25 @@ static void __split_huge_page(struct page *page, struct list_head *list, > > continue; > > unlock_page(subpage); > > > > + /* > > + * If a tail page has only two references left, one inherited > > + * from the isolation of its head and the other from > > + * lru_add_page_tail() which we are about to drop, it means this > > + * tail page was concurrently zapped. Then we can safely free it > > + * and save page reclaim or migration the trouble of trying it. > > + */ > > + if (list && page_ref_freeze(subpage, 2)) { > > + VM_BUG_ON_PAGE(PageLRU(subpage), subpage); > > + VM_BUG_ON_PAGE(PageCompound(subpage), subpage); > > + VM_BUG_ON_PAGE(page_mapped(subpage), subpage); > > + > > + ClearPageActive(subpage); > > + ClearPageUnevictable(subpage); > > Why touch PG_Active/PG_Unevictable? Subpages may inherit these flags from their isolated head. Page reclaim doesn't isolate active or unevictable. But migration does. If we don't clear them here, we'll hit bad_page() later because both flags are included in PAGE_FLAGS_CHECK_AT_FREE. Does it make sense? Thanks. 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 X-Spam-Level: X-Spam-Status: No, score=-18.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 715F4C4338F for ; Sun, 8 Aug 2021 18:05:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EB0E460EE9 for ; Sun, 8 Aug 2021 18:05:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EB0E460EE9 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 4BDB86B0071; Sun, 8 Aug 2021 14:05:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 46E0C6B0073; Sun, 8 Aug 2021 14:05:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 386FA8D0002; Sun, 8 Aug 2021 14:05:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0169.hostedemail.com [216.40.44.169]) by kanga.kvack.org (Postfix) with ESMTP id 1285E6B0073 for ; Sun, 8 Aug 2021 14:05:33 -0400 (EDT) Received: from forelay.prod.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by fograve03.hostedemail.com (Postfix) with ESMTP id 73D94180199B7 for ; Sun, 8 Aug 2021 17:29:00 +0000 (UTC) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 4E529180265AD for ; Sun, 8 Aug 2021 17:28:50 +0000 (UTC) X-FDA: 78452598420.11.9512561 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by imf28.hostedemail.com (Postfix) with ESMTP id 0FEB99006C40 for ; Sun, 8 Aug 2021 17:28:49 +0000 (UTC) Received: by mail-wr1-f43.google.com with SMTP id z4so18215584wrv.11 for ; Sun, 08 Aug 2021 10:28:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=iatl/yvHUEXssqGaxmM3VVGCUZ13Zupn9QAYDy9G4Ic=; b=L8s5/CXK1BrLFzBCHTucpUv+lXw1DZcBfy1WmBT0IH2EugIraGzHYc/cXSG/W2Nh/5 WD5/PfjLu5EHDGGDyEdnCqxnnnrVVYI+hJSS7kLtiJXz1gxT1dgZ3J1oRfrlR433D/GN IKR5L3D773alI6Z0HSdo6Dj4oVEdnv1eqjo3qaZvvowCkVGwc2SO6F7kqfq8mDoAoO4v LF+cvxllz5eVwq+kcFH9/9U6eNF1gec1Lp31i7X3HA6USrLTqQa4iqcfeO/2bCpWo4Nf IRWxgfj+4y/5JnVQCTlNRQ1PClYFP4nCkt86IqjTwSFHHw8j+zeI87QtYekF5ZhfO9V7 /HwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=iatl/yvHUEXssqGaxmM3VVGCUZ13Zupn9QAYDy9G4Ic=; b=FF18648kgM2ITItVUFI+aK3qxxtZSQijn0OZOSehBmfkZxwQ8ObHL9Zm/Z1xcChozu rkXqfXfK3eO7un3olKHYz5pVzhG6d/LqvZnOJbwqhdctUpZz0/l/B7nuua5304Knfq5S mbm+CbhuETqro0oszBwewoHeFfvTOSe3NPrFrDo/Yvlunu03KlgrjD6KylTjno/scNjA BeASVFphcey02nPc+h0DvX19YYqzQ+iYqi2ZRmKzQHdINEPj8Y4CBv4bWGQiWrBhNquX jsA59Hg1whSWZSXmmn+o4q6RYHSfGfx9YBaCrqwXl6puD7Stk+pyJ4Qiz1EIvTDSy8+w 1GSw== X-Gm-Message-State: AOAM530HiLGqy/UmP+YH0dXSS+Zb5ykGc/q0wVbFOhZDkX/LF4KkEdh5 oVFBXZfuCM5mKmdyavIC/s/VvwjBkoeJZn5bFL4JSw== X-Google-Smtp-Source: ABdhPJwIX7nUgxNitNxYTgIOm5Ad/d+mcp90wIYMeBSyeiulv8eOHmZzPAw7bHQDAaA26DPAifYHopw9d/vgLIgW2Gs= X-Received: by 2002:adf:d087:: with SMTP id y7mr20381698wrh.323.1628443728684; Sun, 08 Aug 2021 10:28:48 -0700 (PDT) MIME-Version: 1.0 References: <20210731063938.1391602-1-yuzhao@google.com> <20210731063938.1391602-3-yuzhao@google.com> <20210804142257.tsgzpfc3zq7um7iu@box.shutemov.name> In-Reply-To: <20210804142257.tsgzpfc3zq7um7iu@box.shutemov.name> From: Yu Zhao Date: Sun, 8 Aug 2021 11:28:37 -0600 Message-ID: Subject: Re: [PATCH 2/3] mm: free zapped tail pages when splitting isolated thp To: "Kirill A. Shutemov" Cc: Linux-MM , Andrew Morton , Hugh Dickins , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Yang Shi , Zi Yan , linux-kernel , Shuang Zhai Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0FEB99006C40 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b="L8s5/CXK"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf28.hostedemail.com: domain of yuzhao@google.com designates 209.85.221.43 as permitted sender) smtp.mailfrom=yuzhao@google.com X-Stat-Signature: t8hnrt3cko75zshwg69wa5xr1tx58o3q X-HE-Tag: 1628443729-750307 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: On Wed, Aug 4, 2021 at 8:22 AM Kirill A. Shutemov wrote: > > On Sat, Jul 31, 2021 at 12:39:37AM -0600, Yu Zhao wrote: > > @@ -2506,6 +2508,25 @@ static void __split_huge_page(struct page *page, struct list_head *list, > > continue; > > unlock_page(subpage); > > > > + /* > > + * If a tail page has only two references left, one inherited > > + * from the isolation of its head and the other from > > + * lru_add_page_tail() which we are about to drop, it means this > > + * tail page was concurrently zapped. Then we can safely free it > > + * and save page reclaim or migration the trouble of trying it. > > + */ > > + if (list && page_ref_freeze(subpage, 2)) { > > + VM_BUG_ON_PAGE(PageLRU(subpage), subpage); > > + VM_BUG_ON_PAGE(PageCompound(subpage), subpage); > > + VM_BUG_ON_PAGE(page_mapped(subpage), subpage); > > + > > + ClearPageActive(subpage); > > + ClearPageUnevictable(subpage); > > Why touch PG_Active/PG_Unevictable? Subpages may inherit these flags from their isolated head. Page reclaim doesn't isolate active or unevictable. But migration does. If we don't clear them here, we'll hit bad_page() later because both flags are included in PAGE_FLAGS_CHECK_AT_FREE. Does it make sense? Thanks.