Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp6035459imd; Wed, 31 Oct 2018 06:01:10 -0700 (PDT) X-Google-Smtp-Source: AJdET5cszIb4kSYcZQ22iSwYKMoSaiKyNK4k9Z87Cc/rsxN+hoRp1giaUJ85Pdem0S9Q4GVVf5UC X-Received: by 2002:a62:8a91:: with SMTP id o17-v6mr3365745pfk.184.1540990870149; Wed, 31 Oct 2018 06:01:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540990870; cv=none; d=google.com; s=arc-20160816; b=Dbqacd2VKZ60gJfIC9MVXJgNXS009IZCg4IV0UEqSeGpOBc9LwzgStoOR6A2qctT+x DWidbz/cKzBUfnnT95mii3StAGhuu1OYBn+GXm+rqsxLSfSuHLDke0NpFvs8eYbaZLiH oLLJjPyfV7we7tBnTNvH/f8bxSoA3iVCiGr1SR75fDtUM8hjva6FtNc/qyjW6cxc/jBj AsvX49fbdthqZNu7w8q08Fg9pIoCWKEQRnVjd2ifVU26g7fwb5sKdRkgfhV2p/YThGxP cHuOEyBq/rZujM2M2FEhDwONdfUBXBoJU5L/WJuQPZuQUGDKrERjTcNZWucHk5JjYWRZ BgzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :message-id:references:in-reply-to:date:subject:cc:to:from; bh=yF0JAGxfb2kHnnD5o9sfrALN8GHj+VSrHmCH2z5t4KY=; b=cUoVoQw3TkcaKk5QdS4HIN42eJgYtclWhvJFWTrMZHe+gPaNMr4YywSzYxmPsebpNg 4RXG8nU4lf/xLMJmFKzX+9PMUVlzh+OIqEmfXnnOgjSGvpj+KBa3F+BDcSzHvlSI55D3 lDQrARUfJKnDX2n1AgzOlhvMzGTJHcLGtUz0FynFkhrVoGAdv8gFC2QuPCBkl+EibjAN z5sI6yEt/3L3GHsxtQU3bysD4cfpKTnm+b0ORRaN1fya9DOrNnWOK1J+mKe4FlO6Ca8e xhRr0QL5VJDoWYxT+RdU6AT5qddHC57VjE9fAsJqI/WTKWM0wdrLT14Ql795Y+Y72chd fLRg== 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 b68-v6si27441762plb.398.2018.10.31.06.00.54; Wed, 31 Oct 2018 06:01:10 -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 S1729307AbeJaV6U (ORCPT + 99 others); Wed, 31 Oct 2018 17:58:20 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:41708 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729272AbeJaV6J (ORCPT ); Wed, 31 Oct 2018 17:58:09 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w9VCx69B093335 for ; Wed, 31 Oct 2018 09:00:13 -0400 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2nfag3pxa8-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 31 Oct 2018 09:00:12 -0400 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 31 Oct 2018 13:00:09 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 31 Oct 2018 13:00:07 -0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w9VD063O36307176 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 31 Oct 2018 13:00:06 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5203E11C05E; Wed, 31 Oct 2018 13:00:06 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0D7BE11C058; Wed, 31 Oct 2018 13:00:06 +0000 (GMT) Received: from mschwideX1.boeblingen.de.ibm.com (unknown [9.152.212.164]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 31 Oct 2018 13:00:05 +0000 (GMT) From: Martin Schwidefsky To: Li Wang , Guenter Roeck , Janosch Frank , "Kirill A. Shutemov" , Heiko Carstens , linux-kernel , Linux-MM Cc: Martin Schwidefsky Subject: [PATCH 3/4] mm: add mm_pxd_folded checks to pgtable_bytes accounting functions Date: Wed, 31 Oct 2018 14:00:00 +0100 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1540990801-4261-1-git-send-email-schwidefsky@de.ibm.com> References: <1540990801-4261-1-git-send-email-schwidefsky@de.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18103113-0012-0000-0000-000002C105DD X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18103113-0013-0000-0000-000020F531BF Message-Id: <1540990801-4261-4-git-send-email-schwidefsky@de.ibm.com> Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7BIT MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-10-31_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=709 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810310109 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The common mm code calls mm_dec_nr_pmds() and mm_dec_nr_puds() in free_pgtables() if the address range spans a full pud or pmd. If mm_dec_nr_puds/mm_dec_nr_pmds are non-empty due to configuration settings they blindly subtract the size of the pmd or pud table from pgtable_bytes even if the pud or pmd page table layer is folded. Add explicit mm_[pmd|pud]_folded checks to the four pgtable_bytes accounting functions mm_inc_nr_puds, mm_inc_nr_pmds, mm_dec_nr_puds and mm_dec_nr_pmds. As the check for folded page tables can be overwritten by the architecture, this allows to keep a correct pgtable_bytes value for platforms that use a dynamic number of page table levels. Acked-by: Kirill A. Shutemov Signed-off-by: Martin Schwidefsky --- include/linux/mm.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 1e52b8f..844a853 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1744,11 +1744,15 @@ int __pud_alloc(struct mm_struct *mm, p4d_t *p4d, unsigned long address); static inline void mm_inc_nr_puds(struct mm_struct *mm) { + if (mm_pud_folded(mm)) + return; atomic_long_add(PTRS_PER_PUD * sizeof(pud_t), &mm->pgtables_bytes); } static inline void mm_dec_nr_puds(struct mm_struct *mm) { + if (mm_pud_folded(mm)) + return; atomic_long_sub(PTRS_PER_PUD * sizeof(pud_t), &mm->pgtables_bytes); } #endif @@ -1768,11 +1772,15 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address); static inline void mm_inc_nr_pmds(struct mm_struct *mm) { + if (mm_pmd_folded(mm)) + return; atomic_long_add(PTRS_PER_PMD * sizeof(pmd_t), &mm->pgtables_bytes); } static inline void mm_dec_nr_pmds(struct mm_struct *mm) { + if (mm_pmd_folded(mm)) + return; atomic_long_sub(PTRS_PER_PMD * sizeof(pmd_t), &mm->pgtables_bytes); } #endif -- 2.7.4