Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp4512970rwb; Tue, 8 Aug 2023 09:30:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG2sqasIc12y1PC20jDF8fkkUO6mF3eoM5r0rWLvuIAgW90icnPBGYxHvc2oKJRc3H/BNLh X-Received: by 2002:a05:6512:3156:b0:4fe:7dcb:4150 with SMTP id s22-20020a056512315600b004fe7dcb4150mr639224lfi.67.1691512229615; Tue, 08 Aug 2023 09:30:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691512229; cv=none; d=google.com; s=arc-20160816; b=uzjC9IvFh3DjxhPfCtYpMdOLOvLbQTp05UjKGaJQx4SQPbzJhtNtnJsZiMYynuhvEj c8bxrbBWP/k8JRCRf6MwrWTosjol9wxWsEj3tU5CAMA3+DNXC9Qmf4Dm7w4lXUF422wc z/7n98V9ipRHBLf8GqdmUwD6+T+Hq/pr0dsCUJQS6FQyLZBNVJc6yFqK6Lmn7TJ44jSB sVJVcERllDopNmjKXl1BpTi3fjwrhvbrPZriA7Q0c+vzo/ezPDiXEN3QNIzN9C4Km/CC 7j0jWiehL51+JmFIeiG/gSZC6lIr3U5JAP21W7pQPXu88XAokb8DQzKRf0Db2mcZ4dOj kEuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=6RSNnQZT08dQdFVE5RJv/G+IJCRbc3TJGyCsrhcpmdQ=; fh=a2EQKy2v8S7/Ihf8Zs8idlIHJnXly5JtrL6IOH3KZa8=; b=Om+R+WIpbED3wVaSqJkPHilSneLOJjhNIpqutsLH7g+XOx2ugwE1m+sUPvUXt2mIv4 GHRrcSuvsMbgu2u4VcqUtfLDhCeE8+SxpqoJzKiSco+43oJYKDncCfW8iGlWp7cNeMB5 hp3Sf1i7ct/Exjaz3SjuUk5XLHHHO9qSD9CrEAPm4SpLlUg3DdrCLcuRD5rXJ5fEr54Z /0eGxRqRlS9ofTLunsFXObQcL8H3qklN19nxo3yTfXVyKi2G8q2WiFdy4h3fLUJHJ28u MPIvLcvQcXEZnaeyy+5tccOPnrneIfH4poB5GPer8ElpK8lEMYTyMAt01evMJeG22wt1 xMJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=a272jKXZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u7-20020a170906b10700b00992ca771e3asi7969922ejy.48.2023.08.08.09.30.03; Tue, 08 Aug 2023 09:30:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=a272jKXZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231261AbjHHCuB (ORCPT + 99 others); Mon, 7 Aug 2023 22:50:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231128AbjHHCt7 (ORCPT ); Mon, 7 Aug 2023 22:49:59 -0400 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 765EBE5A for ; Mon, 7 Aug 2023 19:49:56 -0700 (PDT) Received: by mail-qt1-x832.google.com with SMTP id d75a77b69052e-407db3e9669so102231cf.1 for ; Mon, 07 Aug 2023 19:49:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691462995; x=1692067795; 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=6RSNnQZT08dQdFVE5RJv/G+IJCRbc3TJGyCsrhcpmdQ=; b=a272jKXZUQokY6L5C0Br3ocABCJ+A8NpiSSqAW2ukctHWiYUg0oPKJ+vgx0NyQAwv2 UKQDyT/D5JaOlhyZlhwe/G7vvSnImf0tKcfkclJhEKEzV6GEr7q+JBN8MxUO7P9r913M uI+NpMpW3CMQ9TtTqVY509r87gnSnsvdAVwRDCljGI3WsvByZB2H6f4qwRj/RotvSktg n33C1JWAuTsjt7/yM1TrXoyLh3SF/AoKIUPQxtQ8dWgMYhIkOZpoQWzmZ72g46myu1b6 MvfVM6rFEPbilLDFeGW1Gt9RNnEsYUZ/Q63C54Az3wdihv5Q6BKRqdaVa8N0hz7NDLwD inzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691462995; x=1692067795; 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=6RSNnQZT08dQdFVE5RJv/G+IJCRbc3TJGyCsrhcpmdQ=; b=NloRtV6WE2vi/U9HEQILUSjA9A4AMZn3JYuNhQPq1sqKBtfEj7yEfnxJ6nR6QKo11I r8mSQFmQSx0TwATaRMvDYyRVnT2wWBwfBEcAY2HOCgKyu+7K9N28vHHqrzWnH42ykvbE Ef0xe1XeMZzHwp2diKaZthH7Fn9HuxZ2gTvSL3KtmBG2wWSvIdZLTOJjcnK1uiRYkzOo qRp82mGiI4LtkrIkEvTb/O3+oq8shh0EYbRJOKASohyVRbtzCFI/gC+Yplu6PyUT0smI JQ1KVYgvnxSVilVRlmb8iDc40MDTAV9/j6eJECyxoB+9ZJVxhgSIzISSfziHNfQy56yw VXzg== X-Gm-Message-State: AOJu0Yw9vW2i2qwXg1irUP4frV3WZ3RaB1cppfV+sD7HLoSf5pZgfFUt C0/KHzRXkfwoi4cbwDg1azfwUbI5EUwAfwVwE1pqzrQIKGWVhMLkZBOsSw== X-Received: by 2002:ac8:5c53:0:b0:403:b1e5:bcae with SMTP id j19-20020ac85c53000000b00403b1e5bcaemr749780qtj.10.1691462995526; Mon, 07 Aug 2023 19:49:55 -0700 (PDT) MIME-Version: 1.0 References: <20230808020917.2230692-1-fengwei.yin@intel.com> <20230808020917.2230692-3-fengwei.yin@intel.com> In-Reply-To: <20230808020917.2230692-3-fengwei.yin@intel.com> From: Yu Zhao Date: Mon, 7 Aug 2023 20:49:19 -0600 Message-ID: Subject: Re: [PATCH v2 2/3] madvise:madvise_free_huge_pmd(): don't use mapcount() against large folio for sharing check To: Yin Fengwei , akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, willy@infradead.org, vishal.moola@gmail.com, wangkefeng.wang@huawei.com, minchan@kernel.org, david@redhat.com, ryan.roberts@arm.com, shy828301@gmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 7, 2023 at 8:11=E2=80=AFPM Yin Fengwei = wrote: > > Commit fc986a38b670 ("mm: huge_memory: convert madvise_free_huge_pmd to > use a folio") replaced the page_mapcount() with folio_mapcount() to check > whether the folio is shared by other mapping. > > It's not correct for large folios. folio_mapcount() returns the total > mapcount of large folio which is not suitable to detect whether the folio > is shared. > > Use folio_estimated_sharers() which returns a estimated number of shares. > That means it's not 100% correct. It should be OK for madvise case here. > > User-visible effects is that the THP is skipped when user call madvise. > But the correct behavior is THP should be split and processed then. > > NOTE: this change is a temporary fix to reduce the user-visible effects > before the long term fix from David is ready. > > Fixes: fc986a38b670 ("mm: huge_memory: convert madvise_free_huge_pmd to u= se a folio") > Cc: stable@vger.kernel.org Andrew, this one isn't really a bug fix but an optimization, so please feel free to drop the Fixes and Cc tags above. (It seems to me it doesn't hurt for stable to take it though.) Thank you. > Signed-off-by: Yin Fengwei > Reviewed-by: Yu Zhao > Reviewed-by: Ryan Roberts > --- > mm/huge_memory.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 154c210892a1..0b709d2c46c6 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -1612,7 +1612,7 @@ bool madvise_free_huge_pmd(struct mmu_gather *tlb, = struct vm_area_struct *vma, > * If other processes are mapping this folio, we couldn't discard > * the folio unless they all do MADV_FREE so let's skip the folio= . > */ > - if (folio_mapcount(folio) !=3D 1) > + if (folio_estimated_sharers(folio) !=3D 1) > goto out; > > if (!folio_trylock(folio)) > -- > 2.39.2 >