Received: by 10.213.65.68 with SMTP id h4csp1879456imn; Thu, 5 Apr 2018 05:29:23 -0700 (PDT) X-Google-Smtp-Source: AIpwx48joKuKvMltGqXvWTB1UAXKZvxYjmkeOkhILoR9rWAfyFYUnsVMxes5qgrNd7dq8C7u7/xm X-Received: by 2002:a17:902:8bc1:: with SMTP id r1-v6mr22728337plo.310.1522931363921; Thu, 05 Apr 2018 05:29:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522931363; cv=none; d=google.com; s=arc-20160816; b=Q6YbQD+mNqmd/LVH1eIGipPHIqTkuokg1h6wNmLqS0GOp6qUJTWQ+xEUelF9M4h2l2 OPv42yLbKXcdoWBJorV45mgHYEF9SiAkAkO5SBjXSGgAAPRmGEE4EB+kv/0mkuIiK3CN xGvt6WyswqI4cfFs6/l3w3qRSZ+yRyb8w+h5cDjM+WmNqwwwCkNDyBXs3tBB55gsNb6V HK1e0Ngy+D+fdV9n36riQQFRYpFBYxXsr2P1J+hh3iYvyOgKE1fCTbi1DkcUajW4FcZb UsH11HtIOF9q8gUvimVvyZ3U9AhwGF0NHW77quYQJPsEpLM/eqteUz0K8P0Uyk4mOViY FThA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=DBN3c/9BZAhJhCsf4fQ/DePZVpnxs3cKbrxeBBlSvt8=; b=uhtdOtRRA4xQf679uTg6C2+G0aPf5CrXndL5Tll9azDhS8Hf2W7Z5gM+F54ShgZ79r qfvkyz+ZGWCfukxYLjxnYZBO/izm953zXblhoxAh7vuVArt2TbFxUOmFrUNh5Owkgw35 b4k0sXutrCbxsQkAAAxb3HsX1zaMv/jqTOu+ClGAMEQCfYD1DwPnJN1wWD45te9IZo5X DKSQez6y651LuqfqWAgazN/GN/5A8yfw9twY9ckI4QFbfz/QX6oFTGXShDTg0AHSZNtR XSoLaC0bNRa6RwdS8xid44X+NvdLkEFI0OzTHmBQqugRMMuxo1PcWJU/kAnTo5LLKCuY KHYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q10-v6si5768870pll.237.2018.04.05.05.29.09; Thu, 05 Apr 2018 05:29:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751285AbeDEM2E (ORCPT + 99 others); Thu, 5 Apr 2018 08:28:04 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:54442 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751178AbeDEM2D (ORCPT ); Thu, 5 Apr 2018 08:28:03 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w35CPOEF091518 for ; Thu, 5 Apr 2018 08:28:02 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0a-001b2d01.pphosted.com with ESMTP id 2h5h4tqapu-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Thu, 05 Apr 2018 08:28:02 -0400 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 5 Apr 2018 13:28:00 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 5 Apr 2018 13:27:56 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w35CRtW352494394; Thu, 5 Apr 2018 12:27:55 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1C74A11C04C; Thu, 5 Apr 2018 13:20:09 +0100 (BST) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C622C11C050; Thu, 5 Apr 2018 13:20:08 +0100 (BST) Received: from p-imbrenda.boeblingen.de.ibm.com (unknown [9.152.224.149]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 5 Apr 2018 13:20:08 +0100 (BST) From: Claudio Imbrenda To: linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.org, aarcange@redhat.com, minchan@kernel.org, kirill.shutemov@linux.intel.com, linux-mm@kvack.org, hughd@google.com, borntraeger@de.ibm.com, gerald.schaefer@de.ibm.com, stable@vger.kernel.org Subject: [PATCH v1 1/1] mm/ksm: fix inconsistent accounting of zero pages Date: Thu, 5 Apr 2018 14:27:54 +0200 X-Mailer: git-send-email 2.7.4 X-TM-AS-GCONF: 00 x-cbid: 18040512-0044-0000-0000-00000543CDA7 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18040512-0045-0000-0000-00002883E960 Message-Id: <1522931274-15552-1-git-send-email-imbrenda@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-04-05_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1804050131 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When using KSM with use_zero_pages, we replace anonymous pages containing only zeroes with actual zero pages, which are not anonymous. We need to do proper accounting of the mm counters, otherwise we will get wrong values in /proc and a BUG message in dmesg when tearing down the mm. Fixes: e86c59b1b1 ("mm/ksm: improve deduplication of zero pages with colouring") Signed-off-by: Claudio Imbrenda --- mm/ksm.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/ksm.c b/mm/ksm.c index 293721f..2d6b352 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1131,6 +1131,13 @@ static int replace_page(struct vm_area_struct *vma, struct page *page, } else { newpte = pte_mkspecial(pfn_pte(page_to_pfn(kpage), vma->vm_page_prot)); + /* + * We're replacing an anonymous page with a zero page, which is + * not anonymous. We need to do proper accounting otherwise we + * will get wrong values in /proc, and a BUG message in dmesg + * when tearing down the mm. + */ + dec_mm_counter(mm, MM_ANONPAGES); } flush_cache_page(vma, addr, pte_pfn(*ptep)); -- 2.7.4