From patchwork Wed Jun 5 09:53:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexs@kernel.org X-Patchwork-Id: 13686522 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 409C7C25B76 for ; Wed, 5 Jun 2024 09:48:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C2DF16B0096; Wed, 5 Jun 2024 05:48:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BB7326B0098; Wed, 5 Jun 2024 05:48:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A573E6B0099; Wed, 5 Jun 2024 05:48:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8761A6B0096 for ; Wed, 5 Jun 2024 05:48:26 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0B4C11A11DC for ; Wed, 5 Jun 2024 09:48:26 +0000 (UTC) X-FDA: 82196359812.11.B3172A7 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf19.hostedemail.com (Postfix) with ESMTP id E3DD11A0005 for ; Wed, 5 Jun 2024 09:48:23 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hqyx4qbp; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alexs@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717580904; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=s/mRvI3HBUwnpb0GleD2gvnnQDUhydoIMr6R2Pogbqs=; b=Ol2FMHidqXbBLaEk33d2B6o569K6clQb4xLrz1+KTrD8rSIpOLY56eC3nHtiSLvsZ7VzUK fUJI1WlrNAc86uPxDsp8RVt6Wpz8wsoU2kER/OytlJzYS/91/PIUcvPXrkxMxK0dLDUogB z0z4o4MMXQjanARAiiPHyqMiVKC/bFI= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hqyx4qbp; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alexs@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717580904; a=rsa-sha256; cv=none; b=Fi7FOD1VdWU6qcvGw31RE9flYWH7x4NqO6v/Zt354uT2/zBcBPVGq4IRw6yiturhrdYRJG yDtIRx5KxoNzlsUKuD+7c83DfrdgCq4PRokuWRfhqIGOfbEmSKXvT48szpNMj0l9GBW6u7 IEufJ01EhmL2FDK5d+d9uvYppIr1Wn4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id E4E89CE169E; Wed, 5 Jun 2024 09:48:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EAD07C32781; Wed, 5 Jun 2024 09:48:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717580898; bh=H5TT0W89gkFgRO4p1LpEpFm2+mHkOB1T7hF2dgtWVhc=; h=From:To:Cc:Subject:Date:From; b=hqyx4qbpaNNhWJYB6Mi3oYuOjsTV+U6K5ROXZ4OVTgHogSokk0qrl5OWGtoUvC+lQ AplQ+lWnwqaELPRSz2Uz0C1xMmE71OFjKbDcnPITfKGZ4nElXQAfFkgwogVxskQ+p4 YWGiafS+jMRO6JNulFol5+CQpFHwhaL+7O6b6ydTcN+Y69GOh3GWra/mszoNlrW71n u2dQ7s3PuEj1sGf4Vtj0dVPG5FLOWDISoIPi6WyInU2aFryQGmbM6LKI06WwlOVQE6 EIReqbiv9xzaHzQOSSTrOGmrAkKvLd0R7GoVZTHPXXCBkFjq5CEDp097feerGpXzm7 puVzKXd460daQ== From: alexs@kernel.org To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, izik.eidus@ravellosystems.com, willy@infradead.org, aarcange@redhat.com, chrisw@sous-sol.org, hughd@google.com, david@redhat.com Cc: "Alex Shi (tencent)" Subject: [RFC 1/3] mm/ksm: add anonymous check in find_mergeable_vma Date: Wed, 5 Jun 2024 17:53:01 +0800 Message-ID: <20240605095304.66389-1-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: E3DD11A0005 X-Stat-Signature: c6r54woeo1ex5yf4mzxe7rxt5f5o915z X-HE-Tag: 1717580903-952302 X-HE-Meta: U2FsdGVkX1/S+MkYeIG1Rs5TC+OliazkfHakGUmLhL6tABZG00Orx6J3SMT+jH3Agaetdo4NHLGRwObMzvV4N/MpaHsqYHDqOk4Se0vr+h1K/y4ziyuUISdpSLA3mhxi5717dSMej4du3ngb8wYCAQkpqsRjI7is8Ju6ZSLoj+sTxjOT1e3nvXAX2fE12a+v2uciom6iplRHi5uFeQ2RO1IPfYy+/4bHEjhDOkt5nz2RPvXGFWse+c5Zz8z6YBcB0qjPQ1sSWZue3t7rytiq8VKuSk1VhiHrh6Cm9ZVG2KwH8yOnyIXew9UfI9FH4/Ym88MmrO6sNOJ7gj2HlkCmFR5JSNtS2RR57UXV8WqlR2q3tI5pAtwCKVgA+1VUeOU5/zl3jLBEWr1NvWqa+eFFkV3/cTGIk+Z6eWVNjGQuuu9mbkgTAipNQpH3B5vJhVEyIXUYrKlPg7QFqZa76RaJ+2Cnfyu1mUEiAMIS8xHycLKFEOBqoggbSOksRLH3+7F7DuoLhn4aem+lVaiiQjCI3Q2NNb3dONAbpgdLHmRye1PJvP9edN81/yECr1tSLRRejkUeNpIalPN0kVPX5x2KUTDnOZaQ+xlWXq8dtbz2CybPhrTW7Fz9LLNYewOW2PW+7z+t/R1DZ+XACx8E0CD+hRwDLXNbybFbkFMKFXqU9TZQk5zcX6eqEILvwt4hjFWHWC/fGCuqbWXWAuZisazYOIIHCK43rAOThVAvHrGXYv6VdcRZwL1ypFMluXM3mC0zxC5PPpLdzTkQMiWpJemTKAkjY/0MXHgL3s4qFvqfMCN8qayUBcsJ1d7hVwyeRMJIyqUdgjEDTEyMnZ5id2srpmJ85gQbDlypY688+Cs9fGmMJrusrayNXIZLJq1f2vIYNbWJCI578wmQeKMjgFPyYE+PVsFZu9PD+Ii7wEcKMV03sPeRAPXdVytWvhuUspjtPBx9KhP8Ty53BO+5STZ p1VBUKPQ njKDNfFBF6X1uZ7G1SaYzaWoUB97Gn8ID6TimGKFfXOiAjzeIpODyRlb+P85hDZZo5QH4fjPELbWEU1X92/eDO3xOGjc/Y22LQIrcNVu/x3TZFGWxnFIH26wR8jesJ+VVTqp61XaN6QwEoMOCvpRxaQGRR0zV78L0E5B9nKKOQAuE2Ol9C72gmgJ5WkuVSRNTWQW3q7in5HCb7G336cwUfeOdS/hiQLztYImQPXpBi4NTtR7UnBs2Q+O7r1Q3JchLLkdKmqAEhV+vGH//eFmeGEdXUq/hVgQ4pQGpQnWoWQ7If6zHjQwPwvsDpQ== 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: From: "Alex Shi (tencent)" We do vma_set_anonyous in do_mmap(), and then vma_is_anonymous() checking workable, use it as a extra check since ksm only care anonymous pages. Signed-off-by: Alex Shi (tencent) --- mm/ksm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/ksm.c b/mm/ksm.c index f5138f43f0d2..088bce39cd33 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -742,7 +742,8 @@ static struct vm_area_struct *find_mergeable_vma(struct mm_struct *mm, if (ksm_test_exit(mm)) return NULL; vma = vma_lookup(mm, addr); - if (!vma || !(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma) + if (!vma || !(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma || + !vma_is_anonymous(vma)) return NULL; return vma; }