Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp180990lqr; Wed, 5 Jun 2024 02:48:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXRHqi2luapNFKm76961+uDztw9/gdN9w4CEG0AoTymsoiF9Uap6iRq4RSO52cltAVYmNBrWXKBhhueFbZfuw66Rh5+3RVdqexWTspfLQ== X-Google-Smtp-Source: AGHT+IGDLjSCvQgcQEBAh80XA5TYqK3RG7pqy5T4i4xmRweZ6xIr1Mz67Xa5f026gPI1t2GPiijd X-Received: by 2002:a05:6102:3595:b0:48b:a94f:c52 with SMTP id ada2fe7eead31-48c048bc09amr2532014137.15.1717580915932; Wed, 05 Jun 2024 02:48:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717580915; cv=pass; d=google.com; s=arc-20160816; b=yHf77VwYVbi2/GeNcKJqDXi10JuA0zrCrSGX0X+4Er1Ag8ZVwKpxEPQpWX1qAcnmUh eXaKhH1/9pdMw8onjmvw76I4zxOOqaBAXtuqL/2PrUSAHGPA3UjIzEVgXC5DftkV0GLA Sdav9fy35s0aSTS5m1wmmQYTICF3HWHcwOnpXJRIlqD6P3GDjxubkZT959Pyzj50iOSl VB6L4aJePFqgD7tO/r7Po/9EIpnMuy/QimTuQXwH2tifxAYvwka1MV4cyY/yCXQDEunq l8IQoaUBL4s9pNR8XFZUkt1Em4JbGjUWaXdUsmo/17NFzxUuTN5ggMq2adPKfF2X6wsa +5Nw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=s/mRvI3HBUwnpb0GleD2gvnnQDUhydoIMr6R2Pogbqs=; fh=8klvRVDD56yFrB+N2y9E7zuvf70XnrIgM6sxOhtJUBc=; b=D2i1xhxBo5Sw+o4rs+xnOf+jVvPqEIAraeqHU6Bi+rL6QVttKDdhMKs/zrydKbOrec S3YH9qawLZMa74iHiaMic5WQ/VIfhLwSzY0/JcJFaieCWTtPWkIo9X+SD/FOYVUZ/v4v 6a3uYzkiS/ZQhcAEro2btk0WMWSaci2YLvPX333mTF86/cW4w5BXT2HHqLXzF7zctpSh UHYu4tNaxj31xC1GvTILs9+RcfECk17BO4+rwLGxe39bVEN6wVh1sdSNYH3wYcOdD1x0 QQa3qzYhmVWDlPZ6kQsfsbutIVvupEBu9M3hmaphIWP3uah+mEJvT5TLDw/H7vZYTTId CIMw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hqyx4qbp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202142-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202142-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-7952ad871a3si29491485a.515.2024.06.05.02.48.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 02:48:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202142-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hqyx4qbp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202142-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202142-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BFFB11C213AB for ; Wed, 5 Jun 2024 09:48:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8C6E619004A; Wed, 5 Jun 2024 09:48:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hqyx4qbp" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B483114B093 for ; Wed, 5 Jun 2024 09:48:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717580898; cv=none; b=HqSEo+eFvd0nArsEW0tkWCsBw+rWVsUd2LQ3ujB+O6ZCfW0og1EuiHso1QWf3SxbJk+vyMsehLJEwPIQCV7joYbFOUR0xvmzpVWW/MBsOFsJP/t6GywOVk5o4A1jK/6/VhL0EjZpZPmIN5yWQeXmu7VAPOFuPxuzqpQtgfpKNus= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717580898; c=relaxed/simple; bh=H5TT0W89gkFgRO4p1LpEpFm2+mHkOB1T7hF2dgtWVhc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=saKZiajmQrG9r7QJeA4X0BjWFukEUxxQ77XwdV6uyWWRjZo5jJA/+b4YoO5MI6St3t2p4TS4OokRkXNtBnE6MzUYD1QTD/oi6sPFU6L5HyMlpylYfnhDSHcKhLCnjOh2hPGBb49p+NNtd20xCOvKXazNG30MG4CbrKzPw++CV2Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hqyx4qbp; arc=none smtp.client-ip=10.30.226.201 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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; } -- 2.43.0