Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4142384imm; Mon, 15 Oct 2018 09:43:53 -0700 (PDT) X-Google-Smtp-Source: ACcGV628kXAQ/lZHrl8CAjd4g9ZAYswSEGw/LxvBxLvsbbQZRxCCMhWwcMLZ/dzkDPmi3CZ/t++o X-Received: by 2002:a63:c508:: with SMTP id f8-v6mr16845842pgd.412.1539621833825; Mon, 15 Oct 2018 09:43:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539621833; cv=none; d=google.com; s=arc-20160816; b=k+5EVc/zZPwjrQJXJi8PpKGQdYyqhx0jeUxHpeD0VFs9Mhy5IJo02uKfMbaTHnTRGJ 9BfkdIrxZoJLpFUPVzjqJJfYR/FR+UC8qO89qLbyq0QAqDnEeONRXdF0J9ZTozFIluC/ EZZ/u0gX+36ytuObb2XAMP5J/QFW+Afdwdaj8Lk92AiYfPBVAXyAokERm+9g63lLbiH9 Ho8JQu/mzILN6US11KLk0DKLC7la/nIszCR0gAaXFY07Rf5MaHFjNhx1AZzkzYsJNILk USN+XprfrqBmWD0VZHWtJJj8ncMNW9MtnpVC+L1I1v19KvVSj/peJufbwuGgrYC7dheF LWEg== 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=41BP0a+7aEgZHWhOJ0ag8aX2ghfs6RYBSlvVHzfWQtw=; b=QrpBCxjNx21dMHSJqZQZU0BWmdOKdVBZSvQogfDACkHPq8/f2SFLZnhoHLDVjdCArM nI9tEsQXhzBXzSkc8Mf2D/MTFq+fO2qkHK67pz9a0Ot98eSFxm2HNPKI/8PuXN+aiiFW WAslZWesZGeqoh1czPR/qwhs9eX3VSWzLGyPjM7MJY1A85tGN6ed7KVxEB2u+tutkUyD PrBz6nn43bFYTiRpUA2UkHz7PdO4QZ3Eq8GQglSRuFlDRkd99Q5M5wgmDbtAyXvFo6X6 3rQbVrDUp5xPcQo5Uu2rkvhYR5OG+90mSdi1ajTXMenk8IPz3kDsCB7C+szFntfqCRDE KCAA== 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 w6-v6si11763821pgm.557.2018.10.15.09.43.38; Mon, 15 Oct 2018 09:43:53 -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 S1726917AbeJPA3C (ORCPT + 99 others); Mon, 15 Oct 2018 20:29:02 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:39540 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726856AbeJPA3B (ORCPT ); Mon, 15 Oct 2018 20:29:01 -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 w9FGeauR025028 for ; Mon, 15 Oct 2018 12:43:00 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2n4w32ctpk-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 15 Oct 2018 12:43:00 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 15 Oct 2018 17:42:57 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 15 Oct 2018 17:42:55 +0100 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w9FGgsLJ60817446 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 15 Oct 2018 16:42:54 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CB2834203F; Mon, 15 Oct 2018 19:42:27 +0100 (BST) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7D0B842045; Mon, 15 Oct 2018 19:42:27 +0100 (BST) Received: from mschwideX1.emea.ibm.com (unknown [9.145.33.55]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Mon, 15 Oct 2018 19:42:27 +0100 (BST) From: Martin Schwidefsky To: Li Wang , Guenter Roeck , Janosch Frank Cc: "Kirill A. Shutemov" , Heiko Carstens , linux-kernel , Linux-MM , Martin Schwidefsky Subject: [PATCH 2/3] mm: add mm_pxd_folded checks to pgtable_bytes accounting functions Date: Mon, 15 Oct 2018 18:42:38 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1539621759-5967-1-git-send-email-schwidefsky@de.ibm.com> References: <1539621759-5967-1-git-send-email-schwidefsky@de.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18101516-0028-0000-0000-00000307ADB8 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18101516-0029-0000-0000-000023C2B51C Message-Id: <1539621759-5967-3-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-15_08:,, 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=675 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810150147 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. 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 d1029972541c..67f55c71e59a 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1764,11 +1764,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 @@ -1788,11 +1792,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.16.4